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, see <http://www.gnu.org/licenses/>.
32 #include "qemu-common.h"
38 //#define MIPS_DEBUG_DISAS
39 //#define MIPS_DEBUG_SIGN_EXTENSIONS
41 /* MIPS major opcodes */
42 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
45 /* indirect opcode tables */
46 OPC_SPECIAL
= (0x00 << 26),
47 OPC_REGIMM
= (0x01 << 26),
48 OPC_CP0
= (0x10 << 26),
49 OPC_CP1
= (0x11 << 26),
50 OPC_CP2
= (0x12 << 26),
51 OPC_CP3
= (0x13 << 26),
52 OPC_SPECIAL2
= (0x1C << 26),
53 OPC_SPECIAL3
= (0x1F << 26),
54 /* arithmetic with immediate */
55 OPC_ADDI
= (0x08 << 26),
56 OPC_ADDIU
= (0x09 << 26),
57 OPC_SLTI
= (0x0A << 26),
58 OPC_SLTIU
= (0x0B << 26),
59 /* logic with immediate */
60 OPC_ANDI
= (0x0C << 26),
61 OPC_ORI
= (0x0D << 26),
62 OPC_XORI
= (0x0E << 26),
63 OPC_LUI
= (0x0F << 26),
64 /* arithmetic with immediate */
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
, /* unofficial */
191 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
192 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
193 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
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
, bcond
;
433 static TCGv_i32 hflags
;
434 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
436 #include "gen-icount.h"
438 #define gen_helper_0i(name, arg) do { \
439 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
440 gen_helper_##name(helper_tmp); \
441 tcg_temp_free_i32(helper_tmp); \
444 #define gen_helper_1i(name, arg1, arg2) do { \
445 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
446 gen_helper_##name(arg1, helper_tmp); \
447 tcg_temp_free_i32(helper_tmp); \
450 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
451 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
452 gen_helper_##name(arg1, arg2, helper_tmp); \
453 tcg_temp_free_i32(helper_tmp); \
456 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
457 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
458 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
459 tcg_temp_free_i32(helper_tmp); \
462 typedef struct DisasContext
{
463 struct TranslationBlock
*tb
;
464 target_ulong pc
, saved_pc
;
466 int singlestep_enabled
;
467 /* Routine used to access memory */
469 uint32_t hflags
, saved_hflags
;
471 target_ulong btarget
;
475 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
476 * exception condition */
477 BS_STOP
= 1, /* We want to stop translation for any reason */
478 BS_BRANCH
= 2, /* We reached a branch condition */
479 BS_EXCP
= 3, /* We reached an exception condition */
482 static const char *regnames
[] =
483 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
484 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
485 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
486 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
488 static const char *regnames_HI
[] =
489 { "HI0", "HI1", "HI2", "HI3", };
491 static const char *regnames_LO
[] =
492 { "LO0", "LO1", "LO2", "LO3", };
494 static const char *regnames_ACX
[] =
495 { "ACX0", "ACX1", "ACX2", "ACX3", };
497 static const char *fregnames
[] =
498 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
499 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
500 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
501 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
503 #ifdef MIPS_DEBUG_DISAS
504 #define MIPS_DEBUG(fmt, ...) \
505 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
506 TARGET_FMT_lx ": %08x " fmt "\n", \
507 ctx->pc, ctx->opcode , ## __VA_ARGS__)
508 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
510 #define MIPS_DEBUG(fmt, ...) do { } while(0)
511 #define LOG_DISAS(...) do { } while (0)
514 #define MIPS_INVAL(op) \
516 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
517 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
520 /* General purpose registers moves. */
521 static inline void gen_load_gpr (TCGv t
, int reg
)
524 tcg_gen_movi_tl(t
, 0);
526 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
529 static inline void gen_store_gpr (TCGv t
, int reg
)
532 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
535 /* Moves to/from ACX register. */
536 static inline void gen_load_ACX (TCGv t
, int reg
)
538 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
541 static inline void gen_store_ACX (TCGv t
, int reg
)
543 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
546 /* Moves to/from shadow registers. */
547 static inline void gen_load_srsgpr (int from
, int to
)
549 TCGv t0
= tcg_temp_new();
552 tcg_gen_movi_tl(t0
, 0);
554 TCGv_i32 t2
= tcg_temp_new_i32();
555 TCGv_ptr addr
= tcg_temp_new_ptr();
557 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
558 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
559 tcg_gen_andi_i32(t2
, t2
, 0xf);
560 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
561 tcg_gen_ext_i32_ptr(addr
, t2
);
562 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
564 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
565 tcg_temp_free_ptr(addr
);
566 tcg_temp_free_i32(t2
);
568 gen_store_gpr(t0
, to
);
572 static inline void gen_store_srsgpr (int from
, int to
)
575 TCGv t0
= tcg_temp_new();
576 TCGv_i32 t2
= tcg_temp_new_i32();
577 TCGv_ptr addr
= tcg_temp_new_ptr();
579 gen_load_gpr(t0
, from
);
580 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
581 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
582 tcg_gen_andi_i32(t2
, t2
, 0xf);
583 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
584 tcg_gen_ext_i32_ptr(addr
, t2
);
585 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
587 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
588 tcg_temp_free_ptr(addr
);
589 tcg_temp_free_i32(t2
);
594 /* Floating point register moves. */
595 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
597 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
600 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
602 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
605 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
607 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
610 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
612 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
615 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
617 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
618 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
620 TCGv_i32 t0
= tcg_temp_new_i32();
621 TCGv_i32 t1
= tcg_temp_new_i32();
622 gen_load_fpr32(t0
, reg
& ~1);
623 gen_load_fpr32(t1
, reg
| 1);
624 tcg_gen_concat_i32_i64(t
, t0
, t1
);
625 tcg_temp_free_i32(t0
);
626 tcg_temp_free_i32(t1
);
630 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
632 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
633 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
635 TCGv_i64 t0
= tcg_temp_new_i64();
636 TCGv_i32 t1
= tcg_temp_new_i32();
637 tcg_gen_trunc_i64_i32(t1
, t
);
638 gen_store_fpr32(t1
, reg
& ~1);
639 tcg_gen_shri_i64(t0
, t
, 32);
640 tcg_gen_trunc_i64_i32(t1
, t0
);
641 gen_store_fpr32(t1
, reg
| 1);
642 tcg_temp_free_i32(t1
);
643 tcg_temp_free_i64(t0
);
647 static inline int get_fp_bit (int cc
)
655 #define FOP_CONDS(type, fmt, bits) \
656 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
657 TCGv_i##bits b, int cc) \
660 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
661 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
662 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
663 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
664 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
665 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
666 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
667 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
668 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
669 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
670 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
671 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
672 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
673 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
674 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
675 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
681 FOP_CONDS(abs
, d
, 64)
683 FOP_CONDS(abs
, s
, 32)
685 FOP_CONDS(abs
, ps
, 64)
689 #define OP_COND(name, cond) \
690 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, TCGv t1) \
692 int l1 = gen_new_label(); \
693 int l2 = gen_new_label(); \
695 tcg_gen_brcond_tl(cond, t0, t1, l1); \
696 tcg_gen_movi_tl(ret, 0); \
699 tcg_gen_movi_tl(ret, 1); \
702 OP_COND(eq
, TCG_COND_EQ
);
703 OP_COND(ne
, TCG_COND_NE
);
704 OP_COND(ge
, TCG_COND_GE
);
705 OP_COND(geu
, TCG_COND_GEU
);
706 OP_COND(lt
, TCG_COND_LT
);
707 OP_COND(ltu
, TCG_COND_LTU
);
710 #define OP_CONDI(name, cond) \
711 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, target_ulong val) \
713 int l1 = gen_new_label(); \
714 int l2 = gen_new_label(); \
716 tcg_gen_brcondi_tl(cond, t0, val, l1); \
717 tcg_gen_movi_tl(ret, 0); \
720 tcg_gen_movi_tl(ret, 1); \
723 OP_CONDI(lti
, TCG_COND_LT
);
724 OP_CONDI(ltiu
, TCG_COND_LTU
);
727 #define OP_CONDZ(name, cond) \
728 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0) \
730 int l1 = gen_new_label(); \
731 int l2 = gen_new_label(); \
733 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
734 tcg_gen_movi_tl(ret, 0); \
737 tcg_gen_movi_tl(ret, 1); \
740 OP_CONDZ(gez
, TCG_COND_GE
);
741 OP_CONDZ(gtz
, TCG_COND_GT
);
742 OP_CONDZ(lez
, TCG_COND_LE
);
743 OP_CONDZ(ltz
, TCG_COND_LT
);
746 static inline void gen_save_pc(target_ulong pc
)
748 tcg_gen_movi_tl(cpu_PC
, pc
);
751 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
753 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
754 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
755 gen_save_pc(ctx
->pc
);
756 ctx
->saved_pc
= ctx
->pc
;
758 if (ctx
->hflags
!= ctx
->saved_hflags
) {
759 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
760 ctx
->saved_hflags
= ctx
->hflags
;
761 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
767 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
773 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
775 ctx
->saved_hflags
= ctx
->hflags
;
776 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
782 ctx
->btarget
= env
->btarget
;
788 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
790 TCGv_i32 texcp
= tcg_const_i32(excp
);
791 TCGv_i32 terr
= tcg_const_i32(err
);
792 save_cpu_state(ctx
, 1);
793 gen_helper_raise_exception_err(texcp
, terr
);
794 tcg_temp_free_i32(terr
);
795 tcg_temp_free_i32(texcp
);
799 generate_exception (DisasContext
*ctx
, int excp
)
801 save_cpu_state(ctx
, 1);
802 gen_helper_0i(raise_exception
, excp
);
805 /* Addresses computation */
806 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
808 tcg_gen_add_tl(ret
, arg0
, arg1
);
810 #if defined(TARGET_MIPS64)
811 /* For compatibility with 32-bit code, data reference in user mode
812 with Status_UX = 0 should be casted to 32-bit and sign extended.
813 See the MIPS64 PRA manual, section 4.10. */
814 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
815 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
816 tcg_gen_ext32s_i64(ret
, ret
);
821 static inline void check_cp0_enabled(DisasContext
*ctx
)
823 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
824 generate_exception_err(ctx
, EXCP_CpU
, 1);
827 static inline void check_cp1_enabled(DisasContext
*ctx
)
829 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
830 generate_exception_err(ctx
, EXCP_CpU
, 1);
833 /* Verify that the processor is running with COP1X instructions enabled.
834 This is associated with the nabla symbol in the MIPS32 and MIPS64
837 static inline void check_cop1x(DisasContext
*ctx
)
839 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
840 generate_exception(ctx
, EXCP_RI
);
843 /* Verify that the processor is running with 64-bit floating-point
844 operations enabled. */
846 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
848 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
849 generate_exception(ctx
, EXCP_RI
);
853 * Verify if floating point register is valid; an operation is not defined
854 * if bit 0 of any register specification is set and the FR bit in the
855 * Status register equals zero, since the register numbers specify an
856 * even-odd pair of adjacent coprocessor general registers. When the FR bit
857 * in the Status register equals one, both even and odd register numbers
858 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
860 * Multiple 64 bit wide registers can be checked by calling
861 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
863 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
865 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
866 generate_exception(ctx
, EXCP_RI
);
869 /* This code generates a "reserved instruction" exception if the
870 CPU does not support the instruction set corresponding to flags. */
871 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
873 if (unlikely(!(env
->insn_flags
& flags
)))
874 generate_exception(ctx
, EXCP_RI
);
877 /* This code generates a "reserved instruction" exception if 64-bit
878 instructions are not enabled. */
879 static inline void check_mips_64(DisasContext
*ctx
)
881 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
882 generate_exception(ctx
, EXCP_RI
);
885 /* load/store instructions. */
886 #define OP_LD(insn,fname) \
887 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
889 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
896 #if defined(TARGET_MIPS64)
902 #define OP_ST(insn,fname) \
903 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
905 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
910 #if defined(TARGET_MIPS64)
915 #define OP_LD_ATOMIC(insn,fname) \
916 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
918 TCGv t0 = tcg_temp_new(); \
919 tcg_gen_mov_tl(t0, arg1); \
920 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
921 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
922 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
925 OP_LD_ATOMIC(ll
,ld32s
);
926 #if defined(TARGET_MIPS64)
927 OP_LD_ATOMIC(lld
,ld64
);
931 #ifdef CONFIG_USER_ONLY
932 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
933 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
935 TCGv t0 = tcg_temp_new(); \
936 int l1 = gen_new_label(); \
937 int l2 = gen_new_label(); \
939 tcg_gen_andi_tl(t0, arg2, almask); \
940 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
941 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
942 generate_exception(ctx, EXCP_AdES); \
944 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
945 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
946 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
947 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
948 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
949 gen_helper_0i(raise_exception, EXCP_SC); \
951 tcg_gen_movi_tl(t0, 0); \
952 gen_store_gpr(t0, rt); \
956 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
957 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
959 TCGv t0 = tcg_temp_new(); \
960 TCGv t1 = tcg_temp_new(); \
961 int l1 = gen_new_label(); \
962 int l2 = gen_new_label(); \
963 int l3 = gen_new_label(); \
965 tcg_gen_andi_tl(t0, arg2, almask); \
966 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
967 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
968 generate_exception(ctx, EXCP_AdES); \
970 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
971 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
972 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, llval)); \
973 tcg_gen_qemu_##ldname(t1, arg2, ctx->mem_idx); \
974 tcg_gen_brcond_tl(TCG_COND_NE, t0, t1, l2); \
976 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
977 tcg_gen_movi_tl(t0, 1); \
978 gen_store_gpr(t0, rt); \
981 tcg_gen_movi_tl(t0, 0); \
982 gen_store_gpr(t0, rt); \
988 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
989 #if defined(TARGET_MIPS64)
990 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
995 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
996 int base
, int16_t offset
)
998 const char *opn
= "ldst";
999 TCGv t0
= tcg_temp_new();
1000 TCGv t1
= tcg_temp_new();
1003 tcg_gen_movi_tl(t0
, offset
);
1004 } else if (offset
== 0) {
1005 gen_load_gpr(t0
, base
);
1007 tcg_gen_movi_tl(t0
, offset
);
1008 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
1010 /* Don't do NOP if destination is zero: we must perform the actual
1013 #if defined(TARGET_MIPS64)
1015 save_cpu_state(ctx
, 0);
1016 op_ldst_lwu(t0
, t0
, ctx
);
1017 gen_store_gpr(t0
, rt
);
1021 save_cpu_state(ctx
, 0);
1022 op_ldst_ld(t0
, t0
, ctx
);
1023 gen_store_gpr(t0
, rt
);
1027 save_cpu_state(ctx
, 0);
1028 op_ldst_lld(t0
, t0
, ctx
);
1029 gen_store_gpr(t0
, rt
);
1033 save_cpu_state(ctx
, 0);
1034 gen_load_gpr(t1
, rt
);
1035 op_ldst_sd(t1
, t0
, ctx
);
1039 save_cpu_state(ctx
, 1);
1040 gen_load_gpr(t1
, rt
);
1041 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1042 gen_store_gpr(t1
, rt
);
1046 save_cpu_state(ctx
, 1);
1047 gen_load_gpr(t1
, rt
);
1048 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1052 save_cpu_state(ctx
, 1);
1053 gen_load_gpr(t1
, rt
);
1054 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1055 gen_store_gpr(t1
, rt
);
1059 save_cpu_state(ctx
, 1);
1060 gen_load_gpr(t1
, rt
);
1061 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1066 save_cpu_state(ctx
, 0);
1067 op_ldst_lw(t0
, t0
, ctx
);
1068 gen_store_gpr(t0
, rt
);
1072 save_cpu_state(ctx
, 0);
1073 gen_load_gpr(t1
, rt
);
1074 op_ldst_sw(t1
, t0
, ctx
);
1078 save_cpu_state(ctx
, 0);
1079 op_ldst_lh(t0
, t0
, ctx
);
1080 gen_store_gpr(t0
, rt
);
1084 save_cpu_state(ctx
, 0);
1085 gen_load_gpr(t1
, rt
);
1086 op_ldst_sh(t1
, t0
, ctx
);
1090 save_cpu_state(ctx
, 0);
1091 op_ldst_lhu(t0
, t0
, ctx
);
1092 gen_store_gpr(t0
, rt
);
1096 save_cpu_state(ctx
, 0);
1097 op_ldst_lb(t0
, t0
, ctx
);
1098 gen_store_gpr(t0
, rt
);
1102 save_cpu_state(ctx
, 0);
1103 gen_load_gpr(t1
, rt
);
1104 op_ldst_sb(t1
, t0
, ctx
);
1108 save_cpu_state(ctx
, 0);
1109 op_ldst_lbu(t0
, t0
, ctx
);
1110 gen_store_gpr(t0
, rt
);
1114 save_cpu_state(ctx
, 1);
1115 gen_load_gpr(t1
, rt
);
1116 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1117 gen_store_gpr(t1
, rt
);
1121 save_cpu_state(ctx
, 1);
1122 gen_load_gpr(t1
, rt
);
1123 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1127 save_cpu_state(ctx
, 1);
1128 gen_load_gpr(t1
, rt
);
1129 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1130 gen_store_gpr(t1
, rt
);
1134 save_cpu_state(ctx
, 1);
1135 gen_load_gpr(t1
, rt
);
1136 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1140 save_cpu_state(ctx
, 0);
1141 op_ldst_ll(t0
, t0
, ctx
);
1142 gen_store_gpr(t0
, rt
);
1146 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1151 /* Store conditional */
1152 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1153 int base
, int16_t offset
)
1155 const char *opn
= "st_cond";
1158 t0
= tcg_temp_local_new();
1161 tcg_gen_movi_tl(t0
, offset
);
1162 } else if (offset
== 0) {
1163 gen_load_gpr(t0
, base
);
1165 tcg_gen_movi_tl(t0
, offset
);
1166 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
1168 /* Don't do NOP if destination is zero: we must perform the actual
1171 t1
= tcg_temp_local_new();
1172 gen_load_gpr(t1
, rt
);
1174 #if defined(TARGET_MIPS64)
1176 save_cpu_state(ctx
, 0);
1177 op_ldst_scd(t1
, t0
, rt
, ctx
);
1182 save_cpu_state(ctx
, 0);
1183 op_ldst_sc(t1
, t0
, rt
, ctx
);
1187 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1192 /* Load and store */
1193 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1194 int base
, int16_t offset
)
1196 const char *opn
= "flt_ldst";
1197 TCGv t0
= tcg_temp_new();
1200 tcg_gen_movi_tl(t0
, offset
);
1201 } else if (offset
== 0) {
1202 gen_load_gpr(t0
, base
);
1204 tcg_gen_movi_tl(t0
, offset
);
1205 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
1207 /* Don't do NOP if destination is zero: we must perform the actual
1212 TCGv_i32 fp0
= tcg_temp_new_i32();
1214 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1215 tcg_gen_trunc_tl_i32(fp0
, t0
);
1216 gen_store_fpr32(fp0
, ft
);
1217 tcg_temp_free_i32(fp0
);
1223 TCGv_i32 fp0
= tcg_temp_new_i32();
1224 TCGv t1
= tcg_temp_new();
1226 gen_load_fpr32(fp0
, ft
);
1227 tcg_gen_extu_i32_tl(t1
, fp0
);
1228 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1230 tcg_temp_free_i32(fp0
);
1236 TCGv_i64 fp0
= tcg_temp_new_i64();
1238 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1239 gen_store_fpr64(ctx
, fp0
, ft
);
1240 tcg_temp_free_i64(fp0
);
1246 TCGv_i64 fp0
= tcg_temp_new_i64();
1248 gen_load_fpr64(ctx
, fp0
, ft
);
1249 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1250 tcg_temp_free_i64(fp0
);
1256 generate_exception(ctx
, EXCP_RI
);
1259 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1264 /* Arithmetic with immediate operand */
1265 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1266 int rt
, int rs
, int16_t imm
)
1268 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1269 const char *opn
= "imm arith";
1271 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1272 /* If no destination, treat it as a NOP.
1273 For addi, we must generate the overflow exception when needed. */
1280 TCGv t0
= tcg_temp_local_new();
1281 TCGv t1
= tcg_temp_new();
1282 TCGv t2
= tcg_temp_new();
1283 int l1
= gen_new_label();
1285 gen_load_gpr(t1
, rs
);
1286 tcg_gen_addi_tl(t0
, t1
, uimm
);
1287 tcg_gen_ext32s_tl(t0
, t0
);
1289 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1290 tcg_gen_xori_tl(t2
, t0
, uimm
);
1291 tcg_gen_and_tl(t1
, t1
, t2
);
1293 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1295 /* operands of same sign, result different sign */
1296 generate_exception(ctx
, EXCP_OVERFLOW
);
1298 tcg_gen_ext32s_tl(t0
, t0
);
1299 gen_store_gpr(t0
, rt
);
1306 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1307 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1309 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1313 #if defined(TARGET_MIPS64)
1316 TCGv t0
= tcg_temp_local_new();
1317 TCGv t1
= tcg_temp_new();
1318 TCGv t2
= tcg_temp_new();
1319 int l1
= gen_new_label();
1321 gen_load_gpr(t1
, rs
);
1322 tcg_gen_addi_tl(t0
, t1
, uimm
);
1324 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1325 tcg_gen_xori_tl(t2
, t0
, uimm
);
1326 tcg_gen_and_tl(t1
, t1
, t2
);
1328 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1330 /* operands of same sign, result different sign */
1331 generate_exception(ctx
, EXCP_OVERFLOW
);
1333 gen_store_gpr(t0
, rt
);
1340 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1342 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1348 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1351 /* Logic with immediate operand */
1352 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1355 const char *opn
= "imm logic";
1358 /* If no destination, treat it as a NOP. */
1362 uimm
= (uint16_t)imm
;
1365 if (likely(rs
!= 0))
1366 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1368 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1373 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1375 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1379 if (likely(rs
!= 0))
1380 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1382 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1386 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1390 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1393 /* Set on less than with immediate operand */
1394 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1396 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1397 const char *opn
= "imm arith";
1401 /* If no destination, treat it as a NOP. */
1405 t0
= tcg_temp_new();
1406 gen_load_gpr(t0
, rs
);
1409 gen_op_lti(cpu_gpr
[rt
], t0
, uimm
);
1413 gen_op_ltiu(cpu_gpr
[rt
], t0
, uimm
);
1417 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1421 /* Shifts with immediate operand */
1422 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1423 int rt
, int rs
, int16_t imm
)
1425 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1426 const char *opn
= "imm shift";
1430 /* If no destination, treat it as a NOP. */
1435 t0
= tcg_temp_new();
1436 gen_load_gpr(t0
, rs
);
1439 tcg_gen_shli_tl(t0
, t0
, uimm
);
1440 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1444 tcg_gen_ext32s_tl(t0
, t0
);
1445 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1449 switch ((ctx
->opcode
>> 21) & 0x1f) {
1452 tcg_gen_ext32u_tl(t0
, t0
);
1453 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1455 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1460 /* rotr is decoded as srl on non-R2 CPUs */
1461 if (env
->insn_flags
& ISA_MIPS32R2
) {
1463 TCGv_i32 t1
= tcg_temp_new_i32();
1465 tcg_gen_trunc_tl_i32(t1
, t0
);
1466 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1467 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1468 tcg_temp_free_i32(t1
);
1473 tcg_gen_ext32u_tl(t0
, t0
);
1474 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1476 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1482 MIPS_INVAL("invalid srl flag");
1483 generate_exception(ctx
, EXCP_RI
);
1487 #if defined(TARGET_MIPS64)
1489 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1493 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1497 switch ((ctx
->opcode
>> 21) & 0x1f) {
1499 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1503 /* drotr is decoded as dsrl on non-R2 CPUs */
1504 if (env
->insn_flags
& ISA_MIPS32R2
) {
1506 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1510 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1515 MIPS_INVAL("invalid dsrl flag");
1516 generate_exception(ctx
, EXCP_RI
);
1521 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1525 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1529 switch ((ctx
->opcode
>> 21) & 0x1f) {
1531 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1535 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1536 if (env
->insn_flags
& ISA_MIPS32R2
) {
1537 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1540 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1545 MIPS_INVAL("invalid dsrl32 flag");
1546 generate_exception(ctx
, EXCP_RI
);
1552 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1557 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1558 int rd
, int rs
, int rt
)
1560 const char *opn
= "arith";
1562 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1563 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1564 /* If no destination, treat it as a NOP.
1565 For add & sub, we must generate the overflow exception when needed. */
1573 TCGv t0
= tcg_temp_local_new();
1574 TCGv t1
= tcg_temp_new();
1575 TCGv t2
= tcg_temp_new();
1576 int l1
= gen_new_label();
1578 gen_load_gpr(t1
, rs
);
1579 gen_load_gpr(t2
, rt
);
1580 tcg_gen_add_tl(t0
, t1
, t2
);
1581 tcg_gen_ext32s_tl(t0
, t0
);
1582 tcg_gen_xor_tl(t1
, t1
, t2
);
1583 tcg_gen_not_tl(t1
, t1
);
1584 tcg_gen_xor_tl(t2
, t0
, t2
);
1585 tcg_gen_and_tl(t1
, t1
, t2
);
1587 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1589 /* operands of same sign, result different sign */
1590 generate_exception(ctx
, EXCP_OVERFLOW
);
1592 gen_store_gpr(t0
, rd
);
1598 if (rs
!= 0 && rt
!= 0) {
1599 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1600 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1601 } else if (rs
== 0 && rt
!= 0) {
1602 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1603 } else if (rs
!= 0 && rt
== 0) {
1604 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1606 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1612 TCGv t0
= tcg_temp_local_new();
1613 TCGv t1
= tcg_temp_new();
1614 TCGv t2
= tcg_temp_new();
1615 int l1
= gen_new_label();
1617 gen_load_gpr(t1
, rs
);
1618 gen_load_gpr(t2
, rt
);
1619 tcg_gen_sub_tl(t0
, t1
, t2
);
1620 tcg_gen_ext32s_tl(t0
, t0
);
1621 tcg_gen_xor_tl(t2
, t1
, t2
);
1622 tcg_gen_xor_tl(t1
, t0
, t1
);
1623 tcg_gen_and_tl(t1
, t1
, t2
);
1625 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1627 /* operands of different sign, first operand and result different sign */
1628 generate_exception(ctx
, EXCP_OVERFLOW
);
1630 gen_store_gpr(t0
, rd
);
1636 if (rs
!= 0 && rt
!= 0) {
1637 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1638 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1639 } else if (rs
== 0 && rt
!= 0) {
1640 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1641 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1642 } else if (rs
!= 0 && rt
== 0) {
1643 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1645 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1649 #if defined(TARGET_MIPS64)
1652 TCGv t0
= tcg_temp_local_new();
1653 TCGv t1
= tcg_temp_new();
1654 TCGv t2
= tcg_temp_new();
1655 int l1
= gen_new_label();
1657 gen_load_gpr(t1
, rs
);
1658 gen_load_gpr(t2
, rt
);
1659 tcg_gen_add_tl(t0
, t1
, t2
);
1660 tcg_gen_xor_tl(t1
, t1
, t2
);
1661 tcg_gen_not_tl(t1
, t1
);
1662 tcg_gen_xor_tl(t2
, t0
, t2
);
1663 tcg_gen_and_tl(t1
, t1
, t2
);
1665 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1667 /* operands of same sign, result different sign */
1668 generate_exception(ctx
, EXCP_OVERFLOW
);
1670 gen_store_gpr(t0
, rd
);
1676 if (rs
!= 0 && rt
!= 0) {
1677 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1678 } else if (rs
== 0 && rt
!= 0) {
1679 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1680 } else if (rs
!= 0 && rt
== 0) {
1681 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1683 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1689 TCGv t0
= tcg_temp_local_new();
1690 TCGv t1
= tcg_temp_new();
1691 TCGv t2
= tcg_temp_new();
1692 int l1
= gen_new_label();
1694 gen_load_gpr(t1
, rs
);
1695 gen_load_gpr(t2
, rt
);
1696 tcg_gen_sub_tl(t0
, t1
, t2
);
1697 tcg_gen_xor_tl(t2
, t1
, t2
);
1698 tcg_gen_xor_tl(t1
, t0
, t1
);
1699 tcg_gen_and_tl(t1
, t1
, t2
);
1701 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1703 /* operands of different sign, first operand and result different sign */
1704 generate_exception(ctx
, EXCP_OVERFLOW
);
1706 gen_store_gpr(t0
, rd
);
1712 if (rs
!= 0 && rt
!= 0) {
1713 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1714 } else if (rs
== 0 && rt
!= 0) {
1715 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1716 } else if (rs
!= 0 && rt
== 0) {
1717 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1719 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1725 if (likely(rs
!= 0 && rt
!= 0)) {
1726 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1727 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1729 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1734 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1737 /* Conditional move */
1738 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1740 const char *opn
= "cond move";
1744 /* If no destination, treat it as a NOP.
1745 For add & sub, we must generate the overflow exception when needed. */
1750 l1
= gen_new_label();
1753 if (likely(rt
!= 0))
1754 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1760 if (likely(rt
!= 0))
1761 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1766 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1768 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1771 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1775 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1777 const char *opn
= "logic";
1780 /* If no destination, treat it as a NOP. */
1787 if (likely(rs
!= 0 && rt
!= 0)) {
1788 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1790 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1795 if (rs
!= 0 && rt
!= 0) {
1796 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1797 } else if (rs
== 0 && rt
!= 0) {
1798 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1799 } else if (rs
!= 0 && rt
== 0) {
1800 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1802 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1807 if (likely(rs
!= 0 && rt
!= 0)) {
1808 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1809 } else if (rs
== 0 && rt
!= 0) {
1810 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1811 } else if (rs
!= 0 && rt
== 0) {
1812 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1814 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1819 if (likely(rs
!= 0 && rt
!= 0)) {
1820 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1821 } else if (rs
== 0 && rt
!= 0) {
1822 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1823 } else if (rs
!= 0 && rt
== 0) {
1824 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1826 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1831 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1834 /* Set on lower than */
1835 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1837 const char *opn
= "slt";
1841 /* If no destination, treat it as a NOP. */
1846 t0
= tcg_temp_new();
1847 t1
= tcg_temp_new();
1848 gen_load_gpr(t0
, rs
);
1849 gen_load_gpr(t1
, rt
);
1852 gen_op_lt(cpu_gpr
[rd
], t0
, t1
);
1856 gen_op_ltu(cpu_gpr
[rd
], t0
, t1
);
1860 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1866 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1867 int rd
, int rs
, int rt
)
1869 const char *opn
= "shifts";
1873 /* If no destination, treat it as a NOP.
1874 For add & sub, we must generate the overflow exception when needed. */
1879 t0
= tcg_temp_new();
1880 t1
= tcg_temp_new();
1881 gen_load_gpr(t0
, rs
);
1882 gen_load_gpr(t1
, rt
);
1885 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1886 tcg_gen_shl_tl(t0
, t1
, t0
);
1887 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1891 tcg_gen_ext32s_tl(t1
, t1
);
1892 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1893 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1897 switch ((ctx
->opcode
>> 6) & 0x1f) {
1899 tcg_gen_ext32u_tl(t1
, t1
);
1900 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1901 tcg_gen_shr_tl(t0
, t1
, t0
);
1902 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1906 /* rotrv is decoded as srlv on non-R2 CPUs */
1907 if (env
->insn_flags
& ISA_MIPS32R2
) {
1908 TCGv_i32 t2
= tcg_temp_new_i32();
1909 TCGv_i32 t3
= tcg_temp_new_i32();
1911 tcg_gen_trunc_tl_i32(t2
, t0
);
1912 tcg_gen_trunc_tl_i32(t3
, t1
);
1913 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1914 tcg_gen_rotr_i32(t2
, t3
, t2
);
1915 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1916 tcg_temp_free_i32(t2
);
1917 tcg_temp_free_i32(t3
);
1920 tcg_gen_ext32u_tl(t1
, t1
);
1921 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1922 tcg_gen_shr_tl(t0
, t1
, t0
);
1923 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1928 MIPS_INVAL("invalid srlv flag");
1929 generate_exception(ctx
, EXCP_RI
);
1933 #if defined(TARGET_MIPS64)
1935 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1936 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1940 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1941 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1945 switch ((ctx
->opcode
>> 6) & 0x1f) {
1947 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1948 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1952 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1953 if (env
->insn_flags
& ISA_MIPS32R2
) {
1954 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1955 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1958 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1959 tcg_gen_shr_tl(t0
, t1
, t0
);
1964 MIPS_INVAL("invalid dsrlv flag");
1965 generate_exception(ctx
, EXCP_RI
);
1971 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1976 /* Arithmetic on HI/LO registers */
1977 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1979 const char *opn
= "hilo";
1981 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1988 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1992 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1997 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1999 tcg_gen_movi_tl(cpu_HI
[0], 0);
2004 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
2006 tcg_gen_movi_tl(cpu_LO
[0], 0);
2010 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
2013 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
2016 const char *opn
= "mul/div";
2022 #if defined(TARGET_MIPS64)
2026 t0
= tcg_temp_local_new();
2027 t1
= tcg_temp_local_new();
2030 t0
= tcg_temp_new();
2031 t1
= tcg_temp_new();
2035 gen_load_gpr(t0
, rs
);
2036 gen_load_gpr(t1
, rt
);
2040 int l1
= gen_new_label();
2041 int l2
= gen_new_label();
2043 tcg_gen_ext32s_tl(t0
, t0
);
2044 tcg_gen_ext32s_tl(t1
, t1
);
2045 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2046 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2047 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2049 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2050 tcg_gen_movi_tl(cpu_HI
[0], 0);
2053 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
2054 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
2055 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2056 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2063 int l1
= gen_new_label();
2065 tcg_gen_ext32u_tl(t0
, t0
);
2066 tcg_gen_ext32u_tl(t1
, t1
);
2067 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2068 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2069 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2070 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2071 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2078 TCGv_i64 t2
= tcg_temp_new_i64();
2079 TCGv_i64 t3
= tcg_temp_new_i64();
2081 tcg_gen_ext_tl_i64(t2
, t0
);
2082 tcg_gen_ext_tl_i64(t3
, t1
);
2083 tcg_gen_mul_i64(t2
, t2
, t3
);
2084 tcg_temp_free_i64(t3
);
2085 tcg_gen_trunc_i64_tl(t0
, t2
);
2086 tcg_gen_shri_i64(t2
, t2
, 32);
2087 tcg_gen_trunc_i64_tl(t1
, t2
);
2088 tcg_temp_free_i64(t2
);
2089 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2090 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2096 TCGv_i64 t2
= tcg_temp_new_i64();
2097 TCGv_i64 t3
= tcg_temp_new_i64();
2099 tcg_gen_ext32u_tl(t0
, t0
);
2100 tcg_gen_ext32u_tl(t1
, t1
);
2101 tcg_gen_extu_tl_i64(t2
, t0
);
2102 tcg_gen_extu_tl_i64(t3
, t1
);
2103 tcg_gen_mul_i64(t2
, t2
, t3
);
2104 tcg_temp_free_i64(t3
);
2105 tcg_gen_trunc_i64_tl(t0
, t2
);
2106 tcg_gen_shri_i64(t2
, t2
, 32);
2107 tcg_gen_trunc_i64_tl(t1
, t2
);
2108 tcg_temp_free_i64(t2
);
2109 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2110 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2114 #if defined(TARGET_MIPS64)
2117 int l1
= gen_new_label();
2118 int l2
= gen_new_label();
2120 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2121 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2122 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2123 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2124 tcg_gen_movi_tl(cpu_HI
[0], 0);
2127 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2128 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2135 int l1
= gen_new_label();
2137 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2138 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2139 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2145 gen_helper_dmult(t0
, t1
);
2149 gen_helper_dmultu(t0
, t1
);
2155 TCGv_i64 t2
= tcg_temp_new_i64();
2156 TCGv_i64 t3
= tcg_temp_new_i64();
2158 tcg_gen_ext_tl_i64(t2
, t0
);
2159 tcg_gen_ext_tl_i64(t3
, t1
);
2160 tcg_gen_mul_i64(t2
, t2
, t3
);
2161 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2162 tcg_gen_add_i64(t2
, t2
, t3
);
2163 tcg_temp_free_i64(t3
);
2164 tcg_gen_trunc_i64_tl(t0
, t2
);
2165 tcg_gen_shri_i64(t2
, t2
, 32);
2166 tcg_gen_trunc_i64_tl(t1
, t2
);
2167 tcg_temp_free_i64(t2
);
2168 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2169 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2175 TCGv_i64 t2
= tcg_temp_new_i64();
2176 TCGv_i64 t3
= tcg_temp_new_i64();
2178 tcg_gen_ext32u_tl(t0
, t0
);
2179 tcg_gen_ext32u_tl(t1
, t1
);
2180 tcg_gen_extu_tl_i64(t2
, t0
);
2181 tcg_gen_extu_tl_i64(t3
, t1
);
2182 tcg_gen_mul_i64(t2
, t2
, t3
);
2183 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2184 tcg_gen_add_i64(t2
, t2
, t3
);
2185 tcg_temp_free_i64(t3
);
2186 tcg_gen_trunc_i64_tl(t0
, t2
);
2187 tcg_gen_shri_i64(t2
, t2
, 32);
2188 tcg_gen_trunc_i64_tl(t1
, t2
);
2189 tcg_temp_free_i64(t2
);
2190 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2191 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2197 TCGv_i64 t2
= tcg_temp_new_i64();
2198 TCGv_i64 t3
= tcg_temp_new_i64();
2200 tcg_gen_ext_tl_i64(t2
, t0
);
2201 tcg_gen_ext_tl_i64(t3
, t1
);
2202 tcg_gen_mul_i64(t2
, t2
, t3
);
2203 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2204 tcg_gen_sub_i64(t2
, t3
, t2
);
2205 tcg_temp_free_i64(t3
);
2206 tcg_gen_trunc_i64_tl(t0
, t2
);
2207 tcg_gen_shri_i64(t2
, t2
, 32);
2208 tcg_gen_trunc_i64_tl(t1
, t2
);
2209 tcg_temp_free_i64(t2
);
2210 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2211 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2217 TCGv_i64 t2
= tcg_temp_new_i64();
2218 TCGv_i64 t3
= tcg_temp_new_i64();
2220 tcg_gen_ext32u_tl(t0
, t0
);
2221 tcg_gen_ext32u_tl(t1
, t1
);
2222 tcg_gen_extu_tl_i64(t2
, t0
);
2223 tcg_gen_extu_tl_i64(t3
, t1
);
2224 tcg_gen_mul_i64(t2
, t2
, t3
);
2225 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2226 tcg_gen_sub_i64(t2
, t3
, t2
);
2227 tcg_temp_free_i64(t3
);
2228 tcg_gen_trunc_i64_tl(t0
, t2
);
2229 tcg_gen_shri_i64(t2
, t2
, 32);
2230 tcg_gen_trunc_i64_tl(t1
, t2
);
2231 tcg_temp_free_i64(t2
);
2232 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2233 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2239 generate_exception(ctx
, EXCP_RI
);
2242 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2248 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2249 int rd
, int rs
, int rt
)
2251 const char *opn
= "mul vr54xx";
2252 TCGv t0
= tcg_temp_new();
2253 TCGv t1
= tcg_temp_new();
2255 gen_load_gpr(t0
, rs
);
2256 gen_load_gpr(t1
, rt
);
2259 case OPC_VR54XX_MULS
:
2260 gen_helper_muls(t0
, t0
, t1
);
2263 case OPC_VR54XX_MULSU
:
2264 gen_helper_mulsu(t0
, t0
, t1
);
2267 case OPC_VR54XX_MACC
:
2268 gen_helper_macc(t0
, t0
, t1
);
2271 case OPC_VR54XX_MACCU
:
2272 gen_helper_maccu(t0
, t0
, t1
);
2275 case OPC_VR54XX_MSAC
:
2276 gen_helper_msac(t0
, t0
, t1
);
2279 case OPC_VR54XX_MSACU
:
2280 gen_helper_msacu(t0
, t0
, t1
);
2283 case OPC_VR54XX_MULHI
:
2284 gen_helper_mulhi(t0
, t0
, t1
);
2287 case OPC_VR54XX_MULHIU
:
2288 gen_helper_mulhiu(t0
, t0
, t1
);
2291 case OPC_VR54XX_MULSHI
:
2292 gen_helper_mulshi(t0
, t0
, t1
);
2295 case OPC_VR54XX_MULSHIU
:
2296 gen_helper_mulshiu(t0
, t0
, t1
);
2299 case OPC_VR54XX_MACCHI
:
2300 gen_helper_macchi(t0
, t0
, t1
);
2303 case OPC_VR54XX_MACCHIU
:
2304 gen_helper_macchiu(t0
, t0
, t1
);
2307 case OPC_VR54XX_MSACHI
:
2308 gen_helper_msachi(t0
, t0
, t1
);
2311 case OPC_VR54XX_MSACHIU
:
2312 gen_helper_msachiu(t0
, t0
, t1
);
2316 MIPS_INVAL("mul vr54xx");
2317 generate_exception(ctx
, EXCP_RI
);
2320 gen_store_gpr(t0
, rd
);
2321 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2328 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2331 const char *opn
= "CLx";
2339 t0
= tcg_temp_new();
2340 gen_load_gpr(t0
, rs
);
2343 gen_helper_clo(cpu_gpr
[rd
], t0
);
2347 gen_helper_clz(cpu_gpr
[rd
], t0
);
2350 #if defined(TARGET_MIPS64)
2352 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2356 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2361 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2366 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2367 int rs
, int rt
, int16_t imm
)
2370 TCGv t0
= tcg_temp_new();
2371 TCGv t1
= tcg_temp_new();
2374 /* Load needed operands */
2382 /* Compare two registers */
2384 gen_load_gpr(t0
, rs
);
2385 gen_load_gpr(t1
, rt
);
2395 /* Compare register to immediate */
2396 if (rs
!= 0 || imm
!= 0) {
2397 gen_load_gpr(t0
, rs
);
2398 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2405 case OPC_TEQ
: /* rs == rs */
2406 case OPC_TEQI
: /* r0 == 0 */
2407 case OPC_TGE
: /* rs >= rs */
2408 case OPC_TGEI
: /* r0 >= 0 */
2409 case OPC_TGEU
: /* rs >= rs unsigned */
2410 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2412 generate_exception(ctx
, EXCP_TRAP
);
2414 case OPC_TLT
: /* rs < rs */
2415 case OPC_TLTI
: /* r0 < 0 */
2416 case OPC_TLTU
: /* rs < rs unsigned */
2417 case OPC_TLTIU
: /* r0 < 0 unsigned */
2418 case OPC_TNE
: /* rs != rs */
2419 case OPC_TNEI
: /* r0 != 0 */
2420 /* Never trap: treat as NOP. */
2424 int l1
= gen_new_label();
2429 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2433 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2437 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2441 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2445 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2449 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2452 generate_exception(ctx
, EXCP_TRAP
);
2459 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2461 TranslationBlock
*tb
;
2463 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2464 likely(!ctx
->singlestep_enabled
)) {
2467 tcg_gen_exit_tb((long)tb
+ n
);
2470 if (ctx
->singlestep_enabled
) {
2471 save_cpu_state(ctx
, 0);
2472 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
2478 /* Branches (before delay slot) */
2479 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2480 int rs
, int rt
, int32_t offset
)
2482 target_ulong btgt
= -1;
2484 int bcond_compute
= 0;
2485 TCGv t0
= tcg_temp_new();
2486 TCGv t1
= tcg_temp_new();
2488 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2489 #ifdef MIPS_DEBUG_DISAS
2490 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2492 generate_exception(ctx
, EXCP_RI
);
2496 /* Load needed operands */
2502 /* Compare two registers */
2504 gen_load_gpr(t0
, rs
);
2505 gen_load_gpr(t1
, rt
);
2508 btgt
= ctx
->pc
+ 4 + offset
;
2522 /* Compare to zero */
2524 gen_load_gpr(t0
, rs
);
2527 btgt
= ctx
->pc
+ 4 + offset
;
2531 /* Jump to immediate */
2532 btgt
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2536 /* Jump to register */
2537 if (offset
!= 0 && offset
!= 16) {
2538 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2539 others are reserved. */
2540 MIPS_INVAL("jump hint");
2541 generate_exception(ctx
, EXCP_RI
);
2544 gen_load_gpr(btarget
, rs
);
2547 MIPS_INVAL("branch/jump");
2548 generate_exception(ctx
, EXCP_RI
);
2551 if (bcond_compute
== 0) {
2552 /* No condition to be computed */
2554 case OPC_BEQ
: /* rx == rx */
2555 case OPC_BEQL
: /* rx == rx likely */
2556 case OPC_BGEZ
: /* 0 >= 0 */
2557 case OPC_BGEZL
: /* 0 >= 0 likely */
2558 case OPC_BLEZ
: /* 0 <= 0 */
2559 case OPC_BLEZL
: /* 0 <= 0 likely */
2561 ctx
->hflags
|= MIPS_HFLAG_B
;
2562 MIPS_DEBUG("balways");
2564 case OPC_BGEZAL
: /* 0 >= 0 */
2565 case OPC_BGEZALL
: /* 0 >= 0 likely */
2566 /* Always take and link */
2568 ctx
->hflags
|= MIPS_HFLAG_B
;
2569 MIPS_DEBUG("balways and link");
2571 case OPC_BNE
: /* rx != rx */
2572 case OPC_BGTZ
: /* 0 > 0 */
2573 case OPC_BLTZ
: /* 0 < 0 */
2575 MIPS_DEBUG("bnever (NOP)");
2577 case OPC_BLTZAL
: /* 0 < 0 */
2578 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2579 MIPS_DEBUG("bnever and link");
2581 case OPC_BLTZALL
: /* 0 < 0 likely */
2582 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2583 /* Skip the instruction in the delay slot */
2584 MIPS_DEBUG("bnever, link and skip");
2587 case OPC_BNEL
: /* rx != rx likely */
2588 case OPC_BGTZL
: /* 0 > 0 likely */
2589 case OPC_BLTZL
: /* 0 < 0 likely */
2590 /* Skip the instruction in the delay slot */
2591 MIPS_DEBUG("bnever and skip");
2595 ctx
->hflags
|= MIPS_HFLAG_B
;
2596 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2600 ctx
->hflags
|= MIPS_HFLAG_B
;
2601 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2604 ctx
->hflags
|= MIPS_HFLAG_BR
;
2605 MIPS_DEBUG("jr %s", regnames
[rs
]);
2609 ctx
->hflags
|= MIPS_HFLAG_BR
;
2610 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2613 MIPS_INVAL("branch/jump");
2614 generate_exception(ctx
, EXCP_RI
);
2620 gen_op_eq(bcond
, t0
, t1
);
2621 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2622 regnames
[rs
], regnames
[rt
], btgt
);
2625 gen_op_eq(bcond
, t0
, t1
);
2626 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2627 regnames
[rs
], regnames
[rt
], btgt
);
2630 gen_op_ne(bcond
, t0
, t1
);
2631 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2632 regnames
[rs
], regnames
[rt
], btgt
);
2635 gen_op_ne(bcond
, t0
, t1
);
2636 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2637 regnames
[rs
], regnames
[rt
], btgt
);
2640 gen_op_gez(bcond
, t0
);
2641 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2644 gen_op_gez(bcond
, t0
);
2645 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2648 gen_op_gez(bcond
, t0
);
2649 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2653 gen_op_gez(bcond
, t0
);
2655 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2658 gen_op_gtz(bcond
, t0
);
2659 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2662 gen_op_gtz(bcond
, t0
);
2663 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2666 gen_op_lez(bcond
, t0
);
2667 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2670 gen_op_lez(bcond
, t0
);
2671 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2674 gen_op_ltz(bcond
, t0
);
2675 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2678 gen_op_ltz(bcond
, t0
);
2679 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2682 gen_op_ltz(bcond
, t0
);
2684 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2686 ctx
->hflags
|= MIPS_HFLAG_BC
;
2689 gen_op_ltz(bcond
, t0
);
2691 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2693 ctx
->hflags
|= MIPS_HFLAG_BL
;
2696 MIPS_INVAL("conditional branch/jump");
2697 generate_exception(ctx
, EXCP_RI
);
2701 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2702 blink
, ctx
->hflags
, btgt
);
2704 ctx
->btarget
= btgt
;
2706 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ 8);
2714 /* special3 bitfield operations */
2715 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2716 int rs
, int lsb
, int msb
)
2718 TCGv t0
= tcg_temp_new();
2719 TCGv t1
= tcg_temp_new();
2722 gen_load_gpr(t1
, rs
);
2727 tcg_gen_shri_tl(t0
, t1
, lsb
);
2729 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2731 tcg_gen_ext32s_tl(t0
, t0
);
2734 #if defined(TARGET_MIPS64)
2736 tcg_gen_shri_tl(t0
, t1
, lsb
);
2738 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2742 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2743 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2746 tcg_gen_shri_tl(t0
, t1
, lsb
);
2747 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2753 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2754 gen_load_gpr(t0
, rt
);
2755 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2756 tcg_gen_shli_tl(t1
, t1
, lsb
);
2757 tcg_gen_andi_tl(t1
, t1
, mask
);
2758 tcg_gen_or_tl(t0
, t0
, t1
);
2759 tcg_gen_ext32s_tl(t0
, t0
);
2761 #if defined(TARGET_MIPS64)
2765 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2766 gen_load_gpr(t0
, rt
);
2767 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2768 tcg_gen_shli_tl(t1
, t1
, lsb
);
2769 tcg_gen_andi_tl(t1
, t1
, mask
);
2770 tcg_gen_or_tl(t0
, t0
, t1
);
2775 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2776 gen_load_gpr(t0
, rt
);
2777 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2778 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2779 tcg_gen_andi_tl(t1
, t1
, mask
);
2780 tcg_gen_or_tl(t0
, t0
, t1
);
2785 gen_load_gpr(t0
, rt
);
2786 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2787 gen_load_gpr(t0
, rt
);
2788 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2789 tcg_gen_shli_tl(t1
, t1
, lsb
);
2790 tcg_gen_andi_tl(t1
, t1
, mask
);
2791 tcg_gen_or_tl(t0
, t0
, t1
);
2796 MIPS_INVAL("bitops");
2797 generate_exception(ctx
, EXCP_RI
);
2802 gen_store_gpr(t0
, rt
);
2807 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2812 /* If no destination, treat it as a NOP. */
2817 t0
= tcg_temp_new();
2818 gen_load_gpr(t0
, rt
);
2822 TCGv t1
= tcg_temp_new();
2824 tcg_gen_shri_tl(t1
, t0
, 8);
2825 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2826 tcg_gen_shli_tl(t0
, t0
, 8);
2827 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2828 tcg_gen_or_tl(t0
, t0
, t1
);
2830 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2834 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2837 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2839 #if defined(TARGET_MIPS64)
2842 TCGv t1
= tcg_temp_new();
2844 tcg_gen_shri_tl(t1
, t0
, 8);
2845 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2846 tcg_gen_shli_tl(t0
, t0
, 8);
2847 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2848 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2854 TCGv t1
= tcg_temp_new();
2856 tcg_gen_shri_tl(t1
, t0
, 16);
2857 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2858 tcg_gen_shli_tl(t0
, t0
, 16);
2859 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2860 tcg_gen_or_tl(t0
, t0
, t1
);
2861 tcg_gen_shri_tl(t1
, t0
, 32);
2862 tcg_gen_shli_tl(t0
, t0
, 32);
2863 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2869 MIPS_INVAL("bsfhl");
2870 generate_exception(ctx
, EXCP_RI
);
2877 #ifndef CONFIG_USER_ONLY
2878 /* CP0 (MMU and control) */
2879 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
2881 TCGv_i32 t0
= tcg_temp_new_i32();
2883 tcg_gen_ld_i32(t0
, cpu_env
, off
);
2884 tcg_gen_ext_i32_tl(arg
, t0
);
2885 tcg_temp_free_i32(t0
);
2888 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
2890 tcg_gen_ld_tl(arg
, cpu_env
, off
);
2891 tcg_gen_ext32s_tl(arg
, arg
);
2894 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
2896 TCGv_i32 t0
= tcg_temp_new_i32();
2898 tcg_gen_trunc_tl_i32(t0
, arg
);
2899 tcg_gen_st_i32(t0
, cpu_env
, off
);
2900 tcg_temp_free_i32(t0
);
2903 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
2905 tcg_gen_ext32s_tl(arg
, arg
);
2906 tcg_gen_st_tl(arg
, cpu_env
, off
);
2909 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
2911 const char *rn
= "invalid";
2914 check_insn(env
, ctx
, ISA_MIPS32
);
2920 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
2924 check_insn(env
, ctx
, ASE_MT
);
2925 gen_helper_mfc0_mvpcontrol(arg
);
2929 check_insn(env
, ctx
, ASE_MT
);
2930 gen_helper_mfc0_mvpconf0(arg
);
2934 check_insn(env
, ctx
, ASE_MT
);
2935 gen_helper_mfc0_mvpconf1(arg
);
2945 gen_helper_mfc0_random(arg
);
2949 check_insn(env
, ctx
, ASE_MT
);
2950 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
2954 check_insn(env
, ctx
, ASE_MT
);
2955 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
2959 check_insn(env
, ctx
, ASE_MT
);
2960 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
2964 check_insn(env
, ctx
, ASE_MT
);
2965 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
2969 check_insn(env
, ctx
, ASE_MT
);
2970 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
2974 check_insn(env
, ctx
, ASE_MT
);
2975 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
2976 rn
= "VPEScheFBack";
2979 check_insn(env
, ctx
, ASE_MT
);
2980 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
2990 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2991 tcg_gen_ext32s_tl(arg
, arg
);
2995 check_insn(env
, ctx
, ASE_MT
);
2996 gen_helper_mfc0_tcstatus(arg
);
3000 check_insn(env
, ctx
, ASE_MT
);
3001 gen_helper_mfc0_tcbind(arg
);
3005 check_insn(env
, ctx
, ASE_MT
);
3006 gen_helper_mfc0_tcrestart(arg
);
3010 check_insn(env
, ctx
, ASE_MT
);
3011 gen_helper_mfc0_tchalt(arg
);
3015 check_insn(env
, ctx
, ASE_MT
);
3016 gen_helper_mfc0_tccontext(arg
);
3020 check_insn(env
, ctx
, ASE_MT
);
3021 gen_helper_mfc0_tcschedule(arg
);
3025 check_insn(env
, ctx
, ASE_MT
);
3026 gen_helper_mfc0_tcschefback(arg
);
3036 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
3037 tcg_gen_ext32s_tl(arg
, arg
);
3047 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
3048 tcg_gen_ext32s_tl(arg
, arg
);
3052 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3053 rn
= "ContextConfig";
3062 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
3066 check_insn(env
, ctx
, ISA_MIPS32R2
);
3067 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
3077 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
3081 check_insn(env
, ctx
, ISA_MIPS32R2
);
3082 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3086 check_insn(env
, ctx
, ISA_MIPS32R2
);
3087 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3091 check_insn(env
, ctx
, ISA_MIPS32R2
);
3092 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3096 check_insn(env
, ctx
, ISA_MIPS32R2
);
3097 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3101 check_insn(env
, ctx
, ISA_MIPS32R2
);
3102 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3112 check_insn(env
, ctx
, ISA_MIPS32R2
);
3113 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3123 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3124 tcg_gen_ext32s_tl(arg
, arg
);
3134 /* Mark as an IO operation because we read the time. */
3137 gen_helper_mfc0_count(arg
);
3140 ctx
->bstate
= BS_STOP
;
3144 /* 6,7 are implementation dependent */
3152 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3153 tcg_gen_ext32s_tl(arg
, arg
);
3163 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3166 /* 6,7 are implementation dependent */
3174 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3178 check_insn(env
, ctx
, ISA_MIPS32R2
);
3179 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3183 check_insn(env
, ctx
, ISA_MIPS32R2
);
3184 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3188 check_insn(env
, ctx
, ISA_MIPS32R2
);
3189 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3199 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3209 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3210 tcg_gen_ext32s_tl(arg
, arg
);
3220 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3224 check_insn(env
, ctx
, ISA_MIPS32R2
);
3225 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3235 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3239 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3243 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3247 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3250 /* 4,5 are reserved */
3251 /* 6,7 are implementation dependent */
3253 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3257 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3267 gen_helper_mfc0_lladdr(arg
);
3277 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3287 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3297 #if defined(TARGET_MIPS64)
3298 check_insn(env
, ctx
, ISA_MIPS3
);
3299 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3300 tcg_gen_ext32s_tl(arg
, arg
);
3309 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3312 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3320 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3321 rn
= "'Diagnostic"; /* implementation dependent */
3326 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3330 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3331 rn
= "TraceControl";
3334 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3335 rn
= "TraceControl2";
3338 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3339 rn
= "UserTraceData";
3342 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3353 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3354 tcg_gen_ext32s_tl(arg
, arg
);
3364 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3365 rn
= "Performance0";
3368 // gen_helper_mfc0_performance1(arg);
3369 rn
= "Performance1";
3372 // gen_helper_mfc0_performance2(arg);
3373 rn
= "Performance2";
3376 // gen_helper_mfc0_performance3(arg);
3377 rn
= "Performance3";
3380 // gen_helper_mfc0_performance4(arg);
3381 rn
= "Performance4";
3384 // gen_helper_mfc0_performance5(arg);
3385 rn
= "Performance5";
3388 // gen_helper_mfc0_performance6(arg);
3389 rn
= "Performance6";
3392 // gen_helper_mfc0_performance7(arg);
3393 rn
= "Performance7";
3400 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3406 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3419 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3426 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3439 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3446 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3456 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3457 tcg_gen_ext32s_tl(arg
, arg
);
3468 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3478 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3482 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3483 generate_exception(ctx
, EXCP_RI
);
3486 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3488 const char *rn
= "invalid";
3491 check_insn(env
, ctx
, ISA_MIPS32
);
3500 gen_helper_mtc0_index(arg
);
3504 check_insn(env
, ctx
, ASE_MT
);
3505 gen_helper_mtc0_mvpcontrol(arg
);
3509 check_insn(env
, ctx
, ASE_MT
);
3514 check_insn(env
, ctx
, ASE_MT
);
3529 check_insn(env
, ctx
, ASE_MT
);
3530 gen_helper_mtc0_vpecontrol(arg
);
3534 check_insn(env
, ctx
, ASE_MT
);
3535 gen_helper_mtc0_vpeconf0(arg
);
3539 check_insn(env
, ctx
, ASE_MT
);
3540 gen_helper_mtc0_vpeconf1(arg
);
3544 check_insn(env
, ctx
, ASE_MT
);
3545 gen_helper_mtc0_yqmask(arg
);
3549 check_insn(env
, ctx
, ASE_MT
);
3550 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3554 check_insn(env
, ctx
, ASE_MT
);
3555 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3556 rn
= "VPEScheFBack";
3559 check_insn(env
, ctx
, ASE_MT
);
3560 gen_helper_mtc0_vpeopt(arg
);
3570 gen_helper_mtc0_entrylo0(arg
);
3574 check_insn(env
, ctx
, ASE_MT
);
3575 gen_helper_mtc0_tcstatus(arg
);
3579 check_insn(env
, ctx
, ASE_MT
);
3580 gen_helper_mtc0_tcbind(arg
);
3584 check_insn(env
, ctx
, ASE_MT
);
3585 gen_helper_mtc0_tcrestart(arg
);
3589 check_insn(env
, ctx
, ASE_MT
);
3590 gen_helper_mtc0_tchalt(arg
);
3594 check_insn(env
, ctx
, ASE_MT
);
3595 gen_helper_mtc0_tccontext(arg
);
3599 check_insn(env
, ctx
, ASE_MT
);
3600 gen_helper_mtc0_tcschedule(arg
);
3604 check_insn(env
, ctx
, ASE_MT
);
3605 gen_helper_mtc0_tcschefback(arg
);
3615 gen_helper_mtc0_entrylo1(arg
);
3625 gen_helper_mtc0_context(arg
);
3629 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3630 rn
= "ContextConfig";
3639 gen_helper_mtc0_pagemask(arg
);
3643 check_insn(env
, ctx
, ISA_MIPS32R2
);
3644 gen_helper_mtc0_pagegrain(arg
);
3654 gen_helper_mtc0_wired(arg
);
3658 check_insn(env
, ctx
, ISA_MIPS32R2
);
3659 gen_helper_mtc0_srsconf0(arg
);
3663 check_insn(env
, ctx
, ISA_MIPS32R2
);
3664 gen_helper_mtc0_srsconf1(arg
);
3668 check_insn(env
, ctx
, ISA_MIPS32R2
);
3669 gen_helper_mtc0_srsconf2(arg
);
3673 check_insn(env
, ctx
, ISA_MIPS32R2
);
3674 gen_helper_mtc0_srsconf3(arg
);
3678 check_insn(env
, ctx
, ISA_MIPS32R2
);
3679 gen_helper_mtc0_srsconf4(arg
);
3689 check_insn(env
, ctx
, ISA_MIPS32R2
);
3690 gen_helper_mtc0_hwrena(arg
);
3704 gen_helper_mtc0_count(arg
);
3707 /* 6,7 are implementation dependent */
3715 gen_helper_mtc0_entryhi(arg
);
3725 gen_helper_mtc0_compare(arg
);
3728 /* 6,7 are implementation dependent */
3736 save_cpu_state(ctx
, 1);
3737 gen_helper_mtc0_status(arg
);
3738 /* BS_STOP isn't good enough here, hflags may have changed. */
3739 gen_save_pc(ctx
->pc
+ 4);
3740 ctx
->bstate
= BS_EXCP
;
3744 check_insn(env
, ctx
, ISA_MIPS32R2
);
3745 gen_helper_mtc0_intctl(arg
);
3746 /* Stop translation as we may have switched the execution mode */
3747 ctx
->bstate
= BS_STOP
;
3751 check_insn(env
, ctx
, ISA_MIPS32R2
);
3752 gen_helper_mtc0_srsctl(arg
);
3753 /* Stop translation as we may have switched the execution mode */
3754 ctx
->bstate
= BS_STOP
;
3758 check_insn(env
, ctx
, ISA_MIPS32R2
);
3759 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3760 /* Stop translation as we may have switched the execution mode */
3761 ctx
->bstate
= BS_STOP
;
3771 save_cpu_state(ctx
, 1);
3772 gen_helper_mtc0_cause(arg
);
3782 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
3796 check_insn(env
, ctx
, ISA_MIPS32R2
);
3797 gen_helper_mtc0_ebase(arg
);
3807 gen_helper_mtc0_config0(arg
);
3809 /* Stop translation as we may have switched the execution mode */
3810 ctx
->bstate
= BS_STOP
;
3813 /* ignored, read only */
3817 gen_helper_mtc0_config2(arg
);
3819 /* Stop translation as we may have switched the execution mode */
3820 ctx
->bstate
= BS_STOP
;
3823 /* ignored, read only */
3826 /* 4,5 are reserved */
3827 /* 6,7 are implementation dependent */
3837 rn
= "Invalid config selector";
3854 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
3864 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
3874 #if defined(TARGET_MIPS64)
3875 check_insn(env
, ctx
, ISA_MIPS3
);
3876 gen_helper_mtc0_xcontext(arg
);
3885 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3888 gen_helper_mtc0_framemask(arg
);
3897 rn
= "Diagnostic"; /* implementation dependent */
3902 gen_helper_mtc0_debug(arg
); /* EJTAG support */
3903 /* BS_STOP isn't good enough here, hflags may have changed. */
3904 gen_save_pc(ctx
->pc
+ 4);
3905 ctx
->bstate
= BS_EXCP
;
3909 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
3910 rn
= "TraceControl";
3911 /* Stop translation as we may have switched the execution mode */
3912 ctx
->bstate
= BS_STOP
;
3915 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
3916 rn
= "TraceControl2";
3917 /* Stop translation as we may have switched the execution mode */
3918 ctx
->bstate
= BS_STOP
;
3921 /* Stop translation as we may have switched the execution mode */
3922 ctx
->bstate
= BS_STOP
;
3923 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
3924 rn
= "UserTraceData";
3925 /* Stop translation as we may have switched the execution mode */
3926 ctx
->bstate
= BS_STOP
;
3929 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
3930 /* Stop translation as we may have switched the execution mode */
3931 ctx
->bstate
= BS_STOP
;
3942 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
3952 gen_helper_mtc0_performance0(arg
);
3953 rn
= "Performance0";
3956 // gen_helper_mtc0_performance1(arg);
3957 rn
= "Performance1";
3960 // gen_helper_mtc0_performance2(arg);
3961 rn
= "Performance2";
3964 // gen_helper_mtc0_performance3(arg);
3965 rn
= "Performance3";
3968 // gen_helper_mtc0_performance4(arg);
3969 rn
= "Performance4";
3972 // gen_helper_mtc0_performance5(arg);
3973 rn
= "Performance5";
3976 // gen_helper_mtc0_performance6(arg);
3977 rn
= "Performance6";
3980 // gen_helper_mtc0_performance7(arg);
3981 rn
= "Performance7";
4007 gen_helper_mtc0_taglo(arg
);
4014 gen_helper_mtc0_datalo(arg
);
4027 gen_helper_mtc0_taghi(arg
);
4034 gen_helper_mtc0_datahi(arg
);
4045 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
4056 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4062 /* Stop translation as we may have switched the execution mode */
4063 ctx
->bstate
= BS_STOP
;
4068 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4069 /* For simplicity assume that all writes can cause interrupts. */
4072 ctx
->bstate
= BS_STOP
;
4077 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4078 generate_exception(ctx
, EXCP_RI
);
4081 #if defined(TARGET_MIPS64)
4082 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4084 const char *rn
= "invalid";
4087 check_insn(env
, ctx
, ISA_MIPS64
);
4093 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4097 check_insn(env
, ctx
, ASE_MT
);
4098 gen_helper_mfc0_mvpcontrol(arg
);
4102 check_insn(env
, ctx
, ASE_MT
);
4103 gen_helper_mfc0_mvpconf0(arg
);
4107 check_insn(env
, ctx
, ASE_MT
);
4108 gen_helper_mfc0_mvpconf1(arg
);
4118 gen_helper_mfc0_random(arg
);
4122 check_insn(env
, ctx
, ASE_MT
);
4123 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4127 check_insn(env
, ctx
, ASE_MT
);
4128 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4132 check_insn(env
, ctx
, ASE_MT
);
4133 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4137 check_insn(env
, ctx
, ASE_MT
);
4138 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4142 check_insn(env
, ctx
, ASE_MT
);
4143 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4147 check_insn(env
, ctx
, ASE_MT
);
4148 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4149 rn
= "VPEScheFBack";
4152 check_insn(env
, ctx
, ASE_MT
);
4153 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4163 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4167 check_insn(env
, ctx
, ASE_MT
);
4168 gen_helper_mfc0_tcstatus(arg
);
4172 check_insn(env
, ctx
, ASE_MT
);
4173 gen_helper_mfc0_tcbind(arg
);
4177 check_insn(env
, ctx
, ASE_MT
);
4178 gen_helper_dmfc0_tcrestart(arg
);
4182 check_insn(env
, ctx
, ASE_MT
);
4183 gen_helper_dmfc0_tchalt(arg
);
4187 check_insn(env
, ctx
, ASE_MT
);
4188 gen_helper_dmfc0_tccontext(arg
);
4192 check_insn(env
, ctx
, ASE_MT
);
4193 gen_helper_dmfc0_tcschedule(arg
);
4197 check_insn(env
, ctx
, ASE_MT
);
4198 gen_helper_dmfc0_tcschefback(arg
);
4208 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4218 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4222 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4223 rn
= "ContextConfig";
4232 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4236 check_insn(env
, ctx
, ISA_MIPS32R2
);
4237 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4247 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4251 check_insn(env
, ctx
, ISA_MIPS32R2
);
4252 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4256 check_insn(env
, ctx
, ISA_MIPS32R2
);
4257 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4261 check_insn(env
, ctx
, ISA_MIPS32R2
);
4262 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4266 check_insn(env
, ctx
, ISA_MIPS32R2
);
4267 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4271 check_insn(env
, ctx
, ISA_MIPS32R2
);
4272 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4282 check_insn(env
, ctx
, ISA_MIPS32R2
);
4283 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4293 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4303 /* Mark as an IO operation because we read the time. */
4306 gen_helper_mfc0_count(arg
);
4309 ctx
->bstate
= BS_STOP
;
4313 /* 6,7 are implementation dependent */
4321 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4331 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4334 /* 6,7 are implementation dependent */
4342 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4346 check_insn(env
, ctx
, ISA_MIPS32R2
);
4347 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4351 check_insn(env
, ctx
, ISA_MIPS32R2
);
4352 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4356 check_insn(env
, ctx
, ISA_MIPS32R2
);
4357 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4367 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4377 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4387 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4391 check_insn(env
, ctx
, ISA_MIPS32R2
);
4392 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4402 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4406 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4410 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4414 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4417 /* 6,7 are implementation dependent */
4419 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4423 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4433 gen_helper_dmfc0_lladdr(arg
);
4443 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4453 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4463 check_insn(env
, ctx
, ISA_MIPS3
);
4464 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4472 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4475 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4483 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4484 rn
= "'Diagnostic"; /* implementation dependent */
4489 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4493 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4494 rn
= "TraceControl";
4497 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4498 rn
= "TraceControl2";
4501 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4502 rn
= "UserTraceData";
4505 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4516 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4526 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4527 rn
= "Performance0";
4530 // gen_helper_dmfc0_performance1(arg);
4531 rn
= "Performance1";
4534 // gen_helper_dmfc0_performance2(arg);
4535 rn
= "Performance2";
4538 // gen_helper_dmfc0_performance3(arg);
4539 rn
= "Performance3";
4542 // gen_helper_dmfc0_performance4(arg);
4543 rn
= "Performance4";
4546 // gen_helper_dmfc0_performance5(arg);
4547 rn
= "Performance5";
4550 // gen_helper_dmfc0_performance6(arg);
4551 rn
= "Performance6";
4554 // gen_helper_dmfc0_performance7(arg);
4555 rn
= "Performance7";
4562 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4569 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4582 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4589 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4602 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4609 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4619 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4630 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4640 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4644 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4645 generate_exception(ctx
, EXCP_RI
);
4648 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4650 const char *rn
= "invalid";
4653 check_insn(env
, ctx
, ISA_MIPS64
);
4662 gen_helper_mtc0_index(arg
);
4666 check_insn(env
, ctx
, ASE_MT
);
4667 gen_helper_mtc0_mvpcontrol(arg
);
4671 check_insn(env
, ctx
, ASE_MT
);
4676 check_insn(env
, ctx
, ASE_MT
);
4691 check_insn(env
, ctx
, ASE_MT
);
4692 gen_helper_mtc0_vpecontrol(arg
);
4696 check_insn(env
, ctx
, ASE_MT
);
4697 gen_helper_mtc0_vpeconf0(arg
);
4701 check_insn(env
, ctx
, ASE_MT
);
4702 gen_helper_mtc0_vpeconf1(arg
);
4706 check_insn(env
, ctx
, ASE_MT
);
4707 gen_helper_mtc0_yqmask(arg
);
4711 check_insn(env
, ctx
, ASE_MT
);
4712 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4716 check_insn(env
, ctx
, ASE_MT
);
4717 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4718 rn
= "VPEScheFBack";
4721 check_insn(env
, ctx
, ASE_MT
);
4722 gen_helper_mtc0_vpeopt(arg
);
4732 gen_helper_mtc0_entrylo0(arg
);
4736 check_insn(env
, ctx
, ASE_MT
);
4737 gen_helper_mtc0_tcstatus(arg
);
4741 check_insn(env
, ctx
, ASE_MT
);
4742 gen_helper_mtc0_tcbind(arg
);
4746 check_insn(env
, ctx
, ASE_MT
);
4747 gen_helper_mtc0_tcrestart(arg
);
4751 check_insn(env
, ctx
, ASE_MT
);
4752 gen_helper_mtc0_tchalt(arg
);
4756 check_insn(env
, ctx
, ASE_MT
);
4757 gen_helper_mtc0_tccontext(arg
);
4761 check_insn(env
, ctx
, ASE_MT
);
4762 gen_helper_mtc0_tcschedule(arg
);
4766 check_insn(env
, ctx
, ASE_MT
);
4767 gen_helper_mtc0_tcschefback(arg
);
4777 gen_helper_mtc0_entrylo1(arg
);
4787 gen_helper_mtc0_context(arg
);
4791 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
4792 rn
= "ContextConfig";
4801 gen_helper_mtc0_pagemask(arg
);
4805 check_insn(env
, ctx
, ISA_MIPS32R2
);
4806 gen_helper_mtc0_pagegrain(arg
);
4816 gen_helper_mtc0_wired(arg
);
4820 check_insn(env
, ctx
, ISA_MIPS32R2
);
4821 gen_helper_mtc0_srsconf0(arg
);
4825 check_insn(env
, ctx
, ISA_MIPS32R2
);
4826 gen_helper_mtc0_srsconf1(arg
);
4830 check_insn(env
, ctx
, ISA_MIPS32R2
);
4831 gen_helper_mtc0_srsconf2(arg
);
4835 check_insn(env
, ctx
, ISA_MIPS32R2
);
4836 gen_helper_mtc0_srsconf3(arg
);
4840 check_insn(env
, ctx
, ISA_MIPS32R2
);
4841 gen_helper_mtc0_srsconf4(arg
);
4851 check_insn(env
, ctx
, ISA_MIPS32R2
);
4852 gen_helper_mtc0_hwrena(arg
);
4866 gen_helper_mtc0_count(arg
);
4869 /* 6,7 are implementation dependent */
4873 /* Stop translation as we may have switched the execution mode */
4874 ctx
->bstate
= BS_STOP
;
4879 gen_helper_mtc0_entryhi(arg
);
4889 gen_helper_mtc0_compare(arg
);
4892 /* 6,7 are implementation dependent */
4896 /* Stop translation as we may have switched the execution mode */
4897 ctx
->bstate
= BS_STOP
;
4902 save_cpu_state(ctx
, 1);
4903 gen_helper_mtc0_status(arg
);
4904 /* BS_STOP isn't good enough here, hflags may have changed. */
4905 gen_save_pc(ctx
->pc
+ 4);
4906 ctx
->bstate
= BS_EXCP
;
4910 check_insn(env
, ctx
, ISA_MIPS32R2
);
4911 gen_helper_mtc0_intctl(arg
);
4912 /* Stop translation as we may have switched the execution mode */
4913 ctx
->bstate
= BS_STOP
;
4917 check_insn(env
, ctx
, ISA_MIPS32R2
);
4918 gen_helper_mtc0_srsctl(arg
);
4919 /* Stop translation as we may have switched the execution mode */
4920 ctx
->bstate
= BS_STOP
;
4924 check_insn(env
, ctx
, ISA_MIPS32R2
);
4925 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4926 /* Stop translation as we may have switched the execution mode */
4927 ctx
->bstate
= BS_STOP
;
4937 save_cpu_state(ctx
, 1);
4938 gen_helper_mtc0_cause(arg
);
4948 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4962 check_insn(env
, ctx
, ISA_MIPS32R2
);
4963 gen_helper_mtc0_ebase(arg
);
4973 gen_helper_mtc0_config0(arg
);
4975 /* Stop translation as we may have switched the execution mode */
4976 ctx
->bstate
= BS_STOP
;
4979 /* ignored, read only */
4983 gen_helper_mtc0_config2(arg
);
4985 /* Stop translation as we may have switched the execution mode */
4986 ctx
->bstate
= BS_STOP
;
4992 /* 6,7 are implementation dependent */
4994 rn
= "Invalid config selector";
5011 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
5021 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
5031 check_insn(env
, ctx
, ISA_MIPS3
);
5032 gen_helper_mtc0_xcontext(arg
);
5040 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5043 gen_helper_mtc0_framemask(arg
);
5052 rn
= "Diagnostic"; /* implementation dependent */
5057 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5058 /* BS_STOP isn't good enough here, hflags may have changed. */
5059 gen_save_pc(ctx
->pc
+ 4);
5060 ctx
->bstate
= BS_EXCP
;
5064 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5065 /* Stop translation as we may have switched the execution mode */
5066 ctx
->bstate
= BS_STOP
;
5067 rn
= "TraceControl";
5070 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5071 /* Stop translation as we may have switched the execution mode */
5072 ctx
->bstate
= BS_STOP
;
5073 rn
= "TraceControl2";
5076 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5077 /* Stop translation as we may have switched the execution mode */
5078 ctx
->bstate
= BS_STOP
;
5079 rn
= "UserTraceData";
5082 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5083 /* Stop translation as we may have switched the execution mode */
5084 ctx
->bstate
= BS_STOP
;
5095 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5105 gen_helper_mtc0_performance0(arg
);
5106 rn
= "Performance0";
5109 // gen_helper_mtc0_performance1(arg);
5110 rn
= "Performance1";
5113 // gen_helper_mtc0_performance2(arg);
5114 rn
= "Performance2";
5117 // gen_helper_mtc0_performance3(arg);
5118 rn
= "Performance3";
5121 // gen_helper_mtc0_performance4(arg);
5122 rn
= "Performance4";
5125 // gen_helper_mtc0_performance5(arg);
5126 rn
= "Performance5";
5129 // gen_helper_mtc0_performance6(arg);
5130 rn
= "Performance6";
5133 // gen_helper_mtc0_performance7(arg);
5134 rn
= "Performance7";
5160 gen_helper_mtc0_taglo(arg
);
5167 gen_helper_mtc0_datalo(arg
);
5180 gen_helper_mtc0_taghi(arg
);
5187 gen_helper_mtc0_datahi(arg
);
5198 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5209 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5215 /* Stop translation as we may have switched the execution mode */
5216 ctx
->bstate
= BS_STOP
;
5221 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5222 /* For simplicity assume that all writes can cause interrupts. */
5225 ctx
->bstate
= BS_STOP
;
5230 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5231 generate_exception(ctx
, EXCP_RI
);
5233 #endif /* TARGET_MIPS64 */
5235 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5236 int u
, int sel
, int h
)
5238 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5239 TCGv t0
= tcg_temp_local_new();
5241 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5242 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5243 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5244 tcg_gen_movi_tl(t0
, -1);
5245 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5246 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5247 tcg_gen_movi_tl(t0
, -1);
5253 gen_helper_mftc0_tcstatus(t0
);
5256 gen_helper_mftc0_tcbind(t0
);
5259 gen_helper_mftc0_tcrestart(t0
);
5262 gen_helper_mftc0_tchalt(t0
);
5265 gen_helper_mftc0_tccontext(t0
);
5268 gen_helper_mftc0_tcschedule(t0
);
5271 gen_helper_mftc0_tcschefback(t0
);
5274 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5281 gen_helper_mftc0_entryhi(t0
);
5284 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5290 gen_helper_mftc0_status(t0
);
5293 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5299 gen_helper_mftc0_debug(t0
);
5302 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5307 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5309 } else switch (sel
) {
5310 /* GPR registers. */
5312 gen_helper_1i(mftgpr
, t0
, rt
);
5314 /* Auxiliary CPU registers */
5318 gen_helper_1i(mftlo
, t0
, 0);
5321 gen_helper_1i(mfthi
, t0
, 0);
5324 gen_helper_1i(mftacx
, t0
, 0);
5327 gen_helper_1i(mftlo
, t0
, 1);
5330 gen_helper_1i(mfthi
, t0
, 1);
5333 gen_helper_1i(mftacx
, t0
, 1);
5336 gen_helper_1i(mftlo
, t0
, 2);
5339 gen_helper_1i(mfthi
, t0
, 2);
5342 gen_helper_1i(mftacx
, t0
, 2);
5345 gen_helper_1i(mftlo
, t0
, 3);
5348 gen_helper_1i(mfthi
, t0
, 3);
5351 gen_helper_1i(mftacx
, t0
, 3);
5354 gen_helper_mftdsp(t0
);
5360 /* Floating point (COP1). */
5362 /* XXX: For now we support only a single FPU context. */
5364 TCGv_i32 fp0
= tcg_temp_new_i32();
5366 gen_load_fpr32(fp0
, rt
);
5367 tcg_gen_ext_i32_tl(t0
, fp0
);
5368 tcg_temp_free_i32(fp0
);
5370 TCGv_i32 fp0
= tcg_temp_new_i32();
5372 gen_load_fpr32h(fp0
, rt
);
5373 tcg_gen_ext_i32_tl(t0
, fp0
);
5374 tcg_temp_free_i32(fp0
);
5378 /* XXX: For now we support only a single FPU context. */
5379 gen_helper_1i(cfc1
, t0
, rt
);
5381 /* COP2: Not implemented. */
5388 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5389 gen_store_gpr(t0
, rd
);
5395 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5396 generate_exception(ctx
, EXCP_RI
);
5399 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5400 int u
, int sel
, int h
)
5402 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5403 TCGv t0
= tcg_temp_local_new();
5405 gen_load_gpr(t0
, rt
);
5406 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5407 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5408 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5410 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5411 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5418 gen_helper_mttc0_tcstatus(t0
);
5421 gen_helper_mttc0_tcbind(t0
);
5424 gen_helper_mttc0_tcrestart(t0
);
5427 gen_helper_mttc0_tchalt(t0
);
5430 gen_helper_mttc0_tccontext(t0
);
5433 gen_helper_mttc0_tcschedule(t0
);
5436 gen_helper_mttc0_tcschefback(t0
);
5439 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5446 gen_helper_mttc0_entryhi(t0
);
5449 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5455 gen_helper_mttc0_status(t0
);
5458 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5464 gen_helper_mttc0_debug(t0
);
5467 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5472 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5474 } else switch (sel
) {
5475 /* GPR registers. */
5477 gen_helper_1i(mttgpr
, t0
, rd
);
5479 /* Auxiliary CPU registers */
5483 gen_helper_1i(mttlo
, t0
, 0);
5486 gen_helper_1i(mtthi
, t0
, 0);
5489 gen_helper_1i(mttacx
, t0
, 0);
5492 gen_helper_1i(mttlo
, t0
, 1);
5495 gen_helper_1i(mtthi
, t0
, 1);
5498 gen_helper_1i(mttacx
, t0
, 1);
5501 gen_helper_1i(mttlo
, t0
, 2);
5504 gen_helper_1i(mtthi
, t0
, 2);
5507 gen_helper_1i(mttacx
, t0
, 2);
5510 gen_helper_1i(mttlo
, t0
, 3);
5513 gen_helper_1i(mtthi
, t0
, 3);
5516 gen_helper_1i(mttacx
, t0
, 3);
5519 gen_helper_mttdsp(t0
);
5525 /* Floating point (COP1). */
5527 /* XXX: For now we support only a single FPU context. */
5529 TCGv_i32 fp0
= tcg_temp_new_i32();
5531 tcg_gen_trunc_tl_i32(fp0
, t0
);
5532 gen_store_fpr32(fp0
, rd
);
5533 tcg_temp_free_i32(fp0
);
5535 TCGv_i32 fp0
= tcg_temp_new_i32();
5537 tcg_gen_trunc_tl_i32(fp0
, t0
);
5538 gen_store_fpr32h(fp0
, rd
);
5539 tcg_temp_free_i32(fp0
);
5543 /* XXX: For now we support only a single FPU context. */
5544 gen_helper_1i(ctc1
, t0
, rd
);
5546 /* COP2: Not implemented. */
5553 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5559 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5560 generate_exception(ctx
, EXCP_RI
);
5563 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5565 const char *opn
= "ldst";
5573 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5578 TCGv t0
= tcg_temp_new();
5580 gen_load_gpr(t0
, rt
);
5581 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5586 #if defined(TARGET_MIPS64)
5588 check_insn(env
, ctx
, ISA_MIPS3
);
5593 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5597 check_insn(env
, ctx
, ISA_MIPS3
);
5599 TCGv t0
= tcg_temp_new();
5601 gen_load_gpr(t0
, rt
);
5602 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5609 check_insn(env
, ctx
, ASE_MT
);
5614 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5615 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5619 check_insn(env
, ctx
, ASE_MT
);
5620 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5621 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5626 if (!env
->tlb
->helper_tlbwi
)
5632 if (!env
->tlb
->helper_tlbwr
)
5638 if (!env
->tlb
->helper_tlbp
)
5644 if (!env
->tlb
->helper_tlbr
)
5650 check_insn(env
, ctx
, ISA_MIPS2
);
5652 ctx
->bstate
= BS_EXCP
;
5656 check_insn(env
, ctx
, ISA_MIPS32
);
5657 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5659 generate_exception(ctx
, EXCP_RI
);
5662 ctx
->bstate
= BS_EXCP
;
5667 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5668 /* If we get an exception, we want to restart at next instruction */
5670 save_cpu_state(ctx
, 1);
5673 ctx
->bstate
= BS_EXCP
;
5678 generate_exception(ctx
, EXCP_RI
);
5681 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5683 #endif /* !CONFIG_USER_ONLY */
5685 /* CP1 Branches (before delay slot) */
5686 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5687 int32_t cc
, int32_t offset
)
5689 target_ulong btarget
;
5690 const char *opn
= "cp1 cond branch";
5691 TCGv_i32 t0
= tcg_temp_new_i32();
5694 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5696 btarget
= ctx
->pc
+ 4 + offset
;
5700 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5701 tcg_gen_not_i32(t0
, t0
);
5702 tcg_gen_andi_i32(t0
, t0
, 1);
5703 tcg_gen_extu_i32_tl(bcond
, t0
);
5707 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5708 tcg_gen_not_i32(t0
, t0
);
5709 tcg_gen_andi_i32(t0
, t0
, 1);
5710 tcg_gen_extu_i32_tl(bcond
, t0
);
5714 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5715 tcg_gen_andi_i32(t0
, t0
, 1);
5716 tcg_gen_extu_i32_tl(bcond
, t0
);
5720 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5721 tcg_gen_andi_i32(t0
, t0
, 1);
5722 tcg_gen_extu_i32_tl(bcond
, t0
);
5725 ctx
->hflags
|= MIPS_HFLAG_BL
;
5729 TCGv_i32 t1
= tcg_temp_new_i32();
5730 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5731 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5732 tcg_gen_or_i32(t0
, t0
, t1
);
5733 tcg_temp_free_i32(t1
);
5734 tcg_gen_not_i32(t0
, t0
);
5735 tcg_gen_andi_i32(t0
, t0
, 1);
5736 tcg_gen_extu_i32_tl(bcond
, t0
);
5742 TCGv_i32 t1
= tcg_temp_new_i32();
5743 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5744 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5745 tcg_gen_or_i32(t0
, t0
, t1
);
5746 tcg_temp_free_i32(t1
);
5747 tcg_gen_andi_i32(t0
, t0
, 1);
5748 tcg_gen_extu_i32_tl(bcond
, t0
);
5754 TCGv_i32 t1
= tcg_temp_new_i32();
5755 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5756 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5757 tcg_gen_or_i32(t0
, t0
, t1
);
5758 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5759 tcg_gen_or_i32(t0
, t0
, t1
);
5760 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5761 tcg_gen_or_i32(t0
, t0
, t1
);
5762 tcg_temp_free_i32(t1
);
5763 tcg_gen_not_i32(t0
, t0
);
5764 tcg_gen_andi_i32(t0
, t0
, 1);
5765 tcg_gen_extu_i32_tl(bcond
, t0
);
5771 TCGv_i32 t1
= tcg_temp_new_i32();
5772 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5773 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5774 tcg_gen_or_i32(t0
, t0
, t1
);
5775 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5776 tcg_gen_or_i32(t0
, t0
, t1
);
5777 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5778 tcg_gen_or_i32(t0
, t0
, t1
);
5779 tcg_temp_free_i32(t1
);
5780 tcg_gen_andi_i32(t0
, t0
, 1);
5781 tcg_gen_extu_i32_tl(bcond
, t0
);
5785 ctx
->hflags
|= MIPS_HFLAG_BC
;
5789 generate_exception (ctx
, EXCP_RI
);
5792 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5793 ctx
->hflags
, btarget
);
5794 ctx
->btarget
= btarget
;
5797 tcg_temp_free_i32(t0
);
5800 /* Coprocessor 1 (FPU) */
5802 #define FOP(func, fmt) (((fmt) << 21) | (func))
5804 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5806 const char *opn
= "cp1 move";
5807 TCGv t0
= tcg_temp_new();
5812 TCGv_i32 fp0
= tcg_temp_new_i32();
5814 gen_load_fpr32(fp0
, fs
);
5815 tcg_gen_ext_i32_tl(t0
, fp0
);
5816 tcg_temp_free_i32(fp0
);
5818 gen_store_gpr(t0
, rt
);
5822 gen_load_gpr(t0
, rt
);
5824 TCGv_i32 fp0
= tcg_temp_new_i32();
5826 tcg_gen_trunc_tl_i32(fp0
, t0
);
5827 gen_store_fpr32(fp0
, fs
);
5828 tcg_temp_free_i32(fp0
);
5833 gen_helper_1i(cfc1
, t0
, fs
);
5834 gen_store_gpr(t0
, rt
);
5838 gen_load_gpr(t0
, rt
);
5839 gen_helper_1i(ctc1
, t0
, fs
);
5842 #if defined(TARGET_MIPS64)
5844 gen_load_fpr64(ctx
, t0
, fs
);
5845 gen_store_gpr(t0
, rt
);
5849 gen_load_gpr(t0
, rt
);
5850 gen_store_fpr64(ctx
, t0
, fs
);
5856 TCGv_i32 fp0
= tcg_temp_new_i32();
5858 gen_load_fpr32h(fp0
, fs
);
5859 tcg_gen_ext_i32_tl(t0
, fp0
);
5860 tcg_temp_free_i32(fp0
);
5862 gen_store_gpr(t0
, rt
);
5866 gen_load_gpr(t0
, rt
);
5868 TCGv_i32 fp0
= tcg_temp_new_i32();
5870 tcg_gen_trunc_tl_i32(fp0
, t0
);
5871 gen_store_fpr32h(fp0
, fs
);
5872 tcg_temp_free_i32(fp0
);
5878 generate_exception (ctx
, EXCP_RI
);
5881 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5887 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5903 l1
= gen_new_label();
5904 t0
= tcg_temp_new_i32();
5905 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5906 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5907 tcg_temp_free_i32(t0
);
5909 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
5911 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
5916 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5919 TCGv_i32 t0
= tcg_temp_new_i32();
5920 int l1
= gen_new_label();
5927 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5928 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5929 gen_load_fpr32(t0
, fs
);
5930 gen_store_fpr32(t0
, fd
);
5932 tcg_temp_free_i32(t0
);
5935 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5938 TCGv_i32 t0
= tcg_temp_new_i32();
5940 int l1
= gen_new_label();
5947 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5948 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5949 tcg_temp_free_i32(t0
);
5950 fp0
= tcg_temp_new_i64();
5951 gen_load_fpr64(ctx
, fp0
, fs
);
5952 gen_store_fpr64(ctx
, fp0
, fd
);
5953 tcg_temp_free_i64(fp0
);
5957 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5960 TCGv_i32 t0
= tcg_temp_new_i32();
5961 int l1
= gen_new_label();
5962 int l2
= gen_new_label();
5969 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5970 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5971 gen_load_fpr32(t0
, fs
);
5972 gen_store_fpr32(t0
, fd
);
5975 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
5976 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
5977 gen_load_fpr32h(t0
, fs
);
5978 gen_store_fpr32h(t0
, fd
);
5979 tcg_temp_free_i32(t0
);
5984 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5985 int ft
, int fs
, int fd
, int cc
)
5987 const char *opn
= "farith";
5988 const char *condnames
[] = {
6006 const char *condnames_abs
[] = {
6024 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6025 uint32_t func
= ctx
->opcode
& 0x3f;
6027 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
6030 TCGv_i32 fp0
= tcg_temp_new_i32();
6031 TCGv_i32 fp1
= tcg_temp_new_i32();
6033 gen_load_fpr32(fp0
, fs
);
6034 gen_load_fpr32(fp1
, ft
);
6035 gen_helper_float_add_s(fp0
, fp0
, fp1
);
6036 tcg_temp_free_i32(fp1
);
6037 gen_store_fpr32(fp0
, fd
);
6038 tcg_temp_free_i32(fp0
);
6045 TCGv_i32 fp0
= tcg_temp_new_i32();
6046 TCGv_i32 fp1
= tcg_temp_new_i32();
6048 gen_load_fpr32(fp0
, fs
);
6049 gen_load_fpr32(fp1
, ft
);
6050 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6051 tcg_temp_free_i32(fp1
);
6052 gen_store_fpr32(fp0
, fd
);
6053 tcg_temp_free_i32(fp0
);
6060 TCGv_i32 fp0
= tcg_temp_new_i32();
6061 TCGv_i32 fp1
= tcg_temp_new_i32();
6063 gen_load_fpr32(fp0
, fs
);
6064 gen_load_fpr32(fp1
, ft
);
6065 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6066 tcg_temp_free_i32(fp1
);
6067 gen_store_fpr32(fp0
, fd
);
6068 tcg_temp_free_i32(fp0
);
6075 TCGv_i32 fp0
= tcg_temp_new_i32();
6076 TCGv_i32 fp1
= tcg_temp_new_i32();
6078 gen_load_fpr32(fp0
, fs
);
6079 gen_load_fpr32(fp1
, ft
);
6080 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6081 tcg_temp_free_i32(fp1
);
6082 gen_store_fpr32(fp0
, fd
);
6083 tcg_temp_free_i32(fp0
);
6090 TCGv_i32 fp0
= tcg_temp_new_i32();
6092 gen_load_fpr32(fp0
, fs
);
6093 gen_helper_float_sqrt_s(fp0
, fp0
);
6094 gen_store_fpr32(fp0
, fd
);
6095 tcg_temp_free_i32(fp0
);
6101 TCGv_i32 fp0
= tcg_temp_new_i32();
6103 gen_load_fpr32(fp0
, fs
);
6104 gen_helper_float_abs_s(fp0
, fp0
);
6105 gen_store_fpr32(fp0
, fd
);
6106 tcg_temp_free_i32(fp0
);
6112 TCGv_i32 fp0
= tcg_temp_new_i32();
6114 gen_load_fpr32(fp0
, fs
);
6115 gen_store_fpr32(fp0
, fd
);
6116 tcg_temp_free_i32(fp0
);
6122 TCGv_i32 fp0
= tcg_temp_new_i32();
6124 gen_load_fpr32(fp0
, fs
);
6125 gen_helper_float_chs_s(fp0
, fp0
);
6126 gen_store_fpr32(fp0
, fd
);
6127 tcg_temp_free_i32(fp0
);
6132 check_cp1_64bitmode(ctx
);
6134 TCGv_i32 fp32
= tcg_temp_new_i32();
6135 TCGv_i64 fp64
= tcg_temp_new_i64();
6137 gen_load_fpr32(fp32
, fs
);
6138 gen_helper_float_roundl_s(fp64
, fp32
);
6139 tcg_temp_free_i32(fp32
);
6140 gen_store_fpr64(ctx
, fp64
, fd
);
6141 tcg_temp_free_i64(fp64
);
6146 check_cp1_64bitmode(ctx
);
6148 TCGv_i32 fp32
= tcg_temp_new_i32();
6149 TCGv_i64 fp64
= tcg_temp_new_i64();
6151 gen_load_fpr32(fp32
, fs
);
6152 gen_helper_float_truncl_s(fp64
, fp32
);
6153 tcg_temp_free_i32(fp32
);
6154 gen_store_fpr64(ctx
, fp64
, fd
);
6155 tcg_temp_free_i64(fp64
);
6160 check_cp1_64bitmode(ctx
);
6162 TCGv_i32 fp32
= tcg_temp_new_i32();
6163 TCGv_i64 fp64
= tcg_temp_new_i64();
6165 gen_load_fpr32(fp32
, fs
);
6166 gen_helper_float_ceill_s(fp64
, fp32
);
6167 tcg_temp_free_i32(fp32
);
6168 gen_store_fpr64(ctx
, fp64
, fd
);
6169 tcg_temp_free_i64(fp64
);
6174 check_cp1_64bitmode(ctx
);
6176 TCGv_i32 fp32
= tcg_temp_new_i32();
6177 TCGv_i64 fp64
= tcg_temp_new_i64();
6179 gen_load_fpr32(fp32
, fs
);
6180 gen_helper_float_floorl_s(fp64
, fp32
);
6181 tcg_temp_free_i32(fp32
);
6182 gen_store_fpr64(ctx
, fp64
, fd
);
6183 tcg_temp_free_i64(fp64
);
6189 TCGv_i32 fp0
= tcg_temp_new_i32();
6191 gen_load_fpr32(fp0
, fs
);
6192 gen_helper_float_roundw_s(fp0
, fp0
);
6193 gen_store_fpr32(fp0
, fd
);
6194 tcg_temp_free_i32(fp0
);
6200 TCGv_i32 fp0
= tcg_temp_new_i32();
6202 gen_load_fpr32(fp0
, fs
);
6203 gen_helper_float_truncw_s(fp0
, fp0
);
6204 gen_store_fpr32(fp0
, fd
);
6205 tcg_temp_free_i32(fp0
);
6211 TCGv_i32 fp0
= tcg_temp_new_i32();
6213 gen_load_fpr32(fp0
, fs
);
6214 gen_helper_float_ceilw_s(fp0
, fp0
);
6215 gen_store_fpr32(fp0
, fd
);
6216 tcg_temp_free_i32(fp0
);
6222 TCGv_i32 fp0
= tcg_temp_new_i32();
6224 gen_load_fpr32(fp0
, fs
);
6225 gen_helper_float_floorw_s(fp0
, fp0
);
6226 gen_store_fpr32(fp0
, fd
);
6227 tcg_temp_free_i32(fp0
);
6232 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6237 int l1
= gen_new_label();
6241 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6243 fp0
= tcg_temp_new_i32();
6244 gen_load_fpr32(fp0
, fs
);
6245 gen_store_fpr32(fp0
, fd
);
6246 tcg_temp_free_i32(fp0
);
6253 int l1
= gen_new_label();
6257 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6258 fp0
= tcg_temp_new_i32();
6259 gen_load_fpr32(fp0
, fs
);
6260 gen_store_fpr32(fp0
, fd
);
6261 tcg_temp_free_i32(fp0
);
6270 TCGv_i32 fp0
= tcg_temp_new_i32();
6272 gen_load_fpr32(fp0
, fs
);
6273 gen_helper_float_recip_s(fp0
, fp0
);
6274 gen_store_fpr32(fp0
, fd
);
6275 tcg_temp_free_i32(fp0
);
6282 TCGv_i32 fp0
= tcg_temp_new_i32();
6284 gen_load_fpr32(fp0
, fs
);
6285 gen_helper_float_rsqrt_s(fp0
, fp0
);
6286 gen_store_fpr32(fp0
, fd
);
6287 tcg_temp_free_i32(fp0
);
6292 check_cp1_64bitmode(ctx
);
6294 TCGv_i32 fp0
= tcg_temp_new_i32();
6295 TCGv_i32 fp1
= tcg_temp_new_i32();
6297 gen_load_fpr32(fp0
, fs
);
6298 gen_load_fpr32(fp1
, fd
);
6299 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6300 tcg_temp_free_i32(fp1
);
6301 gen_store_fpr32(fp0
, fd
);
6302 tcg_temp_free_i32(fp0
);
6307 check_cp1_64bitmode(ctx
);
6309 TCGv_i32 fp0
= tcg_temp_new_i32();
6311 gen_load_fpr32(fp0
, fs
);
6312 gen_helper_float_recip1_s(fp0
, fp0
);
6313 gen_store_fpr32(fp0
, fd
);
6314 tcg_temp_free_i32(fp0
);
6319 check_cp1_64bitmode(ctx
);
6321 TCGv_i32 fp0
= tcg_temp_new_i32();
6323 gen_load_fpr32(fp0
, fs
);
6324 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6325 gen_store_fpr32(fp0
, fd
);
6326 tcg_temp_free_i32(fp0
);
6331 check_cp1_64bitmode(ctx
);
6333 TCGv_i32 fp0
= tcg_temp_new_i32();
6334 TCGv_i32 fp1
= tcg_temp_new_i32();
6336 gen_load_fpr32(fp0
, fs
);
6337 gen_load_fpr32(fp1
, ft
);
6338 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6339 tcg_temp_free_i32(fp1
);
6340 gen_store_fpr32(fp0
, fd
);
6341 tcg_temp_free_i32(fp0
);
6346 check_cp1_registers(ctx
, fd
);
6348 TCGv_i32 fp32
= tcg_temp_new_i32();
6349 TCGv_i64 fp64
= tcg_temp_new_i64();
6351 gen_load_fpr32(fp32
, fs
);
6352 gen_helper_float_cvtd_s(fp64
, fp32
);
6353 tcg_temp_free_i32(fp32
);
6354 gen_store_fpr64(ctx
, fp64
, fd
);
6355 tcg_temp_free_i64(fp64
);
6361 TCGv_i32 fp0
= tcg_temp_new_i32();
6363 gen_load_fpr32(fp0
, fs
);
6364 gen_helper_float_cvtw_s(fp0
, fp0
);
6365 gen_store_fpr32(fp0
, fd
);
6366 tcg_temp_free_i32(fp0
);
6371 check_cp1_64bitmode(ctx
);
6373 TCGv_i32 fp32
= tcg_temp_new_i32();
6374 TCGv_i64 fp64
= tcg_temp_new_i64();
6376 gen_load_fpr32(fp32
, fs
);
6377 gen_helper_float_cvtl_s(fp64
, fp32
);
6378 tcg_temp_free_i32(fp32
);
6379 gen_store_fpr64(ctx
, fp64
, fd
);
6380 tcg_temp_free_i64(fp64
);
6385 check_cp1_64bitmode(ctx
);
6387 TCGv_i64 fp64
= tcg_temp_new_i64();
6388 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6389 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6391 gen_load_fpr32(fp32_0
, fs
);
6392 gen_load_fpr32(fp32_1
, ft
);
6393 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6394 tcg_temp_free_i32(fp32_1
);
6395 tcg_temp_free_i32(fp32_0
);
6396 gen_store_fpr64(ctx
, fp64
, fd
);
6397 tcg_temp_free_i64(fp64
);
6418 TCGv_i32 fp0
= tcg_temp_new_i32();
6419 TCGv_i32 fp1
= tcg_temp_new_i32();
6421 gen_load_fpr32(fp0
, fs
);
6422 gen_load_fpr32(fp1
, ft
);
6423 if (ctx
->opcode
& (1 << 6)) {
6425 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6426 opn
= condnames_abs
[func
-48];
6428 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6429 opn
= condnames
[func
-48];
6431 tcg_temp_free_i32(fp0
);
6432 tcg_temp_free_i32(fp1
);
6436 check_cp1_registers(ctx
, fs
| ft
| fd
);
6438 TCGv_i64 fp0
= tcg_temp_new_i64();
6439 TCGv_i64 fp1
= tcg_temp_new_i64();
6441 gen_load_fpr64(ctx
, fp0
, fs
);
6442 gen_load_fpr64(ctx
, fp1
, ft
);
6443 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6444 tcg_temp_free_i64(fp1
);
6445 gen_store_fpr64(ctx
, fp0
, fd
);
6446 tcg_temp_free_i64(fp0
);
6452 check_cp1_registers(ctx
, fs
| ft
| fd
);
6454 TCGv_i64 fp0
= tcg_temp_new_i64();
6455 TCGv_i64 fp1
= tcg_temp_new_i64();
6457 gen_load_fpr64(ctx
, fp0
, fs
);
6458 gen_load_fpr64(ctx
, fp1
, ft
);
6459 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6460 tcg_temp_free_i64(fp1
);
6461 gen_store_fpr64(ctx
, fp0
, fd
);
6462 tcg_temp_free_i64(fp0
);
6468 check_cp1_registers(ctx
, fs
| ft
| fd
);
6470 TCGv_i64 fp0
= tcg_temp_new_i64();
6471 TCGv_i64 fp1
= tcg_temp_new_i64();
6473 gen_load_fpr64(ctx
, fp0
, fs
);
6474 gen_load_fpr64(ctx
, fp1
, ft
);
6475 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6476 tcg_temp_free_i64(fp1
);
6477 gen_store_fpr64(ctx
, fp0
, fd
);
6478 tcg_temp_free_i64(fp0
);
6484 check_cp1_registers(ctx
, fs
| ft
| fd
);
6486 TCGv_i64 fp0
= tcg_temp_new_i64();
6487 TCGv_i64 fp1
= tcg_temp_new_i64();
6489 gen_load_fpr64(ctx
, fp0
, fs
);
6490 gen_load_fpr64(ctx
, fp1
, ft
);
6491 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6492 tcg_temp_free_i64(fp1
);
6493 gen_store_fpr64(ctx
, fp0
, fd
);
6494 tcg_temp_free_i64(fp0
);
6500 check_cp1_registers(ctx
, fs
| fd
);
6502 TCGv_i64 fp0
= tcg_temp_new_i64();
6504 gen_load_fpr64(ctx
, fp0
, fs
);
6505 gen_helper_float_sqrt_d(fp0
, fp0
);
6506 gen_store_fpr64(ctx
, fp0
, fd
);
6507 tcg_temp_free_i64(fp0
);
6512 check_cp1_registers(ctx
, fs
| fd
);
6514 TCGv_i64 fp0
= tcg_temp_new_i64();
6516 gen_load_fpr64(ctx
, fp0
, fs
);
6517 gen_helper_float_abs_d(fp0
, fp0
);
6518 gen_store_fpr64(ctx
, fp0
, fd
);
6519 tcg_temp_free_i64(fp0
);
6524 check_cp1_registers(ctx
, fs
| fd
);
6526 TCGv_i64 fp0
= tcg_temp_new_i64();
6528 gen_load_fpr64(ctx
, fp0
, fs
);
6529 gen_store_fpr64(ctx
, fp0
, fd
);
6530 tcg_temp_free_i64(fp0
);
6535 check_cp1_registers(ctx
, fs
| fd
);
6537 TCGv_i64 fp0
= tcg_temp_new_i64();
6539 gen_load_fpr64(ctx
, fp0
, fs
);
6540 gen_helper_float_chs_d(fp0
, fp0
);
6541 gen_store_fpr64(ctx
, fp0
, fd
);
6542 tcg_temp_free_i64(fp0
);
6547 check_cp1_64bitmode(ctx
);
6549 TCGv_i64 fp0
= tcg_temp_new_i64();
6551 gen_load_fpr64(ctx
, fp0
, fs
);
6552 gen_helper_float_roundl_d(fp0
, fp0
);
6553 gen_store_fpr64(ctx
, fp0
, fd
);
6554 tcg_temp_free_i64(fp0
);
6559 check_cp1_64bitmode(ctx
);
6561 TCGv_i64 fp0
= tcg_temp_new_i64();
6563 gen_load_fpr64(ctx
, fp0
, fs
);
6564 gen_helper_float_truncl_d(fp0
, fp0
);
6565 gen_store_fpr64(ctx
, fp0
, fd
);
6566 tcg_temp_free_i64(fp0
);
6571 check_cp1_64bitmode(ctx
);
6573 TCGv_i64 fp0
= tcg_temp_new_i64();
6575 gen_load_fpr64(ctx
, fp0
, fs
);
6576 gen_helper_float_ceill_d(fp0
, fp0
);
6577 gen_store_fpr64(ctx
, fp0
, fd
);
6578 tcg_temp_free_i64(fp0
);
6583 check_cp1_64bitmode(ctx
);
6585 TCGv_i64 fp0
= tcg_temp_new_i64();
6587 gen_load_fpr64(ctx
, fp0
, fs
);
6588 gen_helper_float_floorl_d(fp0
, fp0
);
6589 gen_store_fpr64(ctx
, fp0
, fd
);
6590 tcg_temp_free_i64(fp0
);
6595 check_cp1_registers(ctx
, fs
);
6597 TCGv_i32 fp32
= tcg_temp_new_i32();
6598 TCGv_i64 fp64
= tcg_temp_new_i64();
6600 gen_load_fpr64(ctx
, fp64
, fs
);
6601 gen_helper_float_roundw_d(fp32
, fp64
);
6602 tcg_temp_free_i64(fp64
);
6603 gen_store_fpr32(fp32
, fd
);
6604 tcg_temp_free_i32(fp32
);
6609 check_cp1_registers(ctx
, fs
);
6611 TCGv_i32 fp32
= tcg_temp_new_i32();
6612 TCGv_i64 fp64
= tcg_temp_new_i64();
6614 gen_load_fpr64(ctx
, fp64
, fs
);
6615 gen_helper_float_truncw_d(fp32
, fp64
);
6616 tcg_temp_free_i64(fp64
);
6617 gen_store_fpr32(fp32
, fd
);
6618 tcg_temp_free_i32(fp32
);
6623 check_cp1_registers(ctx
, fs
);
6625 TCGv_i32 fp32
= tcg_temp_new_i32();
6626 TCGv_i64 fp64
= tcg_temp_new_i64();
6628 gen_load_fpr64(ctx
, fp64
, fs
);
6629 gen_helper_float_ceilw_d(fp32
, fp64
);
6630 tcg_temp_free_i64(fp64
);
6631 gen_store_fpr32(fp32
, fd
);
6632 tcg_temp_free_i32(fp32
);
6637 check_cp1_registers(ctx
, fs
);
6639 TCGv_i32 fp32
= tcg_temp_new_i32();
6640 TCGv_i64 fp64
= tcg_temp_new_i64();
6642 gen_load_fpr64(ctx
, fp64
, fs
);
6643 gen_helper_float_floorw_d(fp32
, fp64
);
6644 tcg_temp_free_i64(fp64
);
6645 gen_store_fpr32(fp32
, fd
);
6646 tcg_temp_free_i32(fp32
);
6651 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6656 int l1
= gen_new_label();
6660 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6662 fp0
= tcg_temp_new_i64();
6663 gen_load_fpr64(ctx
, fp0
, fs
);
6664 gen_store_fpr64(ctx
, fp0
, fd
);
6665 tcg_temp_free_i64(fp0
);
6672 int l1
= gen_new_label();
6676 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6677 fp0
= tcg_temp_new_i64();
6678 gen_load_fpr64(ctx
, fp0
, fs
);
6679 gen_store_fpr64(ctx
, fp0
, fd
);
6680 tcg_temp_free_i64(fp0
);
6687 check_cp1_64bitmode(ctx
);
6689 TCGv_i64 fp0
= tcg_temp_new_i64();
6691 gen_load_fpr64(ctx
, fp0
, fs
);
6692 gen_helper_float_recip_d(fp0
, fp0
);
6693 gen_store_fpr64(ctx
, fp0
, fd
);
6694 tcg_temp_free_i64(fp0
);
6699 check_cp1_64bitmode(ctx
);
6701 TCGv_i64 fp0
= tcg_temp_new_i64();
6703 gen_load_fpr64(ctx
, fp0
, fs
);
6704 gen_helper_float_rsqrt_d(fp0
, fp0
);
6705 gen_store_fpr64(ctx
, fp0
, fd
);
6706 tcg_temp_free_i64(fp0
);
6711 check_cp1_64bitmode(ctx
);
6713 TCGv_i64 fp0
= tcg_temp_new_i64();
6714 TCGv_i64 fp1
= tcg_temp_new_i64();
6716 gen_load_fpr64(ctx
, fp0
, fs
);
6717 gen_load_fpr64(ctx
, fp1
, ft
);
6718 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6719 tcg_temp_free_i64(fp1
);
6720 gen_store_fpr64(ctx
, fp0
, fd
);
6721 tcg_temp_free_i64(fp0
);
6726 check_cp1_64bitmode(ctx
);
6728 TCGv_i64 fp0
= tcg_temp_new_i64();
6730 gen_load_fpr64(ctx
, fp0
, fs
);
6731 gen_helper_float_recip1_d(fp0
, fp0
);
6732 gen_store_fpr64(ctx
, fp0
, fd
);
6733 tcg_temp_free_i64(fp0
);
6738 check_cp1_64bitmode(ctx
);
6740 TCGv_i64 fp0
= tcg_temp_new_i64();
6742 gen_load_fpr64(ctx
, fp0
, fs
);
6743 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6744 gen_store_fpr64(ctx
, fp0
, fd
);
6745 tcg_temp_free_i64(fp0
);
6750 check_cp1_64bitmode(ctx
);
6752 TCGv_i64 fp0
= tcg_temp_new_i64();
6753 TCGv_i64 fp1
= tcg_temp_new_i64();
6755 gen_load_fpr64(ctx
, fp0
, fs
);
6756 gen_load_fpr64(ctx
, fp1
, ft
);
6757 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6758 tcg_temp_free_i64(fp1
);
6759 gen_store_fpr64(ctx
, fp0
, fd
);
6760 tcg_temp_free_i64(fp0
);
6781 TCGv_i64 fp0
= tcg_temp_new_i64();
6782 TCGv_i64 fp1
= tcg_temp_new_i64();
6784 gen_load_fpr64(ctx
, fp0
, fs
);
6785 gen_load_fpr64(ctx
, fp1
, ft
);
6786 if (ctx
->opcode
& (1 << 6)) {
6788 check_cp1_registers(ctx
, fs
| ft
);
6789 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6790 opn
= condnames_abs
[func
-48];
6792 check_cp1_registers(ctx
, fs
| ft
);
6793 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6794 opn
= condnames
[func
-48];
6796 tcg_temp_free_i64(fp0
);
6797 tcg_temp_free_i64(fp1
);
6801 check_cp1_registers(ctx
, fs
);
6803 TCGv_i32 fp32
= tcg_temp_new_i32();
6804 TCGv_i64 fp64
= tcg_temp_new_i64();
6806 gen_load_fpr64(ctx
, fp64
, fs
);
6807 gen_helper_float_cvts_d(fp32
, fp64
);
6808 tcg_temp_free_i64(fp64
);
6809 gen_store_fpr32(fp32
, fd
);
6810 tcg_temp_free_i32(fp32
);
6815 check_cp1_registers(ctx
, fs
);
6817 TCGv_i32 fp32
= tcg_temp_new_i32();
6818 TCGv_i64 fp64
= tcg_temp_new_i64();
6820 gen_load_fpr64(ctx
, fp64
, fs
);
6821 gen_helper_float_cvtw_d(fp32
, fp64
);
6822 tcg_temp_free_i64(fp64
);
6823 gen_store_fpr32(fp32
, fd
);
6824 tcg_temp_free_i32(fp32
);
6829 check_cp1_64bitmode(ctx
);
6831 TCGv_i64 fp0
= tcg_temp_new_i64();
6833 gen_load_fpr64(ctx
, fp0
, fs
);
6834 gen_helper_float_cvtl_d(fp0
, fp0
);
6835 gen_store_fpr64(ctx
, fp0
, fd
);
6836 tcg_temp_free_i64(fp0
);
6842 TCGv_i32 fp0
= tcg_temp_new_i32();
6844 gen_load_fpr32(fp0
, fs
);
6845 gen_helper_float_cvts_w(fp0
, fp0
);
6846 gen_store_fpr32(fp0
, fd
);
6847 tcg_temp_free_i32(fp0
);
6852 check_cp1_registers(ctx
, fd
);
6854 TCGv_i32 fp32
= tcg_temp_new_i32();
6855 TCGv_i64 fp64
= tcg_temp_new_i64();
6857 gen_load_fpr32(fp32
, fs
);
6858 gen_helper_float_cvtd_w(fp64
, fp32
);
6859 tcg_temp_free_i32(fp32
);
6860 gen_store_fpr64(ctx
, fp64
, fd
);
6861 tcg_temp_free_i64(fp64
);
6866 check_cp1_64bitmode(ctx
);
6868 TCGv_i32 fp32
= tcg_temp_new_i32();
6869 TCGv_i64 fp64
= tcg_temp_new_i64();
6871 gen_load_fpr64(ctx
, fp64
, fs
);
6872 gen_helper_float_cvts_l(fp32
, fp64
);
6873 tcg_temp_free_i64(fp64
);
6874 gen_store_fpr32(fp32
, fd
);
6875 tcg_temp_free_i32(fp32
);
6880 check_cp1_64bitmode(ctx
);
6882 TCGv_i64 fp0
= tcg_temp_new_i64();
6884 gen_load_fpr64(ctx
, fp0
, fs
);
6885 gen_helper_float_cvtd_l(fp0
, fp0
);
6886 gen_store_fpr64(ctx
, fp0
, fd
);
6887 tcg_temp_free_i64(fp0
);
6892 check_cp1_64bitmode(ctx
);
6894 TCGv_i64 fp0
= tcg_temp_new_i64();
6896 gen_load_fpr64(ctx
, fp0
, fs
);
6897 gen_helper_float_cvtps_pw(fp0
, fp0
);
6898 gen_store_fpr64(ctx
, fp0
, fd
);
6899 tcg_temp_free_i64(fp0
);
6904 check_cp1_64bitmode(ctx
);
6906 TCGv_i64 fp0
= tcg_temp_new_i64();
6907 TCGv_i64 fp1
= tcg_temp_new_i64();
6909 gen_load_fpr64(ctx
, fp0
, fs
);
6910 gen_load_fpr64(ctx
, fp1
, ft
);
6911 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6912 tcg_temp_free_i64(fp1
);
6913 gen_store_fpr64(ctx
, fp0
, fd
);
6914 tcg_temp_free_i64(fp0
);
6919 check_cp1_64bitmode(ctx
);
6921 TCGv_i64 fp0
= tcg_temp_new_i64();
6922 TCGv_i64 fp1
= tcg_temp_new_i64();
6924 gen_load_fpr64(ctx
, fp0
, fs
);
6925 gen_load_fpr64(ctx
, fp1
, ft
);
6926 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6927 tcg_temp_free_i64(fp1
);
6928 gen_store_fpr64(ctx
, fp0
, fd
);
6929 tcg_temp_free_i64(fp0
);
6934 check_cp1_64bitmode(ctx
);
6936 TCGv_i64 fp0
= tcg_temp_new_i64();
6937 TCGv_i64 fp1
= tcg_temp_new_i64();
6939 gen_load_fpr64(ctx
, fp0
, fs
);
6940 gen_load_fpr64(ctx
, fp1
, ft
);
6941 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6942 tcg_temp_free_i64(fp1
);
6943 gen_store_fpr64(ctx
, fp0
, fd
);
6944 tcg_temp_free_i64(fp0
);
6949 check_cp1_64bitmode(ctx
);
6951 TCGv_i64 fp0
= tcg_temp_new_i64();
6953 gen_load_fpr64(ctx
, fp0
, fs
);
6954 gen_helper_float_abs_ps(fp0
, fp0
);
6955 gen_store_fpr64(ctx
, fp0
, fd
);
6956 tcg_temp_free_i64(fp0
);
6961 check_cp1_64bitmode(ctx
);
6963 TCGv_i64 fp0
= tcg_temp_new_i64();
6965 gen_load_fpr64(ctx
, fp0
, fs
);
6966 gen_store_fpr64(ctx
, fp0
, fd
);
6967 tcg_temp_free_i64(fp0
);
6972 check_cp1_64bitmode(ctx
);
6974 TCGv_i64 fp0
= tcg_temp_new_i64();
6976 gen_load_fpr64(ctx
, fp0
, fs
);
6977 gen_helper_float_chs_ps(fp0
, fp0
);
6978 gen_store_fpr64(ctx
, fp0
, fd
);
6979 tcg_temp_free_i64(fp0
);
6984 check_cp1_64bitmode(ctx
);
6985 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6989 check_cp1_64bitmode(ctx
);
6991 int l1
= gen_new_label();
6995 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6996 fp0
= tcg_temp_new_i64();
6997 gen_load_fpr64(ctx
, fp0
, fs
);
6998 gen_store_fpr64(ctx
, fp0
, fd
);
6999 tcg_temp_free_i64(fp0
);
7005 check_cp1_64bitmode(ctx
);
7007 int l1
= gen_new_label();
7011 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7012 fp0
= tcg_temp_new_i64();
7013 gen_load_fpr64(ctx
, fp0
, fs
);
7014 gen_store_fpr64(ctx
, fp0
, fd
);
7015 tcg_temp_free_i64(fp0
);
7022 check_cp1_64bitmode(ctx
);
7024 TCGv_i64 fp0
= tcg_temp_new_i64();
7025 TCGv_i64 fp1
= tcg_temp_new_i64();
7027 gen_load_fpr64(ctx
, fp0
, ft
);
7028 gen_load_fpr64(ctx
, fp1
, fs
);
7029 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
7030 tcg_temp_free_i64(fp1
);
7031 gen_store_fpr64(ctx
, fp0
, fd
);
7032 tcg_temp_free_i64(fp0
);
7037 check_cp1_64bitmode(ctx
);
7039 TCGv_i64 fp0
= tcg_temp_new_i64();
7040 TCGv_i64 fp1
= tcg_temp_new_i64();
7042 gen_load_fpr64(ctx
, fp0
, ft
);
7043 gen_load_fpr64(ctx
, fp1
, fs
);
7044 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7045 tcg_temp_free_i64(fp1
);
7046 gen_store_fpr64(ctx
, fp0
, fd
);
7047 tcg_temp_free_i64(fp0
);
7052 check_cp1_64bitmode(ctx
);
7054 TCGv_i64 fp0
= tcg_temp_new_i64();
7055 TCGv_i64 fp1
= tcg_temp_new_i64();
7057 gen_load_fpr64(ctx
, fp0
, fs
);
7058 gen_load_fpr64(ctx
, fp1
, fd
);
7059 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7060 tcg_temp_free_i64(fp1
);
7061 gen_store_fpr64(ctx
, fp0
, fd
);
7062 tcg_temp_free_i64(fp0
);
7067 check_cp1_64bitmode(ctx
);
7069 TCGv_i64 fp0
= tcg_temp_new_i64();
7071 gen_load_fpr64(ctx
, fp0
, fs
);
7072 gen_helper_float_recip1_ps(fp0
, fp0
);
7073 gen_store_fpr64(ctx
, fp0
, fd
);
7074 tcg_temp_free_i64(fp0
);
7079 check_cp1_64bitmode(ctx
);
7081 TCGv_i64 fp0
= tcg_temp_new_i64();
7083 gen_load_fpr64(ctx
, fp0
, fs
);
7084 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7085 gen_store_fpr64(ctx
, fp0
, fd
);
7086 tcg_temp_free_i64(fp0
);
7091 check_cp1_64bitmode(ctx
);
7093 TCGv_i64 fp0
= tcg_temp_new_i64();
7094 TCGv_i64 fp1
= tcg_temp_new_i64();
7096 gen_load_fpr64(ctx
, fp0
, fs
);
7097 gen_load_fpr64(ctx
, fp1
, ft
);
7098 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7099 tcg_temp_free_i64(fp1
);
7100 gen_store_fpr64(ctx
, fp0
, fd
);
7101 tcg_temp_free_i64(fp0
);
7106 check_cp1_64bitmode(ctx
);
7108 TCGv_i32 fp0
= tcg_temp_new_i32();
7110 gen_load_fpr32h(fp0
, fs
);
7111 gen_helper_float_cvts_pu(fp0
, fp0
);
7112 gen_store_fpr32(fp0
, fd
);
7113 tcg_temp_free_i32(fp0
);
7118 check_cp1_64bitmode(ctx
);
7120 TCGv_i64 fp0
= tcg_temp_new_i64();
7122 gen_load_fpr64(ctx
, fp0
, fs
);
7123 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7124 gen_store_fpr64(ctx
, fp0
, fd
);
7125 tcg_temp_free_i64(fp0
);
7130 check_cp1_64bitmode(ctx
);
7132 TCGv_i32 fp0
= tcg_temp_new_i32();
7134 gen_load_fpr32(fp0
, fs
);
7135 gen_helper_float_cvts_pl(fp0
, fp0
);
7136 gen_store_fpr32(fp0
, fd
);
7137 tcg_temp_free_i32(fp0
);
7142 check_cp1_64bitmode(ctx
);
7144 TCGv_i32 fp0
= tcg_temp_new_i32();
7145 TCGv_i32 fp1
= tcg_temp_new_i32();
7147 gen_load_fpr32(fp0
, fs
);
7148 gen_load_fpr32(fp1
, ft
);
7149 gen_store_fpr32h(fp0
, fd
);
7150 gen_store_fpr32(fp1
, fd
);
7151 tcg_temp_free_i32(fp0
);
7152 tcg_temp_free_i32(fp1
);
7157 check_cp1_64bitmode(ctx
);
7159 TCGv_i32 fp0
= tcg_temp_new_i32();
7160 TCGv_i32 fp1
= tcg_temp_new_i32();
7162 gen_load_fpr32(fp0
, fs
);
7163 gen_load_fpr32h(fp1
, ft
);
7164 gen_store_fpr32(fp1
, fd
);
7165 gen_store_fpr32h(fp0
, fd
);
7166 tcg_temp_free_i32(fp0
);
7167 tcg_temp_free_i32(fp1
);
7172 check_cp1_64bitmode(ctx
);
7174 TCGv_i32 fp0
= tcg_temp_new_i32();
7175 TCGv_i32 fp1
= tcg_temp_new_i32();
7177 gen_load_fpr32h(fp0
, fs
);
7178 gen_load_fpr32(fp1
, ft
);
7179 gen_store_fpr32(fp1
, fd
);
7180 gen_store_fpr32h(fp0
, fd
);
7181 tcg_temp_free_i32(fp0
);
7182 tcg_temp_free_i32(fp1
);
7187 check_cp1_64bitmode(ctx
);
7189 TCGv_i32 fp0
= tcg_temp_new_i32();
7190 TCGv_i32 fp1
= tcg_temp_new_i32();
7192 gen_load_fpr32h(fp0
, fs
);
7193 gen_load_fpr32h(fp1
, ft
);
7194 gen_store_fpr32(fp1
, fd
);
7195 gen_store_fpr32h(fp0
, fd
);
7196 tcg_temp_free_i32(fp0
);
7197 tcg_temp_free_i32(fp1
);
7217 check_cp1_64bitmode(ctx
);
7219 TCGv_i64 fp0
= tcg_temp_new_i64();
7220 TCGv_i64 fp1
= tcg_temp_new_i64();
7222 gen_load_fpr64(ctx
, fp0
, fs
);
7223 gen_load_fpr64(ctx
, fp1
, ft
);
7224 if (ctx
->opcode
& (1 << 6)) {
7225 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7226 opn
= condnames_abs
[func
-48];
7228 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7229 opn
= condnames
[func
-48];
7231 tcg_temp_free_i64(fp0
);
7232 tcg_temp_free_i64(fp1
);
7237 generate_exception (ctx
, EXCP_RI
);
7242 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7245 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7248 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7253 /* Coprocessor 3 (FPU) */
7254 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7255 int fd
, int fs
, int base
, int index
)
7257 const char *opn
= "extended float load/store";
7259 TCGv t0
= tcg_temp_new();
7262 gen_load_gpr(t0
, index
);
7263 } else if (index
== 0) {
7264 gen_load_gpr(t0
, base
);
7266 gen_load_gpr(t0
, index
);
7267 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7269 /* Don't do NOP if destination is zero: we must perform the actual
7271 save_cpu_state(ctx
, 0);
7276 TCGv_i32 fp0
= tcg_temp_new_i32();
7278 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7279 tcg_gen_trunc_tl_i32(fp0
, t0
);
7280 gen_store_fpr32(fp0
, fd
);
7281 tcg_temp_free_i32(fp0
);
7287 check_cp1_registers(ctx
, fd
);
7289 TCGv_i64 fp0
= tcg_temp_new_i64();
7291 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7292 gen_store_fpr64(ctx
, fp0
, fd
);
7293 tcg_temp_free_i64(fp0
);
7298 check_cp1_64bitmode(ctx
);
7299 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7301 TCGv_i64 fp0
= tcg_temp_new_i64();
7303 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7304 gen_store_fpr64(ctx
, fp0
, fd
);
7305 tcg_temp_free_i64(fp0
);
7312 TCGv_i32 fp0
= tcg_temp_new_i32();
7313 TCGv t1
= tcg_temp_new();
7315 gen_load_fpr32(fp0
, fs
);
7316 tcg_gen_extu_i32_tl(t1
, fp0
);
7317 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7318 tcg_temp_free_i32(fp0
);
7326 check_cp1_registers(ctx
, fs
);
7328 TCGv_i64 fp0
= tcg_temp_new_i64();
7330 gen_load_fpr64(ctx
, fp0
, fs
);
7331 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7332 tcg_temp_free_i64(fp0
);
7338 check_cp1_64bitmode(ctx
);
7339 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7341 TCGv_i64 fp0
= tcg_temp_new_i64();
7343 gen_load_fpr64(ctx
, fp0
, fs
);
7344 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7345 tcg_temp_free_i64(fp0
);
7352 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7353 regnames
[index
], regnames
[base
]);
7356 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7357 int fd
, int fr
, int fs
, int ft
)
7359 const char *opn
= "flt3_arith";
7363 check_cp1_64bitmode(ctx
);
7365 TCGv t0
= tcg_temp_local_new();
7366 TCGv_i32 fp
= tcg_temp_new_i32();
7367 TCGv_i32 fph
= tcg_temp_new_i32();
7368 int l1
= gen_new_label();
7369 int l2
= gen_new_label();
7371 gen_load_gpr(t0
, fr
);
7372 tcg_gen_andi_tl(t0
, t0
, 0x7);
7374 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7375 gen_load_fpr32(fp
, fs
);
7376 gen_load_fpr32h(fph
, fs
);
7377 gen_store_fpr32(fp
, fd
);
7378 gen_store_fpr32h(fph
, fd
);
7381 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7383 #ifdef TARGET_WORDS_BIGENDIAN
7384 gen_load_fpr32(fp
, fs
);
7385 gen_load_fpr32h(fph
, ft
);
7386 gen_store_fpr32h(fp
, fd
);
7387 gen_store_fpr32(fph
, fd
);
7389 gen_load_fpr32h(fph
, fs
);
7390 gen_load_fpr32(fp
, ft
);
7391 gen_store_fpr32(fph
, fd
);
7392 gen_store_fpr32h(fp
, fd
);
7395 tcg_temp_free_i32(fp
);
7396 tcg_temp_free_i32(fph
);
7403 TCGv_i32 fp0
= tcg_temp_new_i32();
7404 TCGv_i32 fp1
= tcg_temp_new_i32();
7405 TCGv_i32 fp2
= tcg_temp_new_i32();
7407 gen_load_fpr32(fp0
, fs
);
7408 gen_load_fpr32(fp1
, ft
);
7409 gen_load_fpr32(fp2
, fr
);
7410 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7411 tcg_temp_free_i32(fp0
);
7412 tcg_temp_free_i32(fp1
);
7413 gen_store_fpr32(fp2
, fd
);
7414 tcg_temp_free_i32(fp2
);
7420 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7422 TCGv_i64 fp0
= tcg_temp_new_i64();
7423 TCGv_i64 fp1
= tcg_temp_new_i64();
7424 TCGv_i64 fp2
= tcg_temp_new_i64();
7426 gen_load_fpr64(ctx
, fp0
, fs
);
7427 gen_load_fpr64(ctx
, fp1
, ft
);
7428 gen_load_fpr64(ctx
, fp2
, fr
);
7429 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7430 tcg_temp_free_i64(fp0
);
7431 tcg_temp_free_i64(fp1
);
7432 gen_store_fpr64(ctx
, fp2
, fd
);
7433 tcg_temp_free_i64(fp2
);
7438 check_cp1_64bitmode(ctx
);
7440 TCGv_i64 fp0
= tcg_temp_new_i64();
7441 TCGv_i64 fp1
= tcg_temp_new_i64();
7442 TCGv_i64 fp2
= tcg_temp_new_i64();
7444 gen_load_fpr64(ctx
, fp0
, fs
);
7445 gen_load_fpr64(ctx
, fp1
, ft
);
7446 gen_load_fpr64(ctx
, fp2
, fr
);
7447 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7448 tcg_temp_free_i64(fp0
);
7449 tcg_temp_free_i64(fp1
);
7450 gen_store_fpr64(ctx
, fp2
, fd
);
7451 tcg_temp_free_i64(fp2
);
7458 TCGv_i32 fp0
= tcg_temp_new_i32();
7459 TCGv_i32 fp1
= tcg_temp_new_i32();
7460 TCGv_i32 fp2
= tcg_temp_new_i32();
7462 gen_load_fpr32(fp0
, fs
);
7463 gen_load_fpr32(fp1
, ft
);
7464 gen_load_fpr32(fp2
, fr
);
7465 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7466 tcg_temp_free_i32(fp0
);
7467 tcg_temp_free_i32(fp1
);
7468 gen_store_fpr32(fp2
, fd
);
7469 tcg_temp_free_i32(fp2
);
7475 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7477 TCGv_i64 fp0
= tcg_temp_new_i64();
7478 TCGv_i64 fp1
= tcg_temp_new_i64();
7479 TCGv_i64 fp2
= tcg_temp_new_i64();
7481 gen_load_fpr64(ctx
, fp0
, fs
);
7482 gen_load_fpr64(ctx
, fp1
, ft
);
7483 gen_load_fpr64(ctx
, fp2
, fr
);
7484 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7485 tcg_temp_free_i64(fp0
);
7486 tcg_temp_free_i64(fp1
);
7487 gen_store_fpr64(ctx
, fp2
, fd
);
7488 tcg_temp_free_i64(fp2
);
7493 check_cp1_64bitmode(ctx
);
7495 TCGv_i64 fp0
= tcg_temp_new_i64();
7496 TCGv_i64 fp1
= tcg_temp_new_i64();
7497 TCGv_i64 fp2
= tcg_temp_new_i64();
7499 gen_load_fpr64(ctx
, fp0
, fs
);
7500 gen_load_fpr64(ctx
, fp1
, ft
);
7501 gen_load_fpr64(ctx
, fp2
, fr
);
7502 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7503 tcg_temp_free_i64(fp0
);
7504 tcg_temp_free_i64(fp1
);
7505 gen_store_fpr64(ctx
, fp2
, fd
);
7506 tcg_temp_free_i64(fp2
);
7513 TCGv_i32 fp0
= tcg_temp_new_i32();
7514 TCGv_i32 fp1
= tcg_temp_new_i32();
7515 TCGv_i32 fp2
= tcg_temp_new_i32();
7517 gen_load_fpr32(fp0
, fs
);
7518 gen_load_fpr32(fp1
, ft
);
7519 gen_load_fpr32(fp2
, fr
);
7520 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7521 tcg_temp_free_i32(fp0
);
7522 tcg_temp_free_i32(fp1
);
7523 gen_store_fpr32(fp2
, fd
);
7524 tcg_temp_free_i32(fp2
);
7530 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7532 TCGv_i64 fp0
= tcg_temp_new_i64();
7533 TCGv_i64 fp1
= tcg_temp_new_i64();
7534 TCGv_i64 fp2
= tcg_temp_new_i64();
7536 gen_load_fpr64(ctx
, fp0
, fs
);
7537 gen_load_fpr64(ctx
, fp1
, ft
);
7538 gen_load_fpr64(ctx
, fp2
, fr
);
7539 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7540 tcg_temp_free_i64(fp0
);
7541 tcg_temp_free_i64(fp1
);
7542 gen_store_fpr64(ctx
, fp2
, fd
);
7543 tcg_temp_free_i64(fp2
);
7548 check_cp1_64bitmode(ctx
);
7550 TCGv_i64 fp0
= tcg_temp_new_i64();
7551 TCGv_i64 fp1
= tcg_temp_new_i64();
7552 TCGv_i64 fp2
= tcg_temp_new_i64();
7554 gen_load_fpr64(ctx
, fp0
, fs
);
7555 gen_load_fpr64(ctx
, fp1
, ft
);
7556 gen_load_fpr64(ctx
, fp2
, fr
);
7557 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7558 tcg_temp_free_i64(fp0
);
7559 tcg_temp_free_i64(fp1
);
7560 gen_store_fpr64(ctx
, fp2
, fd
);
7561 tcg_temp_free_i64(fp2
);
7568 TCGv_i32 fp0
= tcg_temp_new_i32();
7569 TCGv_i32 fp1
= tcg_temp_new_i32();
7570 TCGv_i32 fp2
= tcg_temp_new_i32();
7572 gen_load_fpr32(fp0
, fs
);
7573 gen_load_fpr32(fp1
, ft
);
7574 gen_load_fpr32(fp2
, fr
);
7575 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7576 tcg_temp_free_i32(fp0
);
7577 tcg_temp_free_i32(fp1
);
7578 gen_store_fpr32(fp2
, fd
);
7579 tcg_temp_free_i32(fp2
);
7585 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7587 TCGv_i64 fp0
= tcg_temp_new_i64();
7588 TCGv_i64 fp1
= tcg_temp_new_i64();
7589 TCGv_i64 fp2
= tcg_temp_new_i64();
7591 gen_load_fpr64(ctx
, fp0
, fs
);
7592 gen_load_fpr64(ctx
, fp1
, ft
);
7593 gen_load_fpr64(ctx
, fp2
, fr
);
7594 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7595 tcg_temp_free_i64(fp0
);
7596 tcg_temp_free_i64(fp1
);
7597 gen_store_fpr64(ctx
, fp2
, fd
);
7598 tcg_temp_free_i64(fp2
);
7603 check_cp1_64bitmode(ctx
);
7605 TCGv_i64 fp0
= tcg_temp_new_i64();
7606 TCGv_i64 fp1
= tcg_temp_new_i64();
7607 TCGv_i64 fp2
= tcg_temp_new_i64();
7609 gen_load_fpr64(ctx
, fp0
, fs
);
7610 gen_load_fpr64(ctx
, fp1
, ft
);
7611 gen_load_fpr64(ctx
, fp2
, fr
);
7612 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7613 tcg_temp_free_i64(fp0
);
7614 tcg_temp_free_i64(fp1
);
7615 gen_store_fpr64(ctx
, fp2
, fd
);
7616 tcg_temp_free_i64(fp2
);
7622 generate_exception (ctx
, EXCP_RI
);
7625 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7626 fregnames
[fs
], fregnames
[ft
]);
7629 /* ISA extensions (ASEs) */
7630 /* MIPS16 extension to MIPS32 */
7631 /* SmartMIPS extension to MIPS32 */
7633 #if defined(TARGET_MIPS64)
7635 /* MDMX extension to MIPS64 */
7639 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7643 uint32_t op
, op1
, op2
;
7646 /* make sure instructions are on a word boundary */
7647 if (ctx
->pc
& 0x3) {
7648 env
->CP0_BadVAddr
= ctx
->pc
;
7649 generate_exception(ctx
, EXCP_AdEL
);
7653 /* Handle blikely not taken case */
7654 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7655 int l1
= gen_new_label();
7657 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7658 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7659 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7660 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7664 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
7665 tcg_gen_debug_insn_start(ctx
->pc
);
7667 op
= MASK_OP_MAJOR(ctx
->opcode
);
7668 rs
= (ctx
->opcode
>> 21) & 0x1f;
7669 rt
= (ctx
->opcode
>> 16) & 0x1f;
7670 rd
= (ctx
->opcode
>> 11) & 0x1f;
7671 sa
= (ctx
->opcode
>> 6) & 0x1f;
7672 imm
= (int16_t)ctx
->opcode
;
7675 op1
= MASK_SPECIAL(ctx
->opcode
);
7677 case OPC_SLL
: /* Shift with immediate */
7680 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7682 case OPC_MOVN
: /* Conditional move */
7684 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7685 gen_cond_move(env
, op1
, rd
, rs
, rt
);
7687 case OPC_ADD
... OPC_SUBU
:
7688 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7690 case OPC_SLLV
: /* Shifts */
7693 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7695 case OPC_SLT
: /* Set on less than */
7697 gen_slt(env
, op1
, rd
, rs
, rt
);
7699 case OPC_AND
: /* Logic*/
7703 gen_logic(env
, op1
, rd
, rs
, rt
);
7705 case OPC_MULT
... OPC_DIVU
:
7707 check_insn(env
, ctx
, INSN_VR54XX
);
7708 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7709 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7711 gen_muldiv(ctx
, op1
, rs
, rt
);
7713 case OPC_JR
... OPC_JALR
:
7714 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
7716 case OPC_TGE
... OPC_TEQ
: /* Traps */
7718 gen_trap(ctx
, op1
, rs
, rt
, -1);
7720 case OPC_MFHI
: /* Move from HI/LO */
7722 gen_HILO(ctx
, op1
, rd
);
7725 case OPC_MTLO
: /* Move to HI/LO */
7726 gen_HILO(ctx
, op1
, rs
);
7728 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7729 #ifdef MIPS_STRICT_STANDARD
7730 MIPS_INVAL("PMON / selsl");
7731 generate_exception(ctx
, EXCP_RI
);
7733 gen_helper_0i(pmon
, sa
);
7737 generate_exception(ctx
, EXCP_SYSCALL
);
7738 ctx
->bstate
= BS_STOP
;
7741 generate_exception(ctx
, EXCP_BREAK
);
7744 #ifdef MIPS_STRICT_STANDARD
7746 generate_exception(ctx
, EXCP_RI
);
7748 /* Implemented as RI exception for now. */
7749 MIPS_INVAL("spim (unofficial)");
7750 generate_exception(ctx
, EXCP_RI
);
7758 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7759 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7760 check_cp1_enabled(ctx
);
7761 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7762 (ctx
->opcode
>> 16) & 1);
7764 generate_exception_err(ctx
, EXCP_CpU
, 1);
7768 #if defined(TARGET_MIPS64)
7769 /* MIPS64 specific opcodes */
7776 check_insn(env
, ctx
, ISA_MIPS3
);
7778 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7780 case OPC_DADD
... OPC_DSUBU
:
7781 check_insn(env
, ctx
, ISA_MIPS3
);
7783 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7788 check_insn(env
, ctx
, ISA_MIPS3
);
7790 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7792 case OPC_DMULT
... OPC_DDIVU
:
7793 check_insn(env
, ctx
, ISA_MIPS3
);
7795 gen_muldiv(ctx
, op1
, rs
, rt
);
7798 default: /* Invalid */
7799 MIPS_INVAL("special");
7800 generate_exception(ctx
, EXCP_RI
);
7805 op1
= MASK_SPECIAL2(ctx
->opcode
);
7807 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7808 case OPC_MSUB
... OPC_MSUBU
:
7809 check_insn(env
, ctx
, ISA_MIPS32
);
7810 gen_muldiv(ctx
, op1
, rs
, rt
);
7813 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7817 check_insn(env
, ctx
, ISA_MIPS32
);
7818 gen_cl(ctx
, op1
, rd
, rs
);
7821 /* XXX: not clear which exception should be raised
7822 * when in debug mode...
7824 check_insn(env
, ctx
, ISA_MIPS32
);
7825 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7826 generate_exception(ctx
, EXCP_DBp
);
7828 generate_exception(ctx
, EXCP_DBp
);
7832 #if defined(TARGET_MIPS64)
7835 check_insn(env
, ctx
, ISA_MIPS64
);
7837 gen_cl(ctx
, op1
, rd
, rs
);
7840 default: /* Invalid */
7841 MIPS_INVAL("special2");
7842 generate_exception(ctx
, EXCP_RI
);
7847 op1
= MASK_SPECIAL3(ctx
->opcode
);
7851 check_insn(env
, ctx
, ISA_MIPS32R2
);
7852 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7855 check_insn(env
, ctx
, ISA_MIPS32R2
);
7856 op2
= MASK_BSHFL(ctx
->opcode
);
7857 gen_bshfl(ctx
, op2
, rt
, rd
);
7860 check_insn(env
, ctx
, ISA_MIPS32R2
);
7862 TCGv t0
= tcg_temp_new();
7866 save_cpu_state(ctx
, 1);
7867 gen_helper_rdhwr_cpunum(t0
);
7868 gen_store_gpr(t0
, rt
);
7871 save_cpu_state(ctx
, 1);
7872 gen_helper_rdhwr_synci_step(t0
);
7873 gen_store_gpr(t0
, rt
);
7876 save_cpu_state(ctx
, 1);
7877 gen_helper_rdhwr_cc(t0
);
7878 gen_store_gpr(t0
, rt
);
7881 save_cpu_state(ctx
, 1);
7882 gen_helper_rdhwr_ccres(t0
);
7883 gen_store_gpr(t0
, rt
);
7886 #if defined(CONFIG_USER_ONLY)
7887 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7888 gen_store_gpr(t0
, rt
);
7891 /* XXX: Some CPUs implement this in hardware.
7892 Not supported yet. */
7894 default: /* Invalid */
7895 MIPS_INVAL("rdhwr");
7896 generate_exception(ctx
, EXCP_RI
);
7903 check_insn(env
, ctx
, ASE_MT
);
7905 TCGv t0
= tcg_temp_new();
7906 TCGv t1
= tcg_temp_new();
7908 gen_load_gpr(t0
, rt
);
7909 gen_load_gpr(t1
, rs
);
7910 gen_helper_fork(t0
, t1
);
7916 check_insn(env
, ctx
, ASE_MT
);
7918 TCGv t0
= tcg_temp_new();
7920 save_cpu_state(ctx
, 1);
7921 gen_load_gpr(t0
, rs
);
7922 gen_helper_yield(t0
, t0
);
7923 gen_store_gpr(t0
, rd
);
7927 #if defined(TARGET_MIPS64)
7928 case OPC_DEXTM
... OPC_DEXT
:
7929 case OPC_DINSM
... OPC_DINS
:
7930 check_insn(env
, ctx
, ISA_MIPS64R2
);
7932 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7935 check_insn(env
, ctx
, ISA_MIPS64R2
);
7937 op2
= MASK_DBSHFL(ctx
->opcode
);
7938 gen_bshfl(ctx
, op2
, rt
, rd
);
7941 default: /* Invalid */
7942 MIPS_INVAL("special3");
7943 generate_exception(ctx
, EXCP_RI
);
7948 op1
= MASK_REGIMM(ctx
->opcode
);
7950 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
7951 case OPC_BLTZAL
... OPC_BGEZALL
:
7952 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
7954 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
7956 gen_trap(ctx
, op1
, rs
, -1, imm
);
7959 check_insn(env
, ctx
, ISA_MIPS32R2
);
7962 default: /* Invalid */
7963 MIPS_INVAL("regimm");
7964 generate_exception(ctx
, EXCP_RI
);
7969 check_cp0_enabled(ctx
);
7970 op1
= MASK_CP0(ctx
->opcode
);
7976 #if defined(TARGET_MIPS64)
7980 #ifndef CONFIG_USER_ONLY
7981 gen_cp0(env
, ctx
, op1
, rt
, rd
);
7982 #endif /* !CONFIG_USER_ONLY */
7984 case OPC_C0_FIRST
... OPC_C0_LAST
:
7985 #ifndef CONFIG_USER_ONLY
7986 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
7987 #endif /* !CONFIG_USER_ONLY */
7990 #ifndef CONFIG_USER_ONLY
7992 TCGv t0
= tcg_temp_new();
7994 op2
= MASK_MFMC0(ctx
->opcode
);
7997 check_insn(env
, ctx
, ASE_MT
);
7998 gen_helper_dmt(t0
, t0
);
7999 gen_store_gpr(t0
, rt
);
8002 check_insn(env
, ctx
, ASE_MT
);
8003 gen_helper_emt(t0
, t0
);
8004 gen_store_gpr(t0
, rt
);
8007 check_insn(env
, ctx
, ASE_MT
);
8008 gen_helper_dvpe(t0
, t0
);
8009 gen_store_gpr(t0
, rt
);
8012 check_insn(env
, ctx
, ASE_MT
);
8013 gen_helper_evpe(t0
, t0
);
8014 gen_store_gpr(t0
, rt
);
8017 check_insn(env
, ctx
, ISA_MIPS32R2
);
8018 save_cpu_state(ctx
, 1);
8020 gen_store_gpr(t0
, rt
);
8021 /* Stop translation as we may have switched the execution mode */
8022 ctx
->bstate
= BS_STOP
;
8025 check_insn(env
, ctx
, ISA_MIPS32R2
);
8026 save_cpu_state(ctx
, 1);
8028 gen_store_gpr(t0
, rt
);
8029 /* Stop translation as we may have switched the execution mode */
8030 ctx
->bstate
= BS_STOP
;
8032 default: /* Invalid */
8033 MIPS_INVAL("mfmc0");
8034 generate_exception(ctx
, EXCP_RI
);
8039 #endif /* !CONFIG_USER_ONLY */
8042 check_insn(env
, ctx
, ISA_MIPS32R2
);
8043 gen_load_srsgpr(rt
, rd
);
8046 check_insn(env
, ctx
, ISA_MIPS32R2
);
8047 gen_store_srsgpr(rt
, rd
);
8051 generate_exception(ctx
, EXCP_RI
);
8055 case OPC_ADDI
: /* Arithmetic with immediate opcode */
8057 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8059 case OPC_SLTI
: /* Set on less than with immediate opcode */
8061 gen_slt_imm(env
, op
, rt
, rs
, imm
);
8063 case OPC_ANDI
: /* Arithmetic with immediate opcode */
8067 gen_logic_imm(env
, op
, rt
, rs
, imm
);
8069 case OPC_J
... OPC_JAL
: /* Jump */
8070 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
8071 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
8073 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
8074 case OPC_BEQL
... OPC_BGTZL
:
8075 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
8077 case OPC_LB
... OPC_LWR
: /* Load and stores */
8078 case OPC_SB
... OPC_SW
:
8081 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8084 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
8087 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
8091 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8095 /* Floating point (COP1). */
8100 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8101 check_cp1_enabled(ctx
);
8102 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
8104 generate_exception_err(ctx
, EXCP_CpU
, 1);
8109 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8110 check_cp1_enabled(ctx
);
8111 op1
= MASK_CP1(ctx
->opcode
);
8115 check_insn(env
, ctx
, ISA_MIPS32R2
);
8120 gen_cp1(ctx
, op1
, rt
, rd
);
8122 #if defined(TARGET_MIPS64)
8125 check_insn(env
, ctx
, ISA_MIPS3
);
8126 gen_cp1(ctx
, op1
, rt
, rd
);
8132 check_insn(env
, ctx
, ASE_MIPS3D
);
8135 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
8136 (rt
>> 2) & 0x7, imm
<< 2);
8143 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
8148 generate_exception (ctx
, EXCP_RI
);
8152 generate_exception_err(ctx
, EXCP_CpU
, 1);
8162 /* COP2: Not implemented. */
8163 generate_exception_err(ctx
, EXCP_CpU
, 2);
8167 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8168 check_cp1_enabled(ctx
);
8169 op1
= MASK_CP3(ctx
->opcode
);
8177 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
8195 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
8199 generate_exception (ctx
, EXCP_RI
);
8203 generate_exception_err(ctx
, EXCP_CpU
, 1);
8207 #if defined(TARGET_MIPS64)
8208 /* MIPS64 opcodes */
8210 case OPC_LDL
... OPC_LDR
:
8211 case OPC_SDL
... OPC_SDR
:
8215 check_insn(env
, ctx
, ISA_MIPS3
);
8217 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8220 check_insn(env
, ctx
, ISA_MIPS3
);
8222 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
8226 check_insn(env
, ctx
, ISA_MIPS3
);
8228 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8232 check_insn(env
, ctx
, ASE_MIPS16
);
8233 /* MIPS16: Not implemented. */
8235 check_insn(env
, ctx
, ASE_MDMX
);
8236 /* MDMX: Not implemented. */
8237 default: /* Invalid */
8238 MIPS_INVAL("major opcode");
8239 generate_exception(ctx
, EXCP_RI
);
8242 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8243 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8244 /* Branches completion */
8245 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8246 ctx
->bstate
= BS_BRANCH
;
8247 save_cpu_state(ctx
, 0);
8248 /* FIXME: Need to clear can_do_io. */
8251 /* unconditional branch */
8252 MIPS_DEBUG("unconditional branch");
8253 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8256 /* blikely taken case */
8257 MIPS_DEBUG("blikely branch taken");
8258 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8261 /* Conditional branch */
8262 MIPS_DEBUG("conditional branch");
8264 int l1
= gen_new_label();
8266 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8267 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8269 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8273 /* unconditional branch to register */
8274 MIPS_DEBUG("branch to register");
8275 tcg_gen_mov_tl(cpu_PC
, btarget
);
8276 if (ctx
->singlestep_enabled
) {
8277 save_cpu_state(ctx
, 0);
8278 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8283 MIPS_DEBUG("unknown branch");
8290 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
8294 target_ulong pc_start
;
8295 uint16_t *gen_opc_end
;
8302 qemu_log("search pc %d\n", search_pc
);
8305 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
8308 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
8310 ctx
.bstate
= BS_NONE
;
8311 /* Restore delay slot state from the tb context. */
8312 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
8313 restore_cpu_state(env
, &ctx
);
8314 #ifdef CONFIG_USER_ONLY
8315 ctx
.mem_idx
= MIPS_HFLAG_UM
;
8317 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
8320 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8322 max_insns
= CF_COUNT_MASK
;
8324 qemu_log_mask(CPU_LOG_TB_CPU
, "------------------------------------------------\n");
8325 /* FIXME: This may print out stale hflags from env... */
8326 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
8328 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
8330 while (ctx
.bstate
== BS_NONE
) {
8331 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
8332 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
8333 if (bp
->pc
== ctx
.pc
) {
8334 save_cpu_state(&ctx
, 1);
8335 ctx
.bstate
= BS_BRANCH
;
8336 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8337 /* Include the breakpoint location or the tb won't
8338 * be flushed when it must be. */
8340 goto done_generating
;
8346 j
= gen_opc_ptr
- gen_opc_buf
;
8350 gen_opc_instr_start
[lj
++] = 0;
8352 gen_opc_pc
[lj
] = ctx
.pc
;
8353 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
8354 gen_opc_instr_start
[lj
] = 1;
8355 gen_opc_icount
[lj
] = num_insns
;
8357 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8359 ctx
.opcode
= ldl_code(ctx
.pc
);
8360 decode_opc(env
, &ctx
);
8364 /* Execute a branch and its delay slot as a single instruction.
8365 This is what GDB expects and is consistent with what the
8366 hardware does (e.g. if a delay slot instruction faults, the
8367 reported PC is the PC of the branch). */
8368 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
8371 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
8374 if (gen_opc_ptr
>= gen_opc_end
)
8377 if (num_insns
>= max_insns
)
8383 if (tb
->cflags
& CF_LAST_IO
)
8385 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
8386 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
8387 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8389 switch (ctx
.bstate
) {
8391 gen_helper_interrupt_restart();
8392 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8395 save_cpu_state(&ctx
, 0);
8396 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8399 gen_helper_interrupt_restart();
8408 gen_icount_end(tb
, num_insns
);
8409 *gen_opc_ptr
= INDEX_op_end
;
8411 j
= gen_opc_ptr
- gen_opc_buf
;
8414 gen_opc_instr_start
[lj
++] = 0;
8416 tb
->size
= ctx
.pc
- pc_start
;
8417 tb
->icount
= num_insns
;
8421 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
8422 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
8423 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
8426 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
8430 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
8432 gen_intermediate_code_internal(env
, tb
, 0);
8435 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
8437 gen_intermediate_code_internal(env
, tb
, 1);
8440 static void fpu_dump_state(CPUState
*env
, FILE *f
,
8441 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8445 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
8447 #define printfpr(fp) \
8450 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8451 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8452 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8455 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8456 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8457 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8458 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8459 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8464 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8465 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
8466 get_float_exception_flags(&env
->active_fpu
.fp_status
));
8467 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
8468 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
8469 printfpr(&env
->active_fpu
.fpr
[i
]);
8475 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8476 /* Debug help: The architecture requires 32bit code to maintain proper
8477 sign-extended values on 64bit machines. */
8479 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8482 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
8483 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8488 if (!SIGN_EXT_P(env
->active_tc
.PC
))
8489 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
8490 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
8491 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
8492 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
8493 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
8494 if (!SIGN_EXT_P(env
->btarget
))
8495 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
8497 for (i
= 0; i
< 32; i
++) {
8498 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
8499 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
8502 if (!SIGN_EXT_P(env
->CP0_EPC
))
8503 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
8504 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
8505 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
8509 void cpu_dump_state (CPUState
*env
, FILE *f
,
8510 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8515 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",
8516 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
8517 env
->hflags
, env
->btarget
, env
->bcond
);
8518 for (i
= 0; i
< 32; i
++) {
8520 cpu_fprintf(f
, "GPR%02d:", i
);
8521 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
8523 cpu_fprintf(f
, "\n");
8526 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
8527 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
8528 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
8529 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
8530 if (env
->hflags
& MIPS_HFLAG_FPU
)
8531 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
8532 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8533 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
8537 static void mips_tcg_init(void)
8542 /* Initialize various static tables. */
8546 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
8547 TCGV_UNUSED(cpu_gpr
[0]);
8548 for (i
= 1; i
< 32; i
++)
8549 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
8550 offsetof(CPUState
, active_tc
.gpr
[i
]),
8552 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
8553 offsetof(CPUState
, active_tc
.PC
), "PC");
8554 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
8555 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
8556 offsetof(CPUState
, active_tc
.HI
[i
]),
8558 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
8559 offsetof(CPUState
, active_tc
.LO
[i
]),
8561 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
8562 offsetof(CPUState
, active_tc
.ACX
[i
]),
8565 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
8566 offsetof(CPUState
, active_tc
.DSPControl
),
8568 bcond
= tcg_global_mem_new(TCG_AREG0
,
8569 offsetof(CPUState
, bcond
), "bcond");
8570 btarget
= tcg_global_mem_new(TCG_AREG0
,
8571 offsetof(CPUState
, btarget
), "btarget");
8572 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
8573 offsetof(CPUState
, hflags
), "hflags");
8575 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
8576 offsetof(CPUState
, active_fpu
.fcr0
),
8578 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
8579 offsetof(CPUState
, active_fpu
.fcr31
),
8582 /* register helpers */
8583 #define GEN_HELPER 2
8589 #include "translate_init.c"
8591 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
8594 const mips_def_t
*def
;
8596 def
= cpu_mips_find_by_name(cpu_model
);
8599 env
= qemu_mallocz(sizeof(CPUMIPSState
));
8600 env
->cpu_model
= def
;
8603 env
->cpu_model_str
= cpu_model
;
8606 qemu_init_vcpu(env
);
8610 void cpu_reset (CPUMIPSState
*env
)
8612 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
8613 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
8614 log_cpu_state(env
, 0);
8617 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
8622 #if defined(CONFIG_USER_ONLY)
8623 env
->hflags
= MIPS_HFLAG_UM
;
8624 /* Enable access to the SYNCI_Step register. */
8625 env
->CP0_HWREna
|= (1 << 1);
8627 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
8628 /* If the exception was raised from a delay slot,
8629 come back to the jump. */
8630 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
8632 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
8634 env
->active_tc
.PC
= (int32_t)0xBFC00000;
8636 /* SMP not implemented */
8637 env
->CP0_EBase
= 0x80000000;
8638 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8639 /* vectored interrupts not implemented, timer on int 7,
8640 no performance counters. */
8641 env
->CP0_IntCtl
= 0xe0000000;
8645 for (i
= 0; i
< 7; i
++) {
8646 env
->CP0_WatchLo
[i
] = 0;
8647 env
->CP0_WatchHi
[i
] = 0x80000000;
8649 env
->CP0_WatchLo
[7] = 0;
8650 env
->CP0_WatchHi
[7] = 0;
8652 /* Count register increments in debug mode, EJTAG version 1 */
8653 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8654 env
->hflags
= MIPS_HFLAG_CP0
;
8656 env
->exception_index
= EXCP_NONE
;
8657 cpu_mips_register(env
, env
->cpu_model
);
8660 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8661 unsigned long searched_pc
, int pc_pos
, void *puc
)
8663 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
8664 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8665 env
->hflags
|= gen_opc_hflags
[pc_pos
];