]>
git.proxmox.com Git - qemu.git/blob - target-mips/translate.c
2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
33 #include "qemu-common.h"
39 //#define MIPS_DEBUG_DISAS
40 //#define MIPS_DEBUG_SIGN_EXTENSIONS
41 //#define MIPS_SINGLE_STEP
43 /* MIPS major opcodes */
44 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
47 /* indirect opcode tables */
48 OPC_SPECIAL
= (0x00 << 26),
49 OPC_REGIMM
= (0x01 << 26),
50 OPC_CP0
= (0x10 << 26),
51 OPC_CP1
= (0x11 << 26),
52 OPC_CP2
= (0x12 << 26),
53 OPC_CP3
= (0x13 << 26),
54 OPC_SPECIAL2
= (0x1C << 26),
55 OPC_SPECIAL3
= (0x1F << 26),
56 /* arithmetic with immediate */
57 OPC_ADDI
= (0x08 << 26),
58 OPC_ADDIU
= (0x09 << 26),
59 OPC_SLTI
= (0x0A << 26),
60 OPC_SLTIU
= (0x0B << 26),
61 OPC_ANDI
= (0x0C << 26),
62 OPC_ORI
= (0x0D << 26),
63 OPC_XORI
= (0x0E << 26),
64 OPC_LUI
= (0x0F << 26),
65 OPC_DADDI
= (0x18 << 26),
66 OPC_DADDIU
= (0x19 << 26),
67 /* Jump and branches */
69 OPC_JAL
= (0x03 << 26),
70 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
71 OPC_BEQL
= (0x14 << 26),
72 OPC_BNE
= (0x05 << 26),
73 OPC_BNEL
= (0x15 << 26),
74 OPC_BLEZ
= (0x06 << 26),
75 OPC_BLEZL
= (0x16 << 26),
76 OPC_BGTZ
= (0x07 << 26),
77 OPC_BGTZL
= (0x17 << 26),
78 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
80 OPC_LDL
= (0x1A << 26),
81 OPC_LDR
= (0x1B << 26),
82 OPC_LB
= (0x20 << 26),
83 OPC_LH
= (0x21 << 26),
84 OPC_LWL
= (0x22 << 26),
85 OPC_LW
= (0x23 << 26),
86 OPC_LBU
= (0x24 << 26),
87 OPC_LHU
= (0x25 << 26),
88 OPC_LWR
= (0x26 << 26),
89 OPC_LWU
= (0x27 << 26),
90 OPC_SB
= (0x28 << 26),
91 OPC_SH
= (0x29 << 26),
92 OPC_SWL
= (0x2A << 26),
93 OPC_SW
= (0x2B << 26),
94 OPC_SDL
= (0x2C << 26),
95 OPC_SDR
= (0x2D << 26),
96 OPC_SWR
= (0x2E << 26),
97 OPC_LL
= (0x30 << 26),
98 OPC_LLD
= (0x34 << 26),
99 OPC_LD
= (0x37 << 26),
100 OPC_SC
= (0x38 << 26),
101 OPC_SCD
= (0x3C << 26),
102 OPC_SD
= (0x3F << 26),
103 /* Floating point load/store */
104 OPC_LWC1
= (0x31 << 26),
105 OPC_LWC2
= (0x32 << 26),
106 OPC_LDC1
= (0x35 << 26),
107 OPC_LDC2
= (0x36 << 26),
108 OPC_SWC1
= (0x39 << 26),
109 OPC_SWC2
= (0x3A << 26),
110 OPC_SDC1
= (0x3D << 26),
111 OPC_SDC2
= (0x3E << 26),
112 /* MDMX ASE specific */
113 OPC_MDMX
= (0x1E << 26),
114 /* Cache and prefetch */
115 OPC_CACHE
= (0x2F << 26),
116 OPC_PREF
= (0x33 << 26),
117 /* Reserved major opcode */
118 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
121 /* MIPS special opcodes */
122 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
126 OPC_SLL
= 0x00 | OPC_SPECIAL
,
127 /* NOP is SLL r0, r0, 0 */
128 /* SSNOP is SLL r0, r0, 1 */
129 /* EHB is SLL r0, r0, 3 */
130 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
131 OPC_SRA
= 0x03 | OPC_SPECIAL
,
132 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
133 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
134 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
135 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
136 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
137 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
138 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
139 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
140 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
141 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
142 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
143 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
144 /* Multiplication / division */
145 OPC_MULT
= 0x18 | OPC_SPECIAL
,
146 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
147 OPC_DIV
= 0x1A | OPC_SPECIAL
,
148 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
149 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
150 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
151 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
152 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
153 /* 2 registers arithmetic / logic */
154 OPC_ADD
= 0x20 | OPC_SPECIAL
,
155 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
156 OPC_SUB
= 0x22 | OPC_SPECIAL
,
157 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
158 OPC_AND
= 0x24 | OPC_SPECIAL
,
159 OPC_OR
= 0x25 | OPC_SPECIAL
,
160 OPC_XOR
= 0x26 | OPC_SPECIAL
,
161 OPC_NOR
= 0x27 | OPC_SPECIAL
,
162 OPC_SLT
= 0x2A | OPC_SPECIAL
,
163 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
164 OPC_DADD
= 0x2C | OPC_SPECIAL
,
165 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
166 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
167 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
169 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
170 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
172 OPC_TGE
= 0x30 | OPC_SPECIAL
,
173 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
174 OPC_TLT
= 0x32 | OPC_SPECIAL
,
175 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
176 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
177 OPC_TNE
= 0x36 | OPC_SPECIAL
,
178 /* HI / LO registers load & stores */
179 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
180 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
181 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
182 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
183 /* Conditional moves */
184 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
185 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
187 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
190 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
191 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
192 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
193 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
194 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
196 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
197 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
198 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
199 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
200 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
201 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
202 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
205 /* Multiplication variants of the vr54xx. */
206 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
209 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
210 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
211 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
212 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
213 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
214 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
215 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
216 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
217 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
218 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
219 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
220 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
221 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
222 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
225 /* REGIMM (rt field) opcodes */
226 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
229 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
230 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
231 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
232 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
233 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
234 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
235 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
236 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
237 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
238 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
239 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
240 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
241 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
242 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
243 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
246 /* Special2 opcodes */
247 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
250 /* Multiply & xxx operations */
251 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
252 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
253 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
254 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
255 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
257 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
258 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
259 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
260 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
262 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
265 /* Special3 opcodes */
266 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
269 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
270 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
271 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
272 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
273 OPC_INS
= 0x04 | OPC_SPECIAL3
,
274 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
275 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
276 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
277 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
278 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
279 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
280 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
281 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
285 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
288 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
289 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
290 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
294 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
297 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
298 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
301 /* Coprocessor 0 (rs field) */
302 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
305 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
306 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
307 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
308 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
309 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
310 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
311 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
312 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
313 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
314 OPC_C0
= (0x10 << 21) | OPC_CP0
,
315 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
316 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
320 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
323 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
324 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
325 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
326 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
327 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
328 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
331 /* Coprocessor 0 (with rs == C0) */
332 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
335 OPC_TLBR
= 0x01 | OPC_C0
,
336 OPC_TLBWI
= 0x02 | OPC_C0
,
337 OPC_TLBWR
= 0x06 | OPC_C0
,
338 OPC_TLBP
= 0x08 | OPC_C0
,
339 OPC_RFE
= 0x10 | OPC_C0
,
340 OPC_ERET
= 0x18 | OPC_C0
,
341 OPC_DERET
= 0x1F | OPC_C0
,
342 OPC_WAIT
= 0x20 | OPC_C0
,
345 /* Coprocessor 1 (rs field) */
346 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
349 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
350 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
351 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
352 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
353 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
354 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
355 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
356 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
357 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
358 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
359 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
360 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
361 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
362 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
363 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
364 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
365 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
366 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
369 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
370 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
373 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
374 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
375 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
376 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
380 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
381 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
385 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
386 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
389 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
392 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
393 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
394 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
395 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
396 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
397 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
398 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
399 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
400 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
403 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
406 OPC_LWXC1
= 0x00 | OPC_CP3
,
407 OPC_LDXC1
= 0x01 | OPC_CP3
,
408 OPC_LUXC1
= 0x05 | OPC_CP3
,
409 OPC_SWXC1
= 0x08 | OPC_CP3
,
410 OPC_SDXC1
= 0x09 | OPC_CP3
,
411 OPC_SUXC1
= 0x0D | OPC_CP3
,
412 OPC_PREFX
= 0x0F | OPC_CP3
,
413 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
414 OPC_MADD_S
= 0x20 | OPC_CP3
,
415 OPC_MADD_D
= 0x21 | OPC_CP3
,
416 OPC_MADD_PS
= 0x26 | OPC_CP3
,
417 OPC_MSUB_S
= 0x28 | OPC_CP3
,
418 OPC_MSUB_D
= 0x29 | OPC_CP3
,
419 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
420 OPC_NMADD_S
= 0x30 | OPC_CP3
,
421 OPC_NMADD_D
= 0x31 | OPC_CP3
,
422 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
423 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
424 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
425 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
428 /* global register indices */
429 static TCGv_ptr cpu_env
;
430 static TCGv cpu_gpr
[32], cpu_PC
;
431 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
432 static TCGv cpu_dspctrl
, btarget
;
434 static TCGv_i32 fpu_fpr32
[32], fpu_fpr32h
[32];
435 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
437 #include "gen-icount.h"
439 #define gen_helper_0i(name, arg) do { \
440 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
441 gen_helper_##name(helper_tmp); \
442 tcg_temp_free_i32(helper_tmp); \
445 #define gen_helper_1i(name, arg1, arg2) do { \
446 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
447 gen_helper_##name(arg1, helper_tmp); \
448 tcg_temp_free_i32(helper_tmp); \
451 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
452 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
453 gen_helper_##name(arg1, arg2, helper_tmp); \
454 tcg_temp_free_i32(helper_tmp); \
457 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
458 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
459 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
460 tcg_temp_free_i32(helper_tmp); \
463 typedef struct DisasContext
{
464 struct TranslationBlock
*tb
;
465 target_ulong pc
, saved_pc
;
467 /* Routine used to access memory */
469 uint32_t hflags
, saved_hflags
;
471 target_ulong btarget
;
475 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
476 * exception condition */
477 BS_STOP
= 1, /* We want to stop translation for any reason */
478 BS_BRANCH
= 2, /* We reached a branch condition */
479 BS_EXCP
= 3, /* We reached an exception condition */
482 static const char *regnames
[] =
483 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
484 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
485 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
486 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
488 static const char *regnames_HI
[] =
489 { "HI0", "HI1", "HI2", "HI3", };
491 static const char *regnames_LO
[] =
492 { "LO0", "LO1", "LO2", "LO3", };
494 static const char *regnames_ACX
[] =
495 { "ACX0", "ACX1", "ACX2", "ACX3", };
497 static const char *fregnames
[] =
498 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
499 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
500 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
501 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
503 static const char *fregnames_h
[] =
504 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
505 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
506 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
507 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
509 #ifdef MIPS_DEBUG_DISAS
510 #define MIPS_DEBUG(fmt, args...) \
511 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
512 TARGET_FMT_lx ": %08x " fmt "\n", \
513 ctx->pc, ctx->opcode , ##args)
514 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
516 #define MIPS_DEBUG(fmt, args...) do { } while(0)
517 #define LOG_DISAS(...) do { } while (0)
520 #define MIPS_INVAL(op) \
522 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
523 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
526 /* General purpose registers moves. */
527 static inline void gen_load_gpr (TCGv t
, int reg
)
530 tcg_gen_movi_tl(t
, 0);
532 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
535 static inline void gen_store_gpr (TCGv t
, int reg
)
538 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
541 /* Moves to/from ACX register. */
542 static inline void gen_load_ACX (TCGv t
, int reg
)
544 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
547 static inline void gen_store_ACX (TCGv t
, int reg
)
549 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
552 /* Moves to/from shadow registers. */
553 static inline void gen_load_srsgpr (int from
, int to
)
555 TCGv r_tmp1
= tcg_temp_new();
558 tcg_gen_movi_tl(r_tmp1
, 0);
560 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
561 TCGv_ptr addr
= tcg_temp_new_ptr();
563 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
564 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
565 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
566 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
567 tcg_gen_ext_i32_ptr(addr
, r_tmp2
);
568 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
570 tcg_gen_ld_tl(r_tmp1
, addr
, sizeof(target_ulong
) * from
);
571 tcg_temp_free_ptr(addr
);
572 tcg_temp_free_i32(r_tmp2
);
574 gen_store_gpr(r_tmp1
, to
);
575 tcg_temp_free(r_tmp1
);
578 static inline void gen_store_srsgpr (int from
, int to
)
581 TCGv r_tmp1
= tcg_temp_new();
582 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
583 TCGv_ptr addr
= tcg_temp_new_ptr();
585 gen_load_gpr(r_tmp1
, from
);
586 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
587 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
588 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
589 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
590 tcg_gen_ext_i32_ptr(addr
, r_tmp2
);
591 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
593 tcg_gen_st_tl(r_tmp1
, addr
, sizeof(target_ulong
) * to
);
594 tcg_temp_free_ptr(addr
);
595 tcg_temp_free_i32(r_tmp2
);
596 tcg_temp_free(r_tmp1
);
600 /* Floating point register moves. */
601 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
603 tcg_gen_mov_i32(t
, fpu_fpr32
[reg
]);
606 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
608 tcg_gen_mov_i32(fpu_fpr32
[reg
], t
);
611 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
613 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
614 tcg_gen_concat_i32_i64(t
, fpu_fpr32
[reg
], fpu_fpr32h
[reg
]);
616 tcg_gen_concat_i32_i64(t
, fpu_fpr32
[reg
& ~1], fpu_fpr32
[reg
| 1]);
620 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
622 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
623 tcg_gen_trunc_i64_i32(fpu_fpr32
[reg
], t
);
624 tcg_gen_shri_i64(t
, t
, 32);
625 tcg_gen_trunc_i64_i32(fpu_fpr32h
[reg
], t
);
627 tcg_gen_trunc_i64_i32(fpu_fpr32
[reg
& ~1], t
);
628 tcg_gen_shri_i64(t
, t
, 32);
629 tcg_gen_trunc_i64_i32(fpu_fpr32
[reg
| 1], t
);
633 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
635 tcg_gen_mov_i32(t
, fpu_fpr32h
[reg
]);
638 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
640 tcg_gen_mov_i32(fpu_fpr32h
[reg
], t
);
643 static inline void get_fp_cond (TCGv_i32 t
)
645 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
646 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
648 tcg_gen_shri_i32(r_tmp2
, fpu_fcr31
, 24);
649 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xfe);
650 tcg_gen_shri_i32(r_tmp1
, fpu_fcr31
, 23);
651 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, 0x1);
652 tcg_gen_or_i32(t
, r_tmp1
, r_tmp2
);
653 tcg_temp_free_i32(r_tmp1
);
654 tcg_temp_free_i32(r_tmp2
);
657 #define FOP_CONDS(type, fmt, bits) \
658 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
659 TCGv_i##bits b, int cc) \
662 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
663 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
664 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
665 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
666 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
667 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
668 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
669 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
670 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
671 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
672 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
673 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
674 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
675 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
676 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
677 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
683 FOP_CONDS(abs
, d
, 64)
685 FOP_CONDS(abs
, s
, 32)
687 FOP_CONDS(abs
, ps
, 64)
691 #define OP_COND(name, cond) \
692 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, TCGv t1) \
694 int l1 = gen_new_label(); \
695 int l2 = gen_new_label(); \
697 tcg_gen_brcond_tl(cond, t0, t1, l1); \
698 tcg_gen_movi_tl(ret, 0); \
701 tcg_gen_movi_tl(ret, 1); \
704 OP_COND(eq
, TCG_COND_EQ
);
705 OP_COND(ne
, TCG_COND_NE
);
706 OP_COND(ge
, TCG_COND_GE
);
707 OP_COND(geu
, TCG_COND_GEU
);
708 OP_COND(lt
, TCG_COND_LT
);
709 OP_COND(ltu
, TCG_COND_LTU
);
712 #define OP_CONDI(name, cond) \
713 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, target_ulong val) \
715 int l1 = gen_new_label(); \
716 int l2 = gen_new_label(); \
718 tcg_gen_brcondi_tl(cond, t0, val, l1); \
719 tcg_gen_movi_tl(ret, 0); \
722 tcg_gen_movi_tl(ret, 1); \
725 OP_CONDI(lti
, TCG_COND_LT
);
726 OP_CONDI(ltiu
, TCG_COND_LTU
);
729 #define OP_CONDZ(name, cond) \
730 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0) \
732 int l1 = gen_new_label(); \
733 int l2 = gen_new_label(); \
735 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
736 tcg_gen_movi_tl(ret, 0); \
739 tcg_gen_movi_tl(ret, 1); \
742 OP_CONDZ(gez
, TCG_COND_GE
);
743 OP_CONDZ(gtz
, TCG_COND_GT
);
744 OP_CONDZ(lez
, TCG_COND_LE
);
745 OP_CONDZ(ltz
, TCG_COND_LT
);
748 static inline void gen_save_pc(target_ulong pc
)
750 tcg_gen_movi_tl(cpu_PC
, pc
);
753 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
755 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
756 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
757 gen_save_pc(ctx
->pc
);
758 ctx
->saved_pc
= ctx
->pc
;
760 if (ctx
->hflags
!= ctx
->saved_hflags
) {
761 TCGv_i32 r_tmp
= tcg_temp_new_i32();
763 tcg_gen_movi_i32(r_tmp
, ctx
->hflags
);
764 tcg_gen_st_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
765 tcg_temp_free_i32(r_tmp
);
766 ctx
->saved_hflags
= ctx
->hflags
;
767 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
773 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
779 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
781 ctx
->saved_hflags
= ctx
->hflags
;
782 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
788 ctx
->btarget
= env
->btarget
;
794 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
796 TCGv_i32 texcp
= tcg_const_i32(excp
);
797 TCGv_i32 terr
= tcg_const_i32(err
);
798 save_cpu_state(ctx
, 1);
799 gen_helper_raise_exception_err(texcp
, terr
);
800 tcg_temp_free_i32(terr
);
801 tcg_temp_free_i32(texcp
);
802 gen_helper_interrupt_restart();
807 generate_exception (DisasContext
*ctx
, int excp
)
809 save_cpu_state(ctx
, 1);
810 gen_helper_0i(raise_exception
, excp
);
811 gen_helper_interrupt_restart();
815 /* Addresses computation */
816 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv t0
, TCGv t1
)
818 tcg_gen_add_tl(t0
, t0
, t1
);
820 #if defined(TARGET_MIPS64)
821 /* For compatibility with 32-bit code, data reference in user mode
822 with Status_UX = 0 should be casted to 32-bit and sign extended.
823 See the MIPS64 PRA manual, section 4.10. */
824 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
825 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
826 tcg_gen_ext32s_i64(t0
, t0
);
831 static inline void check_cp0_enabled(DisasContext
*ctx
)
833 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
834 generate_exception_err(ctx
, EXCP_CpU
, 1);
837 static inline void check_cp1_enabled(DisasContext
*ctx
)
839 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
840 generate_exception_err(ctx
, EXCP_CpU
, 1);
843 /* Verify that the processor is running with COP1X instructions enabled.
844 This is associated with the nabla symbol in the MIPS32 and MIPS64
847 static inline void check_cop1x(DisasContext
*ctx
)
849 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
850 generate_exception(ctx
, EXCP_RI
);
853 /* Verify that the processor is running with 64-bit floating-point
854 operations enabled. */
856 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
858 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
859 generate_exception(ctx
, EXCP_RI
);
863 * Verify if floating point register is valid; an operation is not defined
864 * if bit 0 of any register specification is set and the FR bit in the
865 * Status register equals zero, since the register numbers specify an
866 * even-odd pair of adjacent coprocessor general registers. When the FR bit
867 * in the Status register equals one, both even and odd register numbers
868 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
870 * Multiple 64 bit wide registers can be checked by calling
871 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
873 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
875 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
876 generate_exception(ctx
, EXCP_RI
);
879 /* This code generates a "reserved instruction" exception if the
880 CPU does not support the instruction set corresponding to flags. */
881 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
883 if (unlikely(!(env
->insn_flags
& flags
)))
884 generate_exception(ctx
, EXCP_RI
);
887 /* This code generates a "reserved instruction" exception if 64-bit
888 instructions are not enabled. */
889 static inline void check_mips_64(DisasContext
*ctx
)
891 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
892 generate_exception(ctx
, EXCP_RI
);
895 /* load/store instructions. */
896 #define OP_LD(insn,fname) \
897 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
899 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
906 #if defined(TARGET_MIPS64)
912 #define OP_ST(insn,fname) \
913 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
915 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
920 #if defined(TARGET_MIPS64)
925 #define OP_LD_ATOMIC(insn,fname) \
926 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
928 tcg_gen_mov_tl(t1, t0); \
929 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
930 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
932 OP_LD_ATOMIC(ll
,ld32s
);
933 #if defined(TARGET_MIPS64)
934 OP_LD_ATOMIC(lld
,ld64
);
938 #define OP_ST_ATOMIC(insn,fname,almask) \
939 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
941 TCGv r_tmp = tcg_temp_local_new(); \
942 int l1 = gen_new_label(); \
943 int l2 = gen_new_label(); \
944 int l3 = gen_new_label(); \
946 tcg_gen_andi_tl(r_tmp, t0, almask); \
947 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
948 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
949 generate_exception(ctx, EXCP_AdES); \
951 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
952 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
953 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
954 tcg_gen_movi_tl(t0, 1); \
957 tcg_gen_movi_tl(t0, 0); \
959 tcg_temp_free(r_tmp); \
961 OP_ST_ATOMIC(sc
,st32
,0x3);
962 #if defined(TARGET_MIPS64)
963 OP_ST_ATOMIC(scd
,st64
,0x7);
968 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
969 int base
, int16_t offset
)
971 const char *opn
= "ldst";
972 TCGv t0
= tcg_temp_local_new();
973 TCGv t1
= tcg_temp_local_new();
976 tcg_gen_movi_tl(t0
, offset
);
977 } else if (offset
== 0) {
978 gen_load_gpr(t0
, base
);
980 tcg_gen_movi_tl(t0
, offset
);
981 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
983 /* Don't do NOP if destination is zero: we must perform the actual
986 #if defined(TARGET_MIPS64)
988 op_ldst_lwu(t0
, ctx
);
989 gen_store_gpr(t0
, rt
);
994 gen_store_gpr(t0
, rt
);
998 op_ldst_lld(t0
, t1
, ctx
);
999 gen_store_gpr(t0
, rt
);
1003 gen_load_gpr(t1
, rt
);
1004 op_ldst_sd(t0
, t1
, ctx
);
1008 save_cpu_state(ctx
, 1);
1009 gen_load_gpr(t1
, rt
);
1010 op_ldst_scd(t0
, t1
, ctx
);
1011 gen_store_gpr(t0
, rt
);
1015 save_cpu_state(ctx
, 1);
1016 gen_load_gpr(t1
, rt
);
1017 gen_helper_3i(ldl
, t1
, t0
, t1
, ctx
->mem_idx
);
1018 gen_store_gpr(t1
, rt
);
1022 save_cpu_state(ctx
, 1);
1023 gen_load_gpr(t1
, rt
);
1024 gen_helper_2i(sdl
, t0
, t1
, ctx
->mem_idx
);
1028 save_cpu_state(ctx
, 1);
1029 gen_load_gpr(t1
, rt
);
1030 gen_helper_3i(ldr
, t1
, t0
, t1
, ctx
->mem_idx
);
1031 gen_store_gpr(t1
, rt
);
1035 save_cpu_state(ctx
, 1);
1036 gen_load_gpr(t1
, rt
);
1037 gen_helper_2i(sdr
, t0
, t1
, ctx
->mem_idx
);
1042 op_ldst_lw(t0
, ctx
);
1043 gen_store_gpr(t0
, rt
);
1047 gen_load_gpr(t1
, rt
);
1048 op_ldst_sw(t0
, t1
, ctx
);
1052 op_ldst_lh(t0
, ctx
);
1053 gen_store_gpr(t0
, rt
);
1057 gen_load_gpr(t1
, rt
);
1058 op_ldst_sh(t0
, t1
, ctx
);
1062 op_ldst_lhu(t0
, ctx
);
1063 gen_store_gpr(t0
, rt
);
1067 op_ldst_lb(t0
, ctx
);
1068 gen_store_gpr(t0
, rt
);
1072 gen_load_gpr(t1
, rt
);
1073 op_ldst_sb(t0
, t1
, ctx
);
1077 op_ldst_lbu(t0
, ctx
);
1078 gen_store_gpr(t0
, rt
);
1082 save_cpu_state(ctx
, 1);
1083 gen_load_gpr(t1
, rt
);
1084 gen_helper_3i(lwl
, t1
, t0
, t1
, ctx
->mem_idx
);
1085 gen_store_gpr(t1
, rt
);
1089 save_cpu_state(ctx
, 1);
1090 gen_load_gpr(t1
, rt
);
1091 gen_helper_2i(swl
, t0
, t1
, ctx
->mem_idx
);
1095 save_cpu_state(ctx
, 1);
1096 gen_load_gpr(t1
, rt
);
1097 gen_helper_3i(lwr
, t1
, t0
, t1
, ctx
->mem_idx
);
1098 gen_store_gpr(t1
, rt
);
1102 save_cpu_state(ctx
, 1);
1103 gen_load_gpr(t1
, rt
);
1104 gen_helper_2i(swr
, t0
, t1
, ctx
->mem_idx
);
1108 op_ldst_ll(t0
, t1
, ctx
);
1109 gen_store_gpr(t0
, rt
);
1113 save_cpu_state(ctx
, 1);
1114 gen_load_gpr(t1
, rt
);
1115 op_ldst_sc(t0
, t1
, ctx
);
1116 gen_store_gpr(t0
, rt
);
1121 generate_exception(ctx
, EXCP_RI
);
1124 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1130 /* Load and store */
1131 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1132 int base
, int16_t offset
)
1134 const char *opn
= "flt_ldst";
1135 TCGv t0
= tcg_temp_local_new();
1138 tcg_gen_movi_tl(t0
, offset
);
1139 } else if (offset
== 0) {
1140 gen_load_gpr(t0
, base
);
1142 tcg_gen_movi_tl(t0
, offset
);
1143 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
1145 /* Don't do NOP if destination is zero: we must perform the actual
1150 TCGv_i32 fp0
= tcg_temp_new_i32();
1151 TCGv t1
= tcg_temp_new();
1153 tcg_gen_qemu_ld32s(t1
, t0
, ctx
->mem_idx
);
1154 tcg_gen_trunc_tl_i32(fp0
, t1
);
1155 gen_store_fpr32(fp0
, ft
);
1157 tcg_temp_free_i32(fp0
);
1163 TCGv_i32 fp0
= tcg_temp_new_i32();
1164 TCGv t1
= tcg_temp_new();
1166 gen_load_fpr32(fp0
, ft
);
1167 tcg_gen_extu_i32_tl(t1
, fp0
);
1168 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1170 tcg_temp_free_i32(fp0
);
1176 TCGv_i64 fp0
= tcg_temp_new_i64();
1178 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1179 gen_store_fpr64(ctx
, fp0
, ft
);
1180 tcg_temp_free_i64(fp0
);
1186 TCGv_i64 fp0
= tcg_temp_new_i64();
1188 gen_load_fpr64(ctx
, fp0
, ft
);
1189 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1190 tcg_temp_free_i64(fp0
);
1196 generate_exception(ctx
, EXCP_RI
);
1199 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1204 /* Arithmetic with immediate operand */
1205 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1206 int rt
, int rs
, int16_t imm
)
1209 const char *opn
= "imm arith";
1210 TCGv t0
= tcg_temp_local_new();
1212 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1213 /* If no destination, treat it as a NOP.
1214 For addi, we must generate the overflow exception when needed. */
1218 uimm
= (uint16_t)imm
;
1222 #if defined(TARGET_MIPS64)
1228 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1233 gen_load_gpr(t0
, rs
);
1236 tcg_gen_movi_tl(t0
, imm
<< 16);
1241 #if defined(TARGET_MIPS64)
1250 gen_load_gpr(t0
, rs
);
1256 TCGv r_tmp1
= tcg_temp_new();
1257 TCGv r_tmp2
= tcg_temp_new();
1258 int l1
= gen_new_label();
1260 save_cpu_state(ctx
, 1);
1261 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1262 tcg_gen_addi_tl(t0
, r_tmp1
, uimm
);
1264 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, ~uimm
);
1265 tcg_gen_xori_tl(r_tmp2
, t0
, uimm
);
1266 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1267 tcg_temp_free(r_tmp2
);
1268 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1269 /* operands of same sign, result different sign */
1270 generate_exception(ctx
, EXCP_OVERFLOW
);
1272 tcg_temp_free(r_tmp1
);
1274 tcg_gen_ext32s_tl(t0
, t0
);
1279 tcg_gen_addi_tl(t0
, t0
, uimm
);
1280 tcg_gen_ext32s_tl(t0
, t0
);
1283 #if defined(TARGET_MIPS64)
1286 TCGv r_tmp1
= tcg_temp_new();
1287 TCGv r_tmp2
= tcg_temp_new();
1288 int l1
= gen_new_label();
1290 save_cpu_state(ctx
, 1);
1291 tcg_gen_mov_tl(r_tmp1
, t0
);
1292 tcg_gen_addi_tl(t0
, t0
, uimm
);
1294 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, ~uimm
);
1295 tcg_gen_xori_tl(r_tmp2
, t0
, uimm
);
1296 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1297 tcg_temp_free(r_tmp2
);
1298 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1299 /* operands of same sign, result different sign */
1300 generate_exception(ctx
, EXCP_OVERFLOW
);
1302 tcg_temp_free(r_tmp1
);
1307 tcg_gen_addi_tl(t0
, t0
, uimm
);
1312 gen_op_lti(t0
, t0
, uimm
);
1316 gen_op_ltiu(t0
, t0
, uimm
);
1320 tcg_gen_andi_tl(t0
, t0
, uimm
);
1324 tcg_gen_ori_tl(t0
, t0
, uimm
);
1328 tcg_gen_xori_tl(t0
, t0
, uimm
);
1335 tcg_gen_shli_tl(t0
, t0
, uimm
);
1336 tcg_gen_ext32s_tl(t0
, t0
);
1340 tcg_gen_ext32s_tl(t0
, t0
);
1341 tcg_gen_sari_tl(t0
, t0
, uimm
);
1345 switch ((ctx
->opcode
>> 21) & 0x1f) {
1348 tcg_gen_ext32u_tl(t0
, t0
);
1349 tcg_gen_shri_tl(t0
, t0
, uimm
);
1351 tcg_gen_ext32s_tl(t0
, t0
);
1356 /* rotr is decoded as srl on non-R2 CPUs */
1357 if (env
->insn_flags
& ISA_MIPS32R2
) {
1359 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
1361 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1362 tcg_gen_rotri_i32(r_tmp1
, r_tmp1
, uimm
);
1363 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
1364 tcg_temp_free_i32(r_tmp1
);
1369 tcg_gen_ext32u_tl(t0
, t0
);
1370 tcg_gen_shri_tl(t0
, t0
, uimm
);
1372 tcg_gen_ext32s_tl(t0
, t0
);
1378 MIPS_INVAL("invalid srl flag");
1379 generate_exception(ctx
, EXCP_RI
);
1383 #if defined(TARGET_MIPS64)
1385 tcg_gen_shli_tl(t0
, t0
, uimm
);
1389 tcg_gen_sari_tl(t0
, t0
, uimm
);
1393 switch ((ctx
->opcode
>> 21) & 0x1f) {
1395 tcg_gen_shri_tl(t0
, t0
, uimm
);
1399 /* drotr is decoded as dsrl on non-R2 CPUs */
1400 if (env
->insn_flags
& ISA_MIPS32R2
) {
1402 tcg_gen_rotri_tl(t0
, t0
, uimm
);
1406 tcg_gen_shri_tl(t0
, t0
, uimm
);
1411 MIPS_INVAL("invalid dsrl flag");
1412 generate_exception(ctx
, EXCP_RI
);
1417 tcg_gen_shli_tl(t0
, t0
, uimm
+ 32);
1421 tcg_gen_sari_tl(t0
, t0
, uimm
+ 32);
1425 switch ((ctx
->opcode
>> 21) & 0x1f) {
1427 tcg_gen_shri_tl(t0
, t0
, uimm
+ 32);
1431 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1432 if (env
->insn_flags
& ISA_MIPS32R2
) {
1433 tcg_gen_rotri_tl(t0
, t0
, uimm
+ 32);
1436 tcg_gen_shri_tl(t0
, t0
, uimm
+ 32);
1441 MIPS_INVAL("invalid dsrl32 flag");
1442 generate_exception(ctx
, EXCP_RI
);
1449 generate_exception(ctx
, EXCP_RI
);
1452 gen_store_gpr(t0
, rt
);
1453 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1459 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1460 int rd
, int rs
, int rt
)
1462 const char *opn
= "arith";
1463 TCGv t0
= tcg_temp_local_new();
1464 TCGv t1
= tcg_temp_local_new();
1466 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1467 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1468 /* If no destination, treat it as a NOP.
1469 For add & sub, we must generate the overflow exception when needed. */
1473 gen_load_gpr(t0
, rs
);
1474 /* Specialcase the conventional move operation. */
1475 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1476 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1477 gen_store_gpr(t0
, rd
);
1480 gen_load_gpr(t1
, rt
);
1484 TCGv r_tmp1
= tcg_temp_new();
1485 TCGv r_tmp2
= tcg_temp_new();
1486 int l1
= gen_new_label();
1488 save_cpu_state(ctx
, 1);
1489 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1490 tcg_gen_ext32s_tl(r_tmp2
, t1
);
1491 tcg_gen_add_tl(t0
, r_tmp1
, r_tmp2
);
1493 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t1
);
1494 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1495 tcg_gen_xor_tl(r_tmp2
, t0
, t1
);
1496 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1497 tcg_temp_free(r_tmp2
);
1498 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1499 /* operands of same sign, result different sign */
1500 generate_exception(ctx
, EXCP_OVERFLOW
);
1502 tcg_temp_free(r_tmp1
);
1504 tcg_gen_ext32s_tl(t0
, t0
);
1509 tcg_gen_add_tl(t0
, t0
, t1
);
1510 tcg_gen_ext32s_tl(t0
, t0
);
1515 TCGv r_tmp1
= tcg_temp_new();
1516 TCGv r_tmp2
= tcg_temp_new();
1517 int l1
= gen_new_label();
1519 save_cpu_state(ctx
, 1);
1520 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1521 tcg_gen_ext32s_tl(r_tmp2
, t1
);
1522 tcg_gen_sub_tl(t0
, r_tmp1
, r_tmp2
);
1524 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, t1
);
1525 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t0
);
1526 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1527 tcg_temp_free(r_tmp2
);
1528 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1529 /* operands of different sign, first operand and result different sign */
1530 generate_exception(ctx
, EXCP_OVERFLOW
);
1532 tcg_temp_free(r_tmp1
);
1534 tcg_gen_ext32s_tl(t0
, t0
);
1539 tcg_gen_sub_tl(t0
, t0
, t1
);
1540 tcg_gen_ext32s_tl(t0
, t0
);
1543 #if defined(TARGET_MIPS64)
1546 TCGv r_tmp1
= tcg_temp_new();
1547 TCGv r_tmp2
= tcg_temp_new();
1548 int l1
= gen_new_label();
1550 save_cpu_state(ctx
, 1);
1551 tcg_gen_mov_tl(r_tmp1
, t0
);
1552 tcg_gen_add_tl(t0
, t0
, t1
);
1554 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t1
);
1555 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1556 tcg_gen_xor_tl(r_tmp2
, t0
, t1
);
1557 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1558 tcg_temp_free(r_tmp2
);
1559 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1560 /* operands of same sign, result different sign */
1561 generate_exception(ctx
, EXCP_OVERFLOW
);
1563 tcg_temp_free(r_tmp1
);
1568 tcg_gen_add_tl(t0
, t0
, t1
);
1573 TCGv r_tmp1
= tcg_temp_new();
1574 TCGv r_tmp2
= tcg_temp_new();
1575 int l1
= gen_new_label();
1577 save_cpu_state(ctx
, 1);
1578 tcg_gen_mov_tl(r_tmp1
, t0
);
1579 tcg_gen_sub_tl(t0
, t0
, t1
);
1581 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, t1
);
1582 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t0
);
1583 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1584 tcg_temp_free(r_tmp2
);
1585 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1586 /* operands of different sign, first operand and result different sign */
1587 generate_exception(ctx
, EXCP_OVERFLOW
);
1589 tcg_temp_free(r_tmp1
);
1594 tcg_gen_sub_tl(t0
, t0
, t1
);
1599 gen_op_lt(t0
, t0
, t1
);
1603 gen_op_ltu(t0
, t0
, t1
);
1607 tcg_gen_and_tl(t0
, t0
, t1
);
1611 tcg_gen_nor_tl(t0
, t0
, t1
);
1615 tcg_gen_or_tl(t0
, t0
, t1
);
1619 tcg_gen_xor_tl(t0
, t0
, t1
);
1623 tcg_gen_mul_tl(t0
, t0
, t1
);
1624 tcg_gen_ext32s_tl(t0
, t0
);
1629 int l1
= gen_new_label();
1631 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1632 gen_store_gpr(t0
, rd
);
1639 int l1
= gen_new_label();
1641 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
1642 gen_store_gpr(t0
, rd
);
1648 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1649 tcg_gen_shl_tl(t0
, t1
, t0
);
1650 tcg_gen_ext32s_tl(t0
, t0
);
1654 tcg_gen_ext32s_tl(t1
, t1
);
1655 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1656 tcg_gen_sar_tl(t0
, t1
, t0
);
1660 switch ((ctx
->opcode
>> 6) & 0x1f) {
1662 tcg_gen_ext32u_tl(t1
, t1
);
1663 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1664 tcg_gen_shr_tl(t0
, t1
, t0
);
1665 tcg_gen_ext32s_tl(t0
, t0
);
1669 /* rotrv is decoded as srlv on non-R2 CPUs */
1670 if (env
->insn_flags
& ISA_MIPS32R2
) {
1671 int l1
= gen_new_label();
1672 int l2
= gen_new_label();
1674 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1675 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1677 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
1678 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
1680 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1681 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1682 tcg_gen_rotr_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1683 tcg_temp_free_i32(r_tmp1
);
1684 tcg_temp_free_i32(r_tmp2
);
1688 tcg_gen_mov_tl(t0
, t1
);
1692 tcg_gen_ext32u_tl(t1
, t1
);
1693 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1694 tcg_gen_shr_tl(t0
, t1
, t0
);
1695 tcg_gen_ext32s_tl(t0
, t0
);
1700 MIPS_INVAL("invalid srlv flag");
1701 generate_exception(ctx
, EXCP_RI
);
1705 #if defined(TARGET_MIPS64)
1707 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1708 tcg_gen_shl_tl(t0
, t1
, t0
);
1712 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1713 tcg_gen_sar_tl(t0
, t1
, t0
);
1717 switch ((ctx
->opcode
>> 6) & 0x1f) {
1719 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1720 tcg_gen_shr_tl(t0
, t1
, t0
);
1724 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1725 if (env
->insn_flags
& ISA_MIPS32R2
) {
1726 int l1
= gen_new_label();
1727 int l2
= gen_new_label();
1729 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1730 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1732 tcg_gen_rotr_tl(t0
, t1
, t0
);
1736 tcg_gen_mov_tl(t0
, t1
);
1740 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1741 tcg_gen_shr_tl(t0
, t1
, t0
);
1746 MIPS_INVAL("invalid dsrlv flag");
1747 generate_exception(ctx
, EXCP_RI
);
1754 generate_exception(ctx
, EXCP_RI
);
1757 gen_store_gpr(t0
, rd
);
1759 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1765 /* Arithmetic on HI/LO registers */
1766 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1768 const char *opn
= "hilo";
1770 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1777 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1781 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1786 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1788 tcg_gen_movi_tl(cpu_HI
[0], 0);
1793 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
1795 tcg_gen_movi_tl(cpu_LO
[0], 0);
1800 generate_exception(ctx
, EXCP_RI
);
1803 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1806 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1809 const char *opn
= "mul/div";
1810 TCGv t0
= tcg_temp_local_new();
1811 TCGv t1
= tcg_temp_local_new();
1813 gen_load_gpr(t0
, rs
);
1814 gen_load_gpr(t1
, rt
);
1818 int l1
= gen_new_label();
1820 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1822 int l2
= gen_new_label();
1823 TCGv_i32 r_tmp1
= tcg_temp_local_new_i32();
1824 TCGv_i32 r_tmp2
= tcg_temp_local_new_i32();
1825 TCGv_i32 r_tmp3
= tcg_temp_local_new_i32();
1827 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1828 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1829 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp1
, -1 << 31, l2
);
1830 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp2
, -1, l2
);
1831 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1832 tcg_gen_movi_tl(cpu_HI
[0], 0);
1835 tcg_gen_div_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1836 tcg_gen_rem_i32(r_tmp2
, r_tmp1
, r_tmp2
);
1837 tcg_gen_ext_i32_tl(cpu_LO
[0], r_tmp3
);
1838 tcg_gen_ext_i32_tl(cpu_HI
[0], r_tmp2
);
1839 tcg_temp_free_i32(r_tmp1
);
1840 tcg_temp_free_i32(r_tmp2
);
1841 tcg_temp_free_i32(r_tmp3
);
1849 int l1
= gen_new_label();
1851 tcg_gen_ext32s_tl(t1
, t1
);
1852 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1854 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
1855 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
1856 TCGv_i32 r_tmp3
= tcg_temp_new_i32();
1858 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1859 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1860 tcg_gen_divu_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1861 tcg_gen_remu_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1862 tcg_gen_ext_i32_tl(cpu_LO
[0], r_tmp3
);
1863 tcg_gen_ext_i32_tl(cpu_HI
[0], r_tmp1
);
1864 tcg_temp_free_i32(r_tmp1
);
1865 tcg_temp_free_i32(r_tmp2
);
1866 tcg_temp_free_i32(r_tmp3
);
1874 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1875 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1877 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
1878 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
1879 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1880 tcg_temp_free_i64(r_tmp2
);
1881 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
1882 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
1883 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
1884 tcg_temp_free_i64(r_tmp1
);
1885 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1886 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
1892 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1893 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1895 tcg_gen_ext32u_tl(t0
, t0
);
1896 tcg_gen_ext32u_tl(t1
, t1
);
1897 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
1898 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
1899 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1900 tcg_temp_free_i64(r_tmp2
);
1901 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
1902 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
1903 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
1904 tcg_temp_free_i64(r_tmp1
);
1905 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1906 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
1910 #if defined(TARGET_MIPS64)
1913 int l1
= gen_new_label();
1915 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1917 int l2
= gen_new_label();
1919 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
1920 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
1921 tcg_gen_mov_tl(cpu_LO
[0], t0
);
1922 tcg_gen_movi_tl(cpu_HI
[0], 0);
1925 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
1926 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
1934 int l1
= gen_new_label();
1936 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1937 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
1938 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
1944 gen_helper_dmult(t0
, t1
);
1948 gen_helper_dmultu(t0
, t1
);
1954 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1955 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1957 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
1958 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
1959 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1960 tcg_gen_concat_tl_i64(r_tmp2
, cpu_LO
[0], cpu_HI
[0]);
1961 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1962 tcg_temp_free_i64(r_tmp2
);
1963 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
1964 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
1965 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
1966 tcg_temp_free_i64(r_tmp1
);
1967 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1968 tcg_gen_ext32s_tl(cpu_LO
[1], t1
);
1974 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1975 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1977 tcg_gen_ext32u_tl(t0
, t0
);
1978 tcg_gen_ext32u_tl(t1
, t1
);
1979 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
1980 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
1981 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1982 tcg_gen_concat_tl_i64(r_tmp2
, cpu_LO
[0], cpu_HI
[0]);
1983 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1984 tcg_temp_free_i64(r_tmp2
);
1985 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
1986 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
1987 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
1988 tcg_temp_free_i64(r_tmp1
);
1989 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1990 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
1996 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1997 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1999 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
2000 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
2001 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2002 tcg_gen_concat_tl_i64(r_tmp2
, cpu_LO
[0], cpu_HI
[0]);
2003 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2004 tcg_temp_free_i64(r_tmp2
);
2005 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2006 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2007 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2008 tcg_temp_free_i64(r_tmp1
);
2009 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2010 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2016 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
2017 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
2019 tcg_gen_ext32u_tl(t0
, t0
);
2020 tcg_gen_ext32u_tl(t1
, t1
);
2021 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
2022 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
2023 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2024 tcg_gen_concat_tl_i64(r_tmp2
, cpu_LO
[0], cpu_HI
[0]);
2025 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2026 tcg_temp_free_i64(r_tmp2
);
2027 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2028 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2029 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2030 tcg_temp_free_i64(r_tmp1
);
2031 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2032 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2038 generate_exception(ctx
, EXCP_RI
);
2041 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2047 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2048 int rd
, int rs
, int rt
)
2050 const char *opn
= "mul vr54xx";
2051 TCGv t0
= tcg_temp_new();
2052 TCGv t1
= tcg_temp_new();
2054 gen_load_gpr(t0
, rs
);
2055 gen_load_gpr(t1
, rt
);
2058 case OPC_VR54XX_MULS
:
2059 gen_helper_muls(t0
, t0
, t1
);
2062 case OPC_VR54XX_MULSU
:
2063 gen_helper_mulsu(t0
, t0
, t1
);
2066 case OPC_VR54XX_MACC
:
2067 gen_helper_macc(t0
, t0
, t1
);
2070 case OPC_VR54XX_MACCU
:
2071 gen_helper_maccu(t0
, t0
, t1
);
2074 case OPC_VR54XX_MSAC
:
2075 gen_helper_msac(t0
, t0
, t1
);
2078 case OPC_VR54XX_MSACU
:
2079 gen_helper_msacu(t0
, t0
, t1
);
2082 case OPC_VR54XX_MULHI
:
2083 gen_helper_mulhi(t0
, t0
, t1
);
2086 case OPC_VR54XX_MULHIU
:
2087 gen_helper_mulhiu(t0
, t0
, t1
);
2090 case OPC_VR54XX_MULSHI
:
2091 gen_helper_mulshi(t0
, t0
, t1
);
2094 case OPC_VR54XX_MULSHIU
:
2095 gen_helper_mulshiu(t0
, t0
, t1
);
2098 case OPC_VR54XX_MACCHI
:
2099 gen_helper_macchi(t0
, t0
, t1
);
2102 case OPC_VR54XX_MACCHIU
:
2103 gen_helper_macchiu(t0
, t0
, t1
);
2106 case OPC_VR54XX_MSACHI
:
2107 gen_helper_msachi(t0
, t0
, t1
);
2110 case OPC_VR54XX_MSACHIU
:
2111 gen_helper_msachiu(t0
, t0
, t1
);
2115 MIPS_INVAL("mul vr54xx");
2116 generate_exception(ctx
, EXCP_RI
);
2119 gen_store_gpr(t0
, rd
);
2120 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2127 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2130 const char *opn
= "CLx";
2138 t0
= tcg_temp_new();
2139 gen_load_gpr(t0
, rs
);
2142 gen_helper_clo(cpu_gpr
[rd
], t0
);
2146 gen_helper_clz(cpu_gpr
[rd
], t0
);
2149 #if defined(TARGET_MIPS64)
2151 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2155 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2160 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2165 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2166 int rs
, int rt
, int16_t imm
)
2169 TCGv t0
= tcg_temp_local_new();
2170 TCGv t1
= tcg_temp_new();
2173 /* Load needed operands */
2181 /* Compare two registers */
2183 gen_load_gpr(t0
, rs
);
2184 gen_load_gpr(t1
, rt
);
2194 /* Compare register to immediate */
2195 if (rs
!= 0 || imm
!= 0) {
2196 gen_load_gpr(t0
, rs
);
2197 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2204 case OPC_TEQ
: /* rs == rs */
2205 case OPC_TEQI
: /* r0 == 0 */
2206 case OPC_TGE
: /* rs >= rs */
2207 case OPC_TGEI
: /* r0 >= 0 */
2208 case OPC_TGEU
: /* rs >= rs unsigned */
2209 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2211 tcg_gen_movi_tl(t0
, 1);
2213 case OPC_TLT
: /* rs < rs */
2214 case OPC_TLTI
: /* r0 < 0 */
2215 case OPC_TLTU
: /* rs < rs unsigned */
2216 case OPC_TLTIU
: /* r0 < 0 unsigned */
2217 case OPC_TNE
: /* rs != rs */
2218 case OPC_TNEI
: /* r0 != 0 */
2219 /* Never trap: treat as NOP. */
2223 generate_exception(ctx
, EXCP_RI
);
2230 gen_op_eq(t0
, t0
, t1
);
2234 gen_op_ge(t0
, t0
, t1
);
2238 gen_op_geu(t0
, t0
, t1
);
2242 gen_op_lt(t0
, t0
, t1
);
2246 gen_op_ltu(t0
, t0
, t1
);
2250 gen_op_ne(t0
, t0
, t1
);
2254 generate_exception(ctx
, EXCP_RI
);
2258 save_cpu_state(ctx
, 1);
2260 int l1
= gen_new_label();
2262 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2263 gen_helper_0i(raise_exception
, EXCP_TRAP
);
2266 ctx
->bstate
= BS_STOP
;
2272 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2274 TranslationBlock
*tb
;
2276 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2279 tcg_gen_exit_tb((long)tb
+ n
);
2286 /* Branches (before delay slot) */
2287 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2288 int rs
, int rt
, int32_t offset
)
2290 target_ulong btgt
= -1;
2292 int bcond_compute
= 0;
2293 TCGv t0
= tcg_temp_new();
2294 TCGv t1
= tcg_temp_new();
2296 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2297 #ifdef MIPS_DEBUG_DISAS
2298 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2300 generate_exception(ctx
, EXCP_RI
);
2304 /* Load needed operands */
2310 /* Compare two registers */
2312 gen_load_gpr(t0
, rs
);
2313 gen_load_gpr(t1
, rt
);
2316 btgt
= ctx
->pc
+ 4 + offset
;
2330 /* Compare to zero */
2332 gen_load_gpr(t0
, rs
);
2335 btgt
= ctx
->pc
+ 4 + offset
;
2339 /* Jump to immediate */
2340 btgt
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2344 /* Jump to register */
2345 if (offset
!= 0 && offset
!= 16) {
2346 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2347 others are reserved. */
2348 MIPS_INVAL("jump hint");
2349 generate_exception(ctx
, EXCP_RI
);
2352 gen_load_gpr(btarget
, rs
);
2355 MIPS_INVAL("branch/jump");
2356 generate_exception(ctx
, EXCP_RI
);
2359 if (bcond_compute
== 0) {
2360 /* No condition to be computed */
2362 case OPC_BEQ
: /* rx == rx */
2363 case OPC_BEQL
: /* rx == rx likely */
2364 case OPC_BGEZ
: /* 0 >= 0 */
2365 case OPC_BGEZL
: /* 0 >= 0 likely */
2366 case OPC_BLEZ
: /* 0 <= 0 */
2367 case OPC_BLEZL
: /* 0 <= 0 likely */
2369 ctx
->hflags
|= MIPS_HFLAG_B
;
2370 MIPS_DEBUG("balways");
2372 case OPC_BGEZAL
: /* 0 >= 0 */
2373 case OPC_BGEZALL
: /* 0 >= 0 likely */
2374 /* Always take and link */
2376 ctx
->hflags
|= MIPS_HFLAG_B
;
2377 MIPS_DEBUG("balways and link");
2379 case OPC_BNE
: /* rx != rx */
2380 case OPC_BGTZ
: /* 0 > 0 */
2381 case OPC_BLTZ
: /* 0 < 0 */
2383 MIPS_DEBUG("bnever (NOP)");
2385 case OPC_BLTZAL
: /* 0 < 0 */
2386 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2387 MIPS_DEBUG("bnever and link");
2389 case OPC_BLTZALL
: /* 0 < 0 likely */
2390 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2391 /* Skip the instruction in the delay slot */
2392 MIPS_DEBUG("bnever, link and skip");
2395 case OPC_BNEL
: /* rx != rx likely */
2396 case OPC_BGTZL
: /* 0 > 0 likely */
2397 case OPC_BLTZL
: /* 0 < 0 likely */
2398 /* Skip the instruction in the delay slot */
2399 MIPS_DEBUG("bnever and skip");
2403 ctx
->hflags
|= MIPS_HFLAG_B
;
2404 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2408 ctx
->hflags
|= MIPS_HFLAG_B
;
2409 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2412 ctx
->hflags
|= MIPS_HFLAG_BR
;
2413 MIPS_DEBUG("jr %s", regnames
[rs
]);
2417 ctx
->hflags
|= MIPS_HFLAG_BR
;
2418 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2421 MIPS_INVAL("branch/jump");
2422 generate_exception(ctx
, EXCP_RI
);
2428 gen_op_eq(bcond
, t0
, t1
);
2429 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2430 regnames
[rs
], regnames
[rt
], btgt
);
2433 gen_op_eq(bcond
, t0
, t1
);
2434 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2435 regnames
[rs
], regnames
[rt
], btgt
);
2438 gen_op_ne(bcond
, t0
, t1
);
2439 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2440 regnames
[rs
], regnames
[rt
], btgt
);
2443 gen_op_ne(bcond
, t0
, t1
);
2444 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2445 regnames
[rs
], regnames
[rt
], btgt
);
2448 gen_op_gez(bcond
, t0
);
2449 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2452 gen_op_gez(bcond
, t0
);
2453 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2456 gen_op_gez(bcond
, t0
);
2457 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2461 gen_op_gez(bcond
, t0
);
2463 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2466 gen_op_gtz(bcond
, t0
);
2467 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2470 gen_op_gtz(bcond
, t0
);
2471 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2474 gen_op_lez(bcond
, t0
);
2475 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2478 gen_op_lez(bcond
, t0
);
2479 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2482 gen_op_ltz(bcond
, t0
);
2483 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2486 gen_op_ltz(bcond
, t0
);
2487 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2490 gen_op_ltz(bcond
, t0
);
2492 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2494 ctx
->hflags
|= MIPS_HFLAG_BC
;
2497 gen_op_ltz(bcond
, t0
);
2499 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2501 ctx
->hflags
|= MIPS_HFLAG_BL
;
2504 MIPS_INVAL("conditional branch/jump");
2505 generate_exception(ctx
, EXCP_RI
);
2509 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2510 blink
, ctx
->hflags
, btgt
);
2512 ctx
->btarget
= btgt
;
2514 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ 8);
2522 /* special3 bitfield operations */
2523 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2524 int rs
, int lsb
, int msb
)
2526 TCGv t0
= tcg_temp_new();
2527 TCGv t1
= tcg_temp_new();
2530 gen_load_gpr(t1
, rs
);
2535 tcg_gen_shri_tl(t0
, t1
, lsb
);
2537 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2539 tcg_gen_ext32s_tl(t0
, t0
);
2542 #if defined(TARGET_MIPS64)
2544 tcg_gen_shri_tl(t0
, t1
, lsb
);
2546 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2550 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2551 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2554 tcg_gen_shri_tl(t0
, t1
, lsb
);
2555 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2561 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2562 gen_load_gpr(t0
, rt
);
2563 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2564 tcg_gen_shli_tl(t1
, t1
, lsb
);
2565 tcg_gen_andi_tl(t1
, t1
, mask
);
2566 tcg_gen_or_tl(t0
, t0
, t1
);
2567 tcg_gen_ext32s_tl(t0
, t0
);
2569 #if defined(TARGET_MIPS64)
2573 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2574 gen_load_gpr(t0
, rt
);
2575 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2576 tcg_gen_shli_tl(t1
, t1
, lsb
);
2577 tcg_gen_andi_tl(t1
, t1
, mask
);
2578 tcg_gen_or_tl(t0
, t0
, t1
);
2583 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2584 gen_load_gpr(t0
, rt
);
2585 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2586 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2587 tcg_gen_andi_tl(t1
, t1
, mask
);
2588 tcg_gen_or_tl(t0
, t0
, t1
);
2593 gen_load_gpr(t0
, rt
);
2594 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2595 gen_load_gpr(t0
, rt
);
2596 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2597 tcg_gen_shli_tl(t1
, t1
, lsb
);
2598 tcg_gen_andi_tl(t1
, t1
, mask
);
2599 tcg_gen_or_tl(t0
, t0
, t1
);
2604 MIPS_INVAL("bitops");
2605 generate_exception(ctx
, EXCP_RI
);
2610 gen_store_gpr(t0
, rt
);
2615 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2620 /* If no destination, treat it as a NOP. */
2625 t0
= tcg_temp_new();
2626 gen_load_gpr(t0
, rt
);
2630 TCGv t1
= tcg_temp_new();
2632 tcg_gen_shri_tl(t1
, t0
, 8);
2633 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2634 tcg_gen_shli_tl(t0
, t0
, 8);
2635 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2636 tcg_gen_or_tl(t0
, t0
, t1
);
2638 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2642 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2645 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2647 #if defined(TARGET_MIPS64)
2650 TCGv t1
= tcg_temp_new();
2652 tcg_gen_shri_tl(t1
, t0
, 8);
2653 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2654 tcg_gen_shli_tl(t0
, t0
, 8);
2655 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2656 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2662 TCGv t1
= tcg_temp_new();
2664 tcg_gen_shri_tl(t1
, t0
, 16);
2665 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2666 tcg_gen_shli_tl(t0
, t0
, 16);
2667 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2668 tcg_gen_or_tl(t0
, t0
, t1
);
2669 tcg_gen_shri_tl(t1
, t0
, 32);
2670 tcg_gen_shli_tl(t0
, t0
, 32);
2671 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2677 MIPS_INVAL("bsfhl");
2678 generate_exception(ctx
, EXCP_RI
);
2685 #ifndef CONFIG_USER_ONLY
2686 /* CP0 (MMU and control) */
2687 static inline void gen_mfc0_load32 (TCGv t
, target_ulong off
)
2689 TCGv_i32 r_tmp
= tcg_temp_new_i32();
2691 tcg_gen_ld_i32(r_tmp
, cpu_env
, off
);
2692 tcg_gen_ext_i32_tl(t
, r_tmp
);
2693 tcg_temp_free_i32(r_tmp
);
2696 static inline void gen_mfc0_load64 (TCGv t
, target_ulong off
)
2698 tcg_gen_ld_tl(t
, cpu_env
, off
);
2699 tcg_gen_ext32s_tl(t
, t
);
2702 static inline void gen_mtc0_store32 (TCGv t
, target_ulong off
)
2704 TCGv_i32 r_tmp
= tcg_temp_new_i32();
2706 tcg_gen_trunc_tl_i32(r_tmp
, t
);
2707 tcg_gen_st_i32(r_tmp
, cpu_env
, off
);
2708 tcg_temp_free_i32(r_tmp
);
2711 static inline void gen_mtc0_store64 (TCGv t
, target_ulong off
)
2713 tcg_gen_ext32s_tl(t
, t
);
2714 tcg_gen_st_tl(t
, cpu_env
, off
);
2717 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
2719 const char *rn
= "invalid";
2722 check_insn(env
, ctx
, ISA_MIPS32
);
2728 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Index
));
2732 check_insn(env
, ctx
, ASE_MT
);
2733 gen_helper_mfc0_mvpcontrol(t0
);
2737 check_insn(env
, ctx
, ASE_MT
);
2738 gen_helper_mfc0_mvpconf0(t0
);
2742 check_insn(env
, ctx
, ASE_MT
);
2743 gen_helper_mfc0_mvpconf1(t0
);
2753 gen_helper_mfc0_random(t0
);
2757 check_insn(env
, ctx
, ASE_MT
);
2758 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEControl
));
2762 check_insn(env
, ctx
, ASE_MT
);
2763 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf0
));
2767 check_insn(env
, ctx
, ASE_MT
);
2768 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf1
));
2772 check_insn(env
, ctx
, ASE_MT
);
2773 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_YQMask
));
2777 check_insn(env
, ctx
, ASE_MT
);
2778 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_VPESchedule
));
2782 check_insn(env
, ctx
, ASE_MT
);
2783 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_VPEScheFBack
));
2784 rn
= "VPEScheFBack";
2787 check_insn(env
, ctx
, ASE_MT
);
2788 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEOpt
));
2798 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2799 tcg_gen_ext32s_tl(t0
, t0
);
2803 check_insn(env
, ctx
, ASE_MT
);
2804 gen_helper_mfc0_tcstatus(t0
);
2808 check_insn(env
, ctx
, ASE_MT
);
2809 gen_helper_mfc0_tcbind(t0
);
2813 check_insn(env
, ctx
, ASE_MT
);
2814 gen_helper_mfc0_tcrestart(t0
);
2818 check_insn(env
, ctx
, ASE_MT
);
2819 gen_helper_mfc0_tchalt(t0
);
2823 check_insn(env
, ctx
, ASE_MT
);
2824 gen_helper_mfc0_tccontext(t0
);
2828 check_insn(env
, ctx
, ASE_MT
);
2829 gen_helper_mfc0_tcschedule(t0
);
2833 check_insn(env
, ctx
, ASE_MT
);
2834 gen_helper_mfc0_tcschefback(t0
);
2844 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2845 tcg_gen_ext32s_tl(t0
, t0
);
2855 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_Context
));
2856 tcg_gen_ext32s_tl(t0
, t0
);
2860 // gen_helper_mfc0_contextconfig(t0); /* SmartMIPS ASE */
2861 rn
= "ContextConfig";
2870 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageMask
));
2874 check_insn(env
, ctx
, ISA_MIPS32R2
);
2875 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageGrain
));
2885 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Wired
));
2889 check_insn(env
, ctx
, ISA_MIPS32R2
);
2890 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf0
));
2894 check_insn(env
, ctx
, ISA_MIPS32R2
);
2895 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf1
));
2899 check_insn(env
, ctx
, ISA_MIPS32R2
);
2900 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf2
));
2904 check_insn(env
, ctx
, ISA_MIPS32R2
);
2905 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf3
));
2909 check_insn(env
, ctx
, ISA_MIPS32R2
);
2910 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf4
));
2920 check_insn(env
, ctx
, ISA_MIPS32R2
);
2921 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_HWREna
));
2931 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
2932 tcg_gen_ext32s_tl(t0
, t0
);
2942 /* Mark as an IO operation because we read the time. */
2945 gen_helper_mfc0_count(t0
);
2948 ctx
->bstate
= BS_STOP
;
2952 /* 6,7 are implementation dependent */
2960 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
2961 tcg_gen_ext32s_tl(t0
, t0
);
2971 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Compare
));
2974 /* 6,7 are implementation dependent */
2982 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Status
));
2986 check_insn(env
, ctx
, ISA_MIPS32R2
);
2987 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_IntCtl
));
2991 check_insn(env
, ctx
, ISA_MIPS32R2
);
2992 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSCtl
));
2996 check_insn(env
, ctx
, ISA_MIPS32R2
);
2997 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSMap
));
3007 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Cause
));
3017 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3018 tcg_gen_ext32s_tl(t0
, t0
);
3028 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PRid
));
3032 check_insn(env
, ctx
, ISA_MIPS32R2
);
3033 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_EBase
));
3043 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config0
));
3047 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config1
));
3051 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config2
));
3055 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config3
));
3058 /* 4,5 are reserved */
3059 /* 6,7 are implementation dependent */
3061 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config6
));
3065 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config7
));
3075 gen_helper_mfc0_lladdr(t0
);
3085 gen_helper_1i(mfc0_watchlo
, t0
, sel
);
3095 gen_helper_1i(mfc0_watchhi
, t0
, sel
);
3105 #if defined(TARGET_MIPS64)
3106 check_insn(env
, ctx
, ISA_MIPS3
);
3107 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3108 tcg_gen_ext32s_tl(t0
, t0
);
3117 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3120 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Framemask
));
3128 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
3129 rn
= "'Diagnostic"; /* implementation dependent */
3134 gen_helper_mfc0_debug(t0
); /* EJTAG support */
3138 // gen_helper_mfc0_tracecontrol(t0); /* PDtrace support */
3139 rn
= "TraceControl";
3142 // gen_helper_mfc0_tracecontrol2(t0); /* PDtrace support */
3143 rn
= "TraceControl2";
3146 // gen_helper_mfc0_usertracedata(t0); /* PDtrace support */
3147 rn
= "UserTraceData";
3150 // gen_helper_mfc0_tracebpc(t0); /* PDtrace support */
3161 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3162 tcg_gen_ext32s_tl(t0
, t0
);
3172 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Performance0
));
3173 rn
= "Performance0";
3176 // gen_helper_mfc0_performance1(t0);
3177 rn
= "Performance1";
3180 // gen_helper_mfc0_performance2(t0);
3181 rn
= "Performance2";
3184 // gen_helper_mfc0_performance3(t0);
3185 rn
= "Performance3";
3188 // gen_helper_mfc0_performance4(t0);
3189 rn
= "Performance4";
3192 // gen_helper_mfc0_performance5(t0);
3193 rn
= "Performance5";
3196 // gen_helper_mfc0_performance6(t0);
3197 rn
= "Performance6";
3200 // gen_helper_mfc0_performance7(t0);
3201 rn
= "Performance7";
3208 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
3214 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
3227 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagLo
));
3234 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataLo
));
3247 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagHi
));
3254 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataHi
));
3264 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3265 tcg_gen_ext32s_tl(t0
, t0
);
3276 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DESAVE
));
3286 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3290 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3291 generate_exception(ctx
, EXCP_RI
);
3294 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
3296 const char *rn
= "invalid";
3299 check_insn(env
, ctx
, ISA_MIPS32
);
3308 gen_helper_mtc0_index(t0
);
3312 check_insn(env
, ctx
, ASE_MT
);
3313 gen_helper_mtc0_mvpcontrol(t0
);
3317 check_insn(env
, ctx
, ASE_MT
);
3322 check_insn(env
, ctx
, ASE_MT
);
3337 check_insn(env
, ctx
, ASE_MT
);
3338 gen_helper_mtc0_vpecontrol(t0
);
3342 check_insn(env
, ctx
, ASE_MT
);
3343 gen_helper_mtc0_vpeconf0(t0
);
3347 check_insn(env
, ctx
, ASE_MT
);
3348 gen_helper_mtc0_vpeconf1(t0
);
3352 check_insn(env
, ctx
, ASE_MT
);
3353 gen_helper_mtc0_yqmask(t0
);
3357 check_insn(env
, ctx
, ASE_MT
);
3358 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_VPESchedule
));
3362 check_insn(env
, ctx
, ASE_MT
);
3363 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_VPEScheFBack
));
3364 rn
= "VPEScheFBack";
3367 check_insn(env
, ctx
, ASE_MT
);
3368 gen_helper_mtc0_vpeopt(t0
);
3378 gen_helper_mtc0_entrylo0(t0
);
3382 check_insn(env
, ctx
, ASE_MT
);
3383 gen_helper_mtc0_tcstatus(t0
);
3387 check_insn(env
, ctx
, ASE_MT
);
3388 gen_helper_mtc0_tcbind(t0
);
3392 check_insn(env
, ctx
, ASE_MT
);
3393 gen_helper_mtc0_tcrestart(t0
);
3397 check_insn(env
, ctx
, ASE_MT
);
3398 gen_helper_mtc0_tchalt(t0
);
3402 check_insn(env
, ctx
, ASE_MT
);
3403 gen_helper_mtc0_tccontext(t0
);
3407 check_insn(env
, ctx
, ASE_MT
);
3408 gen_helper_mtc0_tcschedule(t0
);
3412 check_insn(env
, ctx
, ASE_MT
);
3413 gen_helper_mtc0_tcschefback(t0
);
3423 gen_helper_mtc0_entrylo1(t0
);
3433 gen_helper_mtc0_context(t0
);
3437 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
3438 rn
= "ContextConfig";
3447 gen_helper_mtc0_pagemask(t0
);
3451 check_insn(env
, ctx
, ISA_MIPS32R2
);
3452 gen_helper_mtc0_pagegrain(t0
);
3462 gen_helper_mtc0_wired(t0
);
3466 check_insn(env
, ctx
, ISA_MIPS32R2
);
3467 gen_helper_mtc0_srsconf0(t0
);
3471 check_insn(env
, ctx
, ISA_MIPS32R2
);
3472 gen_helper_mtc0_srsconf1(t0
);
3476 check_insn(env
, ctx
, ISA_MIPS32R2
);
3477 gen_helper_mtc0_srsconf2(t0
);
3481 check_insn(env
, ctx
, ISA_MIPS32R2
);
3482 gen_helper_mtc0_srsconf3(t0
);
3486 check_insn(env
, ctx
, ISA_MIPS32R2
);
3487 gen_helper_mtc0_srsconf4(t0
);
3497 check_insn(env
, ctx
, ISA_MIPS32R2
);
3498 gen_helper_mtc0_hwrena(t0
);
3512 gen_helper_mtc0_count(t0
);
3515 /* 6,7 are implementation dependent */
3519 /* Stop translation as we may have switched the execution mode */
3520 ctx
->bstate
= BS_STOP
;
3525 gen_helper_mtc0_entryhi(t0
);
3535 gen_helper_mtc0_compare(t0
);
3538 /* 6,7 are implementation dependent */
3542 /* Stop translation as we may have switched the execution mode */
3543 ctx
->bstate
= BS_STOP
;
3548 gen_helper_mtc0_status(t0
);
3549 /* BS_STOP isn't good enough here, hflags may have changed. */
3550 gen_save_pc(ctx
->pc
+ 4);
3551 ctx
->bstate
= BS_EXCP
;
3555 check_insn(env
, ctx
, ISA_MIPS32R2
);
3556 gen_helper_mtc0_intctl(t0
);
3557 /* Stop translation as we may have switched the execution mode */
3558 ctx
->bstate
= BS_STOP
;
3562 check_insn(env
, ctx
, ISA_MIPS32R2
);
3563 gen_helper_mtc0_srsctl(t0
);
3564 /* Stop translation as we may have switched the execution mode */
3565 ctx
->bstate
= BS_STOP
;
3569 check_insn(env
, ctx
, ISA_MIPS32R2
);
3570 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_SRSMap
));
3571 /* Stop translation as we may have switched the execution mode */
3572 ctx
->bstate
= BS_STOP
;
3582 gen_helper_mtc0_cause(t0
);
3588 /* Stop translation as we may have switched the execution mode */
3589 ctx
->bstate
= BS_STOP
;
3594 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_EPC
));
3608 check_insn(env
, ctx
, ISA_MIPS32R2
);
3609 gen_helper_mtc0_ebase(t0
);
3619 gen_helper_mtc0_config0(t0
);
3621 /* Stop translation as we may have switched the execution mode */
3622 ctx
->bstate
= BS_STOP
;
3625 /* ignored, read only */
3629 gen_helper_mtc0_config2(t0
);
3631 /* Stop translation as we may have switched the execution mode */
3632 ctx
->bstate
= BS_STOP
;
3635 /* ignored, read only */
3638 /* 4,5 are reserved */
3639 /* 6,7 are implementation dependent */
3649 rn
= "Invalid config selector";
3666 gen_helper_1i(mtc0_watchlo
, t0
, sel
);
3676 gen_helper_1i(mtc0_watchhi
, t0
, sel
);
3686 #if defined(TARGET_MIPS64)
3687 check_insn(env
, ctx
, ISA_MIPS3
);
3688 gen_helper_mtc0_xcontext(t0
);
3697 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3700 gen_helper_mtc0_framemask(t0
);
3709 rn
= "Diagnostic"; /* implementation dependent */
3714 gen_helper_mtc0_debug(t0
); /* EJTAG support */
3715 /* BS_STOP isn't good enough here, hflags may have changed. */
3716 gen_save_pc(ctx
->pc
+ 4);
3717 ctx
->bstate
= BS_EXCP
;
3721 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
3722 rn
= "TraceControl";
3723 /* Stop translation as we may have switched the execution mode */
3724 ctx
->bstate
= BS_STOP
;
3727 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
3728 rn
= "TraceControl2";
3729 /* Stop translation as we may have switched the execution mode */
3730 ctx
->bstate
= BS_STOP
;
3733 /* Stop translation as we may have switched the execution mode */
3734 ctx
->bstate
= BS_STOP
;
3735 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
3736 rn
= "UserTraceData";
3737 /* Stop translation as we may have switched the execution mode */
3738 ctx
->bstate
= BS_STOP
;
3741 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
3742 /* Stop translation as we may have switched the execution mode */
3743 ctx
->bstate
= BS_STOP
;
3754 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_DEPC
));
3764 gen_helper_mtc0_performance0(t0
);
3765 rn
= "Performance0";
3768 // gen_helper_mtc0_performance1(t0);
3769 rn
= "Performance1";
3772 // gen_helper_mtc0_performance2(t0);
3773 rn
= "Performance2";
3776 // gen_helper_mtc0_performance3(t0);
3777 rn
= "Performance3";
3780 // gen_helper_mtc0_performance4(t0);
3781 rn
= "Performance4";
3784 // gen_helper_mtc0_performance5(t0);
3785 rn
= "Performance5";
3788 // gen_helper_mtc0_performance6(t0);
3789 rn
= "Performance6";
3792 // gen_helper_mtc0_performance7(t0);
3793 rn
= "Performance7";
3819 gen_helper_mtc0_taglo(t0
);
3826 gen_helper_mtc0_datalo(t0
);
3839 gen_helper_mtc0_taghi(t0
);
3846 gen_helper_mtc0_datahi(t0
);
3857 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_ErrorEPC
));
3868 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_DESAVE
));
3874 /* Stop translation as we may have switched the execution mode */
3875 ctx
->bstate
= BS_STOP
;
3880 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3881 /* For simplicity assume that all writes can cause interrupts. */
3884 ctx
->bstate
= BS_STOP
;
3889 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3890 generate_exception(ctx
, EXCP_RI
);
3893 #if defined(TARGET_MIPS64)
3894 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
3896 const char *rn
= "invalid";
3899 check_insn(env
, ctx
, ISA_MIPS64
);
3905 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Index
));
3909 check_insn(env
, ctx
, ASE_MT
);
3910 gen_helper_mfc0_mvpcontrol(t0
);
3914 check_insn(env
, ctx
, ASE_MT
);
3915 gen_helper_mfc0_mvpconf0(t0
);
3919 check_insn(env
, ctx
, ASE_MT
);
3920 gen_helper_mfc0_mvpconf1(t0
);
3930 gen_helper_mfc0_random(t0
);
3934 check_insn(env
, ctx
, ASE_MT
);
3935 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEControl
));
3939 check_insn(env
, ctx
, ASE_MT
);
3940 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf0
));
3944 check_insn(env
, ctx
, ASE_MT
);
3945 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf1
));
3949 check_insn(env
, ctx
, ASE_MT
);
3950 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
3954 check_insn(env
, ctx
, ASE_MT
);
3955 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
3959 check_insn(env
, ctx
, ASE_MT
);
3960 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
3961 rn
= "VPEScheFBack";
3964 check_insn(env
, ctx
, ASE_MT
);
3965 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEOpt
));
3975 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
3979 check_insn(env
, ctx
, ASE_MT
);
3980 gen_helper_mfc0_tcstatus(t0
);
3984 check_insn(env
, ctx
, ASE_MT
);
3985 gen_helper_mfc0_tcbind(t0
);
3989 check_insn(env
, ctx
, ASE_MT
);
3990 gen_helper_dmfc0_tcrestart(t0
);
3994 check_insn(env
, ctx
, ASE_MT
);
3995 gen_helper_dmfc0_tchalt(t0
);
3999 check_insn(env
, ctx
, ASE_MT
);
4000 gen_helper_dmfc0_tccontext(t0
);
4004 check_insn(env
, ctx
, ASE_MT
);
4005 gen_helper_dmfc0_tcschedule(t0
);
4009 check_insn(env
, ctx
, ASE_MT
);
4010 gen_helper_dmfc0_tcschefback(t0
);
4020 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4030 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4034 // gen_helper_dmfc0_contextconfig(t0); /* SmartMIPS ASE */
4035 rn
= "ContextConfig";
4044 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageMask
));
4048 check_insn(env
, ctx
, ISA_MIPS32R2
);
4049 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageGrain
));
4059 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Wired
));
4063 check_insn(env
, ctx
, ISA_MIPS32R2
);
4064 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf0
));
4068 check_insn(env
, ctx
, ISA_MIPS32R2
);
4069 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf1
));
4073 check_insn(env
, ctx
, ISA_MIPS32R2
);
4074 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf2
));
4078 check_insn(env
, ctx
, ISA_MIPS32R2
);
4079 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf3
));
4083 check_insn(env
, ctx
, ISA_MIPS32R2
);
4084 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf4
));
4094 check_insn(env
, ctx
, ISA_MIPS32R2
);
4095 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_HWREna
));
4105 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4115 /* Mark as an IO operation because we read the time. */
4118 gen_helper_mfc0_count(t0
);
4121 ctx
->bstate
= BS_STOP
;
4125 /* 6,7 are implementation dependent */
4133 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4143 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Compare
));
4146 /* 6,7 are implementation dependent */
4154 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Status
));
4158 check_insn(env
, ctx
, ISA_MIPS32R2
);
4159 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_IntCtl
));
4163 check_insn(env
, ctx
, ISA_MIPS32R2
);
4164 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSCtl
));
4168 check_insn(env
, ctx
, ISA_MIPS32R2
);
4169 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSMap
));
4179 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Cause
));
4189 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4199 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PRid
));
4203 check_insn(env
, ctx
, ISA_MIPS32R2
);
4204 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_EBase
));
4214 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config0
));
4218 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config1
));
4222 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config2
));
4226 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config3
));
4229 /* 6,7 are implementation dependent */
4231 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config6
));
4235 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config7
));
4245 gen_helper_dmfc0_lladdr(t0
);
4255 gen_helper_1i(dmfc0_watchlo
, t0
, sel
);
4265 gen_helper_1i(mfc0_watchhi
, t0
, sel
);
4275 check_insn(env
, ctx
, ISA_MIPS3
);
4276 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4284 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4287 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Framemask
));
4295 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
4296 rn
= "'Diagnostic"; /* implementation dependent */
4301 gen_helper_mfc0_debug(t0
); /* EJTAG support */
4305 // gen_helper_dmfc0_tracecontrol(t0); /* PDtrace support */
4306 rn
= "TraceControl";
4309 // gen_helper_dmfc0_tracecontrol2(t0); /* PDtrace support */
4310 rn
= "TraceControl2";
4313 // gen_helper_dmfc0_usertracedata(t0); /* PDtrace support */
4314 rn
= "UserTraceData";
4317 // gen_helper_dmfc0_tracebpc(t0); /* PDtrace support */
4328 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4338 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Performance0
));
4339 rn
= "Performance0";
4342 // gen_helper_dmfc0_performance1(t0);
4343 rn
= "Performance1";
4346 // gen_helper_dmfc0_performance2(t0);
4347 rn
= "Performance2";
4350 // gen_helper_dmfc0_performance3(t0);
4351 rn
= "Performance3";
4354 // gen_helper_dmfc0_performance4(t0);
4355 rn
= "Performance4";
4358 // gen_helper_dmfc0_performance5(t0);
4359 rn
= "Performance5";
4362 // gen_helper_dmfc0_performance6(t0);
4363 rn
= "Performance6";
4366 // gen_helper_dmfc0_performance7(t0);
4367 rn
= "Performance7";
4374 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
4381 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
4394 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagLo
));
4401 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataLo
));
4414 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagHi
));
4421 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataHi
));
4431 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4442 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DESAVE
));
4452 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4456 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4457 generate_exception(ctx
, EXCP_RI
);
4460 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
4462 const char *rn
= "invalid";
4465 check_insn(env
, ctx
, ISA_MIPS64
);
4474 gen_helper_mtc0_index(t0
);
4478 check_insn(env
, ctx
, ASE_MT
);
4479 gen_helper_mtc0_mvpcontrol(t0
);
4483 check_insn(env
, ctx
, ASE_MT
);
4488 check_insn(env
, ctx
, ASE_MT
);
4503 check_insn(env
, ctx
, ASE_MT
);
4504 gen_helper_mtc0_vpecontrol(t0
);
4508 check_insn(env
, ctx
, ASE_MT
);
4509 gen_helper_mtc0_vpeconf0(t0
);
4513 check_insn(env
, ctx
, ASE_MT
);
4514 gen_helper_mtc0_vpeconf1(t0
);
4518 check_insn(env
, ctx
, ASE_MT
);
4519 gen_helper_mtc0_yqmask(t0
);
4523 check_insn(env
, ctx
, ASE_MT
);
4524 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4528 check_insn(env
, ctx
, ASE_MT
);
4529 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4530 rn
= "VPEScheFBack";
4533 check_insn(env
, ctx
, ASE_MT
);
4534 gen_helper_mtc0_vpeopt(t0
);
4544 gen_helper_mtc0_entrylo0(t0
);
4548 check_insn(env
, ctx
, ASE_MT
);
4549 gen_helper_mtc0_tcstatus(t0
);
4553 check_insn(env
, ctx
, ASE_MT
);
4554 gen_helper_mtc0_tcbind(t0
);
4558 check_insn(env
, ctx
, ASE_MT
);
4559 gen_helper_mtc0_tcrestart(t0
);
4563 check_insn(env
, ctx
, ASE_MT
);
4564 gen_helper_mtc0_tchalt(t0
);
4568 check_insn(env
, ctx
, ASE_MT
);
4569 gen_helper_mtc0_tccontext(t0
);
4573 check_insn(env
, ctx
, ASE_MT
);
4574 gen_helper_mtc0_tcschedule(t0
);
4578 check_insn(env
, ctx
, ASE_MT
);
4579 gen_helper_mtc0_tcschefback(t0
);
4589 gen_helper_mtc0_entrylo1(t0
);
4599 gen_helper_mtc0_context(t0
);
4603 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
4604 rn
= "ContextConfig";
4613 gen_helper_mtc0_pagemask(t0
);
4617 check_insn(env
, ctx
, ISA_MIPS32R2
);
4618 gen_helper_mtc0_pagegrain(t0
);
4628 gen_helper_mtc0_wired(t0
);
4632 check_insn(env
, ctx
, ISA_MIPS32R2
);
4633 gen_helper_mtc0_srsconf0(t0
);
4637 check_insn(env
, ctx
, ISA_MIPS32R2
);
4638 gen_helper_mtc0_srsconf1(t0
);
4642 check_insn(env
, ctx
, ISA_MIPS32R2
);
4643 gen_helper_mtc0_srsconf2(t0
);
4647 check_insn(env
, ctx
, ISA_MIPS32R2
);
4648 gen_helper_mtc0_srsconf3(t0
);
4652 check_insn(env
, ctx
, ISA_MIPS32R2
);
4653 gen_helper_mtc0_srsconf4(t0
);
4663 check_insn(env
, ctx
, ISA_MIPS32R2
);
4664 gen_helper_mtc0_hwrena(t0
);
4678 gen_helper_mtc0_count(t0
);
4681 /* 6,7 are implementation dependent */
4685 /* Stop translation as we may have switched the execution mode */
4686 ctx
->bstate
= BS_STOP
;
4691 gen_helper_mtc0_entryhi(t0
);
4701 gen_helper_mtc0_compare(t0
);
4704 /* 6,7 are implementation dependent */
4708 /* Stop translation as we may have switched the execution mode */
4709 ctx
->bstate
= BS_STOP
;
4714 gen_helper_mtc0_status(t0
);
4715 /* BS_STOP isn't good enough here, hflags may have changed. */
4716 gen_save_pc(ctx
->pc
+ 4);
4717 ctx
->bstate
= BS_EXCP
;
4721 check_insn(env
, ctx
, ISA_MIPS32R2
);
4722 gen_helper_mtc0_intctl(t0
);
4723 /* Stop translation as we may have switched the execution mode */
4724 ctx
->bstate
= BS_STOP
;
4728 check_insn(env
, ctx
, ISA_MIPS32R2
);
4729 gen_helper_mtc0_srsctl(t0
);
4730 /* Stop translation as we may have switched the execution mode */
4731 ctx
->bstate
= BS_STOP
;
4735 check_insn(env
, ctx
, ISA_MIPS32R2
);
4736 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_SRSMap
));
4737 /* Stop translation as we may have switched the execution mode */
4738 ctx
->bstate
= BS_STOP
;
4748 gen_helper_mtc0_cause(t0
);
4754 /* Stop translation as we may have switched the execution mode */
4755 ctx
->bstate
= BS_STOP
;
4760 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4774 check_insn(env
, ctx
, ISA_MIPS32R2
);
4775 gen_helper_mtc0_ebase(t0
);
4785 gen_helper_mtc0_config0(t0
);
4787 /* Stop translation as we may have switched the execution mode */
4788 ctx
->bstate
= BS_STOP
;
4795 gen_helper_mtc0_config2(t0
);
4797 /* Stop translation as we may have switched the execution mode */
4798 ctx
->bstate
= BS_STOP
;
4804 /* 6,7 are implementation dependent */
4806 rn
= "Invalid config selector";
4823 gen_helper_1i(mtc0_watchlo
, t0
, sel
);
4833 gen_helper_1i(mtc0_watchhi
, t0
, sel
);
4843 check_insn(env
, ctx
, ISA_MIPS3
);
4844 gen_helper_mtc0_xcontext(t0
);
4852 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4855 gen_helper_mtc0_framemask(t0
);
4864 rn
= "Diagnostic"; /* implementation dependent */
4869 gen_helper_mtc0_debug(t0
); /* EJTAG support */
4870 /* BS_STOP isn't good enough here, hflags may have changed. */
4871 gen_save_pc(ctx
->pc
+ 4);
4872 ctx
->bstate
= BS_EXCP
;
4876 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
4877 /* Stop translation as we may have switched the execution mode */
4878 ctx
->bstate
= BS_STOP
;
4879 rn
= "TraceControl";
4882 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
4883 /* Stop translation as we may have switched the execution mode */
4884 ctx
->bstate
= BS_STOP
;
4885 rn
= "TraceControl2";
4888 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
4889 /* Stop translation as we may have switched the execution mode */
4890 ctx
->bstate
= BS_STOP
;
4891 rn
= "UserTraceData";
4894 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
4895 /* Stop translation as we may have switched the execution mode */
4896 ctx
->bstate
= BS_STOP
;
4907 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4917 gen_helper_mtc0_performance0(t0
);
4918 rn
= "Performance0";
4921 // gen_helper_mtc0_performance1(t0);
4922 rn
= "Performance1";
4925 // gen_helper_mtc0_performance2(t0);
4926 rn
= "Performance2";
4929 // gen_helper_mtc0_performance3(t0);
4930 rn
= "Performance3";
4933 // gen_helper_mtc0_performance4(t0);
4934 rn
= "Performance4";
4937 // gen_helper_mtc0_performance5(t0);
4938 rn
= "Performance5";
4941 // gen_helper_mtc0_performance6(t0);
4942 rn
= "Performance6";
4945 // gen_helper_mtc0_performance7(t0);
4946 rn
= "Performance7";
4972 gen_helper_mtc0_taglo(t0
);
4979 gen_helper_mtc0_datalo(t0
);
4992 gen_helper_mtc0_taghi(t0
);
4999 gen_helper_mtc0_datahi(t0
);
5010 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5021 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_DESAVE
));
5027 /* Stop translation as we may have switched the execution mode */
5028 ctx
->bstate
= BS_STOP
;
5033 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5034 /* For simplicity assume that all writes can cause interrupts. */
5037 ctx
->bstate
= BS_STOP
;
5042 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5043 generate_exception(ctx
, EXCP_RI
);
5045 #endif /* TARGET_MIPS64 */
5047 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5048 int u
, int sel
, int h
)
5050 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5051 TCGv t0
= tcg_temp_local_new();
5053 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5054 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5055 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5056 tcg_gen_movi_tl(t0
, -1);
5057 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5058 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5059 tcg_gen_movi_tl(t0
, -1);
5065 gen_helper_mftc0_tcstatus(t0
);
5068 gen_helper_mftc0_tcbind(t0
);
5071 gen_helper_mftc0_tcrestart(t0
);
5074 gen_helper_mftc0_tchalt(t0
);
5077 gen_helper_mftc0_tccontext(t0
);
5080 gen_helper_mftc0_tcschedule(t0
);
5083 gen_helper_mftc0_tcschefback(t0
);
5086 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5093 gen_helper_mftc0_entryhi(t0
);
5096 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5102 gen_helper_mftc0_status(t0
);
5105 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5111 gen_helper_mftc0_debug(t0
);
5114 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5119 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5121 } else switch (sel
) {
5122 /* GPR registers. */
5124 gen_helper_1i(mftgpr
, t0
, rt
);
5126 /* Auxiliary CPU registers */
5130 gen_helper_1i(mftlo
, t0
, 0);
5133 gen_helper_1i(mfthi
, t0
, 0);
5136 gen_helper_1i(mftacx
, t0
, 0);
5139 gen_helper_1i(mftlo
, t0
, 1);
5142 gen_helper_1i(mfthi
, t0
, 1);
5145 gen_helper_1i(mftacx
, t0
, 1);
5148 gen_helper_1i(mftlo
, t0
, 2);
5151 gen_helper_1i(mfthi
, t0
, 2);
5154 gen_helper_1i(mftacx
, t0
, 2);
5157 gen_helper_1i(mftlo
, t0
, 3);
5160 gen_helper_1i(mfthi
, t0
, 3);
5163 gen_helper_1i(mftacx
, t0
, 3);
5166 gen_helper_mftdsp(t0
);
5172 /* Floating point (COP1). */
5174 /* XXX: For now we support only a single FPU context. */
5176 TCGv_i32 fp0
= tcg_temp_new_i32();
5178 gen_load_fpr32(fp0
, rt
);
5179 tcg_gen_ext_i32_tl(t0
, fp0
);
5180 tcg_temp_free_i32(fp0
);
5182 TCGv_i32 fp0
= tcg_temp_new_i32();
5184 gen_load_fpr32h(fp0
, rt
);
5185 tcg_gen_ext_i32_tl(t0
, fp0
);
5186 tcg_temp_free_i32(fp0
);
5190 /* XXX: For now we support only a single FPU context. */
5191 gen_helper_1i(cfc1
, t0
, rt
);
5193 /* COP2: Not implemented. */
5200 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5201 gen_store_gpr(t0
, rd
);
5207 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5208 generate_exception(ctx
, EXCP_RI
);
5211 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5212 int u
, int sel
, int h
)
5214 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5215 TCGv t0
= tcg_temp_local_new();
5217 gen_load_gpr(t0
, rt
);
5218 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5219 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5220 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5222 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5223 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5230 gen_helper_mttc0_tcstatus(t0
);
5233 gen_helper_mttc0_tcbind(t0
);
5236 gen_helper_mttc0_tcrestart(t0
);
5239 gen_helper_mttc0_tchalt(t0
);
5242 gen_helper_mttc0_tccontext(t0
);
5245 gen_helper_mttc0_tcschedule(t0
);
5248 gen_helper_mttc0_tcschefback(t0
);
5251 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5258 gen_helper_mttc0_entryhi(t0
);
5261 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5267 gen_helper_mttc0_status(t0
);
5270 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5276 gen_helper_mttc0_debug(t0
);
5279 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5284 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5286 } else switch (sel
) {
5287 /* GPR registers. */
5289 gen_helper_1i(mttgpr
, t0
, rd
);
5291 /* Auxiliary CPU registers */
5295 gen_helper_1i(mttlo
, t0
, 0);
5298 gen_helper_1i(mtthi
, t0
, 0);
5301 gen_helper_1i(mttacx
, t0
, 0);
5304 gen_helper_1i(mttlo
, t0
, 1);
5307 gen_helper_1i(mtthi
, t0
, 1);
5310 gen_helper_1i(mttacx
, t0
, 1);
5313 gen_helper_1i(mttlo
, t0
, 2);
5316 gen_helper_1i(mtthi
, t0
, 2);
5319 gen_helper_1i(mttacx
, t0
, 2);
5322 gen_helper_1i(mttlo
, t0
, 3);
5325 gen_helper_1i(mtthi
, t0
, 3);
5328 gen_helper_1i(mttacx
, t0
, 3);
5331 gen_helper_mttdsp(t0
);
5337 /* Floating point (COP1). */
5339 /* XXX: For now we support only a single FPU context. */
5341 TCGv_i32 fp0
= tcg_temp_new_i32();
5343 tcg_gen_trunc_tl_i32(fp0
, t0
);
5344 gen_store_fpr32(fp0
, rd
);
5345 tcg_temp_free_i32(fp0
);
5347 TCGv_i32 fp0
= tcg_temp_new_i32();
5349 tcg_gen_trunc_tl_i32(fp0
, t0
);
5350 gen_store_fpr32h(fp0
, rd
);
5351 tcg_temp_free_i32(fp0
);
5355 /* XXX: For now we support only a single FPU context. */
5356 gen_helper_1i(ctc1
, t0
, rd
);
5358 /* COP2: Not implemented. */
5365 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5371 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5372 generate_exception(ctx
, EXCP_RI
);
5375 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5377 const char *opn
= "ldst";
5386 TCGv t0
= tcg_temp_local_new();
5388 gen_mfc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5389 gen_store_gpr(t0
, rt
);
5396 TCGv t0
= tcg_temp_local_new();
5398 gen_load_gpr(t0
, rt
);
5399 save_cpu_state(ctx
, 1);
5400 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5405 #if defined(TARGET_MIPS64)
5407 check_insn(env
, ctx
, ISA_MIPS3
);
5413 TCGv t0
= tcg_temp_local_new();
5415 gen_dmfc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5416 gen_store_gpr(t0
, rt
);
5422 check_insn(env
, ctx
, ISA_MIPS3
);
5424 TCGv t0
= tcg_temp_local_new();
5426 gen_load_gpr(t0
, rt
);
5427 save_cpu_state(ctx
, 1);
5428 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5435 check_insn(env
, ctx
, ASE_MT
);
5440 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5441 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5445 check_insn(env
, ctx
, ASE_MT
);
5446 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5447 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5452 if (!env
->tlb
->helper_tlbwi
)
5458 if (!env
->tlb
->helper_tlbwr
)
5464 if (!env
->tlb
->helper_tlbp
)
5470 if (!env
->tlb
->helper_tlbr
)
5476 check_insn(env
, ctx
, ISA_MIPS2
);
5477 save_cpu_state(ctx
, 1);
5479 ctx
->bstate
= BS_EXCP
;
5483 check_insn(env
, ctx
, ISA_MIPS32
);
5484 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5486 generate_exception(ctx
, EXCP_RI
);
5488 save_cpu_state(ctx
, 1);
5490 ctx
->bstate
= BS_EXCP
;
5495 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5496 /* If we get an exception, we want to restart at next instruction */
5498 save_cpu_state(ctx
, 1);
5501 ctx
->bstate
= BS_EXCP
;
5506 generate_exception(ctx
, EXCP_RI
);
5509 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5511 #endif /* !CONFIG_USER_ONLY */
5513 /* CP1 Branches (before delay slot) */
5514 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5515 int32_t cc
, int32_t offset
)
5517 target_ulong btarget
;
5518 const char *opn
= "cp1 cond branch";
5519 TCGv_i32 t0
= tcg_temp_new_i32();
5522 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5524 btarget
= ctx
->pc
+ 4 + offset
;
5529 int l1
= gen_new_label();
5530 int l2
= gen_new_label();
5533 tcg_gen_andi_i32(t0
, t0
, 0x1 << cc
);
5534 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
5535 tcg_gen_movi_tl(bcond
, 0);
5538 tcg_gen_movi_tl(bcond
, 1);
5545 int l1
= gen_new_label();
5546 int l2
= gen_new_label();
5549 tcg_gen_andi_i32(t0
, t0
, 0x1 << cc
);
5550 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
5551 tcg_gen_movi_tl(bcond
, 0);
5554 tcg_gen_movi_tl(bcond
, 1);
5561 int l1
= gen_new_label();
5562 int l2
= gen_new_label();
5565 tcg_gen_andi_i32(t0
, t0
, 0x1 << cc
);
5566 tcg_gen_brcondi_i32(TCG_COND_NE
, t0
, 0, l1
);
5567 tcg_gen_movi_tl(bcond
, 0);
5570 tcg_gen_movi_tl(bcond
, 1);
5577 int l1
= gen_new_label();
5578 int l2
= gen_new_label();
5581 tcg_gen_andi_i32(t0
, t0
, 0x1 << cc
);
5582 tcg_gen_brcondi_i32(TCG_COND_NE
, t0
, 0, l1
);
5583 tcg_gen_movi_tl(bcond
, 0);
5586 tcg_gen_movi_tl(bcond
, 1);
5591 ctx
->hflags
|= MIPS_HFLAG_BL
;
5595 int l1
= gen_new_label();
5596 int l2
= gen_new_label();
5599 tcg_gen_andi_i32(t0
, t0
, 0x3 << cc
);
5600 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
5601 tcg_gen_movi_tl(bcond
, 0);
5604 tcg_gen_movi_tl(bcond
, 1);
5611 int l1
= gen_new_label();
5612 int l2
= gen_new_label();
5615 tcg_gen_andi_i32(t0
, t0
, 0x3 << cc
);
5616 tcg_gen_brcondi_i32(TCG_COND_NE
, t0
, 0, l1
);
5617 tcg_gen_movi_tl(bcond
, 0);
5620 tcg_gen_movi_tl(bcond
, 1);
5627 int l1
= gen_new_label();
5628 int l2
= gen_new_label();
5631 tcg_gen_andi_i32(t0
, t0
, 0xf << cc
);
5632 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
5633 tcg_gen_movi_tl(bcond
, 0);
5636 tcg_gen_movi_tl(bcond
, 1);
5643 int l1
= gen_new_label();
5644 int l2
= gen_new_label();
5647 tcg_gen_andi_i32(t0
, t0
, 0xf << cc
);
5648 tcg_gen_brcondi_i32(TCG_COND_NE
, t0
, 0, l1
);
5649 tcg_gen_movi_tl(bcond
, 0);
5652 tcg_gen_movi_tl(bcond
, 1);
5657 ctx
->hflags
|= MIPS_HFLAG_BC
;
5661 generate_exception (ctx
, EXCP_RI
);
5664 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5665 ctx
->hflags
, btarget
);
5666 ctx
->btarget
= btarget
;
5669 tcg_temp_free_i32(t0
);
5672 /* Coprocessor 1 (FPU) */
5674 #define FOP(func, fmt) (((fmt) << 21) | (func))
5676 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5678 const char *opn
= "cp1 move";
5679 TCGv t0
= tcg_temp_local_new();
5684 TCGv_i32 fp0
= tcg_temp_new_i32();
5686 gen_load_fpr32(fp0
, fs
);
5687 tcg_gen_ext_i32_tl(t0
, fp0
);
5688 tcg_temp_free_i32(fp0
);
5690 gen_store_gpr(t0
, rt
);
5694 gen_load_gpr(t0
, rt
);
5696 TCGv_i32 fp0
= tcg_temp_new_i32();
5698 tcg_gen_trunc_tl_i32(fp0
, t0
);
5699 gen_store_fpr32(fp0
, fs
);
5700 tcg_temp_free_i32(fp0
);
5705 gen_helper_1i(cfc1
, t0
, fs
);
5706 gen_store_gpr(t0
, rt
);
5710 gen_load_gpr(t0
, rt
);
5711 gen_helper_1i(ctc1
, t0
, fs
);
5716 TCGv_i64 fp0
= tcg_temp_new_i64();
5718 gen_load_fpr64(ctx
, fp0
, fs
);
5719 tcg_gen_trunc_i64_tl(t0
, fp0
);
5720 tcg_temp_free_i64(fp0
);
5722 gen_store_gpr(t0
, rt
);
5726 gen_load_gpr(t0
, rt
);
5728 TCGv_i64 fp0
= tcg_temp_new_i64();
5730 tcg_gen_extu_tl_i64(fp0
, t0
);
5731 gen_store_fpr64(ctx
, fp0
, fs
);
5732 tcg_temp_free_i64(fp0
);
5738 TCGv_i32 fp0
= tcg_temp_new_i32();
5740 gen_load_fpr32h(fp0
, fs
);
5741 tcg_gen_ext_i32_tl(t0
, fp0
);
5742 tcg_temp_free_i32(fp0
);
5744 gen_store_gpr(t0
, rt
);
5748 gen_load_gpr(t0
, rt
);
5750 TCGv_i32 fp0
= tcg_temp_new_i32();
5752 tcg_gen_trunc_tl_i32(fp0
, t0
);
5753 gen_store_fpr32h(fp0
, fs
);
5754 tcg_temp_free_i32(fp0
);
5760 generate_exception (ctx
, EXCP_RI
);
5763 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5769 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5771 int l1
= gen_new_label();
5774 TCGv t0
= tcg_temp_local_new();
5775 TCGv_i32 r_tmp
= tcg_temp_new_i32();
5778 ccbit
= 1 << (24 + cc
);
5786 gen_load_gpr(t0
, rd
);
5787 tcg_gen_andi_i32(r_tmp
, fpu_fcr31
, ccbit
);
5788 tcg_gen_brcondi_i32(cond
, r_tmp
, 0, l1
);
5789 tcg_temp_free_i32(r_tmp
);
5790 gen_load_gpr(t0
, rs
);
5792 gen_store_gpr(t0
, rd
);
5796 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5800 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
5801 TCGv_i32 fp0
= tcg_temp_local_new_i32();
5802 int l1
= gen_new_label();
5805 ccbit
= 1 << (24 + cc
);
5814 gen_load_fpr32(fp0
, fd
);
5815 tcg_gen_andi_i32(r_tmp1
, fpu_fcr31
, ccbit
);
5816 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5817 tcg_temp_free_i32(r_tmp1
);
5818 gen_load_fpr32(fp0
, fs
);
5820 gen_store_fpr32(fp0
, fd
);
5821 tcg_temp_free_i32(fp0
);
5824 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5828 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
5829 TCGv_i64 fp0
= tcg_temp_local_new_i64();
5830 int l1
= gen_new_label();
5833 ccbit
= 1 << (24 + cc
);
5842 gen_load_fpr64(ctx
, fp0
, fd
);
5843 tcg_gen_andi_i32(r_tmp1
, fpu_fcr31
, ccbit
);
5844 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5845 tcg_temp_free_i32(r_tmp1
);
5846 gen_load_fpr64(ctx
, fp0
, fs
);
5848 gen_store_fpr64(ctx
, fp0
, fd
);
5849 tcg_temp_free_i64(fp0
);
5852 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5854 uint32_t ccbit1
, ccbit2
;
5856 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
5857 TCGv_i32 fp0
= tcg_temp_local_new_i32();
5858 int l1
= gen_new_label();
5859 int l2
= gen_new_label();
5862 ccbit1
= 1 << (24 + cc
);
5863 ccbit2
= 1 << (25 + cc
);
5874 gen_load_fpr32(fp0
, fd
);
5875 tcg_gen_andi_i32(r_tmp1
, fpu_fcr31
, ccbit1
);
5876 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5877 gen_load_fpr32(fp0
, fs
);
5879 gen_store_fpr32(fp0
, fd
);
5881 gen_load_fpr32h(fp0
, fd
);
5882 tcg_gen_andi_i32(r_tmp1
, fpu_fcr31
, ccbit2
);
5883 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l2
);
5884 gen_load_fpr32h(fp0
, fs
);
5886 gen_store_fpr32h(fp0
, fd
);
5888 tcg_temp_free_i32(r_tmp1
);
5889 tcg_temp_free_i32(fp0
);
5893 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5894 int ft
, int fs
, int fd
, int cc
)
5896 const char *opn
= "farith";
5897 const char *condnames
[] = {
5915 const char *condnames_abs
[] = {
5933 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5934 uint32_t func
= ctx
->opcode
& 0x3f;
5936 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5939 TCGv_i32 fp0
= tcg_temp_new_i32();
5940 TCGv_i32 fp1
= tcg_temp_new_i32();
5942 gen_load_fpr32(fp0
, fs
);
5943 gen_load_fpr32(fp1
, ft
);
5944 gen_helper_float_add_s(fp0
, fp0
, fp1
);
5945 tcg_temp_free_i32(fp1
);
5946 gen_store_fpr32(fp0
, fd
);
5947 tcg_temp_free_i32(fp0
);
5954 TCGv_i32 fp0
= tcg_temp_new_i32();
5955 TCGv_i32 fp1
= tcg_temp_new_i32();
5957 gen_load_fpr32(fp0
, fs
);
5958 gen_load_fpr32(fp1
, ft
);
5959 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
5960 tcg_temp_free_i32(fp1
);
5961 gen_store_fpr32(fp0
, fd
);
5962 tcg_temp_free_i32(fp0
);
5969 TCGv_i32 fp0
= tcg_temp_new_i32();
5970 TCGv_i32 fp1
= tcg_temp_new_i32();
5972 gen_load_fpr32(fp0
, fs
);
5973 gen_load_fpr32(fp1
, ft
);
5974 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
5975 tcg_temp_free_i32(fp1
);
5976 gen_store_fpr32(fp0
, fd
);
5977 tcg_temp_free_i32(fp0
);
5984 TCGv_i32 fp0
= tcg_temp_new_i32();
5985 TCGv_i32 fp1
= tcg_temp_new_i32();
5987 gen_load_fpr32(fp0
, fs
);
5988 gen_load_fpr32(fp1
, ft
);
5989 gen_helper_float_div_s(fp0
, fp0
, fp1
);
5990 tcg_temp_free_i32(fp1
);
5991 gen_store_fpr32(fp0
, fd
);
5992 tcg_temp_free_i32(fp0
);
5999 TCGv_i32 fp0
= tcg_temp_new_i32();
6001 gen_load_fpr32(fp0
, fs
);
6002 gen_helper_float_sqrt_s(fp0
, fp0
);
6003 gen_store_fpr32(fp0
, fd
);
6004 tcg_temp_free_i32(fp0
);
6010 TCGv_i32 fp0
= tcg_temp_new_i32();
6012 gen_load_fpr32(fp0
, fs
);
6013 gen_helper_float_abs_s(fp0
, fp0
);
6014 gen_store_fpr32(fp0
, fd
);
6015 tcg_temp_free_i32(fp0
);
6021 TCGv_i32 fp0
= tcg_temp_new_i32();
6023 gen_load_fpr32(fp0
, fs
);
6024 gen_store_fpr32(fp0
, fd
);
6025 tcg_temp_free_i32(fp0
);
6031 TCGv_i32 fp0
= tcg_temp_new_i32();
6033 gen_load_fpr32(fp0
, fs
);
6034 gen_helper_float_chs_s(fp0
, fp0
);
6035 gen_store_fpr32(fp0
, fd
);
6036 tcg_temp_free_i32(fp0
);
6041 check_cp1_64bitmode(ctx
);
6043 TCGv_i32 fp32
= tcg_temp_new_i32();
6044 TCGv_i64 fp64
= tcg_temp_new_i64();
6046 gen_load_fpr32(fp32
, fs
);
6047 gen_helper_float_roundl_s(fp64
, fp32
);
6048 tcg_temp_free_i32(fp32
);
6049 gen_store_fpr64(ctx
, fp64
, fd
);
6050 tcg_temp_free_i64(fp64
);
6055 check_cp1_64bitmode(ctx
);
6057 TCGv_i32 fp32
= tcg_temp_new_i32();
6058 TCGv_i64 fp64
= tcg_temp_new_i64();
6060 gen_load_fpr32(fp32
, fs
);
6061 gen_helper_float_truncl_s(fp64
, fp32
);
6062 tcg_temp_free_i32(fp32
);
6063 gen_store_fpr64(ctx
, fp64
, fd
);
6064 tcg_temp_free_i64(fp64
);
6069 check_cp1_64bitmode(ctx
);
6071 TCGv_i32 fp32
= tcg_temp_new_i32();
6072 TCGv_i64 fp64
= tcg_temp_new_i64();
6074 gen_load_fpr32(fp32
, fs
);
6075 gen_helper_float_ceill_s(fp64
, fp32
);
6076 tcg_temp_free_i32(fp32
);
6077 gen_store_fpr64(ctx
, fp64
, fd
);
6078 tcg_temp_free_i64(fp64
);
6083 check_cp1_64bitmode(ctx
);
6085 TCGv_i32 fp32
= tcg_temp_new_i32();
6086 TCGv_i64 fp64
= tcg_temp_new_i64();
6088 gen_load_fpr32(fp32
, fs
);
6089 gen_helper_float_floorl_s(fp64
, fp32
);
6090 tcg_temp_free_i32(fp32
);
6091 gen_store_fpr64(ctx
, fp64
, fd
);
6092 tcg_temp_free_i64(fp64
);
6098 TCGv_i32 fp0
= tcg_temp_new_i32();
6100 gen_load_fpr32(fp0
, fs
);
6101 gen_helper_float_roundw_s(fp0
, fp0
);
6102 gen_store_fpr32(fp0
, fd
);
6103 tcg_temp_free_i32(fp0
);
6109 TCGv_i32 fp0
= tcg_temp_new_i32();
6111 gen_load_fpr32(fp0
, fs
);
6112 gen_helper_float_truncw_s(fp0
, fp0
);
6113 gen_store_fpr32(fp0
, fd
);
6114 tcg_temp_free_i32(fp0
);
6120 TCGv_i32 fp0
= tcg_temp_new_i32();
6122 gen_load_fpr32(fp0
, fs
);
6123 gen_helper_float_ceilw_s(fp0
, fp0
);
6124 gen_store_fpr32(fp0
, fd
);
6125 tcg_temp_free_i32(fp0
);
6131 TCGv_i32 fp0
= tcg_temp_new_i32();
6133 gen_load_fpr32(fp0
, fs
);
6134 gen_helper_float_floorw_s(fp0
, fp0
);
6135 gen_store_fpr32(fp0
, fd
);
6136 tcg_temp_free_i32(fp0
);
6141 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6146 int l1
= gen_new_label();
6147 TCGv t0
= tcg_temp_new();
6148 TCGv_i32 fp0
= tcg_temp_local_new_i32();
6150 gen_load_gpr(t0
, ft
);
6151 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6152 gen_load_fpr32(fp0
, fs
);
6153 gen_store_fpr32(fp0
, fd
);
6154 tcg_temp_free_i32(fp0
);
6162 int l1
= gen_new_label();
6163 TCGv t0
= tcg_temp_new();
6164 TCGv_i32 fp0
= tcg_temp_local_new_i32();
6166 gen_load_gpr(t0
, ft
);
6167 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6168 gen_load_fpr32(fp0
, fs
);
6169 gen_store_fpr32(fp0
, fd
);
6170 tcg_temp_free_i32(fp0
);
6179 TCGv_i32 fp0
= tcg_temp_new_i32();
6181 gen_load_fpr32(fp0
, fs
);
6182 gen_helper_float_recip_s(fp0
, fp0
);
6183 gen_store_fpr32(fp0
, fd
);
6184 tcg_temp_free_i32(fp0
);
6191 TCGv_i32 fp0
= tcg_temp_new_i32();
6193 gen_load_fpr32(fp0
, fs
);
6194 gen_helper_float_rsqrt_s(fp0
, fp0
);
6195 gen_store_fpr32(fp0
, fd
);
6196 tcg_temp_free_i32(fp0
);
6201 check_cp1_64bitmode(ctx
);
6203 TCGv_i32 fp0
= tcg_temp_new_i32();
6204 TCGv_i32 fp1
= tcg_temp_new_i32();
6206 gen_load_fpr32(fp0
, fs
);
6207 gen_load_fpr32(fp1
, fd
);
6208 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6209 tcg_temp_free_i32(fp1
);
6210 gen_store_fpr32(fp0
, fd
);
6211 tcg_temp_free_i32(fp0
);
6216 check_cp1_64bitmode(ctx
);
6218 TCGv_i32 fp0
= tcg_temp_new_i32();
6220 gen_load_fpr32(fp0
, fs
);
6221 gen_helper_float_recip1_s(fp0
, fp0
);
6222 gen_store_fpr32(fp0
, fd
);
6223 tcg_temp_free_i32(fp0
);
6228 check_cp1_64bitmode(ctx
);
6230 TCGv_i32 fp0
= tcg_temp_new_i32();
6232 gen_load_fpr32(fp0
, fs
);
6233 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6234 gen_store_fpr32(fp0
, fd
);
6235 tcg_temp_free_i32(fp0
);
6240 check_cp1_64bitmode(ctx
);
6242 TCGv_i32 fp0
= tcg_temp_new_i32();
6243 TCGv_i32 fp1
= tcg_temp_new_i32();
6245 gen_load_fpr32(fp0
, fs
);
6246 gen_load_fpr32(fp1
, ft
);
6247 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6248 tcg_temp_free_i32(fp1
);
6249 gen_store_fpr32(fp0
, fd
);
6250 tcg_temp_free_i32(fp0
);
6255 check_cp1_registers(ctx
, fd
);
6257 TCGv_i32 fp32
= tcg_temp_new_i32();
6258 TCGv_i64 fp64
= tcg_temp_new_i64();
6260 gen_load_fpr32(fp32
, fs
);
6261 gen_helper_float_cvtd_s(fp64
, fp32
);
6262 tcg_temp_free_i32(fp32
);
6263 gen_store_fpr64(ctx
, fp64
, fd
);
6264 tcg_temp_free_i64(fp64
);
6270 TCGv_i32 fp0
= tcg_temp_new_i32();
6272 gen_load_fpr32(fp0
, fs
);
6273 gen_helper_float_cvtw_s(fp0
, fp0
);
6274 gen_store_fpr32(fp0
, fd
);
6275 tcg_temp_free_i32(fp0
);
6280 check_cp1_64bitmode(ctx
);
6282 TCGv_i32 fp32
= tcg_temp_new_i32();
6283 TCGv_i64 fp64
= tcg_temp_new_i64();
6285 gen_load_fpr32(fp32
, fs
);
6286 gen_helper_float_cvtl_s(fp64
, fp32
);
6287 tcg_temp_free_i32(fp32
);
6288 gen_store_fpr64(ctx
, fp64
, fd
);
6289 tcg_temp_free_i64(fp64
);
6294 check_cp1_64bitmode(ctx
);
6296 TCGv_i64 fp64
= tcg_temp_new_i64();
6297 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6298 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6300 gen_load_fpr32(fp32_0
, fs
);
6301 gen_load_fpr32(fp32_1
, ft
);
6302 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6303 tcg_temp_free_i32(fp32_1
);
6304 tcg_temp_free_i32(fp32_0
);
6305 gen_store_fpr64(ctx
, fp64
, fd
);
6306 tcg_temp_free_i64(fp64
);
6327 TCGv_i32 fp0
= tcg_temp_new_i32();
6328 TCGv_i32 fp1
= tcg_temp_new_i32();
6330 gen_load_fpr32(fp0
, fs
);
6331 gen_load_fpr32(fp1
, ft
);
6332 if (ctx
->opcode
& (1 << 6)) {
6334 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6335 opn
= condnames_abs
[func
-48];
6337 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6338 opn
= condnames
[func
-48];
6340 tcg_temp_free_i32(fp0
);
6341 tcg_temp_free_i32(fp1
);
6345 check_cp1_registers(ctx
, fs
| ft
| fd
);
6347 TCGv_i64 fp0
= tcg_temp_new_i64();
6348 TCGv_i64 fp1
= tcg_temp_new_i64();
6350 gen_load_fpr64(ctx
, fp0
, fs
);
6351 gen_load_fpr64(ctx
, fp1
, ft
);
6352 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6353 tcg_temp_free_i64(fp1
);
6354 gen_store_fpr64(ctx
, fp0
, fd
);
6355 tcg_temp_free_i64(fp0
);
6361 check_cp1_registers(ctx
, fs
| ft
| fd
);
6363 TCGv_i64 fp0
= tcg_temp_new_i64();
6364 TCGv_i64 fp1
= tcg_temp_new_i64();
6366 gen_load_fpr64(ctx
, fp0
, fs
);
6367 gen_load_fpr64(ctx
, fp1
, ft
);
6368 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6369 tcg_temp_free_i64(fp1
);
6370 gen_store_fpr64(ctx
, fp0
, fd
);
6371 tcg_temp_free_i64(fp0
);
6377 check_cp1_registers(ctx
, fs
| ft
| fd
);
6379 TCGv_i64 fp0
= tcg_temp_new_i64();
6380 TCGv_i64 fp1
= tcg_temp_new_i64();
6382 gen_load_fpr64(ctx
, fp0
, fs
);
6383 gen_load_fpr64(ctx
, fp1
, ft
);
6384 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6385 tcg_temp_free_i64(fp1
);
6386 gen_store_fpr64(ctx
, fp0
, fd
);
6387 tcg_temp_free_i64(fp0
);
6393 check_cp1_registers(ctx
, fs
| ft
| fd
);
6395 TCGv_i64 fp0
= tcg_temp_new_i64();
6396 TCGv_i64 fp1
= tcg_temp_new_i64();
6398 gen_load_fpr64(ctx
, fp0
, fs
);
6399 gen_load_fpr64(ctx
, fp1
, ft
);
6400 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6401 tcg_temp_free_i64(fp1
);
6402 gen_store_fpr64(ctx
, fp0
, fd
);
6403 tcg_temp_free_i64(fp0
);
6409 check_cp1_registers(ctx
, fs
| fd
);
6411 TCGv_i64 fp0
= tcg_temp_new_i64();
6413 gen_load_fpr64(ctx
, fp0
, fs
);
6414 gen_helper_float_sqrt_d(fp0
, fp0
);
6415 gen_store_fpr64(ctx
, fp0
, fd
);
6416 tcg_temp_free_i64(fp0
);
6421 check_cp1_registers(ctx
, fs
| fd
);
6423 TCGv_i64 fp0
= tcg_temp_new_i64();
6425 gen_load_fpr64(ctx
, fp0
, fs
);
6426 gen_helper_float_abs_d(fp0
, fp0
);
6427 gen_store_fpr64(ctx
, fp0
, fd
);
6428 tcg_temp_free_i64(fp0
);
6433 check_cp1_registers(ctx
, fs
| fd
);
6435 TCGv_i64 fp0
= tcg_temp_new_i64();
6437 gen_load_fpr64(ctx
, fp0
, fs
);
6438 gen_store_fpr64(ctx
, fp0
, fd
);
6439 tcg_temp_free_i64(fp0
);
6444 check_cp1_registers(ctx
, fs
| fd
);
6446 TCGv_i64 fp0
= tcg_temp_new_i64();
6448 gen_load_fpr64(ctx
, fp0
, fs
);
6449 gen_helper_float_chs_d(fp0
, fp0
);
6450 gen_store_fpr64(ctx
, fp0
, fd
);
6451 tcg_temp_free_i64(fp0
);
6456 check_cp1_64bitmode(ctx
);
6458 TCGv_i64 fp0
= tcg_temp_new_i64();
6460 gen_load_fpr64(ctx
, fp0
, fs
);
6461 gen_helper_float_roundl_d(fp0
, fp0
);
6462 gen_store_fpr64(ctx
, fp0
, fd
);
6463 tcg_temp_free_i64(fp0
);
6468 check_cp1_64bitmode(ctx
);
6470 TCGv_i64 fp0
= tcg_temp_new_i64();
6472 gen_load_fpr64(ctx
, fp0
, fs
);
6473 gen_helper_float_truncl_d(fp0
, fp0
);
6474 gen_store_fpr64(ctx
, fp0
, fd
);
6475 tcg_temp_free_i64(fp0
);
6480 check_cp1_64bitmode(ctx
);
6482 TCGv_i64 fp0
= tcg_temp_new_i64();
6484 gen_load_fpr64(ctx
, fp0
, fs
);
6485 gen_helper_float_ceill_d(fp0
, fp0
);
6486 gen_store_fpr64(ctx
, fp0
, fd
);
6487 tcg_temp_free_i64(fp0
);
6492 check_cp1_64bitmode(ctx
);
6494 TCGv_i64 fp0
= tcg_temp_new_i64();
6496 gen_load_fpr64(ctx
, fp0
, fs
);
6497 gen_helper_float_floorl_d(fp0
, fp0
);
6498 gen_store_fpr64(ctx
, fp0
, fd
);
6499 tcg_temp_free_i64(fp0
);
6504 check_cp1_registers(ctx
, fs
);
6506 TCGv_i32 fp32
= tcg_temp_new_i32();
6507 TCGv_i64 fp64
= tcg_temp_new_i64();
6509 gen_load_fpr64(ctx
, fp64
, fs
);
6510 gen_helper_float_roundw_d(fp32
, fp64
);
6511 tcg_temp_free_i64(fp64
);
6512 gen_store_fpr32(fp32
, fd
);
6513 tcg_temp_free_i32(fp32
);
6518 check_cp1_registers(ctx
, fs
);
6520 TCGv_i32 fp32
= tcg_temp_new_i32();
6521 TCGv_i64 fp64
= tcg_temp_new_i64();
6523 gen_load_fpr64(ctx
, fp64
, fs
);
6524 gen_helper_float_truncw_d(fp32
, fp64
);
6525 tcg_temp_free_i64(fp64
);
6526 gen_store_fpr32(fp32
, fd
);
6527 tcg_temp_free_i32(fp32
);
6532 check_cp1_registers(ctx
, fs
);
6534 TCGv_i32 fp32
= tcg_temp_new_i32();
6535 TCGv_i64 fp64
= tcg_temp_new_i64();
6537 gen_load_fpr64(ctx
, fp64
, fs
);
6538 gen_helper_float_ceilw_d(fp32
, fp64
);
6539 tcg_temp_free_i64(fp64
);
6540 gen_store_fpr32(fp32
, fd
);
6541 tcg_temp_free_i32(fp32
);
6546 check_cp1_registers(ctx
, fs
);
6548 TCGv_i32 fp32
= tcg_temp_new_i32();
6549 TCGv_i64 fp64
= tcg_temp_new_i64();
6551 gen_load_fpr64(ctx
, fp64
, fs
);
6552 gen_helper_float_floorw_d(fp32
, fp64
);
6553 tcg_temp_free_i64(fp64
);
6554 gen_store_fpr32(fp32
, fd
);
6555 tcg_temp_free_i32(fp32
);
6560 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6565 int l1
= gen_new_label();
6566 TCGv t0
= tcg_temp_new();
6567 TCGv_i64 fp0
= tcg_temp_local_new_i64();
6569 gen_load_gpr(t0
, ft
);
6570 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6571 gen_load_fpr64(ctx
, fp0
, fs
);
6572 gen_store_fpr64(ctx
, fp0
, fd
);
6573 tcg_temp_free_i64(fp0
);
6581 int l1
= gen_new_label();
6582 TCGv t0
= tcg_temp_new();
6583 TCGv_i64 fp0
= tcg_temp_local_new_i64();
6585 gen_load_gpr(t0
, ft
);
6586 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6587 gen_load_fpr64(ctx
, fp0
, fs
);
6588 gen_store_fpr64(ctx
, fp0
, fd
);
6589 tcg_temp_free_i64(fp0
);
6596 check_cp1_64bitmode(ctx
);
6598 TCGv_i64 fp0
= tcg_temp_new_i64();
6600 gen_load_fpr64(ctx
, fp0
, fs
);
6601 gen_helper_float_recip_d(fp0
, fp0
);
6602 gen_store_fpr64(ctx
, fp0
, fd
);
6603 tcg_temp_free_i64(fp0
);
6608 check_cp1_64bitmode(ctx
);
6610 TCGv_i64 fp0
= tcg_temp_new_i64();
6612 gen_load_fpr64(ctx
, fp0
, fs
);
6613 gen_helper_float_rsqrt_d(fp0
, fp0
);
6614 gen_store_fpr64(ctx
, fp0
, fd
);
6615 tcg_temp_free_i64(fp0
);
6620 check_cp1_64bitmode(ctx
);
6622 TCGv_i64 fp0
= tcg_temp_new_i64();
6623 TCGv_i64 fp1
= tcg_temp_new_i64();
6625 gen_load_fpr64(ctx
, fp0
, fs
);
6626 gen_load_fpr64(ctx
, fp1
, ft
);
6627 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6628 tcg_temp_free_i64(fp1
);
6629 gen_store_fpr64(ctx
, fp0
, fd
);
6630 tcg_temp_free_i64(fp0
);
6635 check_cp1_64bitmode(ctx
);
6637 TCGv_i64 fp0
= tcg_temp_new_i64();
6639 gen_load_fpr64(ctx
, fp0
, fs
);
6640 gen_helper_float_recip1_d(fp0
, fp0
);
6641 gen_store_fpr64(ctx
, fp0
, fd
);
6642 tcg_temp_free_i64(fp0
);
6647 check_cp1_64bitmode(ctx
);
6649 TCGv_i64 fp0
= tcg_temp_new_i64();
6651 gen_load_fpr64(ctx
, fp0
, fs
);
6652 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6653 gen_store_fpr64(ctx
, fp0
, fd
);
6654 tcg_temp_free_i64(fp0
);
6659 check_cp1_64bitmode(ctx
);
6661 TCGv_i64 fp0
= tcg_temp_new_i64();
6662 TCGv_i64 fp1
= tcg_temp_new_i64();
6664 gen_load_fpr64(ctx
, fp0
, fs
);
6665 gen_load_fpr64(ctx
, fp1
, ft
);
6666 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6667 tcg_temp_free_i64(fp1
);
6668 gen_store_fpr64(ctx
, fp0
, fd
);
6669 tcg_temp_free_i64(fp0
);
6690 TCGv_i64 fp0
= tcg_temp_new_i64();
6691 TCGv_i64 fp1
= tcg_temp_new_i64();
6693 gen_load_fpr64(ctx
, fp0
, fs
);
6694 gen_load_fpr64(ctx
, fp1
, ft
);
6695 if (ctx
->opcode
& (1 << 6)) {
6697 check_cp1_registers(ctx
, fs
| ft
);
6698 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6699 opn
= condnames_abs
[func
-48];
6701 check_cp1_registers(ctx
, fs
| ft
);
6702 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6703 opn
= condnames
[func
-48];
6705 tcg_temp_free_i64(fp0
);
6706 tcg_temp_free_i64(fp1
);
6710 check_cp1_registers(ctx
, fs
);
6712 TCGv_i32 fp32
= tcg_temp_new_i32();
6713 TCGv_i64 fp64
= tcg_temp_new_i64();
6715 gen_load_fpr64(ctx
, fp64
, fs
);
6716 gen_helper_float_cvts_d(fp32
, fp64
);
6717 tcg_temp_free_i64(fp64
);
6718 gen_store_fpr32(fp32
, fd
);
6719 tcg_temp_free_i32(fp32
);
6724 check_cp1_registers(ctx
, fs
);
6726 TCGv_i32 fp32
= tcg_temp_new_i32();
6727 TCGv_i64 fp64
= tcg_temp_new_i64();
6729 gen_load_fpr64(ctx
, fp64
, fs
);
6730 gen_helper_float_cvtw_d(fp32
, fp64
);
6731 tcg_temp_free_i64(fp64
);
6732 gen_store_fpr32(fp32
, fd
);
6733 tcg_temp_free_i32(fp32
);
6738 check_cp1_64bitmode(ctx
);
6740 TCGv_i64 fp0
= tcg_temp_new_i64();
6742 gen_load_fpr64(ctx
, fp0
, fs
);
6743 gen_helper_float_cvtl_d(fp0
, fp0
);
6744 gen_store_fpr64(ctx
, fp0
, fd
);
6745 tcg_temp_free_i64(fp0
);
6751 TCGv_i32 fp0
= tcg_temp_new_i32();
6753 gen_load_fpr32(fp0
, fs
);
6754 gen_helper_float_cvts_w(fp0
, fp0
);
6755 gen_store_fpr32(fp0
, fd
);
6756 tcg_temp_free_i32(fp0
);
6761 check_cp1_registers(ctx
, fd
);
6763 TCGv_i32 fp32
= tcg_temp_new_i32();
6764 TCGv_i64 fp64
= tcg_temp_new_i64();
6766 gen_load_fpr32(fp32
, fs
);
6767 gen_helper_float_cvtd_w(fp64
, fp32
);
6768 tcg_temp_free_i32(fp32
);
6769 gen_store_fpr64(ctx
, fp64
, fd
);
6770 tcg_temp_free_i64(fp64
);
6775 check_cp1_64bitmode(ctx
);
6777 TCGv_i32 fp32
= tcg_temp_new_i32();
6778 TCGv_i64 fp64
= tcg_temp_new_i64();
6780 gen_load_fpr64(ctx
, fp64
, fs
);
6781 gen_helper_float_cvts_l(fp32
, fp64
);
6782 tcg_temp_free_i64(fp64
);
6783 gen_store_fpr32(fp32
, fd
);
6784 tcg_temp_free_i32(fp32
);
6789 check_cp1_64bitmode(ctx
);
6791 TCGv_i64 fp0
= tcg_temp_new_i64();
6793 gen_load_fpr64(ctx
, fp0
, fs
);
6794 gen_helper_float_cvtd_l(fp0
, fp0
);
6795 gen_store_fpr64(ctx
, fp0
, fd
);
6796 tcg_temp_free_i64(fp0
);
6801 check_cp1_64bitmode(ctx
);
6803 TCGv_i64 fp0
= tcg_temp_new_i64();
6805 gen_load_fpr64(ctx
, fp0
, fs
);
6806 gen_helper_float_cvtps_pw(fp0
, fp0
);
6807 gen_store_fpr64(ctx
, fp0
, fd
);
6808 tcg_temp_free_i64(fp0
);
6813 check_cp1_64bitmode(ctx
);
6815 TCGv_i64 fp0
= tcg_temp_new_i64();
6816 TCGv_i64 fp1
= tcg_temp_new_i64();
6818 gen_load_fpr64(ctx
, fp0
, fs
);
6819 gen_load_fpr64(ctx
, fp1
, ft
);
6820 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6821 tcg_temp_free_i64(fp1
);
6822 gen_store_fpr64(ctx
, fp0
, fd
);
6823 tcg_temp_free_i64(fp0
);
6828 check_cp1_64bitmode(ctx
);
6830 TCGv_i64 fp0
= tcg_temp_new_i64();
6831 TCGv_i64 fp1
= tcg_temp_new_i64();
6833 gen_load_fpr64(ctx
, fp0
, fs
);
6834 gen_load_fpr64(ctx
, fp1
, ft
);
6835 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6836 tcg_temp_free_i64(fp1
);
6837 gen_store_fpr64(ctx
, fp0
, fd
);
6838 tcg_temp_free_i64(fp0
);
6843 check_cp1_64bitmode(ctx
);
6845 TCGv_i64 fp0
= tcg_temp_new_i64();
6846 TCGv_i64 fp1
= tcg_temp_new_i64();
6848 gen_load_fpr64(ctx
, fp0
, fs
);
6849 gen_load_fpr64(ctx
, fp1
, ft
);
6850 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6851 tcg_temp_free_i64(fp1
);
6852 gen_store_fpr64(ctx
, fp0
, fd
);
6853 tcg_temp_free_i64(fp0
);
6858 check_cp1_64bitmode(ctx
);
6860 TCGv_i64 fp0
= tcg_temp_new_i64();
6862 gen_load_fpr64(ctx
, fp0
, fs
);
6863 gen_helper_float_abs_ps(fp0
, fp0
);
6864 gen_store_fpr64(ctx
, fp0
, fd
);
6865 tcg_temp_free_i64(fp0
);
6870 check_cp1_64bitmode(ctx
);
6872 TCGv_i64 fp0
= tcg_temp_new_i64();
6874 gen_load_fpr64(ctx
, fp0
, fs
);
6875 gen_store_fpr64(ctx
, fp0
, fd
);
6876 tcg_temp_free_i64(fp0
);
6881 check_cp1_64bitmode(ctx
);
6883 TCGv_i64 fp0
= tcg_temp_new_i64();
6885 gen_load_fpr64(ctx
, fp0
, fs
);
6886 gen_helper_float_chs_ps(fp0
, fp0
);
6887 gen_store_fpr64(ctx
, fp0
, fd
);
6888 tcg_temp_free_i64(fp0
);
6893 check_cp1_64bitmode(ctx
);
6894 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6898 check_cp1_64bitmode(ctx
);
6900 int l1
= gen_new_label();
6901 TCGv t0
= tcg_temp_new();
6902 TCGv_i32 fp0
= tcg_temp_local_new_i32();
6903 TCGv_i32 fph0
= tcg_temp_local_new_i32();
6905 gen_load_gpr(t0
, ft
);
6906 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6907 gen_load_fpr32(fp0
, fs
);
6908 gen_load_fpr32h(fph0
, fs
);
6909 gen_store_fpr32(fp0
, fd
);
6910 gen_store_fpr32h(fph0
, fd
);
6911 tcg_temp_free_i32(fp0
);
6912 tcg_temp_free_i32(fph0
);
6919 check_cp1_64bitmode(ctx
);
6921 int l1
= gen_new_label();
6922 TCGv t0
= tcg_temp_new();
6923 TCGv_i32 fp0
= tcg_temp_local_new_i32();
6924 TCGv_i32 fph0
= tcg_temp_local_new_i32();
6926 gen_load_gpr(t0
, ft
);
6927 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6928 gen_load_fpr32(fp0
, fs
);
6929 gen_load_fpr32h(fph0
, fs
);
6930 gen_store_fpr32(fp0
, fd
);
6931 gen_store_fpr32h(fph0
, fd
);
6932 tcg_temp_free_i32(fp0
);
6933 tcg_temp_free_i32(fph0
);
6940 check_cp1_64bitmode(ctx
);
6942 TCGv_i64 fp0
= tcg_temp_new_i64();
6943 TCGv_i64 fp1
= tcg_temp_new_i64();
6945 gen_load_fpr64(ctx
, fp0
, ft
);
6946 gen_load_fpr64(ctx
, fp1
, fs
);
6947 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
6948 tcg_temp_free_i64(fp1
);
6949 gen_store_fpr64(ctx
, fp0
, fd
);
6950 tcg_temp_free_i64(fp0
);
6955 check_cp1_64bitmode(ctx
);
6957 TCGv_i64 fp0
= tcg_temp_new_i64();
6958 TCGv_i64 fp1
= tcg_temp_new_i64();
6960 gen_load_fpr64(ctx
, fp0
, ft
);
6961 gen_load_fpr64(ctx
, fp1
, fs
);
6962 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
6963 tcg_temp_free_i64(fp1
);
6964 gen_store_fpr64(ctx
, fp0
, fd
);
6965 tcg_temp_free_i64(fp0
);
6970 check_cp1_64bitmode(ctx
);
6972 TCGv_i64 fp0
= tcg_temp_new_i64();
6973 TCGv_i64 fp1
= tcg_temp_new_i64();
6975 gen_load_fpr64(ctx
, fp0
, fs
);
6976 gen_load_fpr64(ctx
, fp1
, fd
);
6977 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
6978 tcg_temp_free_i64(fp1
);
6979 gen_store_fpr64(ctx
, fp0
, fd
);
6980 tcg_temp_free_i64(fp0
);
6985 check_cp1_64bitmode(ctx
);
6987 TCGv_i64 fp0
= tcg_temp_new_i64();
6989 gen_load_fpr64(ctx
, fp0
, fs
);
6990 gen_helper_float_recip1_ps(fp0
, fp0
);
6991 gen_store_fpr64(ctx
, fp0
, fd
);
6992 tcg_temp_free_i64(fp0
);
6997 check_cp1_64bitmode(ctx
);
6999 TCGv_i64 fp0
= tcg_temp_new_i64();
7001 gen_load_fpr64(ctx
, fp0
, fs
);
7002 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7003 gen_store_fpr64(ctx
, fp0
, fd
);
7004 tcg_temp_free_i64(fp0
);
7009 check_cp1_64bitmode(ctx
);
7011 TCGv_i64 fp0
= tcg_temp_new_i64();
7012 TCGv_i64 fp1
= tcg_temp_new_i64();
7014 gen_load_fpr64(ctx
, fp0
, fs
);
7015 gen_load_fpr64(ctx
, fp1
, ft
);
7016 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7017 tcg_temp_free_i64(fp1
);
7018 gen_store_fpr64(ctx
, fp0
, fd
);
7019 tcg_temp_free_i64(fp0
);
7024 check_cp1_64bitmode(ctx
);
7026 TCGv_i32 fp0
= tcg_temp_new_i32();
7028 gen_load_fpr32h(fp0
, fs
);
7029 gen_helper_float_cvts_pu(fp0
, fp0
);
7030 gen_store_fpr32(fp0
, fd
);
7031 tcg_temp_free_i32(fp0
);
7036 check_cp1_64bitmode(ctx
);
7038 TCGv_i64 fp0
= tcg_temp_new_i64();
7040 gen_load_fpr64(ctx
, fp0
, fs
);
7041 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7042 gen_store_fpr64(ctx
, fp0
, fd
);
7043 tcg_temp_free_i64(fp0
);
7048 check_cp1_64bitmode(ctx
);
7050 TCGv_i32 fp0
= tcg_temp_new_i32();
7052 gen_load_fpr32(fp0
, fs
);
7053 gen_helper_float_cvts_pl(fp0
, fp0
);
7054 gen_store_fpr32(fp0
, fd
);
7055 tcg_temp_free_i32(fp0
);
7060 check_cp1_64bitmode(ctx
);
7062 TCGv_i32 fp0
= tcg_temp_new_i32();
7063 TCGv_i32 fp1
= tcg_temp_new_i32();
7065 gen_load_fpr32(fp0
, fs
);
7066 gen_load_fpr32(fp1
, ft
);
7067 gen_store_fpr32h(fp0
, fd
);
7068 gen_store_fpr32(fp1
, fd
);
7069 tcg_temp_free_i32(fp0
);
7070 tcg_temp_free_i32(fp1
);
7075 check_cp1_64bitmode(ctx
);
7077 TCGv_i32 fp0
= tcg_temp_new_i32();
7078 TCGv_i32 fp1
= tcg_temp_new_i32();
7080 gen_load_fpr32(fp0
, fs
);
7081 gen_load_fpr32h(fp1
, ft
);
7082 gen_store_fpr32(fp1
, fd
);
7083 gen_store_fpr32h(fp0
, fd
);
7084 tcg_temp_free_i32(fp0
);
7085 tcg_temp_free_i32(fp1
);
7090 check_cp1_64bitmode(ctx
);
7092 TCGv_i32 fp0
= tcg_temp_new_i32();
7093 TCGv_i32 fp1
= tcg_temp_new_i32();
7095 gen_load_fpr32h(fp0
, fs
);
7096 gen_load_fpr32(fp1
, ft
);
7097 gen_store_fpr32(fp1
, fd
);
7098 gen_store_fpr32h(fp0
, fd
);
7099 tcg_temp_free_i32(fp0
);
7100 tcg_temp_free_i32(fp1
);
7105 check_cp1_64bitmode(ctx
);
7107 TCGv_i32 fp0
= tcg_temp_new_i32();
7108 TCGv_i32 fp1
= tcg_temp_new_i32();
7110 gen_load_fpr32h(fp0
, fs
);
7111 gen_load_fpr32h(fp1
, ft
);
7112 gen_store_fpr32(fp1
, fd
);
7113 gen_store_fpr32h(fp0
, fd
);
7114 tcg_temp_free_i32(fp0
);
7115 tcg_temp_free_i32(fp1
);
7135 check_cp1_64bitmode(ctx
);
7137 TCGv_i64 fp0
= tcg_temp_new_i64();
7138 TCGv_i64 fp1
= tcg_temp_new_i64();
7140 gen_load_fpr64(ctx
, fp0
, fs
);
7141 gen_load_fpr64(ctx
, fp1
, ft
);
7142 if (ctx
->opcode
& (1 << 6)) {
7143 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7144 opn
= condnames_abs
[func
-48];
7146 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7147 opn
= condnames
[func
-48];
7149 tcg_temp_free_i64(fp0
);
7150 tcg_temp_free_i64(fp1
);
7155 generate_exception (ctx
, EXCP_RI
);
7160 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7163 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7166 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7171 /* Coprocessor 3 (FPU) */
7172 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7173 int fd
, int fs
, int base
, int index
)
7175 const char *opn
= "extended float load/store";
7177 TCGv t0
= tcg_temp_local_new();
7178 TCGv t1
= tcg_temp_local_new();
7181 gen_load_gpr(t0
, index
);
7182 } else if (index
== 0) {
7183 gen_load_gpr(t0
, base
);
7185 gen_load_gpr(t0
, index
);
7186 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
7188 /* Don't do NOP if destination is zero: we must perform the actual
7194 TCGv_i32 fp0
= tcg_temp_new_i32();
7196 tcg_gen_qemu_ld32s(t1
, t0
, ctx
->mem_idx
);
7197 tcg_gen_trunc_tl_i32(fp0
, t1
);
7198 gen_store_fpr32(fp0
, fd
);
7199 tcg_temp_free_i32(fp0
);
7205 check_cp1_registers(ctx
, fd
);
7207 TCGv_i64 fp0
= tcg_temp_new_i64();
7209 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7210 gen_store_fpr64(ctx
, fp0
, fd
);
7211 tcg_temp_free_i64(fp0
);
7216 check_cp1_64bitmode(ctx
);
7217 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7219 TCGv_i64 fp0
= tcg_temp_new_i64();
7221 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7222 gen_store_fpr64(ctx
, fp0
, fd
);
7223 tcg_temp_free_i64(fp0
);
7230 TCGv_i32 fp0
= tcg_temp_new_i32();
7232 gen_load_fpr32(fp0
, fs
);
7233 tcg_gen_extu_i32_tl(t1
, fp0
);
7234 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7235 tcg_temp_free_i32(fp0
);
7242 check_cp1_registers(ctx
, fs
);
7244 TCGv_i64 fp0
= tcg_temp_new_i64();
7246 gen_load_fpr64(ctx
, fp0
, fs
);
7247 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7248 tcg_temp_free_i64(fp0
);
7254 check_cp1_64bitmode(ctx
);
7255 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7257 TCGv_i64 fp0
= tcg_temp_new_i64();
7259 gen_load_fpr64(ctx
, fp0
, fs
);
7260 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7261 tcg_temp_free_i64(fp0
);
7268 generate_exception(ctx
, EXCP_RI
);
7275 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7276 regnames
[index
], regnames
[base
]);
7279 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7280 int fd
, int fr
, int fs
, int ft
)
7282 const char *opn
= "flt3_arith";
7286 check_cp1_64bitmode(ctx
);
7288 TCGv t0
= tcg_temp_local_new();
7289 TCGv_i32 fp0
= tcg_temp_local_new_i32();
7290 TCGv_i32 fph0
= tcg_temp_local_new_i32();
7291 TCGv_i32 fp1
= tcg_temp_local_new_i32();
7292 TCGv_i32 fph1
= tcg_temp_local_new_i32();
7293 int l1
= gen_new_label();
7294 int l2
= gen_new_label();
7296 gen_load_gpr(t0
, fr
);
7297 tcg_gen_andi_tl(t0
, t0
, 0x7);
7298 gen_load_fpr32(fp0
, fs
);
7299 gen_load_fpr32h(fph0
, fs
);
7300 gen_load_fpr32(fp1
, ft
);
7301 gen_load_fpr32h(fph1
, ft
);
7303 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7304 gen_store_fpr32(fp0
, fd
);
7305 gen_store_fpr32h(fph0
, fd
);
7308 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7310 #ifdef TARGET_WORDS_BIGENDIAN
7311 gen_store_fpr32(fph1
, fd
);
7312 gen_store_fpr32h(fp0
, fd
);
7314 gen_store_fpr32(fph0
, fd
);
7315 gen_store_fpr32h(fp1
, fd
);
7318 tcg_temp_free_i32(fp0
);
7319 tcg_temp_free_i32(fph0
);
7320 tcg_temp_free_i32(fp1
);
7321 tcg_temp_free_i32(fph1
);
7328 TCGv_i32 fp0
= tcg_temp_new_i32();
7329 TCGv_i32 fp1
= tcg_temp_new_i32();
7330 TCGv_i32 fp2
= tcg_temp_new_i32();
7332 gen_load_fpr32(fp0
, fs
);
7333 gen_load_fpr32(fp1
, ft
);
7334 gen_load_fpr32(fp2
, fr
);
7335 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7336 tcg_temp_free_i32(fp0
);
7337 tcg_temp_free_i32(fp1
);
7338 gen_store_fpr32(fp2
, fd
);
7339 tcg_temp_free_i32(fp2
);
7345 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7347 TCGv_i64 fp0
= tcg_temp_new_i64();
7348 TCGv_i64 fp1
= tcg_temp_new_i64();
7349 TCGv_i64 fp2
= tcg_temp_new_i64();
7351 gen_load_fpr64(ctx
, fp0
, fs
);
7352 gen_load_fpr64(ctx
, fp1
, ft
);
7353 gen_load_fpr64(ctx
, fp2
, fr
);
7354 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7355 tcg_temp_free_i64(fp0
);
7356 tcg_temp_free_i64(fp1
);
7357 gen_store_fpr64(ctx
, fp2
, fd
);
7358 tcg_temp_free_i64(fp2
);
7363 check_cp1_64bitmode(ctx
);
7365 TCGv_i64 fp0
= tcg_temp_new_i64();
7366 TCGv_i64 fp1
= tcg_temp_new_i64();
7367 TCGv_i64 fp2
= tcg_temp_new_i64();
7369 gen_load_fpr64(ctx
, fp0
, fs
);
7370 gen_load_fpr64(ctx
, fp1
, ft
);
7371 gen_load_fpr64(ctx
, fp2
, fr
);
7372 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7373 tcg_temp_free_i64(fp0
);
7374 tcg_temp_free_i64(fp1
);
7375 gen_store_fpr64(ctx
, fp2
, fd
);
7376 tcg_temp_free_i64(fp2
);
7383 TCGv_i32 fp0
= tcg_temp_new_i32();
7384 TCGv_i32 fp1
= tcg_temp_new_i32();
7385 TCGv_i32 fp2
= tcg_temp_new_i32();
7387 gen_load_fpr32(fp0
, fs
);
7388 gen_load_fpr32(fp1
, ft
);
7389 gen_load_fpr32(fp2
, fr
);
7390 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7391 tcg_temp_free_i32(fp0
);
7392 tcg_temp_free_i32(fp1
);
7393 gen_store_fpr32(fp2
, fd
);
7394 tcg_temp_free_i32(fp2
);
7400 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7402 TCGv_i64 fp0
= tcg_temp_new_i64();
7403 TCGv_i64 fp1
= tcg_temp_new_i64();
7404 TCGv_i64 fp2
= tcg_temp_new_i64();
7406 gen_load_fpr64(ctx
, fp0
, fs
);
7407 gen_load_fpr64(ctx
, fp1
, ft
);
7408 gen_load_fpr64(ctx
, fp2
, fr
);
7409 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7410 tcg_temp_free_i64(fp0
);
7411 tcg_temp_free_i64(fp1
);
7412 gen_store_fpr64(ctx
, fp2
, fd
);
7413 tcg_temp_free_i64(fp2
);
7418 check_cp1_64bitmode(ctx
);
7420 TCGv_i64 fp0
= tcg_temp_new_i64();
7421 TCGv_i64 fp1
= tcg_temp_new_i64();
7422 TCGv_i64 fp2
= tcg_temp_new_i64();
7424 gen_load_fpr64(ctx
, fp0
, fs
);
7425 gen_load_fpr64(ctx
, fp1
, ft
);
7426 gen_load_fpr64(ctx
, fp2
, fr
);
7427 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7428 tcg_temp_free_i64(fp0
);
7429 tcg_temp_free_i64(fp1
);
7430 gen_store_fpr64(ctx
, fp2
, fd
);
7431 tcg_temp_free_i64(fp2
);
7438 TCGv_i32 fp0
= tcg_temp_new_i32();
7439 TCGv_i32 fp1
= tcg_temp_new_i32();
7440 TCGv_i32 fp2
= tcg_temp_new_i32();
7442 gen_load_fpr32(fp0
, fs
);
7443 gen_load_fpr32(fp1
, ft
);
7444 gen_load_fpr32(fp2
, fr
);
7445 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7446 tcg_temp_free_i32(fp0
);
7447 tcg_temp_free_i32(fp1
);
7448 gen_store_fpr32(fp2
, fd
);
7449 tcg_temp_free_i32(fp2
);
7455 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7457 TCGv_i64 fp0
= tcg_temp_new_i64();
7458 TCGv_i64 fp1
= tcg_temp_new_i64();
7459 TCGv_i64 fp2
= tcg_temp_new_i64();
7461 gen_load_fpr64(ctx
, fp0
, fs
);
7462 gen_load_fpr64(ctx
, fp1
, ft
);
7463 gen_load_fpr64(ctx
, fp2
, fr
);
7464 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7465 tcg_temp_free_i64(fp0
);
7466 tcg_temp_free_i64(fp1
);
7467 gen_store_fpr64(ctx
, fp2
, fd
);
7468 tcg_temp_free_i64(fp2
);
7473 check_cp1_64bitmode(ctx
);
7475 TCGv_i64 fp0
= tcg_temp_new_i64();
7476 TCGv_i64 fp1
= tcg_temp_new_i64();
7477 TCGv_i64 fp2
= tcg_temp_new_i64();
7479 gen_load_fpr64(ctx
, fp0
, fs
);
7480 gen_load_fpr64(ctx
, fp1
, ft
);
7481 gen_load_fpr64(ctx
, fp2
, fr
);
7482 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7483 tcg_temp_free_i64(fp0
);
7484 tcg_temp_free_i64(fp1
);
7485 gen_store_fpr64(ctx
, fp2
, fd
);
7486 tcg_temp_free_i64(fp2
);
7493 TCGv_i32 fp0
= tcg_temp_new_i32();
7494 TCGv_i32 fp1
= tcg_temp_new_i32();
7495 TCGv_i32 fp2
= tcg_temp_new_i32();
7497 gen_load_fpr32(fp0
, fs
);
7498 gen_load_fpr32(fp1
, ft
);
7499 gen_load_fpr32(fp2
, fr
);
7500 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7501 tcg_temp_free_i32(fp0
);
7502 tcg_temp_free_i32(fp1
);
7503 gen_store_fpr32(fp2
, fd
);
7504 tcg_temp_free_i32(fp2
);
7510 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7512 TCGv_i64 fp0
= tcg_temp_new_i64();
7513 TCGv_i64 fp1
= tcg_temp_new_i64();
7514 TCGv_i64 fp2
= tcg_temp_new_i64();
7516 gen_load_fpr64(ctx
, fp0
, fs
);
7517 gen_load_fpr64(ctx
, fp1
, ft
);
7518 gen_load_fpr64(ctx
, fp2
, fr
);
7519 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7520 tcg_temp_free_i64(fp0
);
7521 tcg_temp_free_i64(fp1
);
7522 gen_store_fpr64(ctx
, fp2
, fd
);
7523 tcg_temp_free_i64(fp2
);
7528 check_cp1_64bitmode(ctx
);
7530 TCGv_i64 fp0
= tcg_temp_new_i64();
7531 TCGv_i64 fp1
= tcg_temp_new_i64();
7532 TCGv_i64 fp2
= tcg_temp_new_i64();
7534 gen_load_fpr64(ctx
, fp0
, fs
);
7535 gen_load_fpr64(ctx
, fp1
, ft
);
7536 gen_load_fpr64(ctx
, fp2
, fr
);
7537 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7538 tcg_temp_free_i64(fp0
);
7539 tcg_temp_free_i64(fp1
);
7540 gen_store_fpr64(ctx
, fp2
, fd
);
7541 tcg_temp_free_i64(fp2
);
7547 generate_exception (ctx
, EXCP_RI
);
7550 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7551 fregnames
[fs
], fregnames
[ft
]);
7554 /* ISA extensions (ASEs) */
7555 /* MIPS16 extension to MIPS32 */
7556 /* SmartMIPS extension to MIPS32 */
7558 #if defined(TARGET_MIPS64)
7560 /* MDMX extension to MIPS64 */
7564 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7568 uint32_t op
, op1
, op2
;
7571 /* make sure instructions are on a word boundary */
7572 if (ctx
->pc
& 0x3) {
7573 env
->CP0_BadVAddr
= ctx
->pc
;
7574 generate_exception(ctx
, EXCP_AdEL
);
7578 /* Handle blikely not taken case */
7579 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7580 int l1
= gen_new_label();
7582 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7583 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7585 TCGv_i32 r_tmp
= tcg_temp_new_i32();
7587 tcg_gen_movi_i32(r_tmp
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7588 tcg_gen_st_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
7589 tcg_temp_free_i32(r_tmp
);
7591 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7594 op
= MASK_OP_MAJOR(ctx
->opcode
);
7595 rs
= (ctx
->opcode
>> 21) & 0x1f;
7596 rt
= (ctx
->opcode
>> 16) & 0x1f;
7597 rd
= (ctx
->opcode
>> 11) & 0x1f;
7598 sa
= (ctx
->opcode
>> 6) & 0x1f;
7599 imm
= (int16_t)ctx
->opcode
;
7602 op1
= MASK_SPECIAL(ctx
->opcode
);
7604 case OPC_SLL
: /* Arithmetic with immediate */
7605 case OPC_SRL
... OPC_SRA
:
7606 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7608 case OPC_MOVZ
... OPC_MOVN
:
7609 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7610 case OPC_SLLV
: /* Arithmetic */
7611 case OPC_SRLV
... OPC_SRAV
:
7612 case OPC_ADD
... OPC_NOR
:
7613 case OPC_SLT
... OPC_SLTU
:
7614 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7616 case OPC_MULT
... OPC_DIVU
:
7618 check_insn(env
, ctx
, INSN_VR54XX
);
7619 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7620 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7622 gen_muldiv(ctx
, op1
, rs
, rt
);
7624 case OPC_JR
... OPC_JALR
:
7625 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
7627 case OPC_TGE
... OPC_TEQ
: /* Traps */
7629 gen_trap(ctx
, op1
, rs
, rt
, -1);
7631 case OPC_MFHI
: /* Move from HI/LO */
7633 gen_HILO(ctx
, op1
, rd
);
7636 case OPC_MTLO
: /* Move to HI/LO */
7637 gen_HILO(ctx
, op1
, rs
);
7639 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7640 #ifdef MIPS_STRICT_STANDARD
7641 MIPS_INVAL("PMON / selsl");
7642 generate_exception(ctx
, EXCP_RI
);
7644 gen_helper_0i(pmon
, sa
);
7648 generate_exception(ctx
, EXCP_SYSCALL
);
7651 generate_exception(ctx
, EXCP_BREAK
);
7654 #ifdef MIPS_STRICT_STANDARD
7656 generate_exception(ctx
, EXCP_RI
);
7658 /* Implemented as RI exception for now. */
7659 MIPS_INVAL("spim (unofficial)");
7660 generate_exception(ctx
, EXCP_RI
);
7668 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7669 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7670 save_cpu_state(ctx
, 1);
7671 check_cp1_enabled(ctx
);
7672 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7673 (ctx
->opcode
>> 16) & 1);
7675 generate_exception_err(ctx
, EXCP_CpU
, 1);
7679 #if defined(TARGET_MIPS64)
7680 /* MIPS64 specific opcodes */
7682 case OPC_DSRL
... OPC_DSRA
:
7684 case OPC_DSRL32
... OPC_DSRA32
:
7685 check_insn(env
, ctx
, ISA_MIPS3
);
7687 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7690 case OPC_DSRLV
... OPC_DSRAV
:
7691 case OPC_DADD
... OPC_DSUBU
:
7692 check_insn(env
, ctx
, ISA_MIPS3
);
7694 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7696 case OPC_DMULT
... OPC_DDIVU
:
7697 check_insn(env
, ctx
, ISA_MIPS3
);
7699 gen_muldiv(ctx
, op1
, rs
, rt
);
7702 default: /* Invalid */
7703 MIPS_INVAL("special");
7704 generate_exception(ctx
, EXCP_RI
);
7709 op1
= MASK_SPECIAL2(ctx
->opcode
);
7711 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7712 case OPC_MSUB
... OPC_MSUBU
:
7713 check_insn(env
, ctx
, ISA_MIPS32
);
7714 gen_muldiv(ctx
, op1
, rs
, rt
);
7717 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7721 check_insn(env
, ctx
, ISA_MIPS32
);
7722 gen_cl(ctx
, op1
, rd
, rs
);
7725 /* XXX: not clear which exception should be raised
7726 * when in debug mode...
7728 check_insn(env
, ctx
, ISA_MIPS32
);
7729 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7730 generate_exception(ctx
, EXCP_DBp
);
7732 generate_exception(ctx
, EXCP_DBp
);
7736 #if defined(TARGET_MIPS64)
7739 check_insn(env
, ctx
, ISA_MIPS64
);
7741 gen_cl(ctx
, op1
, rd
, rs
);
7744 default: /* Invalid */
7745 MIPS_INVAL("special2");
7746 generate_exception(ctx
, EXCP_RI
);
7751 op1
= MASK_SPECIAL3(ctx
->opcode
);
7755 check_insn(env
, ctx
, ISA_MIPS32R2
);
7756 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7759 check_insn(env
, ctx
, ISA_MIPS32R2
);
7760 op2
= MASK_BSHFL(ctx
->opcode
);
7761 gen_bshfl(ctx
, op2
, rt
, rd
);
7764 check_insn(env
, ctx
, ISA_MIPS32R2
);
7766 TCGv t0
= tcg_temp_local_new();
7770 save_cpu_state(ctx
, 1);
7771 gen_helper_rdhwr_cpunum(t0
);
7774 save_cpu_state(ctx
, 1);
7775 gen_helper_rdhwr_synci_step(t0
);
7778 save_cpu_state(ctx
, 1);
7779 gen_helper_rdhwr_cc(t0
);
7782 save_cpu_state(ctx
, 1);
7783 gen_helper_rdhwr_ccres(t0
);
7786 #if defined(CONFIG_USER_ONLY)
7787 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7790 /* XXX: Some CPUs implement this in hardware.
7791 Not supported yet. */
7793 default: /* Invalid */
7794 MIPS_INVAL("rdhwr");
7795 generate_exception(ctx
, EXCP_RI
);
7798 gen_store_gpr(t0
, rt
);
7803 check_insn(env
, ctx
, ASE_MT
);
7805 TCGv t0
= tcg_temp_local_new();
7806 TCGv t1
= tcg_temp_local_new();
7808 gen_load_gpr(t0
, rt
);
7809 gen_load_gpr(t1
, rs
);
7810 gen_helper_fork(t0
, t1
);
7816 check_insn(env
, ctx
, ASE_MT
);
7818 TCGv t0
= tcg_temp_local_new();
7820 gen_load_gpr(t0
, rs
);
7821 gen_helper_yield(t0
, t0
);
7822 gen_store_gpr(t0
, rd
);
7826 #if defined(TARGET_MIPS64)
7827 case OPC_DEXTM
... OPC_DEXT
:
7828 case OPC_DINSM
... OPC_DINS
:
7829 check_insn(env
, ctx
, ISA_MIPS64R2
);
7831 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7834 check_insn(env
, ctx
, ISA_MIPS64R2
);
7836 op2
= MASK_DBSHFL(ctx
->opcode
);
7837 gen_bshfl(ctx
, op2
, rt
, rd
);
7840 default: /* Invalid */
7841 MIPS_INVAL("special3");
7842 generate_exception(ctx
, EXCP_RI
);
7847 op1
= MASK_REGIMM(ctx
->opcode
);
7849 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
7850 case OPC_BLTZAL
... OPC_BGEZALL
:
7851 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
7853 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
7855 gen_trap(ctx
, op1
, rs
, -1, imm
);
7858 check_insn(env
, ctx
, ISA_MIPS32R2
);
7861 default: /* Invalid */
7862 MIPS_INVAL("regimm");
7863 generate_exception(ctx
, EXCP_RI
);
7868 check_cp0_enabled(ctx
);
7869 op1
= MASK_CP0(ctx
->opcode
);
7875 #if defined(TARGET_MIPS64)
7879 #ifndef CONFIG_USER_ONLY
7880 gen_cp0(env
, ctx
, op1
, rt
, rd
);
7881 #endif /* !CONFIG_USER_ONLY */
7883 case OPC_C0_FIRST
... OPC_C0_LAST
:
7884 #ifndef CONFIG_USER_ONLY
7885 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
7886 #endif /* !CONFIG_USER_ONLY */
7889 #ifndef CONFIG_USER_ONLY
7891 TCGv t0
= tcg_temp_local_new();
7893 op2
= MASK_MFMC0(ctx
->opcode
);
7896 check_insn(env
, ctx
, ASE_MT
);
7897 gen_helper_dmt(t0
, t0
);
7900 check_insn(env
, ctx
, ASE_MT
);
7901 gen_helper_emt(t0
, t0
);
7904 check_insn(env
, ctx
, ASE_MT
);
7905 gen_helper_dvpe(t0
, t0
);
7908 check_insn(env
, ctx
, ASE_MT
);
7909 gen_helper_evpe(t0
, t0
);
7912 check_insn(env
, ctx
, ISA_MIPS32R2
);
7913 save_cpu_state(ctx
, 1);
7915 /* Stop translation as we may have switched the execution mode */
7916 ctx
->bstate
= BS_STOP
;
7919 check_insn(env
, ctx
, ISA_MIPS32R2
);
7920 save_cpu_state(ctx
, 1);
7922 /* Stop translation as we may have switched the execution mode */
7923 ctx
->bstate
= BS_STOP
;
7925 default: /* Invalid */
7926 MIPS_INVAL("mfmc0");
7927 generate_exception(ctx
, EXCP_RI
);
7930 gen_store_gpr(t0
, rt
);
7933 #endif /* !CONFIG_USER_ONLY */
7936 check_insn(env
, ctx
, ISA_MIPS32R2
);
7937 gen_load_srsgpr(rt
, rd
);
7940 check_insn(env
, ctx
, ISA_MIPS32R2
);
7941 gen_store_srsgpr(rt
, rd
);
7945 generate_exception(ctx
, EXCP_RI
);
7949 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
7950 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7952 case OPC_J
... OPC_JAL
: /* Jump */
7953 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
7954 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
7956 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
7957 case OPC_BEQL
... OPC_BGTZL
:
7958 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
7960 case OPC_LB
... OPC_LWR
: /* Load and stores */
7961 case OPC_SB
... OPC_SW
:
7965 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7968 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
7972 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7976 /* Floating point (COP1). */
7981 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7982 save_cpu_state(ctx
, 1);
7983 check_cp1_enabled(ctx
);
7984 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
7986 generate_exception_err(ctx
, EXCP_CpU
, 1);
7991 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7992 save_cpu_state(ctx
, 1);
7993 check_cp1_enabled(ctx
);
7994 op1
= MASK_CP1(ctx
->opcode
);
7998 check_insn(env
, ctx
, ISA_MIPS32R2
);
8003 gen_cp1(ctx
, op1
, rt
, rd
);
8005 #if defined(TARGET_MIPS64)
8008 check_insn(env
, ctx
, ISA_MIPS3
);
8009 gen_cp1(ctx
, op1
, rt
, rd
);
8015 check_insn(env
, ctx
, ASE_MIPS3D
);
8018 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
8019 (rt
>> 2) & 0x7, imm
<< 2);
8026 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
8031 generate_exception (ctx
, EXCP_RI
);
8035 generate_exception_err(ctx
, EXCP_CpU
, 1);
8045 /* COP2: Not implemented. */
8046 generate_exception_err(ctx
, EXCP_CpU
, 2);
8050 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8051 save_cpu_state(ctx
, 1);
8052 check_cp1_enabled(ctx
);
8053 op1
= MASK_CP3(ctx
->opcode
);
8061 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
8079 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
8083 generate_exception (ctx
, EXCP_RI
);
8087 generate_exception_err(ctx
, EXCP_CpU
, 1);
8091 #if defined(TARGET_MIPS64)
8092 /* MIPS64 opcodes */
8094 case OPC_LDL
... OPC_LDR
:
8095 case OPC_SDL
... OPC_SDR
:
8100 check_insn(env
, ctx
, ISA_MIPS3
);
8102 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8104 case OPC_DADDI
... OPC_DADDIU
:
8105 check_insn(env
, ctx
, ISA_MIPS3
);
8107 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8111 check_insn(env
, ctx
, ASE_MIPS16
);
8112 /* MIPS16: Not implemented. */
8114 check_insn(env
, ctx
, ASE_MDMX
);
8115 /* MDMX: Not implemented. */
8116 default: /* Invalid */
8117 MIPS_INVAL("major opcode");
8118 generate_exception(ctx
, EXCP_RI
);
8121 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8122 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8123 /* Branches completion */
8124 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8125 ctx
->bstate
= BS_BRANCH
;
8126 save_cpu_state(ctx
, 0);
8127 /* FIXME: Need to clear can_do_io. */
8130 /* unconditional branch */
8131 MIPS_DEBUG("unconditional branch");
8132 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8135 /* blikely taken case */
8136 MIPS_DEBUG("blikely branch taken");
8137 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8140 /* Conditional branch */
8141 MIPS_DEBUG("conditional branch");
8143 int l1
= gen_new_label();
8145 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8146 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8148 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8152 /* unconditional branch to register */
8153 MIPS_DEBUG("branch to register");
8154 tcg_gen_mov_tl(cpu_PC
, btarget
);
8158 MIPS_DEBUG("unknown branch");
8165 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
8169 target_ulong pc_start
;
8170 uint16_t *gen_opc_end
;
8177 qemu_log("search pc %d\n", search_pc
);
8180 /* Leave some spare opc slots for branch handling. */
8181 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
- 16;
8185 ctx
.bstate
= BS_NONE
;
8186 /* Restore delay slot state from the tb context. */
8187 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
8188 restore_cpu_state(env
, &ctx
);
8189 #ifdef CONFIG_USER_ONLY
8190 ctx
.mem_idx
= MIPS_HFLAG_UM
;
8192 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
8195 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8197 max_insns
= CF_COUNT_MASK
;
8199 qemu_log_mask(CPU_LOG_TB_CPU
, "------------------------------------------------\n");
8200 /* FIXME: This may print out stale hflags from env... */
8201 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
8203 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
8205 while (ctx
.bstate
== BS_NONE
) {
8206 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
8207 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
8208 if (bp
->pc
== ctx
.pc
) {
8209 save_cpu_state(&ctx
, 1);
8210 ctx
.bstate
= BS_BRANCH
;
8211 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8212 /* Include the breakpoint location or the tb won't
8213 * be flushed when it must be. */
8215 goto done_generating
;
8221 j
= gen_opc_ptr
- gen_opc_buf
;
8225 gen_opc_instr_start
[lj
++] = 0;
8227 gen_opc_pc
[lj
] = ctx
.pc
;
8228 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
8229 gen_opc_instr_start
[lj
] = 1;
8230 gen_opc_icount
[lj
] = num_insns
;
8232 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8234 ctx
.opcode
= ldl_code(ctx
.pc
);
8235 decode_opc(env
, &ctx
);
8239 if (env
->singlestep_enabled
)
8242 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
8245 if (gen_opc_ptr
>= gen_opc_end
)
8248 if (num_insns
>= max_insns
)
8250 #if defined (MIPS_SINGLE_STEP)
8254 if (tb
->cflags
& CF_LAST_IO
)
8256 if (env
->singlestep_enabled
) {
8257 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
8258 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8260 switch (ctx
.bstate
) {
8262 gen_helper_interrupt_restart();
8263 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8266 save_cpu_state(&ctx
, 0);
8267 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8270 gen_helper_interrupt_restart();
8279 gen_icount_end(tb
, num_insns
);
8280 *gen_opc_ptr
= INDEX_op_end
;
8282 j
= gen_opc_ptr
- gen_opc_buf
;
8285 gen_opc_instr_start
[lj
++] = 0;
8287 tb
->size
= ctx
.pc
- pc_start
;
8288 tb
->icount
= num_insns
;
8292 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
8293 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
8294 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
8297 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
8301 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
8303 gen_intermediate_code_internal(env
, tb
, 0);
8306 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
8308 gen_intermediate_code_internal(env
, tb
, 1);
8311 static void fpu_dump_state(CPUState
*env
, FILE *f
,
8312 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8316 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
8318 #define printfpr(fp) \
8321 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8322 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8323 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8326 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8327 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8328 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8329 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8330 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8335 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8336 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
8337 get_float_exception_flags(&env
->active_fpu
.fp_status
));
8338 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
8339 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
8340 printfpr(&env
->active_fpu
.fpr
[i
]);
8346 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8347 /* Debug help: The architecture requires 32bit code to maintain proper
8348 sign-extended values on 64bit machines. */
8350 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8353 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
8354 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8359 if (!SIGN_EXT_P(env
->active_tc
.PC
))
8360 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
8361 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
8362 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
8363 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
8364 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
8365 if (!SIGN_EXT_P(env
->btarget
))
8366 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
8368 for (i
= 0; i
< 32; i
++) {
8369 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
8370 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
8373 if (!SIGN_EXT_P(env
->CP0_EPC
))
8374 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
8375 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
8376 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
8380 void cpu_dump_state (CPUState
*env
, FILE *f
,
8381 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8386 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",
8387 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
8388 env
->hflags
, env
->btarget
, env
->bcond
);
8389 for (i
= 0; i
< 32; i
++) {
8391 cpu_fprintf(f
, "GPR%02d:", i
);
8392 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
8394 cpu_fprintf(f
, "\n");
8397 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
8398 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
8399 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
8400 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
8401 if (env
->hflags
& MIPS_HFLAG_FPU
)
8402 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
8403 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8404 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
8408 static void mips_tcg_init(void)
8413 /* Initialize various static tables. */
8417 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
8418 for (i
= 0; i
< 32; i
++)
8419 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
8420 offsetof(CPUState
, active_tc
.gpr
[i
]),
8422 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
8423 offsetof(CPUState
, active_tc
.PC
), "PC");
8424 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
8425 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
8426 offsetof(CPUState
, active_tc
.HI
[i
]),
8428 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
8429 offsetof(CPUState
, active_tc
.LO
[i
]),
8431 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
8432 offsetof(CPUState
, active_tc
.ACX
[i
]),
8435 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
8436 offsetof(CPUState
, active_tc
.DSPControl
),
8438 bcond
= tcg_global_mem_new(TCG_AREG0
,
8439 offsetof(CPUState
, bcond
), "bcond");
8440 btarget
= tcg_global_mem_new(TCG_AREG0
,
8441 offsetof(CPUState
, btarget
), "btarget");
8442 for (i
= 0; i
< 32; i
++)
8443 fpu_fpr32
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
8444 offsetof(CPUState
, active_fpu
.fpr
[i
].w
[FP_ENDIAN_IDX
]),
8446 for (i
= 0; i
< 32; i
++)
8447 fpu_fpr32h
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
8448 offsetof(CPUState
, active_fpu
.fpr
[i
].w
[!FP_ENDIAN_IDX
]),
8450 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
8451 offsetof(CPUState
, active_fpu
.fcr0
),
8453 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
8454 offsetof(CPUState
, active_fpu
.fcr31
),
8457 /* register helpers */
8458 #define GEN_HELPER 2
8464 #include "translate_init.c"
8466 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
8469 const mips_def_t
*def
;
8471 def
= cpu_mips_find_by_name(cpu_model
);
8474 env
= qemu_mallocz(sizeof(CPUMIPSState
));
8475 env
->cpu_model
= def
;
8478 env
->cpu_model_str
= cpu_model
;
8484 void cpu_reset (CPUMIPSState
*env
)
8486 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
8487 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
8488 log_cpu_state(env
, 0);
8491 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
8496 #if defined(CONFIG_USER_ONLY)
8497 env
->hflags
= MIPS_HFLAG_UM
;
8499 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
8500 /* If the exception was raised from a delay slot,
8501 come back to the jump. */
8502 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
8504 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
8506 env
->active_tc
.PC
= (int32_t)0xBFC00000;
8508 /* SMP not implemented */
8509 env
->CP0_EBase
= 0x80000000;
8510 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8511 /* vectored interrupts not implemented, timer on int 7,
8512 no performance counters. */
8513 env
->CP0_IntCtl
= 0xe0000000;
8517 for (i
= 0; i
< 7; i
++) {
8518 env
->CP0_WatchLo
[i
] = 0;
8519 env
->CP0_WatchHi
[i
] = 0x80000000;
8521 env
->CP0_WatchLo
[7] = 0;
8522 env
->CP0_WatchHi
[7] = 0;
8524 /* Count register increments in debug mode, EJTAG version 1 */
8525 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8526 env
->hflags
= MIPS_HFLAG_CP0
;
8528 env
->exception_index
= EXCP_NONE
;
8529 cpu_mips_register(env
, env
->cpu_model
);
8532 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8533 unsigned long searched_pc
, int pc_pos
, void *puc
)
8535 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
8536 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8537 env
->hflags
|= gen_opc_hflags
[pc_pos
];