2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
32 #include "qemu-common.h"
38 //#define MIPS_DEBUG_DISAS
39 //#define MIPS_DEBUG_SIGN_EXTENSIONS
41 /* MIPS major opcodes */
42 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
45 /* indirect opcode tables */
46 OPC_SPECIAL
= (0x00 << 26),
47 OPC_REGIMM
= (0x01 << 26),
48 OPC_CP0
= (0x10 << 26),
49 OPC_CP1
= (0x11 << 26),
50 OPC_CP2
= (0x12 << 26),
51 OPC_CP3
= (0x13 << 26),
52 OPC_SPECIAL2
= (0x1C << 26),
53 OPC_SPECIAL3
= (0x1F << 26),
54 /* arithmetic with immediate */
55 OPC_ADDI
= (0x08 << 26),
56 OPC_ADDIU
= (0x09 << 26),
57 OPC_SLTI
= (0x0A << 26),
58 OPC_SLTIU
= (0x0B << 26),
59 /* logic with immediate */
60 OPC_ANDI
= (0x0C << 26),
61 OPC_ORI
= (0x0D << 26),
62 OPC_XORI
= (0x0E << 26),
63 OPC_LUI
= (0x0F << 26),
64 /* arithmetic with immediate */
65 OPC_DADDI
= (0x18 << 26),
66 OPC_DADDIU
= (0x19 << 26),
67 /* Jump and branches */
69 OPC_JAL
= (0x03 << 26),
70 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
71 OPC_BEQL
= (0x14 << 26),
72 OPC_BNE
= (0x05 << 26),
73 OPC_BNEL
= (0x15 << 26),
74 OPC_BLEZ
= (0x06 << 26),
75 OPC_BLEZL
= (0x16 << 26),
76 OPC_BGTZ
= (0x07 << 26),
77 OPC_BGTZL
= (0x17 << 26),
78 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
80 OPC_LDL
= (0x1A << 26),
81 OPC_LDR
= (0x1B << 26),
82 OPC_LB
= (0x20 << 26),
83 OPC_LH
= (0x21 << 26),
84 OPC_LWL
= (0x22 << 26),
85 OPC_LW
= (0x23 << 26),
86 OPC_LBU
= (0x24 << 26),
87 OPC_LHU
= (0x25 << 26),
88 OPC_LWR
= (0x26 << 26),
89 OPC_LWU
= (0x27 << 26),
90 OPC_SB
= (0x28 << 26),
91 OPC_SH
= (0x29 << 26),
92 OPC_SWL
= (0x2A << 26),
93 OPC_SW
= (0x2B << 26),
94 OPC_SDL
= (0x2C << 26),
95 OPC_SDR
= (0x2D << 26),
96 OPC_SWR
= (0x2E << 26),
97 OPC_LL
= (0x30 << 26),
98 OPC_LLD
= (0x34 << 26),
99 OPC_LD
= (0x37 << 26),
100 OPC_SC
= (0x38 << 26),
101 OPC_SCD
= (0x3C << 26),
102 OPC_SD
= (0x3F << 26),
103 /* Floating point load/store */
104 OPC_LWC1
= (0x31 << 26),
105 OPC_LWC2
= (0x32 << 26),
106 OPC_LDC1
= (0x35 << 26),
107 OPC_LDC2
= (0x36 << 26),
108 OPC_SWC1
= (0x39 << 26),
109 OPC_SWC2
= (0x3A << 26),
110 OPC_SDC1
= (0x3D << 26),
111 OPC_SDC2
= (0x3E << 26),
112 /* MDMX ASE specific */
113 OPC_MDMX
= (0x1E << 26),
114 /* Cache and prefetch */
115 OPC_CACHE
= (0x2F << 26),
116 OPC_PREF
= (0x33 << 26),
117 /* Reserved major opcode */
118 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
121 /* MIPS special opcodes */
122 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
126 OPC_SLL
= 0x00 | OPC_SPECIAL
,
127 /* NOP is SLL r0, r0, 0 */
128 /* SSNOP is SLL r0, r0, 1 */
129 /* EHB is SLL r0, r0, 3 */
130 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
131 OPC_SRA
= 0x03 | OPC_SPECIAL
,
132 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
133 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
134 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
135 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
136 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
137 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
138 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
139 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
140 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
141 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
142 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
143 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
144 /* Multiplication / division */
145 OPC_MULT
= 0x18 | OPC_SPECIAL
,
146 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
147 OPC_DIV
= 0x1A | OPC_SPECIAL
,
148 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
149 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
150 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
151 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
152 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
153 /* 2 registers arithmetic / logic */
154 OPC_ADD
= 0x20 | OPC_SPECIAL
,
155 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
156 OPC_SUB
= 0x22 | OPC_SPECIAL
,
157 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
158 OPC_AND
= 0x24 | OPC_SPECIAL
,
159 OPC_OR
= 0x25 | OPC_SPECIAL
,
160 OPC_XOR
= 0x26 | OPC_SPECIAL
,
161 OPC_NOR
= 0x27 | OPC_SPECIAL
,
162 OPC_SLT
= 0x2A | OPC_SPECIAL
,
163 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
164 OPC_DADD
= 0x2C | OPC_SPECIAL
,
165 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
166 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
167 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
169 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
170 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
172 OPC_TGE
= 0x30 | OPC_SPECIAL
,
173 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
174 OPC_TLT
= 0x32 | OPC_SPECIAL
,
175 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
176 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
177 OPC_TNE
= 0x36 | OPC_SPECIAL
,
178 /* HI / LO registers load & stores */
179 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
180 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
181 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
182 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
183 /* Conditional moves */
184 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
185 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
187 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
190 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* 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
, bcond
;
433 static TCGv_i32 hflags
;
434 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
436 #include "gen-icount.h"
438 #define gen_helper_0i(name, arg) do { \
439 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
440 gen_helper_##name(helper_tmp); \
441 tcg_temp_free_i32(helper_tmp); \
444 #define gen_helper_1i(name, arg1, arg2) do { \
445 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
446 gen_helper_##name(arg1, helper_tmp); \
447 tcg_temp_free_i32(helper_tmp); \
450 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
451 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
452 gen_helper_##name(arg1, arg2, helper_tmp); \
453 tcg_temp_free_i32(helper_tmp); \
456 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
457 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
458 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
459 tcg_temp_free_i32(helper_tmp); \
462 typedef struct DisasContext
{
463 struct TranslationBlock
*tb
;
464 target_ulong pc
, saved_pc
;
466 /* Routine used to access memory */
468 uint32_t hflags
, saved_hflags
;
470 target_ulong btarget
;
474 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
475 * exception condition */
476 BS_STOP
= 1, /* We want to stop translation for any reason */
477 BS_BRANCH
= 2, /* We reached a branch condition */
478 BS_EXCP
= 3, /* We reached an exception condition */
481 static const char *regnames
[] =
482 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
483 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
484 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
485 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
487 static const char *regnames_HI
[] =
488 { "HI0", "HI1", "HI2", "HI3", };
490 static const char *regnames_LO
[] =
491 { "LO0", "LO1", "LO2", "LO3", };
493 static const char *regnames_ACX
[] =
494 { "ACX0", "ACX1", "ACX2", "ACX3", };
496 static const char *fregnames
[] =
497 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
498 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
499 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
500 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
502 #ifdef MIPS_DEBUG_DISAS
503 #define MIPS_DEBUG(fmt, ...) \
504 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
505 TARGET_FMT_lx ": %08x " fmt "\n", \
506 ctx->pc, ctx->opcode , ## __VA_ARGS__)
507 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
509 #define MIPS_DEBUG(fmt, ...) do { } while(0)
510 #define LOG_DISAS(...) do { } while (0)
513 #define MIPS_INVAL(op) \
515 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
516 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
519 /* General purpose registers moves. */
520 static inline void gen_load_gpr (TCGv t
, int reg
)
523 tcg_gen_movi_tl(t
, 0);
525 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
528 static inline void gen_store_gpr (TCGv t
, int reg
)
531 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
534 /* Moves to/from ACX register. */
535 static inline void gen_load_ACX (TCGv t
, int reg
)
537 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
540 static inline void gen_store_ACX (TCGv t
, int reg
)
542 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
545 /* Moves to/from shadow registers. */
546 static inline void gen_load_srsgpr (int from
, int to
)
548 TCGv t0
= tcg_temp_new();
551 tcg_gen_movi_tl(t0
, 0);
553 TCGv_i32 t2
= tcg_temp_new_i32();
554 TCGv_ptr addr
= tcg_temp_new_ptr();
556 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
557 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
558 tcg_gen_andi_i32(t2
, t2
, 0xf);
559 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
560 tcg_gen_ext_i32_ptr(addr
, t2
);
561 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
563 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
564 tcg_temp_free_ptr(addr
);
565 tcg_temp_free_i32(t2
);
567 gen_store_gpr(t0
, to
);
571 static inline void gen_store_srsgpr (int from
, int to
)
574 TCGv t0
= tcg_temp_new();
575 TCGv_i32 t2
= tcg_temp_new_i32();
576 TCGv_ptr addr
= tcg_temp_new_ptr();
578 gen_load_gpr(t0
, from
);
579 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
580 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
581 tcg_gen_andi_i32(t2
, t2
, 0xf);
582 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
583 tcg_gen_ext_i32_ptr(addr
, t2
);
584 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
586 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
587 tcg_temp_free_ptr(addr
);
588 tcg_temp_free_i32(t2
);
593 /* Floating point register moves. */
594 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
596 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
599 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
601 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
604 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
606 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
609 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
611 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
614 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
616 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
617 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
619 TCGv_i32 t0
= tcg_temp_new_i32();
620 TCGv_i32 t1
= tcg_temp_new_i32();
621 gen_load_fpr32(t0
, reg
& ~1);
622 gen_load_fpr32(t1
, reg
| 1);
623 tcg_gen_concat_i32_i64(t
, t0
, t1
);
624 tcg_temp_free_i32(t0
);
625 tcg_temp_free_i32(t1
);
629 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
631 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
632 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
634 TCGv_i64 t0
= tcg_temp_new_i64();
635 TCGv_i32 t1
= tcg_temp_new_i32();
636 tcg_gen_trunc_i64_i32(t1
, t
);
637 gen_store_fpr32(t1
, reg
& ~1);
638 tcg_gen_shri_i64(t0
, t
, 32);
639 tcg_gen_trunc_i64_i32(t1
, t0
);
640 gen_store_fpr32(t1
, reg
| 1);
641 tcg_temp_free_i32(t1
);
642 tcg_temp_free_i64(t0
);
646 static inline int get_fp_bit (int cc
)
654 #define FOP_CONDS(type, fmt, bits) \
655 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
656 TCGv_i##bits b, int cc) \
659 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
660 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
661 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
662 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
663 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
664 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
665 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
666 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
667 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
668 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
669 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
670 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
671 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
672 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
673 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
674 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
680 FOP_CONDS(abs
, d
, 64)
682 FOP_CONDS(abs
, s
, 32)
684 FOP_CONDS(abs
, ps
, 64)
688 #define OP_COND(name, cond) \
689 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, TCGv t1) \
691 int l1 = gen_new_label(); \
692 int l2 = gen_new_label(); \
694 tcg_gen_brcond_tl(cond, t0, t1, l1); \
695 tcg_gen_movi_tl(ret, 0); \
698 tcg_gen_movi_tl(ret, 1); \
701 OP_COND(eq
, TCG_COND_EQ
);
702 OP_COND(ne
, TCG_COND_NE
);
703 OP_COND(ge
, TCG_COND_GE
);
704 OP_COND(geu
, TCG_COND_GEU
);
705 OP_COND(lt
, TCG_COND_LT
);
706 OP_COND(ltu
, TCG_COND_LTU
);
709 #define OP_CONDI(name, cond) \
710 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, target_ulong val) \
712 int l1 = gen_new_label(); \
713 int l2 = gen_new_label(); \
715 tcg_gen_brcondi_tl(cond, t0, val, l1); \
716 tcg_gen_movi_tl(ret, 0); \
719 tcg_gen_movi_tl(ret, 1); \
722 OP_CONDI(lti
, TCG_COND_LT
);
723 OP_CONDI(ltiu
, TCG_COND_LTU
);
726 #define OP_CONDZ(name, cond) \
727 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0) \
729 int l1 = gen_new_label(); \
730 int l2 = gen_new_label(); \
732 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
733 tcg_gen_movi_tl(ret, 0); \
736 tcg_gen_movi_tl(ret, 1); \
739 OP_CONDZ(gez
, TCG_COND_GE
);
740 OP_CONDZ(gtz
, TCG_COND_GT
);
741 OP_CONDZ(lez
, TCG_COND_LE
);
742 OP_CONDZ(ltz
, TCG_COND_LT
);
745 static inline void gen_save_pc(target_ulong pc
)
747 tcg_gen_movi_tl(cpu_PC
, pc
);
750 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
752 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
753 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
754 gen_save_pc(ctx
->pc
);
755 ctx
->saved_pc
= ctx
->pc
;
757 if (ctx
->hflags
!= ctx
->saved_hflags
) {
758 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
759 ctx
->saved_hflags
= ctx
->hflags
;
760 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
766 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
772 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
774 ctx
->saved_hflags
= ctx
->hflags
;
775 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
781 ctx
->btarget
= env
->btarget
;
787 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
789 TCGv_i32 texcp
= tcg_const_i32(excp
);
790 TCGv_i32 terr
= tcg_const_i32(err
);
791 save_cpu_state(ctx
, 1);
792 gen_helper_raise_exception_err(texcp
, terr
);
793 tcg_temp_free_i32(terr
);
794 tcg_temp_free_i32(texcp
);
798 generate_exception (DisasContext
*ctx
, int excp
)
800 save_cpu_state(ctx
, 1);
801 gen_helper_0i(raise_exception
, excp
);
804 /* Addresses computation */
805 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv t0
, TCGv t1
)
807 tcg_gen_add_tl(t0
, t0
, t1
);
809 #if defined(TARGET_MIPS64)
810 /* For compatibility with 32-bit code, data reference in user mode
811 with Status_UX = 0 should be casted to 32-bit and sign extended.
812 See the MIPS64 PRA manual, section 4.10. */
813 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
814 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
815 tcg_gen_ext32s_i64(t0
, t0
);
820 static inline void check_cp0_enabled(DisasContext
*ctx
)
822 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
823 generate_exception_err(ctx
, EXCP_CpU
, 1);
826 static inline void check_cp1_enabled(DisasContext
*ctx
)
828 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
829 generate_exception_err(ctx
, EXCP_CpU
, 1);
832 /* Verify that the processor is running with COP1X instructions enabled.
833 This is associated with the nabla symbol in the MIPS32 and MIPS64
836 static inline void check_cop1x(DisasContext
*ctx
)
838 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
839 generate_exception(ctx
, EXCP_RI
);
842 /* Verify that the processor is running with 64-bit floating-point
843 operations enabled. */
845 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
847 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
848 generate_exception(ctx
, EXCP_RI
);
852 * Verify if floating point register is valid; an operation is not defined
853 * if bit 0 of any register specification is set and the FR bit in the
854 * Status register equals zero, since the register numbers specify an
855 * even-odd pair of adjacent coprocessor general registers. When the FR bit
856 * in the Status register equals one, both even and odd register numbers
857 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
859 * Multiple 64 bit wide registers can be checked by calling
860 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
862 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
864 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
865 generate_exception(ctx
, EXCP_RI
);
868 /* This code generates a "reserved instruction" exception if the
869 CPU does not support the instruction set corresponding to flags. */
870 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
872 if (unlikely(!(env
->insn_flags
& flags
)))
873 generate_exception(ctx
, EXCP_RI
);
876 /* This code generates a "reserved instruction" exception if 64-bit
877 instructions are not enabled. */
878 static inline void check_mips_64(DisasContext
*ctx
)
880 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
881 generate_exception(ctx
, EXCP_RI
);
884 /* load/store instructions. */
885 #define OP_LD(insn,fname) \
886 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
888 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
895 #if defined(TARGET_MIPS64)
901 #define OP_ST(insn,fname) \
902 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
904 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
909 #if defined(TARGET_MIPS64)
914 #define OP_LD_ATOMIC(insn,fname) \
915 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
917 TCGv t0 = tcg_temp_new(); \
918 tcg_gen_mov_tl(t0, arg1); \
919 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
920 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
921 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
924 OP_LD_ATOMIC(ll
,ld32s
);
925 #if defined(TARGET_MIPS64)
926 OP_LD_ATOMIC(lld
,ld64
);
930 #ifdef CONFIG_USER_ONLY
931 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
932 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
934 TCGv t0 = tcg_temp_new(); \
935 int l1 = gen_new_label(); \
936 int l2 = gen_new_label(); \
938 tcg_gen_andi_tl(t0, arg2, almask); \
939 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
940 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
941 generate_exception(ctx, EXCP_AdES); \
943 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
944 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
945 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
946 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
947 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
948 gen_helper_0i(raise_exception, EXCP_SC); \
950 tcg_gen_movi_tl(t0, 0); \
951 gen_store_gpr(t0, rt); \
955 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
956 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
958 TCGv t0 = tcg_temp_new(); \
959 TCGv t1 = tcg_temp_new(); \
960 int l1 = gen_new_label(); \
961 int l2 = gen_new_label(); \
962 int l3 = gen_new_label(); \
964 tcg_gen_andi_tl(t0, arg2, almask); \
965 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
966 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
967 generate_exception(ctx, EXCP_AdES); \
969 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
970 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
971 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, llval)); \
972 tcg_gen_qemu_##ldname(t1, arg2, ctx->mem_idx); \
973 tcg_gen_brcond_tl(TCG_COND_NE, t0, t1, l2); \
975 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
976 tcg_gen_movi_tl(t0, 1); \
977 gen_store_gpr(t0, rt); \
980 tcg_gen_movi_tl(t0, 0); \
981 gen_store_gpr(t0, rt); \
987 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
988 #if defined(TARGET_MIPS64)
989 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
994 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
995 int base
, int16_t offset
)
997 const char *opn
= "ldst";
998 TCGv t0
= tcg_temp_new();
999 TCGv t1
= tcg_temp_new();
1002 tcg_gen_movi_tl(t0
, offset
);
1003 } else if (offset
== 0) {
1004 gen_load_gpr(t0
, base
);
1006 tcg_gen_movi_tl(t0
, offset
);
1007 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
1009 /* Don't do NOP if destination is zero: we must perform the actual
1012 #if defined(TARGET_MIPS64)
1014 save_cpu_state(ctx
, 0);
1015 op_ldst_lwu(t0
, t0
, ctx
);
1016 gen_store_gpr(t0
, rt
);
1020 save_cpu_state(ctx
, 0);
1021 op_ldst_ld(t0
, t0
, ctx
);
1022 gen_store_gpr(t0
, rt
);
1026 save_cpu_state(ctx
, 0);
1027 op_ldst_lld(t0
, t0
, ctx
);
1028 gen_store_gpr(t0
, rt
);
1032 save_cpu_state(ctx
, 0);
1033 gen_load_gpr(t1
, rt
);
1034 op_ldst_sd(t1
, t0
, ctx
);
1038 save_cpu_state(ctx
, 1);
1039 gen_load_gpr(t1
, rt
);
1040 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1041 gen_store_gpr(t1
, rt
);
1045 save_cpu_state(ctx
, 1);
1046 gen_load_gpr(t1
, rt
);
1047 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1051 save_cpu_state(ctx
, 1);
1052 gen_load_gpr(t1
, rt
);
1053 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1054 gen_store_gpr(t1
, rt
);
1058 save_cpu_state(ctx
, 1);
1059 gen_load_gpr(t1
, rt
);
1060 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1065 save_cpu_state(ctx
, 0);
1066 op_ldst_lw(t0
, t0
, ctx
);
1067 gen_store_gpr(t0
, rt
);
1071 save_cpu_state(ctx
, 0);
1072 gen_load_gpr(t1
, rt
);
1073 op_ldst_sw(t1
, t0
, ctx
);
1077 save_cpu_state(ctx
, 0);
1078 op_ldst_lh(t0
, t0
, ctx
);
1079 gen_store_gpr(t0
, rt
);
1083 save_cpu_state(ctx
, 0);
1084 gen_load_gpr(t1
, rt
);
1085 op_ldst_sh(t1
, t0
, ctx
);
1089 save_cpu_state(ctx
, 0);
1090 op_ldst_lhu(t0
, t0
, ctx
);
1091 gen_store_gpr(t0
, rt
);
1095 save_cpu_state(ctx
, 0);
1096 op_ldst_lb(t0
, t0
, ctx
);
1097 gen_store_gpr(t0
, rt
);
1101 save_cpu_state(ctx
, 0);
1102 gen_load_gpr(t1
, rt
);
1103 op_ldst_sb(t1
, t0
, ctx
);
1107 save_cpu_state(ctx
, 0);
1108 op_ldst_lbu(t0
, t0
, ctx
);
1109 gen_store_gpr(t0
, rt
);
1113 save_cpu_state(ctx
, 1);
1114 gen_load_gpr(t1
, rt
);
1115 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1116 gen_store_gpr(t1
, rt
);
1120 save_cpu_state(ctx
, 1);
1121 gen_load_gpr(t1
, rt
);
1122 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1126 save_cpu_state(ctx
, 1);
1127 gen_load_gpr(t1
, rt
);
1128 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1129 gen_store_gpr(t1
, rt
);
1133 save_cpu_state(ctx
, 1);
1134 gen_load_gpr(t1
, rt
);
1135 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1139 save_cpu_state(ctx
, 0);
1140 op_ldst_ll(t0
, t0
, ctx
);
1141 gen_store_gpr(t0
, rt
);
1145 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1150 /* Store conditional */
1151 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1152 int base
, int16_t offset
)
1154 const char *opn
= "st_cond";
1157 t0
= tcg_temp_local_new();
1160 tcg_gen_movi_tl(t0
, offset
);
1161 } else if (offset
== 0) {
1162 gen_load_gpr(t0
, base
);
1164 tcg_gen_movi_tl(t0
, offset
);
1165 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
1167 /* Don't do NOP if destination is zero: we must perform the actual
1170 t1
= tcg_temp_local_new();
1171 gen_load_gpr(t1
, rt
);
1173 #if defined(TARGET_MIPS64)
1175 save_cpu_state(ctx
, 0);
1176 op_ldst_scd(t1
, t0
, rt
, ctx
);
1181 save_cpu_state(ctx
, 0);
1182 op_ldst_sc(t1
, t0
, rt
, ctx
);
1186 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1191 /* Load and store */
1192 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1193 int base
, int16_t offset
)
1195 const char *opn
= "flt_ldst";
1196 TCGv t0
= tcg_temp_new();
1199 tcg_gen_movi_tl(t0
, offset
);
1200 } else if (offset
== 0) {
1201 gen_load_gpr(t0
, base
);
1203 tcg_gen_movi_tl(t0
, offset
);
1204 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
1206 /* Don't do NOP if destination is zero: we must perform the actual
1211 TCGv_i32 fp0
= tcg_temp_new_i32();
1213 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1214 tcg_gen_trunc_tl_i32(fp0
, t0
);
1215 gen_store_fpr32(fp0
, ft
);
1216 tcg_temp_free_i32(fp0
);
1222 TCGv_i32 fp0
= tcg_temp_new_i32();
1223 TCGv t1
= tcg_temp_new();
1225 gen_load_fpr32(fp0
, ft
);
1226 tcg_gen_extu_i32_tl(t1
, fp0
);
1227 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1229 tcg_temp_free_i32(fp0
);
1235 TCGv_i64 fp0
= tcg_temp_new_i64();
1237 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1238 gen_store_fpr64(ctx
, fp0
, ft
);
1239 tcg_temp_free_i64(fp0
);
1245 TCGv_i64 fp0
= tcg_temp_new_i64();
1247 gen_load_fpr64(ctx
, fp0
, ft
);
1248 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1249 tcg_temp_free_i64(fp0
);
1255 generate_exception(ctx
, EXCP_RI
);
1258 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1263 /* Arithmetic with immediate operand */
1264 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1265 int rt
, int rs
, int16_t imm
)
1267 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1268 const char *opn
= "imm arith";
1270 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1271 /* If no destination, treat it as a NOP.
1272 For addi, we must generate the overflow exception when needed. */
1279 TCGv t0
= tcg_temp_local_new();
1280 TCGv t1
= tcg_temp_new();
1281 TCGv t2
= tcg_temp_new();
1282 int l1
= gen_new_label();
1284 gen_load_gpr(t1
, rs
);
1285 tcg_gen_addi_tl(t0
, t1
, uimm
);
1286 tcg_gen_ext32s_tl(t0
, t0
);
1288 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1289 tcg_gen_xori_tl(t2
, t0
, uimm
);
1290 tcg_gen_and_tl(t1
, t1
, t2
);
1292 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1294 /* operands of same sign, result different sign */
1295 generate_exception(ctx
, EXCP_OVERFLOW
);
1297 tcg_gen_ext32s_tl(t0
, t0
);
1298 gen_store_gpr(t0
, rt
);
1305 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1306 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1308 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1312 #if defined(TARGET_MIPS64)
1315 TCGv t0
= tcg_temp_local_new();
1316 TCGv t1
= tcg_temp_new();
1317 TCGv t2
= tcg_temp_new();
1318 int l1
= gen_new_label();
1320 gen_load_gpr(t1
, rs
);
1321 tcg_gen_addi_tl(t0
, t1
, uimm
);
1323 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1324 tcg_gen_xori_tl(t2
, t0
, uimm
);
1325 tcg_gen_and_tl(t1
, t1
, t2
);
1327 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1329 /* operands of same sign, result different sign */
1330 generate_exception(ctx
, EXCP_OVERFLOW
);
1332 gen_store_gpr(t0
, rt
);
1339 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1341 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1347 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1350 /* Logic with immediate operand */
1351 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1354 const char *opn
= "imm logic";
1357 /* If no destination, treat it as a NOP. */
1361 uimm
= (uint16_t)imm
;
1364 if (likely(rs
!= 0))
1365 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1367 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1372 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1374 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1378 if (likely(rs
!= 0))
1379 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1381 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1385 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1389 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1392 /* Set on less than with immediate operand */
1393 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1395 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1396 const char *opn
= "imm arith";
1400 /* If no destination, treat it as a NOP. */
1404 t0
= tcg_temp_new();
1405 gen_load_gpr(t0
, rs
);
1408 gen_op_lti(cpu_gpr
[rt
], t0
, uimm
);
1412 gen_op_ltiu(cpu_gpr
[rt
], t0
, uimm
);
1416 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1420 /* Shifts with immediate operand */
1421 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1422 int rt
, int rs
, int16_t imm
)
1424 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1425 const char *opn
= "imm shift";
1429 /* If no destination, treat it as a NOP. */
1434 t0
= tcg_temp_new();
1435 gen_load_gpr(t0
, rs
);
1438 tcg_gen_shli_tl(t0
, t0
, uimm
);
1439 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1443 tcg_gen_ext32s_tl(t0
, t0
);
1444 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1448 switch ((ctx
->opcode
>> 21) & 0x1f) {
1451 tcg_gen_ext32u_tl(t0
, t0
);
1452 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1454 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1459 /* rotr is decoded as srl on non-R2 CPUs */
1460 if (env
->insn_flags
& ISA_MIPS32R2
) {
1462 TCGv_i32 t1
= tcg_temp_new_i32();
1464 tcg_gen_trunc_tl_i32(t1
, t0
);
1465 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1466 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1467 tcg_temp_free_i32(t1
);
1472 tcg_gen_ext32u_tl(t0
, t0
);
1473 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1475 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1481 MIPS_INVAL("invalid srl flag");
1482 generate_exception(ctx
, EXCP_RI
);
1486 #if defined(TARGET_MIPS64)
1488 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1492 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1496 switch ((ctx
->opcode
>> 21) & 0x1f) {
1498 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1502 /* drotr is decoded as dsrl on non-R2 CPUs */
1503 if (env
->insn_flags
& ISA_MIPS32R2
) {
1505 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1509 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1514 MIPS_INVAL("invalid dsrl flag");
1515 generate_exception(ctx
, EXCP_RI
);
1520 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1524 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1528 switch ((ctx
->opcode
>> 21) & 0x1f) {
1530 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1534 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1535 if (env
->insn_flags
& ISA_MIPS32R2
) {
1536 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1539 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1544 MIPS_INVAL("invalid dsrl32 flag");
1545 generate_exception(ctx
, EXCP_RI
);
1551 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1556 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1557 int rd
, int rs
, int rt
)
1559 const char *opn
= "arith";
1561 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1562 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1563 /* If no destination, treat it as a NOP.
1564 For add & sub, we must generate the overflow exception when needed. */
1572 TCGv t0
= tcg_temp_local_new();
1573 TCGv t1
= tcg_temp_new();
1574 TCGv t2
= tcg_temp_new();
1575 int l1
= gen_new_label();
1577 gen_load_gpr(t1
, rs
);
1578 gen_load_gpr(t2
, rt
);
1579 tcg_gen_add_tl(t0
, t1
, t2
);
1580 tcg_gen_ext32s_tl(t0
, t0
);
1581 tcg_gen_xor_tl(t1
, t1
, t2
);
1582 tcg_gen_not_tl(t1
, t1
);
1583 tcg_gen_xor_tl(t2
, t0
, t2
);
1584 tcg_gen_and_tl(t1
, t1
, t2
);
1586 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1588 /* operands of same sign, result different sign */
1589 generate_exception(ctx
, EXCP_OVERFLOW
);
1591 gen_store_gpr(t0
, rd
);
1597 if (rs
!= 0 && rt
!= 0) {
1598 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1599 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1600 } else if (rs
== 0 && rt
!= 0) {
1601 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1602 } else if (rs
!= 0 && rt
== 0) {
1603 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1605 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1611 TCGv t0
= tcg_temp_local_new();
1612 TCGv t1
= tcg_temp_new();
1613 TCGv t2
= tcg_temp_new();
1614 int l1
= gen_new_label();
1616 gen_load_gpr(t1
, rs
);
1617 gen_load_gpr(t2
, rt
);
1618 tcg_gen_sub_tl(t0
, t1
, t2
);
1619 tcg_gen_ext32s_tl(t0
, t0
);
1620 tcg_gen_xor_tl(t2
, t1
, t2
);
1621 tcg_gen_xor_tl(t1
, t0
, t1
);
1622 tcg_gen_and_tl(t1
, t1
, t2
);
1624 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1626 /* operands of different sign, first operand and result different sign */
1627 generate_exception(ctx
, EXCP_OVERFLOW
);
1629 gen_store_gpr(t0
, rd
);
1635 if (rs
!= 0 && rt
!= 0) {
1636 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1637 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1638 } else if (rs
== 0 && rt
!= 0) {
1639 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1640 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1641 } else if (rs
!= 0 && rt
== 0) {
1642 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1644 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1648 #if defined(TARGET_MIPS64)
1651 TCGv t0
= tcg_temp_local_new();
1652 TCGv t1
= tcg_temp_new();
1653 TCGv t2
= tcg_temp_new();
1654 int l1
= gen_new_label();
1656 gen_load_gpr(t1
, rs
);
1657 gen_load_gpr(t2
, rt
);
1658 tcg_gen_add_tl(t0
, t1
, t2
);
1659 tcg_gen_xor_tl(t1
, t1
, t2
);
1660 tcg_gen_not_tl(t1
, t1
);
1661 tcg_gen_xor_tl(t2
, t0
, t2
);
1662 tcg_gen_and_tl(t1
, t1
, t2
);
1664 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1666 /* operands of same sign, result different sign */
1667 generate_exception(ctx
, EXCP_OVERFLOW
);
1669 gen_store_gpr(t0
, rd
);
1675 if (rs
!= 0 && rt
!= 0) {
1676 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1677 } else if (rs
== 0 && rt
!= 0) {
1678 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1679 } else if (rs
!= 0 && rt
== 0) {
1680 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1682 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1688 TCGv t0
= tcg_temp_local_new();
1689 TCGv t1
= tcg_temp_new();
1690 TCGv t2
= tcg_temp_new();
1691 int l1
= gen_new_label();
1693 gen_load_gpr(t1
, rs
);
1694 gen_load_gpr(t2
, rt
);
1695 tcg_gen_sub_tl(t0
, t1
, t2
);
1696 tcg_gen_xor_tl(t2
, t1
, t2
);
1697 tcg_gen_xor_tl(t1
, t0
, t1
);
1698 tcg_gen_and_tl(t1
, t1
, t2
);
1700 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1702 /* operands of different sign, first operand and result different sign */
1703 generate_exception(ctx
, EXCP_OVERFLOW
);
1705 gen_store_gpr(t0
, rd
);
1711 if (rs
!= 0 && rt
!= 0) {
1712 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1713 } else if (rs
== 0 && rt
!= 0) {
1714 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1715 } else if (rs
!= 0 && rt
== 0) {
1716 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1718 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1724 if (likely(rs
!= 0 && rt
!= 0)) {
1725 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1726 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1728 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1733 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1736 /* Conditional move */
1737 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1739 const char *opn
= "cond move";
1743 /* If no destination, treat it as a NOP.
1744 For add & sub, we must generate the overflow exception when needed. */
1749 l1
= gen_new_label();
1752 if (likely(rt
!= 0))
1753 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1759 if (likely(rt
!= 0))
1760 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1765 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1767 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1770 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1774 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1776 const char *opn
= "logic";
1779 /* If no destination, treat it as a NOP. */
1786 if (likely(rs
!= 0 && rt
!= 0)) {
1787 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1789 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1794 if (rs
!= 0 && rt
!= 0) {
1795 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1796 } else if (rs
== 0 && rt
!= 0) {
1797 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1798 } else if (rs
!= 0 && rt
== 0) {
1799 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1801 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1806 if (likely(rs
!= 0 && rt
!= 0)) {
1807 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1808 } else if (rs
== 0 && rt
!= 0) {
1809 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1810 } else if (rs
!= 0 && rt
== 0) {
1811 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1813 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1818 if (likely(rs
!= 0 && rt
!= 0)) {
1819 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1820 } else if (rs
== 0 && rt
!= 0) {
1821 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1822 } else if (rs
!= 0 && rt
== 0) {
1823 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1825 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1830 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1833 /* Set on lower than */
1834 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1836 const char *opn
= "slt";
1840 /* If no destination, treat it as a NOP. */
1845 t0
= tcg_temp_new();
1846 t1
= tcg_temp_new();
1847 gen_load_gpr(t0
, rs
);
1848 gen_load_gpr(t1
, rt
);
1851 gen_op_lt(cpu_gpr
[rd
], t0
, t1
);
1855 gen_op_ltu(cpu_gpr
[rd
], t0
, t1
);
1859 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1865 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1866 int rd
, int rs
, int rt
)
1868 const char *opn
= "shifts";
1872 /* If no destination, treat it as a NOP.
1873 For add & sub, we must generate the overflow exception when needed. */
1878 t0
= tcg_temp_new();
1879 t1
= tcg_temp_new();
1880 gen_load_gpr(t0
, rs
);
1881 gen_load_gpr(t1
, rt
);
1884 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1885 tcg_gen_shl_tl(t0
, t1
, t0
);
1886 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1890 tcg_gen_ext32s_tl(t1
, t1
);
1891 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1892 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1896 switch ((ctx
->opcode
>> 6) & 0x1f) {
1898 tcg_gen_ext32u_tl(t1
, t1
);
1899 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1900 tcg_gen_shr_tl(t0
, t1
, t0
);
1901 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1905 /* rotrv is decoded as srlv on non-R2 CPUs */
1906 if (env
->insn_flags
& ISA_MIPS32R2
) {
1907 TCGv_i32 t2
= tcg_temp_new_i32();
1908 TCGv_i32 t3
= tcg_temp_new_i32();
1910 tcg_gen_trunc_tl_i32(t2
, t0
);
1911 tcg_gen_trunc_tl_i32(t3
, t1
);
1912 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1913 tcg_gen_rotr_i32(t2
, t3
, t2
);
1914 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1915 tcg_temp_free_i32(t2
);
1916 tcg_temp_free_i32(t3
);
1919 tcg_gen_ext32u_tl(t1
, t1
);
1920 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1921 tcg_gen_shr_tl(t0
, t1
, t0
);
1922 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1927 MIPS_INVAL("invalid srlv flag");
1928 generate_exception(ctx
, EXCP_RI
);
1932 #if defined(TARGET_MIPS64)
1934 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1935 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1939 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1940 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1944 switch ((ctx
->opcode
>> 6) & 0x1f) {
1946 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1947 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1951 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1952 if (env
->insn_flags
& ISA_MIPS32R2
) {
1953 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1954 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1957 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1958 tcg_gen_shr_tl(t0
, t1
, t0
);
1963 MIPS_INVAL("invalid dsrlv flag");
1964 generate_exception(ctx
, EXCP_RI
);
1970 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1975 /* Arithmetic on HI/LO registers */
1976 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1978 const char *opn
= "hilo";
1980 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1987 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1991 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1996 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1998 tcg_gen_movi_tl(cpu_HI
[0], 0);
2003 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
2005 tcg_gen_movi_tl(cpu_LO
[0], 0);
2009 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
2012 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
2015 const char *opn
= "mul/div";
2021 #if defined(TARGET_MIPS64)
2025 t0
= tcg_temp_local_new();
2026 t1
= tcg_temp_local_new();
2029 t0
= tcg_temp_new();
2030 t1
= tcg_temp_new();
2034 gen_load_gpr(t0
, rs
);
2035 gen_load_gpr(t1
, rt
);
2039 int l1
= gen_new_label();
2040 int l2
= gen_new_label();
2042 tcg_gen_ext32s_tl(t0
, t0
);
2043 tcg_gen_ext32s_tl(t1
, t1
);
2044 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2045 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2046 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2048 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2049 tcg_gen_movi_tl(cpu_HI
[0], 0);
2052 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
2053 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
2054 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2055 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2062 int l1
= gen_new_label();
2064 tcg_gen_ext32u_tl(t0
, t0
);
2065 tcg_gen_ext32u_tl(t1
, t1
);
2066 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2067 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2068 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2069 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2070 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2077 TCGv_i64 t2
= tcg_temp_new_i64();
2078 TCGv_i64 t3
= tcg_temp_new_i64();
2080 tcg_gen_ext_tl_i64(t2
, t0
);
2081 tcg_gen_ext_tl_i64(t3
, t1
);
2082 tcg_gen_mul_i64(t2
, t2
, t3
);
2083 tcg_temp_free_i64(t3
);
2084 tcg_gen_trunc_i64_tl(t0
, t2
);
2085 tcg_gen_shri_i64(t2
, t2
, 32);
2086 tcg_gen_trunc_i64_tl(t1
, t2
);
2087 tcg_temp_free_i64(t2
);
2088 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2089 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2095 TCGv_i64 t2
= tcg_temp_new_i64();
2096 TCGv_i64 t3
= tcg_temp_new_i64();
2098 tcg_gen_ext32u_tl(t0
, t0
);
2099 tcg_gen_ext32u_tl(t1
, t1
);
2100 tcg_gen_extu_tl_i64(t2
, t0
);
2101 tcg_gen_extu_tl_i64(t3
, t1
);
2102 tcg_gen_mul_i64(t2
, t2
, t3
);
2103 tcg_temp_free_i64(t3
);
2104 tcg_gen_trunc_i64_tl(t0
, t2
);
2105 tcg_gen_shri_i64(t2
, t2
, 32);
2106 tcg_gen_trunc_i64_tl(t1
, t2
);
2107 tcg_temp_free_i64(t2
);
2108 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2109 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2113 #if defined(TARGET_MIPS64)
2116 int l1
= gen_new_label();
2117 int l2
= gen_new_label();
2119 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2120 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2121 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2122 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2123 tcg_gen_movi_tl(cpu_HI
[0], 0);
2126 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2127 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2134 int l1
= gen_new_label();
2136 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2137 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2138 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2144 gen_helper_dmult(t0
, t1
);
2148 gen_helper_dmultu(t0
, t1
);
2154 TCGv_i64 t2
= tcg_temp_new_i64();
2155 TCGv_i64 t3
= tcg_temp_new_i64();
2157 tcg_gen_ext_tl_i64(t2
, t0
);
2158 tcg_gen_ext_tl_i64(t3
, t1
);
2159 tcg_gen_mul_i64(t2
, t2
, t3
);
2160 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2161 tcg_gen_add_i64(t2
, t2
, t3
);
2162 tcg_temp_free_i64(t3
);
2163 tcg_gen_trunc_i64_tl(t0
, t2
);
2164 tcg_gen_shri_i64(t2
, t2
, 32);
2165 tcg_gen_trunc_i64_tl(t1
, t2
);
2166 tcg_temp_free_i64(t2
);
2167 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2168 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2174 TCGv_i64 t2
= tcg_temp_new_i64();
2175 TCGv_i64 t3
= tcg_temp_new_i64();
2177 tcg_gen_ext32u_tl(t0
, t0
);
2178 tcg_gen_ext32u_tl(t1
, t1
);
2179 tcg_gen_extu_tl_i64(t2
, t0
);
2180 tcg_gen_extu_tl_i64(t3
, t1
);
2181 tcg_gen_mul_i64(t2
, t2
, t3
);
2182 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2183 tcg_gen_add_i64(t2
, t2
, t3
);
2184 tcg_temp_free_i64(t3
);
2185 tcg_gen_trunc_i64_tl(t0
, t2
);
2186 tcg_gen_shri_i64(t2
, t2
, 32);
2187 tcg_gen_trunc_i64_tl(t1
, t2
);
2188 tcg_temp_free_i64(t2
);
2189 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2190 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2196 TCGv_i64 t2
= tcg_temp_new_i64();
2197 TCGv_i64 t3
= tcg_temp_new_i64();
2199 tcg_gen_ext_tl_i64(t2
, t0
);
2200 tcg_gen_ext_tl_i64(t3
, t1
);
2201 tcg_gen_mul_i64(t2
, t2
, t3
);
2202 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2203 tcg_gen_sub_i64(t2
, t3
, t2
);
2204 tcg_temp_free_i64(t3
);
2205 tcg_gen_trunc_i64_tl(t0
, t2
);
2206 tcg_gen_shri_i64(t2
, t2
, 32);
2207 tcg_gen_trunc_i64_tl(t1
, t2
);
2208 tcg_temp_free_i64(t2
);
2209 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2210 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2216 TCGv_i64 t2
= tcg_temp_new_i64();
2217 TCGv_i64 t3
= tcg_temp_new_i64();
2219 tcg_gen_ext32u_tl(t0
, t0
);
2220 tcg_gen_ext32u_tl(t1
, t1
);
2221 tcg_gen_extu_tl_i64(t2
, t0
);
2222 tcg_gen_extu_tl_i64(t3
, t1
);
2223 tcg_gen_mul_i64(t2
, t2
, t3
);
2224 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2225 tcg_gen_sub_i64(t2
, t3
, t2
);
2226 tcg_temp_free_i64(t3
);
2227 tcg_gen_trunc_i64_tl(t0
, t2
);
2228 tcg_gen_shri_i64(t2
, t2
, 32);
2229 tcg_gen_trunc_i64_tl(t1
, t2
);
2230 tcg_temp_free_i64(t2
);
2231 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2232 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2238 generate_exception(ctx
, EXCP_RI
);
2241 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2247 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2248 int rd
, int rs
, int rt
)
2250 const char *opn
= "mul vr54xx";
2251 TCGv t0
= tcg_temp_new();
2252 TCGv t1
= tcg_temp_new();
2254 gen_load_gpr(t0
, rs
);
2255 gen_load_gpr(t1
, rt
);
2258 case OPC_VR54XX_MULS
:
2259 gen_helper_muls(t0
, t0
, t1
);
2262 case OPC_VR54XX_MULSU
:
2263 gen_helper_mulsu(t0
, t0
, t1
);
2266 case OPC_VR54XX_MACC
:
2267 gen_helper_macc(t0
, t0
, t1
);
2270 case OPC_VR54XX_MACCU
:
2271 gen_helper_maccu(t0
, t0
, t1
);
2274 case OPC_VR54XX_MSAC
:
2275 gen_helper_msac(t0
, t0
, t1
);
2278 case OPC_VR54XX_MSACU
:
2279 gen_helper_msacu(t0
, t0
, t1
);
2282 case OPC_VR54XX_MULHI
:
2283 gen_helper_mulhi(t0
, t0
, t1
);
2286 case OPC_VR54XX_MULHIU
:
2287 gen_helper_mulhiu(t0
, t0
, t1
);
2290 case OPC_VR54XX_MULSHI
:
2291 gen_helper_mulshi(t0
, t0
, t1
);
2294 case OPC_VR54XX_MULSHIU
:
2295 gen_helper_mulshiu(t0
, t0
, t1
);
2298 case OPC_VR54XX_MACCHI
:
2299 gen_helper_macchi(t0
, t0
, t1
);
2302 case OPC_VR54XX_MACCHIU
:
2303 gen_helper_macchiu(t0
, t0
, t1
);
2306 case OPC_VR54XX_MSACHI
:
2307 gen_helper_msachi(t0
, t0
, t1
);
2310 case OPC_VR54XX_MSACHIU
:
2311 gen_helper_msachiu(t0
, t0
, t1
);
2315 MIPS_INVAL("mul vr54xx");
2316 generate_exception(ctx
, EXCP_RI
);
2319 gen_store_gpr(t0
, rd
);
2320 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2327 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2330 const char *opn
= "CLx";
2338 t0
= tcg_temp_new();
2339 gen_load_gpr(t0
, rs
);
2342 gen_helper_clo(cpu_gpr
[rd
], t0
);
2346 gen_helper_clz(cpu_gpr
[rd
], t0
);
2349 #if defined(TARGET_MIPS64)
2351 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2355 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2360 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2365 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2366 int rs
, int rt
, int16_t imm
)
2369 TCGv t0
= tcg_temp_new();
2370 TCGv t1
= tcg_temp_new();
2373 /* Load needed operands */
2381 /* Compare two registers */
2383 gen_load_gpr(t0
, rs
);
2384 gen_load_gpr(t1
, rt
);
2394 /* Compare register to immediate */
2395 if (rs
!= 0 || imm
!= 0) {
2396 gen_load_gpr(t0
, rs
);
2397 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2404 case OPC_TEQ
: /* rs == rs */
2405 case OPC_TEQI
: /* r0 == 0 */
2406 case OPC_TGE
: /* rs >= rs */
2407 case OPC_TGEI
: /* r0 >= 0 */
2408 case OPC_TGEU
: /* rs >= rs unsigned */
2409 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2411 generate_exception(ctx
, EXCP_TRAP
);
2413 case OPC_TLT
: /* rs < rs */
2414 case OPC_TLTI
: /* r0 < 0 */
2415 case OPC_TLTU
: /* rs < rs unsigned */
2416 case OPC_TLTIU
: /* r0 < 0 unsigned */
2417 case OPC_TNE
: /* rs != rs */
2418 case OPC_TNEI
: /* r0 != 0 */
2419 /* Never trap: treat as NOP. */
2423 int l1
= gen_new_label();
2428 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2432 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2436 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2440 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2444 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2448 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2451 generate_exception(ctx
, EXCP_TRAP
);
2458 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2460 TranslationBlock
*tb
;
2462 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2465 tcg_gen_exit_tb((long)tb
+ n
);
2472 /* Branches (before delay slot) */
2473 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2474 int rs
, int rt
, int32_t offset
)
2476 target_ulong btgt
= -1;
2478 int bcond_compute
= 0;
2479 TCGv t0
= tcg_temp_new();
2480 TCGv t1
= tcg_temp_new();
2482 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2483 #ifdef MIPS_DEBUG_DISAS
2484 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2486 generate_exception(ctx
, EXCP_RI
);
2490 /* Load needed operands */
2496 /* Compare two registers */
2498 gen_load_gpr(t0
, rs
);
2499 gen_load_gpr(t1
, rt
);
2502 btgt
= ctx
->pc
+ 4 + offset
;
2516 /* Compare to zero */
2518 gen_load_gpr(t0
, rs
);
2521 btgt
= ctx
->pc
+ 4 + offset
;
2525 /* Jump to immediate */
2526 btgt
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2530 /* Jump to register */
2531 if (offset
!= 0 && offset
!= 16) {
2532 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2533 others are reserved. */
2534 MIPS_INVAL("jump hint");
2535 generate_exception(ctx
, EXCP_RI
);
2538 gen_load_gpr(btarget
, rs
);
2541 MIPS_INVAL("branch/jump");
2542 generate_exception(ctx
, EXCP_RI
);
2545 if (bcond_compute
== 0) {
2546 /* No condition to be computed */
2548 case OPC_BEQ
: /* rx == rx */
2549 case OPC_BEQL
: /* rx == rx likely */
2550 case OPC_BGEZ
: /* 0 >= 0 */
2551 case OPC_BGEZL
: /* 0 >= 0 likely */
2552 case OPC_BLEZ
: /* 0 <= 0 */
2553 case OPC_BLEZL
: /* 0 <= 0 likely */
2555 ctx
->hflags
|= MIPS_HFLAG_B
;
2556 MIPS_DEBUG("balways");
2558 case OPC_BGEZAL
: /* 0 >= 0 */
2559 case OPC_BGEZALL
: /* 0 >= 0 likely */
2560 /* Always take and link */
2562 ctx
->hflags
|= MIPS_HFLAG_B
;
2563 MIPS_DEBUG("balways and link");
2565 case OPC_BNE
: /* rx != rx */
2566 case OPC_BGTZ
: /* 0 > 0 */
2567 case OPC_BLTZ
: /* 0 < 0 */
2569 MIPS_DEBUG("bnever (NOP)");
2571 case OPC_BLTZAL
: /* 0 < 0 */
2572 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2573 MIPS_DEBUG("bnever and link");
2575 case OPC_BLTZALL
: /* 0 < 0 likely */
2576 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2577 /* Skip the instruction in the delay slot */
2578 MIPS_DEBUG("bnever, link and skip");
2581 case OPC_BNEL
: /* rx != rx likely */
2582 case OPC_BGTZL
: /* 0 > 0 likely */
2583 case OPC_BLTZL
: /* 0 < 0 likely */
2584 /* Skip the instruction in the delay slot */
2585 MIPS_DEBUG("bnever and skip");
2589 ctx
->hflags
|= MIPS_HFLAG_B
;
2590 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2594 ctx
->hflags
|= MIPS_HFLAG_B
;
2595 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2598 ctx
->hflags
|= MIPS_HFLAG_BR
;
2599 MIPS_DEBUG("jr %s", regnames
[rs
]);
2603 ctx
->hflags
|= MIPS_HFLAG_BR
;
2604 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2607 MIPS_INVAL("branch/jump");
2608 generate_exception(ctx
, EXCP_RI
);
2614 gen_op_eq(bcond
, t0
, t1
);
2615 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2616 regnames
[rs
], regnames
[rt
], btgt
);
2619 gen_op_eq(bcond
, t0
, t1
);
2620 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2621 regnames
[rs
], regnames
[rt
], btgt
);
2624 gen_op_ne(bcond
, t0
, t1
);
2625 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2626 regnames
[rs
], regnames
[rt
], btgt
);
2629 gen_op_ne(bcond
, t0
, t1
);
2630 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2631 regnames
[rs
], regnames
[rt
], btgt
);
2634 gen_op_gez(bcond
, t0
);
2635 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2638 gen_op_gez(bcond
, t0
);
2639 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2642 gen_op_gez(bcond
, t0
);
2643 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2647 gen_op_gez(bcond
, t0
);
2649 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2652 gen_op_gtz(bcond
, t0
);
2653 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2656 gen_op_gtz(bcond
, t0
);
2657 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2660 gen_op_lez(bcond
, t0
);
2661 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2664 gen_op_lez(bcond
, t0
);
2665 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2668 gen_op_ltz(bcond
, t0
);
2669 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2672 gen_op_ltz(bcond
, t0
);
2673 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2676 gen_op_ltz(bcond
, t0
);
2678 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2680 ctx
->hflags
|= MIPS_HFLAG_BC
;
2683 gen_op_ltz(bcond
, t0
);
2685 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2687 ctx
->hflags
|= MIPS_HFLAG_BL
;
2690 MIPS_INVAL("conditional branch/jump");
2691 generate_exception(ctx
, EXCP_RI
);
2695 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2696 blink
, ctx
->hflags
, btgt
);
2698 ctx
->btarget
= btgt
;
2700 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ 8);
2708 /* special3 bitfield operations */
2709 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2710 int rs
, int lsb
, int msb
)
2712 TCGv t0
= tcg_temp_new();
2713 TCGv t1
= tcg_temp_new();
2716 gen_load_gpr(t1
, rs
);
2721 tcg_gen_shri_tl(t0
, t1
, lsb
);
2723 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2725 tcg_gen_ext32s_tl(t0
, t0
);
2728 #if defined(TARGET_MIPS64)
2730 tcg_gen_shri_tl(t0
, t1
, lsb
);
2732 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2736 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2737 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2740 tcg_gen_shri_tl(t0
, t1
, lsb
);
2741 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2747 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2748 gen_load_gpr(t0
, rt
);
2749 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2750 tcg_gen_shli_tl(t1
, t1
, lsb
);
2751 tcg_gen_andi_tl(t1
, t1
, mask
);
2752 tcg_gen_or_tl(t0
, t0
, t1
);
2753 tcg_gen_ext32s_tl(t0
, t0
);
2755 #if defined(TARGET_MIPS64)
2759 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2760 gen_load_gpr(t0
, rt
);
2761 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2762 tcg_gen_shli_tl(t1
, t1
, lsb
);
2763 tcg_gen_andi_tl(t1
, t1
, mask
);
2764 tcg_gen_or_tl(t0
, t0
, t1
);
2769 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2770 gen_load_gpr(t0
, rt
);
2771 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2772 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2773 tcg_gen_andi_tl(t1
, t1
, mask
);
2774 tcg_gen_or_tl(t0
, t0
, t1
);
2779 gen_load_gpr(t0
, rt
);
2780 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2781 gen_load_gpr(t0
, rt
);
2782 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2783 tcg_gen_shli_tl(t1
, t1
, lsb
);
2784 tcg_gen_andi_tl(t1
, t1
, mask
);
2785 tcg_gen_or_tl(t0
, t0
, t1
);
2790 MIPS_INVAL("bitops");
2791 generate_exception(ctx
, EXCP_RI
);
2796 gen_store_gpr(t0
, rt
);
2801 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2806 /* If no destination, treat it as a NOP. */
2811 t0
= tcg_temp_new();
2812 gen_load_gpr(t0
, rt
);
2816 TCGv t1
= tcg_temp_new();
2818 tcg_gen_shri_tl(t1
, t0
, 8);
2819 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2820 tcg_gen_shli_tl(t0
, t0
, 8);
2821 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2822 tcg_gen_or_tl(t0
, t0
, t1
);
2824 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2828 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2831 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2833 #if defined(TARGET_MIPS64)
2836 TCGv t1
= tcg_temp_new();
2838 tcg_gen_shri_tl(t1
, t0
, 8);
2839 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2840 tcg_gen_shli_tl(t0
, t0
, 8);
2841 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2842 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2848 TCGv t1
= tcg_temp_new();
2850 tcg_gen_shri_tl(t1
, t0
, 16);
2851 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2852 tcg_gen_shli_tl(t0
, t0
, 16);
2853 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2854 tcg_gen_or_tl(t0
, t0
, t1
);
2855 tcg_gen_shri_tl(t1
, t0
, 32);
2856 tcg_gen_shli_tl(t0
, t0
, 32);
2857 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2863 MIPS_INVAL("bsfhl");
2864 generate_exception(ctx
, EXCP_RI
);
2871 #ifndef CONFIG_USER_ONLY
2872 /* CP0 (MMU and control) */
2873 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
2875 TCGv_i32 t0
= tcg_temp_new_i32();
2877 tcg_gen_ld_i32(t0
, cpu_env
, off
);
2878 tcg_gen_ext_i32_tl(arg
, t0
);
2879 tcg_temp_free_i32(t0
);
2882 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
2884 tcg_gen_ld_tl(arg
, cpu_env
, off
);
2885 tcg_gen_ext32s_tl(arg
, arg
);
2888 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
2890 TCGv_i32 t0
= tcg_temp_new_i32();
2892 tcg_gen_trunc_tl_i32(t0
, arg
);
2893 tcg_gen_st_i32(t0
, cpu_env
, off
);
2894 tcg_temp_free_i32(t0
);
2897 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
2899 tcg_gen_ext32s_tl(arg
, arg
);
2900 tcg_gen_st_tl(arg
, cpu_env
, off
);
2903 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
2905 const char *rn
= "invalid";
2908 check_insn(env
, ctx
, ISA_MIPS32
);
2914 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
2918 check_insn(env
, ctx
, ASE_MT
);
2919 gen_helper_mfc0_mvpcontrol(arg
);
2923 check_insn(env
, ctx
, ASE_MT
);
2924 gen_helper_mfc0_mvpconf0(arg
);
2928 check_insn(env
, ctx
, ASE_MT
);
2929 gen_helper_mfc0_mvpconf1(arg
);
2939 gen_helper_mfc0_random(arg
);
2943 check_insn(env
, ctx
, ASE_MT
);
2944 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
2948 check_insn(env
, ctx
, ASE_MT
);
2949 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
2953 check_insn(env
, ctx
, ASE_MT
);
2954 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
2958 check_insn(env
, ctx
, ASE_MT
);
2959 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
2963 check_insn(env
, ctx
, ASE_MT
);
2964 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
2968 check_insn(env
, ctx
, ASE_MT
);
2969 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
2970 rn
= "VPEScheFBack";
2973 check_insn(env
, ctx
, ASE_MT
);
2974 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
2984 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2985 tcg_gen_ext32s_tl(arg
, arg
);
2989 check_insn(env
, ctx
, ASE_MT
);
2990 gen_helper_mfc0_tcstatus(arg
);
2994 check_insn(env
, ctx
, ASE_MT
);
2995 gen_helper_mfc0_tcbind(arg
);
2999 check_insn(env
, ctx
, ASE_MT
);
3000 gen_helper_mfc0_tcrestart(arg
);
3004 check_insn(env
, ctx
, ASE_MT
);
3005 gen_helper_mfc0_tchalt(arg
);
3009 check_insn(env
, ctx
, ASE_MT
);
3010 gen_helper_mfc0_tccontext(arg
);
3014 check_insn(env
, ctx
, ASE_MT
);
3015 gen_helper_mfc0_tcschedule(arg
);
3019 check_insn(env
, ctx
, ASE_MT
);
3020 gen_helper_mfc0_tcschefback(arg
);
3030 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
3031 tcg_gen_ext32s_tl(arg
, arg
);
3041 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
3042 tcg_gen_ext32s_tl(arg
, arg
);
3046 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3047 rn
= "ContextConfig";
3056 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
3060 check_insn(env
, ctx
, ISA_MIPS32R2
);
3061 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
3071 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
3075 check_insn(env
, ctx
, ISA_MIPS32R2
);
3076 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3080 check_insn(env
, ctx
, ISA_MIPS32R2
);
3081 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3085 check_insn(env
, ctx
, ISA_MIPS32R2
);
3086 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3090 check_insn(env
, ctx
, ISA_MIPS32R2
);
3091 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3095 check_insn(env
, ctx
, ISA_MIPS32R2
);
3096 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3106 check_insn(env
, ctx
, ISA_MIPS32R2
);
3107 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3117 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3118 tcg_gen_ext32s_tl(arg
, arg
);
3128 /* Mark as an IO operation because we read the time. */
3131 gen_helper_mfc0_count(arg
);
3134 ctx
->bstate
= BS_STOP
;
3138 /* 6,7 are implementation dependent */
3146 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3147 tcg_gen_ext32s_tl(arg
, arg
);
3157 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3160 /* 6,7 are implementation dependent */
3168 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3172 check_insn(env
, ctx
, ISA_MIPS32R2
);
3173 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3177 check_insn(env
, ctx
, ISA_MIPS32R2
);
3178 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3182 check_insn(env
, ctx
, ISA_MIPS32R2
);
3183 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3193 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3203 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3204 tcg_gen_ext32s_tl(arg
, arg
);
3214 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3218 check_insn(env
, ctx
, ISA_MIPS32R2
);
3219 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3229 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3233 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3237 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3241 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3244 /* 4,5 are reserved */
3245 /* 6,7 are implementation dependent */
3247 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3251 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3261 gen_helper_mfc0_lladdr(arg
);
3271 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3281 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3291 #if defined(TARGET_MIPS64)
3292 check_insn(env
, ctx
, ISA_MIPS3
);
3293 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3294 tcg_gen_ext32s_tl(arg
, arg
);
3303 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3306 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3314 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3315 rn
= "'Diagnostic"; /* implementation dependent */
3320 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3324 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3325 rn
= "TraceControl";
3328 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3329 rn
= "TraceControl2";
3332 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3333 rn
= "UserTraceData";
3336 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3347 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3348 tcg_gen_ext32s_tl(arg
, arg
);
3358 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3359 rn
= "Performance0";
3362 // gen_helper_mfc0_performance1(arg);
3363 rn
= "Performance1";
3366 // gen_helper_mfc0_performance2(arg);
3367 rn
= "Performance2";
3370 // gen_helper_mfc0_performance3(arg);
3371 rn
= "Performance3";
3374 // gen_helper_mfc0_performance4(arg);
3375 rn
= "Performance4";
3378 // gen_helper_mfc0_performance5(arg);
3379 rn
= "Performance5";
3382 // gen_helper_mfc0_performance6(arg);
3383 rn
= "Performance6";
3386 // gen_helper_mfc0_performance7(arg);
3387 rn
= "Performance7";
3394 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3400 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3413 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3420 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3433 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3440 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3450 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3451 tcg_gen_ext32s_tl(arg
, arg
);
3462 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3472 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3476 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3477 generate_exception(ctx
, EXCP_RI
);
3480 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3482 const char *rn
= "invalid";
3485 check_insn(env
, ctx
, ISA_MIPS32
);
3494 gen_helper_mtc0_index(arg
);
3498 check_insn(env
, ctx
, ASE_MT
);
3499 gen_helper_mtc0_mvpcontrol(arg
);
3503 check_insn(env
, ctx
, ASE_MT
);
3508 check_insn(env
, ctx
, ASE_MT
);
3523 check_insn(env
, ctx
, ASE_MT
);
3524 gen_helper_mtc0_vpecontrol(arg
);
3528 check_insn(env
, ctx
, ASE_MT
);
3529 gen_helper_mtc0_vpeconf0(arg
);
3533 check_insn(env
, ctx
, ASE_MT
);
3534 gen_helper_mtc0_vpeconf1(arg
);
3538 check_insn(env
, ctx
, ASE_MT
);
3539 gen_helper_mtc0_yqmask(arg
);
3543 check_insn(env
, ctx
, ASE_MT
);
3544 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3548 check_insn(env
, ctx
, ASE_MT
);
3549 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3550 rn
= "VPEScheFBack";
3553 check_insn(env
, ctx
, ASE_MT
);
3554 gen_helper_mtc0_vpeopt(arg
);
3564 gen_helper_mtc0_entrylo0(arg
);
3568 check_insn(env
, ctx
, ASE_MT
);
3569 gen_helper_mtc0_tcstatus(arg
);
3573 check_insn(env
, ctx
, ASE_MT
);
3574 gen_helper_mtc0_tcbind(arg
);
3578 check_insn(env
, ctx
, ASE_MT
);
3579 gen_helper_mtc0_tcrestart(arg
);
3583 check_insn(env
, ctx
, ASE_MT
);
3584 gen_helper_mtc0_tchalt(arg
);
3588 check_insn(env
, ctx
, ASE_MT
);
3589 gen_helper_mtc0_tccontext(arg
);
3593 check_insn(env
, ctx
, ASE_MT
);
3594 gen_helper_mtc0_tcschedule(arg
);
3598 check_insn(env
, ctx
, ASE_MT
);
3599 gen_helper_mtc0_tcschefback(arg
);
3609 gen_helper_mtc0_entrylo1(arg
);
3619 gen_helper_mtc0_context(arg
);
3623 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3624 rn
= "ContextConfig";
3633 gen_helper_mtc0_pagemask(arg
);
3637 check_insn(env
, ctx
, ISA_MIPS32R2
);
3638 gen_helper_mtc0_pagegrain(arg
);
3648 gen_helper_mtc0_wired(arg
);
3652 check_insn(env
, ctx
, ISA_MIPS32R2
);
3653 gen_helper_mtc0_srsconf0(arg
);
3657 check_insn(env
, ctx
, ISA_MIPS32R2
);
3658 gen_helper_mtc0_srsconf1(arg
);
3662 check_insn(env
, ctx
, ISA_MIPS32R2
);
3663 gen_helper_mtc0_srsconf2(arg
);
3667 check_insn(env
, ctx
, ISA_MIPS32R2
);
3668 gen_helper_mtc0_srsconf3(arg
);
3672 check_insn(env
, ctx
, ISA_MIPS32R2
);
3673 gen_helper_mtc0_srsconf4(arg
);
3683 check_insn(env
, ctx
, ISA_MIPS32R2
);
3684 gen_helper_mtc0_hwrena(arg
);
3698 gen_helper_mtc0_count(arg
);
3701 /* 6,7 are implementation dependent */
3709 gen_helper_mtc0_entryhi(arg
);
3719 gen_helper_mtc0_compare(arg
);
3722 /* 6,7 are implementation dependent */
3730 save_cpu_state(ctx
, 1);
3731 gen_helper_mtc0_status(arg
);
3732 /* BS_STOP isn't good enough here, hflags may have changed. */
3733 gen_save_pc(ctx
->pc
+ 4);
3734 ctx
->bstate
= BS_EXCP
;
3738 check_insn(env
, ctx
, ISA_MIPS32R2
);
3739 gen_helper_mtc0_intctl(arg
);
3740 /* Stop translation as we may have switched the execution mode */
3741 ctx
->bstate
= BS_STOP
;
3745 check_insn(env
, ctx
, ISA_MIPS32R2
);
3746 gen_helper_mtc0_srsctl(arg
);
3747 /* Stop translation as we may have switched the execution mode */
3748 ctx
->bstate
= BS_STOP
;
3752 check_insn(env
, ctx
, ISA_MIPS32R2
);
3753 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3754 /* Stop translation as we may have switched the execution mode */
3755 ctx
->bstate
= BS_STOP
;
3765 save_cpu_state(ctx
, 1);
3766 gen_helper_mtc0_cause(arg
);
3776 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
3790 check_insn(env
, ctx
, ISA_MIPS32R2
);
3791 gen_helper_mtc0_ebase(arg
);
3801 gen_helper_mtc0_config0(arg
);
3803 /* Stop translation as we may have switched the execution mode */
3804 ctx
->bstate
= BS_STOP
;
3807 /* ignored, read only */
3811 gen_helper_mtc0_config2(arg
);
3813 /* Stop translation as we may have switched the execution mode */
3814 ctx
->bstate
= BS_STOP
;
3817 /* ignored, read only */
3820 /* 4,5 are reserved */
3821 /* 6,7 are implementation dependent */
3831 rn
= "Invalid config selector";
3848 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
3858 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
3868 #if defined(TARGET_MIPS64)
3869 check_insn(env
, ctx
, ISA_MIPS3
);
3870 gen_helper_mtc0_xcontext(arg
);
3879 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3882 gen_helper_mtc0_framemask(arg
);
3891 rn
= "Diagnostic"; /* implementation dependent */
3896 gen_helper_mtc0_debug(arg
); /* EJTAG support */
3897 /* BS_STOP isn't good enough here, hflags may have changed. */
3898 gen_save_pc(ctx
->pc
+ 4);
3899 ctx
->bstate
= BS_EXCP
;
3903 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
3904 rn
= "TraceControl";
3905 /* Stop translation as we may have switched the execution mode */
3906 ctx
->bstate
= BS_STOP
;
3909 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
3910 rn
= "TraceControl2";
3911 /* Stop translation as we may have switched the execution mode */
3912 ctx
->bstate
= BS_STOP
;
3915 /* Stop translation as we may have switched the execution mode */
3916 ctx
->bstate
= BS_STOP
;
3917 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
3918 rn
= "UserTraceData";
3919 /* Stop translation as we may have switched the execution mode */
3920 ctx
->bstate
= BS_STOP
;
3923 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
3924 /* Stop translation as we may have switched the execution mode */
3925 ctx
->bstate
= BS_STOP
;
3936 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
3946 gen_helper_mtc0_performance0(arg
);
3947 rn
= "Performance0";
3950 // gen_helper_mtc0_performance1(arg);
3951 rn
= "Performance1";
3954 // gen_helper_mtc0_performance2(arg);
3955 rn
= "Performance2";
3958 // gen_helper_mtc0_performance3(arg);
3959 rn
= "Performance3";
3962 // gen_helper_mtc0_performance4(arg);
3963 rn
= "Performance4";
3966 // gen_helper_mtc0_performance5(arg);
3967 rn
= "Performance5";
3970 // gen_helper_mtc0_performance6(arg);
3971 rn
= "Performance6";
3974 // gen_helper_mtc0_performance7(arg);
3975 rn
= "Performance7";
4001 gen_helper_mtc0_taglo(arg
);
4008 gen_helper_mtc0_datalo(arg
);
4021 gen_helper_mtc0_taghi(arg
);
4028 gen_helper_mtc0_datahi(arg
);
4039 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
4050 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4056 /* Stop translation as we may have switched the execution mode */
4057 ctx
->bstate
= BS_STOP
;
4062 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4063 /* For simplicity assume that all writes can cause interrupts. */
4066 ctx
->bstate
= BS_STOP
;
4071 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4072 generate_exception(ctx
, EXCP_RI
);
4075 #if defined(TARGET_MIPS64)
4076 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4078 const char *rn
= "invalid";
4081 check_insn(env
, ctx
, ISA_MIPS64
);
4087 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4091 check_insn(env
, ctx
, ASE_MT
);
4092 gen_helper_mfc0_mvpcontrol(arg
);
4096 check_insn(env
, ctx
, ASE_MT
);
4097 gen_helper_mfc0_mvpconf0(arg
);
4101 check_insn(env
, ctx
, ASE_MT
);
4102 gen_helper_mfc0_mvpconf1(arg
);
4112 gen_helper_mfc0_random(arg
);
4116 check_insn(env
, ctx
, ASE_MT
);
4117 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4121 check_insn(env
, ctx
, ASE_MT
);
4122 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4126 check_insn(env
, ctx
, ASE_MT
);
4127 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4131 check_insn(env
, ctx
, ASE_MT
);
4132 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4136 check_insn(env
, ctx
, ASE_MT
);
4137 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4141 check_insn(env
, ctx
, ASE_MT
);
4142 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4143 rn
= "VPEScheFBack";
4146 check_insn(env
, ctx
, ASE_MT
);
4147 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4157 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4161 check_insn(env
, ctx
, ASE_MT
);
4162 gen_helper_mfc0_tcstatus(arg
);
4166 check_insn(env
, ctx
, ASE_MT
);
4167 gen_helper_mfc0_tcbind(arg
);
4171 check_insn(env
, ctx
, ASE_MT
);
4172 gen_helper_dmfc0_tcrestart(arg
);
4176 check_insn(env
, ctx
, ASE_MT
);
4177 gen_helper_dmfc0_tchalt(arg
);
4181 check_insn(env
, ctx
, ASE_MT
);
4182 gen_helper_dmfc0_tccontext(arg
);
4186 check_insn(env
, ctx
, ASE_MT
);
4187 gen_helper_dmfc0_tcschedule(arg
);
4191 check_insn(env
, ctx
, ASE_MT
);
4192 gen_helper_dmfc0_tcschefback(arg
);
4202 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4212 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4216 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4217 rn
= "ContextConfig";
4226 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4230 check_insn(env
, ctx
, ISA_MIPS32R2
);
4231 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4241 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4245 check_insn(env
, ctx
, ISA_MIPS32R2
);
4246 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4250 check_insn(env
, ctx
, ISA_MIPS32R2
);
4251 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4255 check_insn(env
, ctx
, ISA_MIPS32R2
);
4256 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4260 check_insn(env
, ctx
, ISA_MIPS32R2
);
4261 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4265 check_insn(env
, ctx
, ISA_MIPS32R2
);
4266 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4276 check_insn(env
, ctx
, ISA_MIPS32R2
);
4277 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4287 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4297 /* Mark as an IO operation because we read the time. */
4300 gen_helper_mfc0_count(arg
);
4303 ctx
->bstate
= BS_STOP
;
4307 /* 6,7 are implementation dependent */
4315 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4325 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4328 /* 6,7 are implementation dependent */
4336 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4340 check_insn(env
, ctx
, ISA_MIPS32R2
);
4341 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4345 check_insn(env
, ctx
, ISA_MIPS32R2
);
4346 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4350 check_insn(env
, ctx
, ISA_MIPS32R2
);
4351 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4361 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4371 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4381 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4385 check_insn(env
, ctx
, ISA_MIPS32R2
);
4386 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4396 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4400 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4404 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4408 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4411 /* 6,7 are implementation dependent */
4413 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4417 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4427 gen_helper_dmfc0_lladdr(arg
);
4437 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4447 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4457 check_insn(env
, ctx
, ISA_MIPS3
);
4458 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4466 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4469 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4477 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4478 rn
= "'Diagnostic"; /* implementation dependent */
4483 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4487 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4488 rn
= "TraceControl";
4491 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4492 rn
= "TraceControl2";
4495 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4496 rn
= "UserTraceData";
4499 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4510 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4520 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4521 rn
= "Performance0";
4524 // gen_helper_dmfc0_performance1(arg);
4525 rn
= "Performance1";
4528 // gen_helper_dmfc0_performance2(arg);
4529 rn
= "Performance2";
4532 // gen_helper_dmfc0_performance3(arg);
4533 rn
= "Performance3";
4536 // gen_helper_dmfc0_performance4(arg);
4537 rn
= "Performance4";
4540 // gen_helper_dmfc0_performance5(arg);
4541 rn
= "Performance5";
4544 // gen_helper_dmfc0_performance6(arg);
4545 rn
= "Performance6";
4548 // gen_helper_dmfc0_performance7(arg);
4549 rn
= "Performance7";
4556 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4563 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4576 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4583 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4596 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4603 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4613 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4624 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4634 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4638 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4639 generate_exception(ctx
, EXCP_RI
);
4642 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4644 const char *rn
= "invalid";
4647 check_insn(env
, ctx
, ISA_MIPS64
);
4656 gen_helper_mtc0_index(arg
);
4660 check_insn(env
, ctx
, ASE_MT
);
4661 gen_helper_mtc0_mvpcontrol(arg
);
4665 check_insn(env
, ctx
, ASE_MT
);
4670 check_insn(env
, ctx
, ASE_MT
);
4685 check_insn(env
, ctx
, ASE_MT
);
4686 gen_helper_mtc0_vpecontrol(arg
);
4690 check_insn(env
, ctx
, ASE_MT
);
4691 gen_helper_mtc0_vpeconf0(arg
);
4695 check_insn(env
, ctx
, ASE_MT
);
4696 gen_helper_mtc0_vpeconf1(arg
);
4700 check_insn(env
, ctx
, ASE_MT
);
4701 gen_helper_mtc0_yqmask(arg
);
4705 check_insn(env
, ctx
, ASE_MT
);
4706 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4710 check_insn(env
, ctx
, ASE_MT
);
4711 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4712 rn
= "VPEScheFBack";
4715 check_insn(env
, ctx
, ASE_MT
);
4716 gen_helper_mtc0_vpeopt(arg
);
4726 gen_helper_mtc0_entrylo0(arg
);
4730 check_insn(env
, ctx
, ASE_MT
);
4731 gen_helper_mtc0_tcstatus(arg
);
4735 check_insn(env
, ctx
, ASE_MT
);
4736 gen_helper_mtc0_tcbind(arg
);
4740 check_insn(env
, ctx
, ASE_MT
);
4741 gen_helper_mtc0_tcrestart(arg
);
4745 check_insn(env
, ctx
, ASE_MT
);
4746 gen_helper_mtc0_tchalt(arg
);
4750 check_insn(env
, ctx
, ASE_MT
);
4751 gen_helper_mtc0_tccontext(arg
);
4755 check_insn(env
, ctx
, ASE_MT
);
4756 gen_helper_mtc0_tcschedule(arg
);
4760 check_insn(env
, ctx
, ASE_MT
);
4761 gen_helper_mtc0_tcschefback(arg
);
4771 gen_helper_mtc0_entrylo1(arg
);
4781 gen_helper_mtc0_context(arg
);
4785 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
4786 rn
= "ContextConfig";
4795 gen_helper_mtc0_pagemask(arg
);
4799 check_insn(env
, ctx
, ISA_MIPS32R2
);
4800 gen_helper_mtc0_pagegrain(arg
);
4810 gen_helper_mtc0_wired(arg
);
4814 check_insn(env
, ctx
, ISA_MIPS32R2
);
4815 gen_helper_mtc0_srsconf0(arg
);
4819 check_insn(env
, ctx
, ISA_MIPS32R2
);
4820 gen_helper_mtc0_srsconf1(arg
);
4824 check_insn(env
, ctx
, ISA_MIPS32R2
);
4825 gen_helper_mtc0_srsconf2(arg
);
4829 check_insn(env
, ctx
, ISA_MIPS32R2
);
4830 gen_helper_mtc0_srsconf3(arg
);
4834 check_insn(env
, ctx
, ISA_MIPS32R2
);
4835 gen_helper_mtc0_srsconf4(arg
);
4845 check_insn(env
, ctx
, ISA_MIPS32R2
);
4846 gen_helper_mtc0_hwrena(arg
);
4860 gen_helper_mtc0_count(arg
);
4863 /* 6,7 are implementation dependent */
4867 /* Stop translation as we may have switched the execution mode */
4868 ctx
->bstate
= BS_STOP
;
4873 gen_helper_mtc0_entryhi(arg
);
4883 gen_helper_mtc0_compare(arg
);
4886 /* 6,7 are implementation dependent */
4890 /* Stop translation as we may have switched the execution mode */
4891 ctx
->bstate
= BS_STOP
;
4896 save_cpu_state(ctx
, 1);
4897 gen_helper_mtc0_status(arg
);
4898 /* BS_STOP isn't good enough here, hflags may have changed. */
4899 gen_save_pc(ctx
->pc
+ 4);
4900 ctx
->bstate
= BS_EXCP
;
4904 check_insn(env
, ctx
, ISA_MIPS32R2
);
4905 gen_helper_mtc0_intctl(arg
);
4906 /* Stop translation as we may have switched the execution mode */
4907 ctx
->bstate
= BS_STOP
;
4911 check_insn(env
, ctx
, ISA_MIPS32R2
);
4912 gen_helper_mtc0_srsctl(arg
);
4913 /* Stop translation as we may have switched the execution mode */
4914 ctx
->bstate
= BS_STOP
;
4918 check_insn(env
, ctx
, ISA_MIPS32R2
);
4919 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4920 /* Stop translation as we may have switched the execution mode */
4921 ctx
->bstate
= BS_STOP
;
4931 save_cpu_state(ctx
, 1);
4932 gen_helper_mtc0_cause(arg
);
4942 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4956 check_insn(env
, ctx
, ISA_MIPS32R2
);
4957 gen_helper_mtc0_ebase(arg
);
4967 gen_helper_mtc0_config0(arg
);
4969 /* Stop translation as we may have switched the execution mode */
4970 ctx
->bstate
= BS_STOP
;
4973 /* ignored, read only */
4977 gen_helper_mtc0_config2(arg
);
4979 /* Stop translation as we may have switched the execution mode */
4980 ctx
->bstate
= BS_STOP
;
4986 /* 6,7 are implementation dependent */
4988 rn
= "Invalid config selector";
5005 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
5015 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
5025 check_insn(env
, ctx
, ISA_MIPS3
);
5026 gen_helper_mtc0_xcontext(arg
);
5034 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5037 gen_helper_mtc0_framemask(arg
);
5046 rn
= "Diagnostic"; /* implementation dependent */
5051 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5052 /* BS_STOP isn't good enough here, hflags may have changed. */
5053 gen_save_pc(ctx
->pc
+ 4);
5054 ctx
->bstate
= BS_EXCP
;
5058 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5059 /* Stop translation as we may have switched the execution mode */
5060 ctx
->bstate
= BS_STOP
;
5061 rn
= "TraceControl";
5064 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5065 /* Stop translation as we may have switched the execution mode */
5066 ctx
->bstate
= BS_STOP
;
5067 rn
= "TraceControl2";
5070 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5071 /* Stop translation as we may have switched the execution mode */
5072 ctx
->bstate
= BS_STOP
;
5073 rn
= "UserTraceData";
5076 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5077 /* Stop translation as we may have switched the execution mode */
5078 ctx
->bstate
= BS_STOP
;
5089 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5099 gen_helper_mtc0_performance0(arg
);
5100 rn
= "Performance0";
5103 // gen_helper_mtc0_performance1(arg);
5104 rn
= "Performance1";
5107 // gen_helper_mtc0_performance2(arg);
5108 rn
= "Performance2";
5111 // gen_helper_mtc0_performance3(arg);
5112 rn
= "Performance3";
5115 // gen_helper_mtc0_performance4(arg);
5116 rn
= "Performance4";
5119 // gen_helper_mtc0_performance5(arg);
5120 rn
= "Performance5";
5123 // gen_helper_mtc0_performance6(arg);
5124 rn
= "Performance6";
5127 // gen_helper_mtc0_performance7(arg);
5128 rn
= "Performance7";
5154 gen_helper_mtc0_taglo(arg
);
5161 gen_helper_mtc0_datalo(arg
);
5174 gen_helper_mtc0_taghi(arg
);
5181 gen_helper_mtc0_datahi(arg
);
5192 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5203 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5209 /* Stop translation as we may have switched the execution mode */
5210 ctx
->bstate
= BS_STOP
;
5215 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5216 /* For simplicity assume that all writes can cause interrupts. */
5219 ctx
->bstate
= BS_STOP
;
5224 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5225 generate_exception(ctx
, EXCP_RI
);
5227 #endif /* TARGET_MIPS64 */
5229 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5230 int u
, int sel
, int h
)
5232 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5233 TCGv t0
= tcg_temp_local_new();
5235 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5236 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5237 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5238 tcg_gen_movi_tl(t0
, -1);
5239 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5240 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5241 tcg_gen_movi_tl(t0
, -1);
5247 gen_helper_mftc0_tcstatus(t0
);
5250 gen_helper_mftc0_tcbind(t0
);
5253 gen_helper_mftc0_tcrestart(t0
);
5256 gen_helper_mftc0_tchalt(t0
);
5259 gen_helper_mftc0_tccontext(t0
);
5262 gen_helper_mftc0_tcschedule(t0
);
5265 gen_helper_mftc0_tcschefback(t0
);
5268 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5275 gen_helper_mftc0_entryhi(t0
);
5278 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5284 gen_helper_mftc0_status(t0
);
5287 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5293 gen_helper_mftc0_debug(t0
);
5296 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5301 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5303 } else switch (sel
) {
5304 /* GPR registers. */
5306 gen_helper_1i(mftgpr
, t0
, rt
);
5308 /* Auxiliary CPU registers */
5312 gen_helper_1i(mftlo
, t0
, 0);
5315 gen_helper_1i(mfthi
, t0
, 0);
5318 gen_helper_1i(mftacx
, t0
, 0);
5321 gen_helper_1i(mftlo
, t0
, 1);
5324 gen_helper_1i(mfthi
, t0
, 1);
5327 gen_helper_1i(mftacx
, t0
, 1);
5330 gen_helper_1i(mftlo
, t0
, 2);
5333 gen_helper_1i(mfthi
, t0
, 2);
5336 gen_helper_1i(mftacx
, t0
, 2);
5339 gen_helper_1i(mftlo
, t0
, 3);
5342 gen_helper_1i(mfthi
, t0
, 3);
5345 gen_helper_1i(mftacx
, t0
, 3);
5348 gen_helper_mftdsp(t0
);
5354 /* Floating point (COP1). */
5356 /* XXX: For now we support only a single FPU context. */
5358 TCGv_i32 fp0
= tcg_temp_new_i32();
5360 gen_load_fpr32(fp0
, rt
);
5361 tcg_gen_ext_i32_tl(t0
, fp0
);
5362 tcg_temp_free_i32(fp0
);
5364 TCGv_i32 fp0
= tcg_temp_new_i32();
5366 gen_load_fpr32h(fp0
, rt
);
5367 tcg_gen_ext_i32_tl(t0
, fp0
);
5368 tcg_temp_free_i32(fp0
);
5372 /* XXX: For now we support only a single FPU context. */
5373 gen_helper_1i(cfc1
, t0
, rt
);
5375 /* COP2: Not implemented. */
5382 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5383 gen_store_gpr(t0
, rd
);
5389 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5390 generate_exception(ctx
, EXCP_RI
);
5393 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5394 int u
, int sel
, int h
)
5396 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5397 TCGv t0
= tcg_temp_local_new();
5399 gen_load_gpr(t0
, rt
);
5400 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5401 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5402 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5404 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5405 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5412 gen_helper_mttc0_tcstatus(t0
);
5415 gen_helper_mttc0_tcbind(t0
);
5418 gen_helper_mttc0_tcrestart(t0
);
5421 gen_helper_mttc0_tchalt(t0
);
5424 gen_helper_mttc0_tccontext(t0
);
5427 gen_helper_mttc0_tcschedule(t0
);
5430 gen_helper_mttc0_tcschefback(t0
);
5433 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5440 gen_helper_mttc0_entryhi(t0
);
5443 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5449 gen_helper_mttc0_status(t0
);
5452 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5458 gen_helper_mttc0_debug(t0
);
5461 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5466 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5468 } else switch (sel
) {
5469 /* GPR registers. */
5471 gen_helper_1i(mttgpr
, t0
, rd
);
5473 /* Auxiliary CPU registers */
5477 gen_helper_1i(mttlo
, t0
, 0);
5480 gen_helper_1i(mtthi
, t0
, 0);
5483 gen_helper_1i(mttacx
, t0
, 0);
5486 gen_helper_1i(mttlo
, t0
, 1);
5489 gen_helper_1i(mtthi
, t0
, 1);
5492 gen_helper_1i(mttacx
, t0
, 1);
5495 gen_helper_1i(mttlo
, t0
, 2);
5498 gen_helper_1i(mtthi
, t0
, 2);
5501 gen_helper_1i(mttacx
, t0
, 2);
5504 gen_helper_1i(mttlo
, t0
, 3);
5507 gen_helper_1i(mtthi
, t0
, 3);
5510 gen_helper_1i(mttacx
, t0
, 3);
5513 gen_helper_mttdsp(t0
);
5519 /* Floating point (COP1). */
5521 /* XXX: For now we support only a single FPU context. */
5523 TCGv_i32 fp0
= tcg_temp_new_i32();
5525 tcg_gen_trunc_tl_i32(fp0
, t0
);
5526 gen_store_fpr32(fp0
, rd
);
5527 tcg_temp_free_i32(fp0
);
5529 TCGv_i32 fp0
= tcg_temp_new_i32();
5531 tcg_gen_trunc_tl_i32(fp0
, t0
);
5532 gen_store_fpr32h(fp0
, rd
);
5533 tcg_temp_free_i32(fp0
);
5537 /* XXX: For now we support only a single FPU context. */
5538 gen_helper_1i(ctc1
, t0
, rd
);
5540 /* COP2: Not implemented. */
5547 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5553 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5554 generate_exception(ctx
, EXCP_RI
);
5557 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5559 const char *opn
= "ldst";
5567 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5572 TCGv t0
= tcg_temp_new();
5574 gen_load_gpr(t0
, rt
);
5575 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5580 #if defined(TARGET_MIPS64)
5582 check_insn(env
, ctx
, ISA_MIPS3
);
5587 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5591 check_insn(env
, ctx
, ISA_MIPS3
);
5593 TCGv t0
= tcg_temp_new();
5595 gen_load_gpr(t0
, rt
);
5596 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5603 check_insn(env
, ctx
, ASE_MT
);
5608 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5609 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5613 check_insn(env
, ctx
, ASE_MT
);
5614 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5615 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5620 if (!env
->tlb
->helper_tlbwi
)
5626 if (!env
->tlb
->helper_tlbwr
)
5632 if (!env
->tlb
->helper_tlbp
)
5638 if (!env
->tlb
->helper_tlbr
)
5644 check_insn(env
, ctx
, ISA_MIPS2
);
5646 ctx
->bstate
= BS_EXCP
;
5650 check_insn(env
, ctx
, ISA_MIPS32
);
5651 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5653 generate_exception(ctx
, EXCP_RI
);
5656 ctx
->bstate
= BS_EXCP
;
5661 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5662 /* If we get an exception, we want to restart at next instruction */
5664 save_cpu_state(ctx
, 1);
5667 ctx
->bstate
= BS_EXCP
;
5672 generate_exception(ctx
, EXCP_RI
);
5675 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5677 #endif /* !CONFIG_USER_ONLY */
5679 /* CP1 Branches (before delay slot) */
5680 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5681 int32_t cc
, int32_t offset
)
5683 target_ulong btarget
;
5684 const char *opn
= "cp1 cond branch";
5685 TCGv_i32 t0
= tcg_temp_new_i32();
5688 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5690 btarget
= ctx
->pc
+ 4 + offset
;
5694 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5695 tcg_gen_not_i32(t0
, t0
);
5696 tcg_gen_andi_i32(t0
, t0
, 1);
5697 tcg_gen_extu_i32_tl(bcond
, t0
);
5701 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5702 tcg_gen_not_i32(t0
, t0
);
5703 tcg_gen_andi_i32(t0
, t0
, 1);
5704 tcg_gen_extu_i32_tl(bcond
, t0
);
5708 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5709 tcg_gen_andi_i32(t0
, t0
, 1);
5710 tcg_gen_extu_i32_tl(bcond
, t0
);
5714 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5715 tcg_gen_andi_i32(t0
, t0
, 1);
5716 tcg_gen_extu_i32_tl(bcond
, t0
);
5719 ctx
->hflags
|= MIPS_HFLAG_BL
;
5723 TCGv_i32 t1
= tcg_temp_new_i32();
5724 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5725 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5726 tcg_gen_or_i32(t0
, t0
, t1
);
5727 tcg_temp_free_i32(t1
);
5728 tcg_gen_not_i32(t0
, t0
);
5729 tcg_gen_andi_i32(t0
, t0
, 1);
5730 tcg_gen_extu_i32_tl(bcond
, t0
);
5736 TCGv_i32 t1
= tcg_temp_new_i32();
5737 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5738 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5739 tcg_gen_or_i32(t0
, t0
, t1
);
5740 tcg_temp_free_i32(t1
);
5741 tcg_gen_andi_i32(t0
, t0
, 1);
5742 tcg_gen_extu_i32_tl(bcond
, t0
);
5748 TCGv_i32 t1
= tcg_temp_new_i32();
5749 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5750 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5751 tcg_gen_or_i32(t0
, t0
, t1
);
5752 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5753 tcg_gen_or_i32(t0
, t0
, t1
);
5754 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5755 tcg_gen_or_i32(t0
, t0
, t1
);
5756 tcg_temp_free_i32(t1
);
5757 tcg_gen_not_i32(t0
, t0
);
5758 tcg_gen_andi_i32(t0
, t0
, 1);
5759 tcg_gen_extu_i32_tl(bcond
, t0
);
5765 TCGv_i32 t1
= tcg_temp_new_i32();
5766 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5767 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5768 tcg_gen_or_i32(t0
, t0
, t1
);
5769 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5770 tcg_gen_or_i32(t0
, t0
, t1
);
5771 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5772 tcg_gen_or_i32(t0
, t0
, t1
);
5773 tcg_temp_free_i32(t1
);
5774 tcg_gen_andi_i32(t0
, t0
, 1);
5775 tcg_gen_extu_i32_tl(bcond
, t0
);
5779 ctx
->hflags
|= MIPS_HFLAG_BC
;
5783 generate_exception (ctx
, EXCP_RI
);
5786 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5787 ctx
->hflags
, btarget
);
5788 ctx
->btarget
= btarget
;
5791 tcg_temp_free_i32(t0
);
5794 /* Coprocessor 1 (FPU) */
5796 #define FOP(func, fmt) (((fmt) << 21) | (func))
5798 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5800 const char *opn
= "cp1 move";
5801 TCGv t0
= tcg_temp_new();
5806 TCGv_i32 fp0
= tcg_temp_new_i32();
5808 gen_load_fpr32(fp0
, fs
);
5809 tcg_gen_ext_i32_tl(t0
, fp0
);
5810 tcg_temp_free_i32(fp0
);
5812 gen_store_gpr(t0
, rt
);
5816 gen_load_gpr(t0
, rt
);
5818 TCGv_i32 fp0
= tcg_temp_new_i32();
5820 tcg_gen_trunc_tl_i32(fp0
, t0
);
5821 gen_store_fpr32(fp0
, fs
);
5822 tcg_temp_free_i32(fp0
);
5827 gen_helper_1i(cfc1
, t0
, fs
);
5828 gen_store_gpr(t0
, rt
);
5832 gen_load_gpr(t0
, rt
);
5833 gen_helper_1i(ctc1
, t0
, fs
);
5836 #if defined(TARGET_MIPS64)
5838 gen_load_fpr64(ctx
, t0
, fs
);
5839 gen_store_gpr(t0
, rt
);
5843 gen_load_gpr(t0
, rt
);
5844 gen_store_fpr64(ctx
, t0
, fs
);
5850 TCGv_i32 fp0
= tcg_temp_new_i32();
5852 gen_load_fpr32h(fp0
, fs
);
5853 tcg_gen_ext_i32_tl(t0
, fp0
);
5854 tcg_temp_free_i32(fp0
);
5856 gen_store_gpr(t0
, rt
);
5860 gen_load_gpr(t0
, rt
);
5862 TCGv_i32 fp0
= tcg_temp_new_i32();
5864 tcg_gen_trunc_tl_i32(fp0
, t0
);
5865 gen_store_fpr32h(fp0
, fs
);
5866 tcg_temp_free_i32(fp0
);
5872 generate_exception (ctx
, EXCP_RI
);
5875 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5881 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5897 l1
= gen_new_label();
5898 t0
= tcg_temp_new_i32();
5899 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5900 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5901 tcg_temp_free_i32(t0
);
5903 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
5905 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
5910 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5913 TCGv_i32 t0
= tcg_temp_new_i32();
5914 int l1
= gen_new_label();
5921 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5922 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5923 gen_load_fpr32(t0
, fs
);
5924 gen_store_fpr32(t0
, fd
);
5926 tcg_temp_free_i32(t0
);
5929 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5932 TCGv_i32 t0
= tcg_temp_new_i32();
5934 int l1
= gen_new_label();
5941 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5942 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5943 tcg_temp_free_i32(t0
);
5944 fp0
= tcg_temp_new_i64();
5945 gen_load_fpr64(ctx
, fp0
, fs
);
5946 gen_store_fpr64(ctx
, fp0
, fd
);
5947 tcg_temp_free_i64(fp0
);
5951 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5954 TCGv_i32 t0
= tcg_temp_new_i32();
5955 int l1
= gen_new_label();
5956 int l2
= gen_new_label();
5963 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5964 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5965 gen_load_fpr32(t0
, fs
);
5966 gen_store_fpr32(t0
, fd
);
5969 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
5970 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
5971 gen_load_fpr32h(t0
, fs
);
5972 gen_store_fpr32h(t0
, fd
);
5973 tcg_temp_free_i32(t0
);
5978 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5979 int ft
, int fs
, int fd
, int cc
)
5981 const char *opn
= "farith";
5982 const char *condnames
[] = {
6000 const char *condnames_abs
[] = {
6018 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6019 uint32_t func
= ctx
->opcode
& 0x3f;
6021 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
6024 TCGv_i32 fp0
= tcg_temp_new_i32();
6025 TCGv_i32 fp1
= tcg_temp_new_i32();
6027 gen_load_fpr32(fp0
, fs
);
6028 gen_load_fpr32(fp1
, ft
);
6029 gen_helper_float_add_s(fp0
, fp0
, fp1
);
6030 tcg_temp_free_i32(fp1
);
6031 gen_store_fpr32(fp0
, fd
);
6032 tcg_temp_free_i32(fp0
);
6039 TCGv_i32 fp0
= tcg_temp_new_i32();
6040 TCGv_i32 fp1
= tcg_temp_new_i32();
6042 gen_load_fpr32(fp0
, fs
);
6043 gen_load_fpr32(fp1
, ft
);
6044 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6045 tcg_temp_free_i32(fp1
);
6046 gen_store_fpr32(fp0
, fd
);
6047 tcg_temp_free_i32(fp0
);
6054 TCGv_i32 fp0
= tcg_temp_new_i32();
6055 TCGv_i32 fp1
= tcg_temp_new_i32();
6057 gen_load_fpr32(fp0
, fs
);
6058 gen_load_fpr32(fp1
, ft
);
6059 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6060 tcg_temp_free_i32(fp1
);
6061 gen_store_fpr32(fp0
, fd
);
6062 tcg_temp_free_i32(fp0
);
6069 TCGv_i32 fp0
= tcg_temp_new_i32();
6070 TCGv_i32 fp1
= tcg_temp_new_i32();
6072 gen_load_fpr32(fp0
, fs
);
6073 gen_load_fpr32(fp1
, ft
);
6074 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6075 tcg_temp_free_i32(fp1
);
6076 gen_store_fpr32(fp0
, fd
);
6077 tcg_temp_free_i32(fp0
);
6084 TCGv_i32 fp0
= tcg_temp_new_i32();
6086 gen_load_fpr32(fp0
, fs
);
6087 gen_helper_float_sqrt_s(fp0
, fp0
);
6088 gen_store_fpr32(fp0
, fd
);
6089 tcg_temp_free_i32(fp0
);
6095 TCGv_i32 fp0
= tcg_temp_new_i32();
6097 gen_load_fpr32(fp0
, fs
);
6098 gen_helper_float_abs_s(fp0
, fp0
);
6099 gen_store_fpr32(fp0
, fd
);
6100 tcg_temp_free_i32(fp0
);
6106 TCGv_i32 fp0
= tcg_temp_new_i32();
6108 gen_load_fpr32(fp0
, fs
);
6109 gen_store_fpr32(fp0
, fd
);
6110 tcg_temp_free_i32(fp0
);
6116 TCGv_i32 fp0
= tcg_temp_new_i32();
6118 gen_load_fpr32(fp0
, fs
);
6119 gen_helper_float_chs_s(fp0
, fp0
);
6120 gen_store_fpr32(fp0
, fd
);
6121 tcg_temp_free_i32(fp0
);
6126 check_cp1_64bitmode(ctx
);
6128 TCGv_i32 fp32
= tcg_temp_new_i32();
6129 TCGv_i64 fp64
= tcg_temp_new_i64();
6131 gen_load_fpr32(fp32
, fs
);
6132 gen_helper_float_roundl_s(fp64
, fp32
);
6133 tcg_temp_free_i32(fp32
);
6134 gen_store_fpr64(ctx
, fp64
, fd
);
6135 tcg_temp_free_i64(fp64
);
6140 check_cp1_64bitmode(ctx
);
6142 TCGv_i32 fp32
= tcg_temp_new_i32();
6143 TCGv_i64 fp64
= tcg_temp_new_i64();
6145 gen_load_fpr32(fp32
, fs
);
6146 gen_helper_float_truncl_s(fp64
, fp32
);
6147 tcg_temp_free_i32(fp32
);
6148 gen_store_fpr64(ctx
, fp64
, fd
);
6149 tcg_temp_free_i64(fp64
);
6154 check_cp1_64bitmode(ctx
);
6156 TCGv_i32 fp32
= tcg_temp_new_i32();
6157 TCGv_i64 fp64
= tcg_temp_new_i64();
6159 gen_load_fpr32(fp32
, fs
);
6160 gen_helper_float_ceill_s(fp64
, fp32
);
6161 tcg_temp_free_i32(fp32
);
6162 gen_store_fpr64(ctx
, fp64
, fd
);
6163 tcg_temp_free_i64(fp64
);
6168 check_cp1_64bitmode(ctx
);
6170 TCGv_i32 fp32
= tcg_temp_new_i32();
6171 TCGv_i64 fp64
= tcg_temp_new_i64();
6173 gen_load_fpr32(fp32
, fs
);
6174 gen_helper_float_floorl_s(fp64
, fp32
);
6175 tcg_temp_free_i32(fp32
);
6176 gen_store_fpr64(ctx
, fp64
, fd
);
6177 tcg_temp_free_i64(fp64
);
6183 TCGv_i32 fp0
= tcg_temp_new_i32();
6185 gen_load_fpr32(fp0
, fs
);
6186 gen_helper_float_roundw_s(fp0
, fp0
);
6187 gen_store_fpr32(fp0
, fd
);
6188 tcg_temp_free_i32(fp0
);
6194 TCGv_i32 fp0
= tcg_temp_new_i32();
6196 gen_load_fpr32(fp0
, fs
);
6197 gen_helper_float_truncw_s(fp0
, fp0
);
6198 gen_store_fpr32(fp0
, fd
);
6199 tcg_temp_free_i32(fp0
);
6205 TCGv_i32 fp0
= tcg_temp_new_i32();
6207 gen_load_fpr32(fp0
, fs
);
6208 gen_helper_float_ceilw_s(fp0
, fp0
);
6209 gen_store_fpr32(fp0
, fd
);
6210 tcg_temp_free_i32(fp0
);
6216 TCGv_i32 fp0
= tcg_temp_new_i32();
6218 gen_load_fpr32(fp0
, fs
);
6219 gen_helper_float_floorw_s(fp0
, fp0
);
6220 gen_store_fpr32(fp0
, fd
);
6221 tcg_temp_free_i32(fp0
);
6226 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6231 int l1
= gen_new_label();
6235 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6237 fp0
= tcg_temp_new_i32();
6238 gen_load_fpr32(fp0
, fs
);
6239 gen_store_fpr32(fp0
, fd
);
6240 tcg_temp_free_i32(fp0
);
6247 int l1
= gen_new_label();
6251 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6252 fp0
= tcg_temp_new_i32();
6253 gen_load_fpr32(fp0
, fs
);
6254 gen_store_fpr32(fp0
, fd
);
6255 tcg_temp_free_i32(fp0
);
6264 TCGv_i32 fp0
= tcg_temp_new_i32();
6266 gen_load_fpr32(fp0
, fs
);
6267 gen_helper_float_recip_s(fp0
, fp0
);
6268 gen_store_fpr32(fp0
, fd
);
6269 tcg_temp_free_i32(fp0
);
6276 TCGv_i32 fp0
= tcg_temp_new_i32();
6278 gen_load_fpr32(fp0
, fs
);
6279 gen_helper_float_rsqrt_s(fp0
, fp0
);
6280 gen_store_fpr32(fp0
, fd
);
6281 tcg_temp_free_i32(fp0
);
6286 check_cp1_64bitmode(ctx
);
6288 TCGv_i32 fp0
= tcg_temp_new_i32();
6289 TCGv_i32 fp1
= tcg_temp_new_i32();
6291 gen_load_fpr32(fp0
, fs
);
6292 gen_load_fpr32(fp1
, fd
);
6293 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6294 tcg_temp_free_i32(fp1
);
6295 gen_store_fpr32(fp0
, fd
);
6296 tcg_temp_free_i32(fp0
);
6301 check_cp1_64bitmode(ctx
);
6303 TCGv_i32 fp0
= tcg_temp_new_i32();
6305 gen_load_fpr32(fp0
, fs
);
6306 gen_helper_float_recip1_s(fp0
, fp0
);
6307 gen_store_fpr32(fp0
, fd
);
6308 tcg_temp_free_i32(fp0
);
6313 check_cp1_64bitmode(ctx
);
6315 TCGv_i32 fp0
= tcg_temp_new_i32();
6317 gen_load_fpr32(fp0
, fs
);
6318 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6319 gen_store_fpr32(fp0
, fd
);
6320 tcg_temp_free_i32(fp0
);
6325 check_cp1_64bitmode(ctx
);
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 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6333 tcg_temp_free_i32(fp1
);
6334 gen_store_fpr32(fp0
, fd
);
6335 tcg_temp_free_i32(fp0
);
6340 check_cp1_registers(ctx
, fd
);
6342 TCGv_i32 fp32
= tcg_temp_new_i32();
6343 TCGv_i64 fp64
= tcg_temp_new_i64();
6345 gen_load_fpr32(fp32
, fs
);
6346 gen_helper_float_cvtd_s(fp64
, fp32
);
6347 tcg_temp_free_i32(fp32
);
6348 gen_store_fpr64(ctx
, fp64
, fd
);
6349 tcg_temp_free_i64(fp64
);
6355 TCGv_i32 fp0
= tcg_temp_new_i32();
6357 gen_load_fpr32(fp0
, fs
);
6358 gen_helper_float_cvtw_s(fp0
, fp0
);
6359 gen_store_fpr32(fp0
, fd
);
6360 tcg_temp_free_i32(fp0
);
6365 check_cp1_64bitmode(ctx
);
6367 TCGv_i32 fp32
= tcg_temp_new_i32();
6368 TCGv_i64 fp64
= tcg_temp_new_i64();
6370 gen_load_fpr32(fp32
, fs
);
6371 gen_helper_float_cvtl_s(fp64
, fp32
);
6372 tcg_temp_free_i32(fp32
);
6373 gen_store_fpr64(ctx
, fp64
, fd
);
6374 tcg_temp_free_i64(fp64
);
6379 check_cp1_64bitmode(ctx
);
6381 TCGv_i64 fp64
= tcg_temp_new_i64();
6382 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6383 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6385 gen_load_fpr32(fp32_0
, fs
);
6386 gen_load_fpr32(fp32_1
, ft
);
6387 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6388 tcg_temp_free_i32(fp32_1
);
6389 tcg_temp_free_i32(fp32_0
);
6390 gen_store_fpr64(ctx
, fp64
, fd
);
6391 tcg_temp_free_i64(fp64
);
6412 TCGv_i32 fp0
= tcg_temp_new_i32();
6413 TCGv_i32 fp1
= tcg_temp_new_i32();
6415 gen_load_fpr32(fp0
, fs
);
6416 gen_load_fpr32(fp1
, ft
);
6417 if (ctx
->opcode
& (1 << 6)) {
6419 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6420 opn
= condnames_abs
[func
-48];
6422 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6423 opn
= condnames
[func
-48];
6425 tcg_temp_free_i32(fp0
);
6426 tcg_temp_free_i32(fp1
);
6430 check_cp1_registers(ctx
, fs
| ft
| fd
);
6432 TCGv_i64 fp0
= tcg_temp_new_i64();
6433 TCGv_i64 fp1
= tcg_temp_new_i64();
6435 gen_load_fpr64(ctx
, fp0
, fs
);
6436 gen_load_fpr64(ctx
, fp1
, ft
);
6437 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6438 tcg_temp_free_i64(fp1
);
6439 gen_store_fpr64(ctx
, fp0
, fd
);
6440 tcg_temp_free_i64(fp0
);
6446 check_cp1_registers(ctx
, fs
| ft
| fd
);
6448 TCGv_i64 fp0
= tcg_temp_new_i64();
6449 TCGv_i64 fp1
= tcg_temp_new_i64();
6451 gen_load_fpr64(ctx
, fp0
, fs
);
6452 gen_load_fpr64(ctx
, fp1
, ft
);
6453 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6454 tcg_temp_free_i64(fp1
);
6455 gen_store_fpr64(ctx
, fp0
, fd
);
6456 tcg_temp_free_i64(fp0
);
6462 check_cp1_registers(ctx
, fs
| ft
| fd
);
6464 TCGv_i64 fp0
= tcg_temp_new_i64();
6465 TCGv_i64 fp1
= tcg_temp_new_i64();
6467 gen_load_fpr64(ctx
, fp0
, fs
);
6468 gen_load_fpr64(ctx
, fp1
, ft
);
6469 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6470 tcg_temp_free_i64(fp1
);
6471 gen_store_fpr64(ctx
, fp0
, fd
);
6472 tcg_temp_free_i64(fp0
);
6478 check_cp1_registers(ctx
, fs
| ft
| fd
);
6480 TCGv_i64 fp0
= tcg_temp_new_i64();
6481 TCGv_i64 fp1
= tcg_temp_new_i64();
6483 gen_load_fpr64(ctx
, fp0
, fs
);
6484 gen_load_fpr64(ctx
, fp1
, ft
);
6485 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6486 tcg_temp_free_i64(fp1
);
6487 gen_store_fpr64(ctx
, fp0
, fd
);
6488 tcg_temp_free_i64(fp0
);
6494 check_cp1_registers(ctx
, fs
| fd
);
6496 TCGv_i64 fp0
= tcg_temp_new_i64();
6498 gen_load_fpr64(ctx
, fp0
, fs
);
6499 gen_helper_float_sqrt_d(fp0
, fp0
);
6500 gen_store_fpr64(ctx
, fp0
, fd
);
6501 tcg_temp_free_i64(fp0
);
6506 check_cp1_registers(ctx
, fs
| fd
);
6508 TCGv_i64 fp0
= tcg_temp_new_i64();
6510 gen_load_fpr64(ctx
, fp0
, fs
);
6511 gen_helper_float_abs_d(fp0
, fp0
);
6512 gen_store_fpr64(ctx
, fp0
, fd
);
6513 tcg_temp_free_i64(fp0
);
6518 check_cp1_registers(ctx
, fs
| fd
);
6520 TCGv_i64 fp0
= tcg_temp_new_i64();
6522 gen_load_fpr64(ctx
, fp0
, fs
);
6523 gen_store_fpr64(ctx
, fp0
, fd
);
6524 tcg_temp_free_i64(fp0
);
6529 check_cp1_registers(ctx
, fs
| fd
);
6531 TCGv_i64 fp0
= tcg_temp_new_i64();
6533 gen_load_fpr64(ctx
, fp0
, fs
);
6534 gen_helper_float_chs_d(fp0
, fp0
);
6535 gen_store_fpr64(ctx
, fp0
, fd
);
6536 tcg_temp_free_i64(fp0
);
6541 check_cp1_64bitmode(ctx
);
6543 TCGv_i64 fp0
= tcg_temp_new_i64();
6545 gen_load_fpr64(ctx
, fp0
, fs
);
6546 gen_helper_float_roundl_d(fp0
, fp0
);
6547 gen_store_fpr64(ctx
, fp0
, fd
);
6548 tcg_temp_free_i64(fp0
);
6553 check_cp1_64bitmode(ctx
);
6555 TCGv_i64 fp0
= tcg_temp_new_i64();
6557 gen_load_fpr64(ctx
, fp0
, fs
);
6558 gen_helper_float_truncl_d(fp0
, fp0
);
6559 gen_store_fpr64(ctx
, fp0
, fd
);
6560 tcg_temp_free_i64(fp0
);
6565 check_cp1_64bitmode(ctx
);
6567 TCGv_i64 fp0
= tcg_temp_new_i64();
6569 gen_load_fpr64(ctx
, fp0
, fs
);
6570 gen_helper_float_ceill_d(fp0
, fp0
);
6571 gen_store_fpr64(ctx
, fp0
, fd
);
6572 tcg_temp_free_i64(fp0
);
6577 check_cp1_64bitmode(ctx
);
6579 TCGv_i64 fp0
= tcg_temp_new_i64();
6581 gen_load_fpr64(ctx
, fp0
, fs
);
6582 gen_helper_float_floorl_d(fp0
, fp0
);
6583 gen_store_fpr64(ctx
, fp0
, fd
);
6584 tcg_temp_free_i64(fp0
);
6589 check_cp1_registers(ctx
, fs
);
6591 TCGv_i32 fp32
= tcg_temp_new_i32();
6592 TCGv_i64 fp64
= tcg_temp_new_i64();
6594 gen_load_fpr64(ctx
, fp64
, fs
);
6595 gen_helper_float_roundw_d(fp32
, fp64
);
6596 tcg_temp_free_i64(fp64
);
6597 gen_store_fpr32(fp32
, fd
);
6598 tcg_temp_free_i32(fp32
);
6603 check_cp1_registers(ctx
, fs
);
6605 TCGv_i32 fp32
= tcg_temp_new_i32();
6606 TCGv_i64 fp64
= tcg_temp_new_i64();
6608 gen_load_fpr64(ctx
, fp64
, fs
);
6609 gen_helper_float_truncw_d(fp32
, fp64
);
6610 tcg_temp_free_i64(fp64
);
6611 gen_store_fpr32(fp32
, fd
);
6612 tcg_temp_free_i32(fp32
);
6617 check_cp1_registers(ctx
, fs
);
6619 TCGv_i32 fp32
= tcg_temp_new_i32();
6620 TCGv_i64 fp64
= tcg_temp_new_i64();
6622 gen_load_fpr64(ctx
, fp64
, fs
);
6623 gen_helper_float_ceilw_d(fp32
, fp64
);
6624 tcg_temp_free_i64(fp64
);
6625 gen_store_fpr32(fp32
, fd
);
6626 tcg_temp_free_i32(fp32
);
6631 check_cp1_registers(ctx
, fs
);
6633 TCGv_i32 fp32
= tcg_temp_new_i32();
6634 TCGv_i64 fp64
= tcg_temp_new_i64();
6636 gen_load_fpr64(ctx
, fp64
, fs
);
6637 gen_helper_float_floorw_d(fp32
, fp64
);
6638 tcg_temp_free_i64(fp64
);
6639 gen_store_fpr32(fp32
, fd
);
6640 tcg_temp_free_i32(fp32
);
6645 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6650 int l1
= gen_new_label();
6654 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6656 fp0
= tcg_temp_new_i64();
6657 gen_load_fpr64(ctx
, fp0
, fs
);
6658 gen_store_fpr64(ctx
, fp0
, fd
);
6659 tcg_temp_free_i64(fp0
);
6666 int l1
= gen_new_label();
6670 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6671 fp0
= tcg_temp_new_i64();
6672 gen_load_fpr64(ctx
, fp0
, fs
);
6673 gen_store_fpr64(ctx
, fp0
, fd
);
6674 tcg_temp_free_i64(fp0
);
6681 check_cp1_64bitmode(ctx
);
6683 TCGv_i64 fp0
= tcg_temp_new_i64();
6685 gen_load_fpr64(ctx
, fp0
, fs
);
6686 gen_helper_float_recip_d(fp0
, fp0
);
6687 gen_store_fpr64(ctx
, fp0
, fd
);
6688 tcg_temp_free_i64(fp0
);
6693 check_cp1_64bitmode(ctx
);
6695 TCGv_i64 fp0
= tcg_temp_new_i64();
6697 gen_load_fpr64(ctx
, fp0
, fs
);
6698 gen_helper_float_rsqrt_d(fp0
, fp0
);
6699 gen_store_fpr64(ctx
, fp0
, fd
);
6700 tcg_temp_free_i64(fp0
);
6705 check_cp1_64bitmode(ctx
);
6707 TCGv_i64 fp0
= tcg_temp_new_i64();
6708 TCGv_i64 fp1
= tcg_temp_new_i64();
6710 gen_load_fpr64(ctx
, fp0
, fs
);
6711 gen_load_fpr64(ctx
, fp1
, ft
);
6712 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6713 tcg_temp_free_i64(fp1
);
6714 gen_store_fpr64(ctx
, fp0
, fd
);
6715 tcg_temp_free_i64(fp0
);
6720 check_cp1_64bitmode(ctx
);
6722 TCGv_i64 fp0
= tcg_temp_new_i64();
6724 gen_load_fpr64(ctx
, fp0
, fs
);
6725 gen_helper_float_recip1_d(fp0
, fp0
);
6726 gen_store_fpr64(ctx
, fp0
, fd
);
6727 tcg_temp_free_i64(fp0
);
6732 check_cp1_64bitmode(ctx
);
6734 TCGv_i64 fp0
= tcg_temp_new_i64();
6736 gen_load_fpr64(ctx
, fp0
, fs
);
6737 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6738 gen_store_fpr64(ctx
, fp0
, fd
);
6739 tcg_temp_free_i64(fp0
);
6744 check_cp1_64bitmode(ctx
);
6746 TCGv_i64 fp0
= tcg_temp_new_i64();
6747 TCGv_i64 fp1
= tcg_temp_new_i64();
6749 gen_load_fpr64(ctx
, fp0
, fs
);
6750 gen_load_fpr64(ctx
, fp1
, ft
);
6751 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6752 tcg_temp_free_i64(fp1
);
6753 gen_store_fpr64(ctx
, fp0
, fd
);
6754 tcg_temp_free_i64(fp0
);
6775 TCGv_i64 fp0
= tcg_temp_new_i64();
6776 TCGv_i64 fp1
= tcg_temp_new_i64();
6778 gen_load_fpr64(ctx
, fp0
, fs
);
6779 gen_load_fpr64(ctx
, fp1
, ft
);
6780 if (ctx
->opcode
& (1 << 6)) {
6782 check_cp1_registers(ctx
, fs
| ft
);
6783 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6784 opn
= condnames_abs
[func
-48];
6786 check_cp1_registers(ctx
, fs
| ft
);
6787 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6788 opn
= condnames
[func
-48];
6790 tcg_temp_free_i64(fp0
);
6791 tcg_temp_free_i64(fp1
);
6795 check_cp1_registers(ctx
, fs
);
6797 TCGv_i32 fp32
= tcg_temp_new_i32();
6798 TCGv_i64 fp64
= tcg_temp_new_i64();
6800 gen_load_fpr64(ctx
, fp64
, fs
);
6801 gen_helper_float_cvts_d(fp32
, fp64
);
6802 tcg_temp_free_i64(fp64
);
6803 gen_store_fpr32(fp32
, fd
);
6804 tcg_temp_free_i32(fp32
);
6809 check_cp1_registers(ctx
, fs
);
6811 TCGv_i32 fp32
= tcg_temp_new_i32();
6812 TCGv_i64 fp64
= tcg_temp_new_i64();
6814 gen_load_fpr64(ctx
, fp64
, fs
);
6815 gen_helper_float_cvtw_d(fp32
, fp64
);
6816 tcg_temp_free_i64(fp64
);
6817 gen_store_fpr32(fp32
, fd
);
6818 tcg_temp_free_i32(fp32
);
6823 check_cp1_64bitmode(ctx
);
6825 TCGv_i64 fp0
= tcg_temp_new_i64();
6827 gen_load_fpr64(ctx
, fp0
, fs
);
6828 gen_helper_float_cvtl_d(fp0
, fp0
);
6829 gen_store_fpr64(ctx
, fp0
, fd
);
6830 tcg_temp_free_i64(fp0
);
6836 TCGv_i32 fp0
= tcg_temp_new_i32();
6838 gen_load_fpr32(fp0
, fs
);
6839 gen_helper_float_cvts_w(fp0
, fp0
);
6840 gen_store_fpr32(fp0
, fd
);
6841 tcg_temp_free_i32(fp0
);
6846 check_cp1_registers(ctx
, fd
);
6848 TCGv_i32 fp32
= tcg_temp_new_i32();
6849 TCGv_i64 fp64
= tcg_temp_new_i64();
6851 gen_load_fpr32(fp32
, fs
);
6852 gen_helper_float_cvtd_w(fp64
, fp32
);
6853 tcg_temp_free_i32(fp32
);
6854 gen_store_fpr64(ctx
, fp64
, fd
);
6855 tcg_temp_free_i64(fp64
);
6860 check_cp1_64bitmode(ctx
);
6862 TCGv_i32 fp32
= tcg_temp_new_i32();
6863 TCGv_i64 fp64
= tcg_temp_new_i64();
6865 gen_load_fpr64(ctx
, fp64
, fs
);
6866 gen_helper_float_cvts_l(fp32
, fp64
);
6867 tcg_temp_free_i64(fp64
);
6868 gen_store_fpr32(fp32
, fd
);
6869 tcg_temp_free_i32(fp32
);
6874 check_cp1_64bitmode(ctx
);
6876 TCGv_i64 fp0
= tcg_temp_new_i64();
6878 gen_load_fpr64(ctx
, fp0
, fs
);
6879 gen_helper_float_cvtd_l(fp0
, fp0
);
6880 gen_store_fpr64(ctx
, fp0
, fd
);
6881 tcg_temp_free_i64(fp0
);
6886 check_cp1_64bitmode(ctx
);
6888 TCGv_i64 fp0
= tcg_temp_new_i64();
6890 gen_load_fpr64(ctx
, fp0
, fs
);
6891 gen_helper_float_cvtps_pw(fp0
, fp0
);
6892 gen_store_fpr64(ctx
, fp0
, fd
);
6893 tcg_temp_free_i64(fp0
);
6898 check_cp1_64bitmode(ctx
);
6900 TCGv_i64 fp0
= tcg_temp_new_i64();
6901 TCGv_i64 fp1
= tcg_temp_new_i64();
6903 gen_load_fpr64(ctx
, fp0
, fs
);
6904 gen_load_fpr64(ctx
, fp1
, ft
);
6905 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6906 tcg_temp_free_i64(fp1
);
6907 gen_store_fpr64(ctx
, fp0
, fd
);
6908 tcg_temp_free_i64(fp0
);
6913 check_cp1_64bitmode(ctx
);
6915 TCGv_i64 fp0
= tcg_temp_new_i64();
6916 TCGv_i64 fp1
= tcg_temp_new_i64();
6918 gen_load_fpr64(ctx
, fp0
, fs
);
6919 gen_load_fpr64(ctx
, fp1
, ft
);
6920 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6921 tcg_temp_free_i64(fp1
);
6922 gen_store_fpr64(ctx
, fp0
, fd
);
6923 tcg_temp_free_i64(fp0
);
6928 check_cp1_64bitmode(ctx
);
6930 TCGv_i64 fp0
= tcg_temp_new_i64();
6931 TCGv_i64 fp1
= tcg_temp_new_i64();
6933 gen_load_fpr64(ctx
, fp0
, fs
);
6934 gen_load_fpr64(ctx
, fp1
, ft
);
6935 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6936 tcg_temp_free_i64(fp1
);
6937 gen_store_fpr64(ctx
, fp0
, fd
);
6938 tcg_temp_free_i64(fp0
);
6943 check_cp1_64bitmode(ctx
);
6945 TCGv_i64 fp0
= tcg_temp_new_i64();
6947 gen_load_fpr64(ctx
, fp0
, fs
);
6948 gen_helper_float_abs_ps(fp0
, fp0
);
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();
6959 gen_load_fpr64(ctx
, fp0
, fs
);
6960 gen_store_fpr64(ctx
, fp0
, fd
);
6961 tcg_temp_free_i64(fp0
);
6966 check_cp1_64bitmode(ctx
);
6968 TCGv_i64 fp0
= tcg_temp_new_i64();
6970 gen_load_fpr64(ctx
, fp0
, fs
);
6971 gen_helper_float_chs_ps(fp0
, fp0
);
6972 gen_store_fpr64(ctx
, fp0
, fd
);
6973 tcg_temp_free_i64(fp0
);
6978 check_cp1_64bitmode(ctx
);
6979 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6983 check_cp1_64bitmode(ctx
);
6985 int l1
= gen_new_label();
6989 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6990 fp0
= tcg_temp_new_i64();
6991 gen_load_fpr64(ctx
, fp0
, fs
);
6992 gen_store_fpr64(ctx
, fp0
, fd
);
6993 tcg_temp_free_i64(fp0
);
6999 check_cp1_64bitmode(ctx
);
7001 int l1
= gen_new_label();
7005 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7006 fp0
= tcg_temp_new_i64();
7007 gen_load_fpr64(ctx
, fp0
, fs
);
7008 gen_store_fpr64(ctx
, fp0
, fd
);
7009 tcg_temp_free_i64(fp0
);
7016 check_cp1_64bitmode(ctx
);
7018 TCGv_i64 fp0
= tcg_temp_new_i64();
7019 TCGv_i64 fp1
= tcg_temp_new_i64();
7021 gen_load_fpr64(ctx
, fp0
, ft
);
7022 gen_load_fpr64(ctx
, fp1
, fs
);
7023 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
7024 tcg_temp_free_i64(fp1
);
7025 gen_store_fpr64(ctx
, fp0
, fd
);
7026 tcg_temp_free_i64(fp0
);
7031 check_cp1_64bitmode(ctx
);
7033 TCGv_i64 fp0
= tcg_temp_new_i64();
7034 TCGv_i64 fp1
= tcg_temp_new_i64();
7036 gen_load_fpr64(ctx
, fp0
, ft
);
7037 gen_load_fpr64(ctx
, fp1
, fs
);
7038 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7039 tcg_temp_free_i64(fp1
);
7040 gen_store_fpr64(ctx
, fp0
, fd
);
7041 tcg_temp_free_i64(fp0
);
7046 check_cp1_64bitmode(ctx
);
7048 TCGv_i64 fp0
= tcg_temp_new_i64();
7049 TCGv_i64 fp1
= tcg_temp_new_i64();
7051 gen_load_fpr64(ctx
, fp0
, fs
);
7052 gen_load_fpr64(ctx
, fp1
, fd
);
7053 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7054 tcg_temp_free_i64(fp1
);
7055 gen_store_fpr64(ctx
, fp0
, fd
);
7056 tcg_temp_free_i64(fp0
);
7061 check_cp1_64bitmode(ctx
);
7063 TCGv_i64 fp0
= tcg_temp_new_i64();
7065 gen_load_fpr64(ctx
, fp0
, fs
);
7066 gen_helper_float_recip1_ps(fp0
, fp0
);
7067 gen_store_fpr64(ctx
, fp0
, fd
);
7068 tcg_temp_free_i64(fp0
);
7073 check_cp1_64bitmode(ctx
);
7075 TCGv_i64 fp0
= tcg_temp_new_i64();
7077 gen_load_fpr64(ctx
, fp0
, fs
);
7078 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7079 gen_store_fpr64(ctx
, fp0
, fd
);
7080 tcg_temp_free_i64(fp0
);
7085 check_cp1_64bitmode(ctx
);
7087 TCGv_i64 fp0
= tcg_temp_new_i64();
7088 TCGv_i64 fp1
= tcg_temp_new_i64();
7090 gen_load_fpr64(ctx
, fp0
, fs
);
7091 gen_load_fpr64(ctx
, fp1
, ft
);
7092 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7093 tcg_temp_free_i64(fp1
);
7094 gen_store_fpr64(ctx
, fp0
, fd
);
7095 tcg_temp_free_i64(fp0
);
7100 check_cp1_64bitmode(ctx
);
7102 TCGv_i32 fp0
= tcg_temp_new_i32();
7104 gen_load_fpr32h(fp0
, fs
);
7105 gen_helper_float_cvts_pu(fp0
, fp0
);
7106 gen_store_fpr32(fp0
, fd
);
7107 tcg_temp_free_i32(fp0
);
7112 check_cp1_64bitmode(ctx
);
7114 TCGv_i64 fp0
= tcg_temp_new_i64();
7116 gen_load_fpr64(ctx
, fp0
, fs
);
7117 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7118 gen_store_fpr64(ctx
, fp0
, fd
);
7119 tcg_temp_free_i64(fp0
);
7124 check_cp1_64bitmode(ctx
);
7126 TCGv_i32 fp0
= tcg_temp_new_i32();
7128 gen_load_fpr32(fp0
, fs
);
7129 gen_helper_float_cvts_pl(fp0
, fp0
);
7130 gen_store_fpr32(fp0
, fd
);
7131 tcg_temp_free_i32(fp0
);
7136 check_cp1_64bitmode(ctx
);
7138 TCGv_i32 fp0
= tcg_temp_new_i32();
7139 TCGv_i32 fp1
= tcg_temp_new_i32();
7141 gen_load_fpr32(fp0
, fs
);
7142 gen_load_fpr32(fp1
, ft
);
7143 gen_store_fpr32h(fp0
, fd
);
7144 gen_store_fpr32(fp1
, fd
);
7145 tcg_temp_free_i32(fp0
);
7146 tcg_temp_free_i32(fp1
);
7151 check_cp1_64bitmode(ctx
);
7153 TCGv_i32 fp0
= tcg_temp_new_i32();
7154 TCGv_i32 fp1
= tcg_temp_new_i32();
7156 gen_load_fpr32(fp0
, fs
);
7157 gen_load_fpr32h(fp1
, ft
);
7158 gen_store_fpr32(fp1
, fd
);
7159 gen_store_fpr32h(fp0
, fd
);
7160 tcg_temp_free_i32(fp0
);
7161 tcg_temp_free_i32(fp1
);
7166 check_cp1_64bitmode(ctx
);
7168 TCGv_i32 fp0
= tcg_temp_new_i32();
7169 TCGv_i32 fp1
= tcg_temp_new_i32();
7171 gen_load_fpr32h(fp0
, fs
);
7172 gen_load_fpr32(fp1
, ft
);
7173 gen_store_fpr32(fp1
, fd
);
7174 gen_store_fpr32h(fp0
, fd
);
7175 tcg_temp_free_i32(fp0
);
7176 tcg_temp_free_i32(fp1
);
7181 check_cp1_64bitmode(ctx
);
7183 TCGv_i32 fp0
= tcg_temp_new_i32();
7184 TCGv_i32 fp1
= tcg_temp_new_i32();
7186 gen_load_fpr32h(fp0
, fs
);
7187 gen_load_fpr32h(fp1
, ft
);
7188 gen_store_fpr32(fp1
, fd
);
7189 gen_store_fpr32h(fp0
, fd
);
7190 tcg_temp_free_i32(fp0
);
7191 tcg_temp_free_i32(fp1
);
7211 check_cp1_64bitmode(ctx
);
7213 TCGv_i64 fp0
= tcg_temp_new_i64();
7214 TCGv_i64 fp1
= tcg_temp_new_i64();
7216 gen_load_fpr64(ctx
, fp0
, fs
);
7217 gen_load_fpr64(ctx
, fp1
, ft
);
7218 if (ctx
->opcode
& (1 << 6)) {
7219 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7220 opn
= condnames_abs
[func
-48];
7222 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7223 opn
= condnames
[func
-48];
7225 tcg_temp_free_i64(fp0
);
7226 tcg_temp_free_i64(fp1
);
7231 generate_exception (ctx
, EXCP_RI
);
7236 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7239 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7242 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7247 /* Coprocessor 3 (FPU) */
7248 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7249 int fd
, int fs
, int base
, int index
)
7251 const char *opn
= "extended float load/store";
7253 TCGv t0
= tcg_temp_new();
7256 gen_load_gpr(t0
, index
);
7257 } else if (index
== 0) {
7258 gen_load_gpr(t0
, base
);
7260 gen_load_gpr(t0
, index
);
7261 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
7263 /* Don't do NOP if destination is zero: we must perform the actual
7265 save_cpu_state(ctx
, 0);
7270 TCGv_i32 fp0
= tcg_temp_new_i32();
7272 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7273 tcg_gen_trunc_tl_i32(fp0
, t0
);
7274 gen_store_fpr32(fp0
, fd
);
7275 tcg_temp_free_i32(fp0
);
7281 check_cp1_registers(ctx
, fd
);
7283 TCGv_i64 fp0
= tcg_temp_new_i64();
7285 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7286 gen_store_fpr64(ctx
, fp0
, fd
);
7287 tcg_temp_free_i64(fp0
);
7292 check_cp1_64bitmode(ctx
);
7293 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7295 TCGv_i64 fp0
= tcg_temp_new_i64();
7297 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7298 gen_store_fpr64(ctx
, fp0
, fd
);
7299 tcg_temp_free_i64(fp0
);
7306 TCGv_i32 fp0
= tcg_temp_new_i32();
7307 TCGv t1
= tcg_temp_new();
7309 gen_load_fpr32(fp0
, fs
);
7310 tcg_gen_extu_i32_tl(t1
, fp0
);
7311 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7312 tcg_temp_free_i32(fp0
);
7320 check_cp1_registers(ctx
, fs
);
7322 TCGv_i64 fp0
= tcg_temp_new_i64();
7324 gen_load_fpr64(ctx
, fp0
, fs
);
7325 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7326 tcg_temp_free_i64(fp0
);
7332 check_cp1_64bitmode(ctx
);
7333 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7335 TCGv_i64 fp0
= tcg_temp_new_i64();
7337 gen_load_fpr64(ctx
, fp0
, fs
);
7338 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7339 tcg_temp_free_i64(fp0
);
7346 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7347 regnames
[index
], regnames
[base
]);
7350 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7351 int fd
, int fr
, int fs
, int ft
)
7353 const char *opn
= "flt3_arith";
7357 check_cp1_64bitmode(ctx
);
7359 TCGv t0
= tcg_temp_local_new();
7360 TCGv_i32 fp
= tcg_temp_new_i32();
7361 TCGv_i32 fph
= tcg_temp_new_i32();
7362 int l1
= gen_new_label();
7363 int l2
= gen_new_label();
7365 gen_load_gpr(t0
, fr
);
7366 tcg_gen_andi_tl(t0
, t0
, 0x7);
7368 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7369 gen_load_fpr32(fp
, fs
);
7370 gen_load_fpr32h(fph
, fs
);
7371 gen_store_fpr32(fp
, fd
);
7372 gen_store_fpr32h(fph
, fd
);
7375 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7377 #ifdef TARGET_WORDS_BIGENDIAN
7378 gen_load_fpr32(fp
, fs
);
7379 gen_load_fpr32h(fph
, ft
);
7380 gen_store_fpr32h(fp
, fd
);
7381 gen_store_fpr32(fph
, fd
);
7383 gen_load_fpr32h(fph
, fs
);
7384 gen_load_fpr32(fp
, ft
);
7385 gen_store_fpr32(fph
, fd
);
7386 gen_store_fpr32h(fp
, fd
);
7389 tcg_temp_free_i32(fp
);
7390 tcg_temp_free_i32(fph
);
7397 TCGv_i32 fp0
= tcg_temp_new_i32();
7398 TCGv_i32 fp1
= tcg_temp_new_i32();
7399 TCGv_i32 fp2
= tcg_temp_new_i32();
7401 gen_load_fpr32(fp0
, fs
);
7402 gen_load_fpr32(fp1
, ft
);
7403 gen_load_fpr32(fp2
, fr
);
7404 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7405 tcg_temp_free_i32(fp0
);
7406 tcg_temp_free_i32(fp1
);
7407 gen_store_fpr32(fp2
, fd
);
7408 tcg_temp_free_i32(fp2
);
7414 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7416 TCGv_i64 fp0
= tcg_temp_new_i64();
7417 TCGv_i64 fp1
= tcg_temp_new_i64();
7418 TCGv_i64 fp2
= tcg_temp_new_i64();
7420 gen_load_fpr64(ctx
, fp0
, fs
);
7421 gen_load_fpr64(ctx
, fp1
, ft
);
7422 gen_load_fpr64(ctx
, fp2
, fr
);
7423 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7424 tcg_temp_free_i64(fp0
);
7425 tcg_temp_free_i64(fp1
);
7426 gen_store_fpr64(ctx
, fp2
, fd
);
7427 tcg_temp_free_i64(fp2
);
7432 check_cp1_64bitmode(ctx
);
7434 TCGv_i64 fp0
= tcg_temp_new_i64();
7435 TCGv_i64 fp1
= tcg_temp_new_i64();
7436 TCGv_i64 fp2
= tcg_temp_new_i64();
7438 gen_load_fpr64(ctx
, fp0
, fs
);
7439 gen_load_fpr64(ctx
, fp1
, ft
);
7440 gen_load_fpr64(ctx
, fp2
, fr
);
7441 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7442 tcg_temp_free_i64(fp0
);
7443 tcg_temp_free_i64(fp1
);
7444 gen_store_fpr64(ctx
, fp2
, fd
);
7445 tcg_temp_free_i64(fp2
);
7452 TCGv_i32 fp0
= tcg_temp_new_i32();
7453 TCGv_i32 fp1
= tcg_temp_new_i32();
7454 TCGv_i32 fp2
= tcg_temp_new_i32();
7456 gen_load_fpr32(fp0
, fs
);
7457 gen_load_fpr32(fp1
, ft
);
7458 gen_load_fpr32(fp2
, fr
);
7459 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7460 tcg_temp_free_i32(fp0
);
7461 tcg_temp_free_i32(fp1
);
7462 gen_store_fpr32(fp2
, fd
);
7463 tcg_temp_free_i32(fp2
);
7469 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7471 TCGv_i64 fp0
= tcg_temp_new_i64();
7472 TCGv_i64 fp1
= tcg_temp_new_i64();
7473 TCGv_i64 fp2
= tcg_temp_new_i64();
7475 gen_load_fpr64(ctx
, fp0
, fs
);
7476 gen_load_fpr64(ctx
, fp1
, ft
);
7477 gen_load_fpr64(ctx
, fp2
, fr
);
7478 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7479 tcg_temp_free_i64(fp0
);
7480 tcg_temp_free_i64(fp1
);
7481 gen_store_fpr64(ctx
, fp2
, fd
);
7482 tcg_temp_free_i64(fp2
);
7487 check_cp1_64bitmode(ctx
);
7489 TCGv_i64 fp0
= tcg_temp_new_i64();
7490 TCGv_i64 fp1
= tcg_temp_new_i64();
7491 TCGv_i64 fp2
= tcg_temp_new_i64();
7493 gen_load_fpr64(ctx
, fp0
, fs
);
7494 gen_load_fpr64(ctx
, fp1
, ft
);
7495 gen_load_fpr64(ctx
, fp2
, fr
);
7496 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7497 tcg_temp_free_i64(fp0
);
7498 tcg_temp_free_i64(fp1
);
7499 gen_store_fpr64(ctx
, fp2
, fd
);
7500 tcg_temp_free_i64(fp2
);
7507 TCGv_i32 fp0
= tcg_temp_new_i32();
7508 TCGv_i32 fp1
= tcg_temp_new_i32();
7509 TCGv_i32 fp2
= tcg_temp_new_i32();
7511 gen_load_fpr32(fp0
, fs
);
7512 gen_load_fpr32(fp1
, ft
);
7513 gen_load_fpr32(fp2
, fr
);
7514 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7515 tcg_temp_free_i32(fp0
);
7516 tcg_temp_free_i32(fp1
);
7517 gen_store_fpr32(fp2
, fd
);
7518 tcg_temp_free_i32(fp2
);
7524 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7526 TCGv_i64 fp0
= tcg_temp_new_i64();
7527 TCGv_i64 fp1
= tcg_temp_new_i64();
7528 TCGv_i64 fp2
= tcg_temp_new_i64();
7530 gen_load_fpr64(ctx
, fp0
, fs
);
7531 gen_load_fpr64(ctx
, fp1
, ft
);
7532 gen_load_fpr64(ctx
, fp2
, fr
);
7533 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7534 tcg_temp_free_i64(fp0
);
7535 tcg_temp_free_i64(fp1
);
7536 gen_store_fpr64(ctx
, fp2
, fd
);
7537 tcg_temp_free_i64(fp2
);
7542 check_cp1_64bitmode(ctx
);
7544 TCGv_i64 fp0
= tcg_temp_new_i64();
7545 TCGv_i64 fp1
= tcg_temp_new_i64();
7546 TCGv_i64 fp2
= tcg_temp_new_i64();
7548 gen_load_fpr64(ctx
, fp0
, fs
);
7549 gen_load_fpr64(ctx
, fp1
, ft
);
7550 gen_load_fpr64(ctx
, fp2
, fr
);
7551 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7552 tcg_temp_free_i64(fp0
);
7553 tcg_temp_free_i64(fp1
);
7554 gen_store_fpr64(ctx
, fp2
, fd
);
7555 tcg_temp_free_i64(fp2
);
7562 TCGv_i32 fp0
= tcg_temp_new_i32();
7563 TCGv_i32 fp1
= tcg_temp_new_i32();
7564 TCGv_i32 fp2
= tcg_temp_new_i32();
7566 gen_load_fpr32(fp0
, fs
);
7567 gen_load_fpr32(fp1
, ft
);
7568 gen_load_fpr32(fp2
, fr
);
7569 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7570 tcg_temp_free_i32(fp0
);
7571 tcg_temp_free_i32(fp1
);
7572 gen_store_fpr32(fp2
, fd
);
7573 tcg_temp_free_i32(fp2
);
7579 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7581 TCGv_i64 fp0
= tcg_temp_new_i64();
7582 TCGv_i64 fp1
= tcg_temp_new_i64();
7583 TCGv_i64 fp2
= tcg_temp_new_i64();
7585 gen_load_fpr64(ctx
, fp0
, fs
);
7586 gen_load_fpr64(ctx
, fp1
, ft
);
7587 gen_load_fpr64(ctx
, fp2
, fr
);
7588 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7589 tcg_temp_free_i64(fp0
);
7590 tcg_temp_free_i64(fp1
);
7591 gen_store_fpr64(ctx
, fp2
, fd
);
7592 tcg_temp_free_i64(fp2
);
7597 check_cp1_64bitmode(ctx
);
7599 TCGv_i64 fp0
= tcg_temp_new_i64();
7600 TCGv_i64 fp1
= tcg_temp_new_i64();
7601 TCGv_i64 fp2
= tcg_temp_new_i64();
7603 gen_load_fpr64(ctx
, fp0
, fs
);
7604 gen_load_fpr64(ctx
, fp1
, ft
);
7605 gen_load_fpr64(ctx
, fp2
, fr
);
7606 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7607 tcg_temp_free_i64(fp0
);
7608 tcg_temp_free_i64(fp1
);
7609 gen_store_fpr64(ctx
, fp2
, fd
);
7610 tcg_temp_free_i64(fp2
);
7616 generate_exception (ctx
, EXCP_RI
);
7619 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7620 fregnames
[fs
], fregnames
[ft
]);
7623 /* ISA extensions (ASEs) */
7624 /* MIPS16 extension to MIPS32 */
7625 /* SmartMIPS extension to MIPS32 */
7627 #if defined(TARGET_MIPS64)
7629 /* MDMX extension to MIPS64 */
7633 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7637 uint32_t op
, op1
, op2
;
7640 /* make sure instructions are on a word boundary */
7641 if (ctx
->pc
& 0x3) {
7642 env
->CP0_BadVAddr
= ctx
->pc
;
7643 generate_exception(ctx
, EXCP_AdEL
);
7647 /* Handle blikely not taken case */
7648 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7649 int l1
= gen_new_label();
7651 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7652 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7653 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7654 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7657 op
= MASK_OP_MAJOR(ctx
->opcode
);
7658 rs
= (ctx
->opcode
>> 21) & 0x1f;
7659 rt
= (ctx
->opcode
>> 16) & 0x1f;
7660 rd
= (ctx
->opcode
>> 11) & 0x1f;
7661 sa
= (ctx
->opcode
>> 6) & 0x1f;
7662 imm
= (int16_t)ctx
->opcode
;
7665 op1
= MASK_SPECIAL(ctx
->opcode
);
7667 case OPC_SLL
: /* Shift with immediate */
7670 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7672 case OPC_MOVN
: /* Conditional move */
7674 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7675 gen_cond_move(env
, op1
, rd
, rs
, rt
);
7677 case OPC_ADD
... OPC_SUBU
:
7678 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7680 case OPC_SLLV
: /* Shifts */
7683 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7685 case OPC_SLT
: /* Set on less than */
7687 gen_slt(env
, op1
, rd
, rs
, rt
);
7689 case OPC_AND
: /* Logic*/
7693 gen_logic(env
, op1
, rd
, rs
, rt
);
7695 case OPC_MULT
... OPC_DIVU
:
7697 check_insn(env
, ctx
, INSN_VR54XX
);
7698 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7699 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7701 gen_muldiv(ctx
, op1
, rs
, rt
);
7703 case OPC_JR
... OPC_JALR
:
7704 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
7706 case OPC_TGE
... OPC_TEQ
: /* Traps */
7708 gen_trap(ctx
, op1
, rs
, rt
, -1);
7710 case OPC_MFHI
: /* Move from HI/LO */
7712 gen_HILO(ctx
, op1
, rd
);
7715 case OPC_MTLO
: /* Move to HI/LO */
7716 gen_HILO(ctx
, op1
, rs
);
7718 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7719 #ifdef MIPS_STRICT_STANDARD
7720 MIPS_INVAL("PMON / selsl");
7721 generate_exception(ctx
, EXCP_RI
);
7723 gen_helper_0i(pmon
, sa
);
7727 generate_exception(ctx
, EXCP_SYSCALL
);
7728 ctx
->bstate
= BS_STOP
;
7731 generate_exception(ctx
, EXCP_BREAK
);
7734 #ifdef MIPS_STRICT_STANDARD
7736 generate_exception(ctx
, EXCP_RI
);
7738 /* Implemented as RI exception for now. */
7739 MIPS_INVAL("spim (unofficial)");
7740 generate_exception(ctx
, EXCP_RI
);
7748 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7749 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7750 check_cp1_enabled(ctx
);
7751 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7752 (ctx
->opcode
>> 16) & 1);
7754 generate_exception_err(ctx
, EXCP_CpU
, 1);
7758 #if defined(TARGET_MIPS64)
7759 /* MIPS64 specific opcodes */
7766 check_insn(env
, ctx
, ISA_MIPS3
);
7768 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7770 case OPC_DADD
... OPC_DSUBU
:
7771 check_insn(env
, ctx
, ISA_MIPS3
);
7773 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7778 check_insn(env
, ctx
, ISA_MIPS3
);
7780 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7782 case OPC_DMULT
... OPC_DDIVU
:
7783 check_insn(env
, ctx
, ISA_MIPS3
);
7785 gen_muldiv(ctx
, op1
, rs
, rt
);
7788 default: /* Invalid */
7789 MIPS_INVAL("special");
7790 generate_exception(ctx
, EXCP_RI
);
7795 op1
= MASK_SPECIAL2(ctx
->opcode
);
7797 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7798 case OPC_MSUB
... OPC_MSUBU
:
7799 check_insn(env
, ctx
, ISA_MIPS32
);
7800 gen_muldiv(ctx
, op1
, rs
, rt
);
7803 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7807 check_insn(env
, ctx
, ISA_MIPS32
);
7808 gen_cl(ctx
, op1
, rd
, rs
);
7811 /* XXX: not clear which exception should be raised
7812 * when in debug mode...
7814 check_insn(env
, ctx
, ISA_MIPS32
);
7815 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7816 generate_exception(ctx
, EXCP_DBp
);
7818 generate_exception(ctx
, EXCP_DBp
);
7822 #if defined(TARGET_MIPS64)
7825 check_insn(env
, ctx
, ISA_MIPS64
);
7827 gen_cl(ctx
, op1
, rd
, rs
);
7830 default: /* Invalid */
7831 MIPS_INVAL("special2");
7832 generate_exception(ctx
, EXCP_RI
);
7837 op1
= MASK_SPECIAL3(ctx
->opcode
);
7841 check_insn(env
, ctx
, ISA_MIPS32R2
);
7842 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7845 check_insn(env
, ctx
, ISA_MIPS32R2
);
7846 op2
= MASK_BSHFL(ctx
->opcode
);
7847 gen_bshfl(ctx
, op2
, rt
, rd
);
7850 check_insn(env
, ctx
, ISA_MIPS32R2
);
7852 TCGv t0
= tcg_temp_new();
7856 save_cpu_state(ctx
, 1);
7857 gen_helper_rdhwr_cpunum(t0
);
7858 gen_store_gpr(t0
, rt
);
7861 save_cpu_state(ctx
, 1);
7862 gen_helper_rdhwr_synci_step(t0
);
7863 gen_store_gpr(t0
, rt
);
7866 save_cpu_state(ctx
, 1);
7867 gen_helper_rdhwr_cc(t0
);
7868 gen_store_gpr(t0
, rt
);
7871 save_cpu_state(ctx
, 1);
7872 gen_helper_rdhwr_ccres(t0
);
7873 gen_store_gpr(t0
, rt
);
7876 #if defined(CONFIG_USER_ONLY)
7877 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7878 gen_store_gpr(t0
, rt
);
7881 /* XXX: Some CPUs implement this in hardware.
7882 Not supported yet. */
7884 default: /* Invalid */
7885 MIPS_INVAL("rdhwr");
7886 generate_exception(ctx
, EXCP_RI
);
7893 check_insn(env
, ctx
, ASE_MT
);
7895 TCGv t0
= tcg_temp_new();
7896 TCGv t1
= tcg_temp_new();
7898 gen_load_gpr(t0
, rt
);
7899 gen_load_gpr(t1
, rs
);
7900 gen_helper_fork(t0
, t1
);
7906 check_insn(env
, ctx
, ASE_MT
);
7908 TCGv t0
= tcg_temp_new();
7910 save_cpu_state(ctx
, 1);
7911 gen_load_gpr(t0
, rs
);
7912 gen_helper_yield(t0
, t0
);
7913 gen_store_gpr(t0
, rd
);
7917 #if defined(TARGET_MIPS64)
7918 case OPC_DEXTM
... OPC_DEXT
:
7919 case OPC_DINSM
... OPC_DINS
:
7920 check_insn(env
, ctx
, ISA_MIPS64R2
);
7922 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7925 check_insn(env
, ctx
, ISA_MIPS64R2
);
7927 op2
= MASK_DBSHFL(ctx
->opcode
);
7928 gen_bshfl(ctx
, op2
, rt
, rd
);
7931 default: /* Invalid */
7932 MIPS_INVAL("special3");
7933 generate_exception(ctx
, EXCP_RI
);
7938 op1
= MASK_REGIMM(ctx
->opcode
);
7940 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
7941 case OPC_BLTZAL
... OPC_BGEZALL
:
7942 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
7944 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
7946 gen_trap(ctx
, op1
, rs
, -1, imm
);
7949 check_insn(env
, ctx
, ISA_MIPS32R2
);
7952 default: /* Invalid */
7953 MIPS_INVAL("regimm");
7954 generate_exception(ctx
, EXCP_RI
);
7959 check_cp0_enabled(ctx
);
7960 op1
= MASK_CP0(ctx
->opcode
);
7966 #if defined(TARGET_MIPS64)
7970 #ifndef CONFIG_USER_ONLY
7971 gen_cp0(env
, ctx
, op1
, rt
, rd
);
7972 #endif /* !CONFIG_USER_ONLY */
7974 case OPC_C0_FIRST
... OPC_C0_LAST
:
7975 #ifndef CONFIG_USER_ONLY
7976 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
7977 #endif /* !CONFIG_USER_ONLY */
7980 #ifndef CONFIG_USER_ONLY
7982 TCGv t0
= tcg_temp_new();
7984 op2
= MASK_MFMC0(ctx
->opcode
);
7987 check_insn(env
, ctx
, ASE_MT
);
7988 gen_helper_dmt(t0
, t0
);
7989 gen_store_gpr(t0
, rt
);
7992 check_insn(env
, ctx
, ASE_MT
);
7993 gen_helper_emt(t0
, t0
);
7994 gen_store_gpr(t0
, rt
);
7997 check_insn(env
, ctx
, ASE_MT
);
7998 gen_helper_dvpe(t0
, t0
);
7999 gen_store_gpr(t0
, rt
);
8002 check_insn(env
, ctx
, ASE_MT
);
8003 gen_helper_evpe(t0
, t0
);
8004 gen_store_gpr(t0
, rt
);
8007 check_insn(env
, ctx
, ISA_MIPS32R2
);
8008 save_cpu_state(ctx
, 1);
8010 gen_store_gpr(t0
, rt
);
8011 /* Stop translation as we may have switched the execution mode */
8012 ctx
->bstate
= BS_STOP
;
8015 check_insn(env
, ctx
, ISA_MIPS32R2
);
8016 save_cpu_state(ctx
, 1);
8018 gen_store_gpr(t0
, rt
);
8019 /* Stop translation as we may have switched the execution mode */
8020 ctx
->bstate
= BS_STOP
;
8022 default: /* Invalid */
8023 MIPS_INVAL("mfmc0");
8024 generate_exception(ctx
, EXCP_RI
);
8029 #endif /* !CONFIG_USER_ONLY */
8032 check_insn(env
, ctx
, ISA_MIPS32R2
);
8033 gen_load_srsgpr(rt
, rd
);
8036 check_insn(env
, ctx
, ISA_MIPS32R2
);
8037 gen_store_srsgpr(rt
, rd
);
8041 generate_exception(ctx
, EXCP_RI
);
8045 case OPC_ADDI
: /* Arithmetic with immediate opcode */
8047 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8049 case OPC_SLTI
: /* Set on less than with immediate opcode */
8051 gen_slt_imm(env
, op
, rt
, rs
, imm
);
8053 case OPC_ANDI
: /* Arithmetic with immediate opcode */
8057 gen_logic_imm(env
, op
, rt
, rs
, imm
);
8059 case OPC_J
... OPC_JAL
: /* Jump */
8060 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
8061 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
8063 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
8064 case OPC_BEQL
... OPC_BGTZL
:
8065 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
8067 case OPC_LB
... OPC_LWR
: /* Load and stores */
8068 case OPC_SB
... OPC_SW
:
8071 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8074 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
8077 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
8081 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8085 /* Floating point (COP1). */
8090 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8091 check_cp1_enabled(ctx
);
8092 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
8094 generate_exception_err(ctx
, EXCP_CpU
, 1);
8099 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8100 check_cp1_enabled(ctx
);
8101 op1
= MASK_CP1(ctx
->opcode
);
8105 check_insn(env
, ctx
, ISA_MIPS32R2
);
8110 gen_cp1(ctx
, op1
, rt
, rd
);
8112 #if defined(TARGET_MIPS64)
8115 check_insn(env
, ctx
, ISA_MIPS3
);
8116 gen_cp1(ctx
, op1
, rt
, rd
);
8122 check_insn(env
, ctx
, ASE_MIPS3D
);
8125 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
8126 (rt
>> 2) & 0x7, imm
<< 2);
8133 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
8138 generate_exception (ctx
, EXCP_RI
);
8142 generate_exception_err(ctx
, EXCP_CpU
, 1);
8152 /* COP2: Not implemented. */
8153 generate_exception_err(ctx
, EXCP_CpU
, 2);
8157 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8158 check_cp1_enabled(ctx
);
8159 op1
= MASK_CP3(ctx
->opcode
);
8167 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
8185 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
8189 generate_exception (ctx
, EXCP_RI
);
8193 generate_exception_err(ctx
, EXCP_CpU
, 1);
8197 #if defined(TARGET_MIPS64)
8198 /* MIPS64 opcodes */
8200 case OPC_LDL
... OPC_LDR
:
8201 case OPC_SDL
... OPC_SDR
:
8205 check_insn(env
, ctx
, ISA_MIPS3
);
8207 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8210 check_insn(env
, ctx
, ISA_MIPS3
);
8212 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
8216 check_insn(env
, ctx
, ISA_MIPS3
);
8218 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8222 check_insn(env
, ctx
, ASE_MIPS16
);
8223 /* MIPS16: Not implemented. */
8225 check_insn(env
, ctx
, ASE_MDMX
);
8226 /* MDMX: Not implemented. */
8227 default: /* Invalid */
8228 MIPS_INVAL("major opcode");
8229 generate_exception(ctx
, EXCP_RI
);
8232 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8233 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8234 /* Branches completion */
8235 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8236 ctx
->bstate
= BS_BRANCH
;
8237 save_cpu_state(ctx
, 0);
8238 /* FIXME: Need to clear can_do_io. */
8241 /* unconditional branch */
8242 MIPS_DEBUG("unconditional branch");
8243 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8246 /* blikely taken case */
8247 MIPS_DEBUG("blikely branch taken");
8248 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8251 /* Conditional branch */
8252 MIPS_DEBUG("conditional branch");
8254 int l1
= gen_new_label();
8256 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8257 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8259 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8263 /* unconditional branch to register */
8264 MIPS_DEBUG("branch to register");
8265 tcg_gen_mov_tl(cpu_PC
, btarget
);
8269 MIPS_DEBUG("unknown branch");
8276 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
8280 target_ulong pc_start
;
8281 uint16_t *gen_opc_end
;
8288 qemu_log("search pc %d\n", search_pc
);
8291 /* Leave some spare opc slots for branch handling. */
8292 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
- 16;
8296 ctx
.bstate
= BS_NONE
;
8297 /* Restore delay slot state from the tb context. */
8298 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
8299 restore_cpu_state(env
, &ctx
);
8300 #ifdef CONFIG_USER_ONLY
8301 ctx
.mem_idx
= MIPS_HFLAG_UM
;
8303 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
8306 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8308 max_insns
= CF_COUNT_MASK
;
8310 qemu_log_mask(CPU_LOG_TB_CPU
, "------------------------------------------------\n");
8311 /* FIXME: This may print out stale hflags from env... */
8312 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
8314 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
8316 while (ctx
.bstate
== BS_NONE
) {
8317 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
8318 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
8319 if (bp
->pc
== ctx
.pc
) {
8320 save_cpu_state(&ctx
, 1);
8321 ctx
.bstate
= BS_BRANCH
;
8322 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8323 /* Include the breakpoint location or the tb won't
8324 * be flushed when it must be. */
8326 goto done_generating
;
8332 j
= gen_opc_ptr
- gen_opc_buf
;
8336 gen_opc_instr_start
[lj
++] = 0;
8338 gen_opc_pc
[lj
] = ctx
.pc
;
8339 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
8340 gen_opc_instr_start
[lj
] = 1;
8341 gen_opc_icount
[lj
] = num_insns
;
8343 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8345 ctx
.opcode
= ldl_code(ctx
.pc
);
8346 decode_opc(env
, &ctx
);
8350 if (env
->singlestep_enabled
)
8353 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
8356 if (gen_opc_ptr
>= gen_opc_end
)
8359 if (num_insns
>= max_insns
)
8365 if (tb
->cflags
& CF_LAST_IO
)
8367 if (env
->singlestep_enabled
) {
8368 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
8369 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8371 switch (ctx
.bstate
) {
8373 gen_helper_interrupt_restart();
8374 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8377 save_cpu_state(&ctx
, 0);
8378 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8381 gen_helper_interrupt_restart();
8390 gen_icount_end(tb
, num_insns
);
8391 *gen_opc_ptr
= INDEX_op_end
;
8393 j
= gen_opc_ptr
- gen_opc_buf
;
8396 gen_opc_instr_start
[lj
++] = 0;
8398 tb
->size
= ctx
.pc
- pc_start
;
8399 tb
->icount
= num_insns
;
8403 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
8404 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
8405 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
8408 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
8412 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
8414 gen_intermediate_code_internal(env
, tb
, 0);
8417 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
8419 gen_intermediate_code_internal(env
, tb
, 1);
8422 static void fpu_dump_state(CPUState
*env
, FILE *f
,
8423 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8427 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
8429 #define printfpr(fp) \
8432 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8433 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8434 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8437 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8438 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8439 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8440 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8441 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8446 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8447 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
8448 get_float_exception_flags(&env
->active_fpu
.fp_status
));
8449 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
8450 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
8451 printfpr(&env
->active_fpu
.fpr
[i
]);
8457 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8458 /* Debug help: The architecture requires 32bit code to maintain proper
8459 sign-extended values on 64bit machines. */
8461 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8464 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
8465 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8470 if (!SIGN_EXT_P(env
->active_tc
.PC
))
8471 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
8472 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
8473 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
8474 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
8475 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
8476 if (!SIGN_EXT_P(env
->btarget
))
8477 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
8479 for (i
= 0; i
< 32; i
++) {
8480 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
8481 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
8484 if (!SIGN_EXT_P(env
->CP0_EPC
))
8485 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
8486 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
8487 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
8491 void cpu_dump_state (CPUState
*env
, FILE *f
,
8492 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8497 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",
8498 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
8499 env
->hflags
, env
->btarget
, env
->bcond
);
8500 for (i
= 0; i
< 32; i
++) {
8502 cpu_fprintf(f
, "GPR%02d:", i
);
8503 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
8505 cpu_fprintf(f
, "\n");
8508 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
8509 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
8510 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
8511 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
8512 if (env
->hflags
& MIPS_HFLAG_FPU
)
8513 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
8514 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8515 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
8519 static void mips_tcg_init(void)
8524 /* Initialize various static tables. */
8528 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
8529 TCGV_UNUSED(cpu_gpr
[0]);
8530 for (i
= 1; i
< 32; i
++)
8531 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
8532 offsetof(CPUState
, active_tc
.gpr
[i
]),
8534 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
8535 offsetof(CPUState
, active_tc
.PC
), "PC");
8536 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
8537 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
8538 offsetof(CPUState
, active_tc
.HI
[i
]),
8540 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
8541 offsetof(CPUState
, active_tc
.LO
[i
]),
8543 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
8544 offsetof(CPUState
, active_tc
.ACX
[i
]),
8547 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
8548 offsetof(CPUState
, active_tc
.DSPControl
),
8550 bcond
= tcg_global_mem_new(TCG_AREG0
,
8551 offsetof(CPUState
, bcond
), "bcond");
8552 btarget
= tcg_global_mem_new(TCG_AREG0
,
8553 offsetof(CPUState
, btarget
), "btarget");
8554 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
8555 offsetof(CPUState
, hflags
), "hflags");
8557 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
8558 offsetof(CPUState
, active_fpu
.fcr0
),
8560 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
8561 offsetof(CPUState
, active_fpu
.fcr31
),
8564 /* register helpers */
8565 #define GEN_HELPER 2
8571 #include "translate_init.c"
8573 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
8576 const mips_def_t
*def
;
8578 def
= cpu_mips_find_by_name(cpu_model
);
8581 env
= qemu_mallocz(sizeof(CPUMIPSState
));
8582 env
->cpu_model
= def
;
8585 env
->cpu_model_str
= cpu_model
;
8588 qemu_init_vcpu(env
);
8592 void cpu_reset (CPUMIPSState
*env
)
8594 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
8595 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
8596 log_cpu_state(env
, 0);
8599 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
8604 #if defined(CONFIG_USER_ONLY)
8605 env
->hflags
= MIPS_HFLAG_UM
;
8606 /* Enable access to the SYNCI_Step register. */
8607 env
->CP0_HWREna
|= (1 << 1);
8609 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
8610 /* If the exception was raised from a delay slot,
8611 come back to the jump. */
8612 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
8614 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
8616 env
->active_tc
.PC
= (int32_t)0xBFC00000;
8618 /* SMP not implemented */
8619 env
->CP0_EBase
= 0x80000000;
8620 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8621 /* vectored interrupts not implemented, timer on int 7,
8622 no performance counters. */
8623 env
->CP0_IntCtl
= 0xe0000000;
8627 for (i
= 0; i
< 7; i
++) {
8628 env
->CP0_WatchLo
[i
] = 0;
8629 env
->CP0_WatchHi
[i
] = 0x80000000;
8631 env
->CP0_WatchLo
[7] = 0;
8632 env
->CP0_WatchHi
[7] = 0;
8634 /* Count register increments in debug mode, EJTAG version 1 */
8635 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8636 env
->hflags
= MIPS_HFLAG_CP0
;
8638 env
->exception_index
= EXCP_NONE
;
8639 cpu_mips_register(env
, env
->cpu_model
);
8642 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8643 unsigned long searched_pc
, int pc_pos
, void *puc
)
8645 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
8646 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8647 env
->hflags
|= gen_opc_hflags
[pc_pos
];