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)
7 * Copyright (c) 2009 CodeSourcery (MIPS16 and microMIPS support)
8 * Copyright (c) 2012 Jia Liu & Dongxue Zhang (MIPS ASE DSP support)
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 #include "disas/disas.h"
27 #include "exec/cpu_ldst.h"
29 #include "exec/helper-proto.h"
30 #include "exec/helper-gen.h"
31 #include "sysemu/kvm.h"
32 #include "exec/semihost.h"
34 #include "trace-tcg.h"
37 #define MIPS_DEBUG_DISAS 0
38 //#define MIPS_DEBUG_SIGN_EXTENSIONS
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL
= (0x00 << 26),
46 OPC_REGIMM
= (0x01 << 26),
47 OPC_CP0
= (0x10 << 26),
48 OPC_CP1
= (0x11 << 26),
49 OPC_CP2
= (0x12 << 26),
50 OPC_CP3
= (0x13 << 26),
51 OPC_SPECIAL2
= (0x1C << 26),
52 OPC_SPECIAL3
= (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI
= (0x08 << 26),
55 OPC_ADDIU
= (0x09 << 26),
56 OPC_SLTI
= (0x0A << 26),
57 OPC_SLTIU
= (0x0B << 26),
58 /* logic with immediate */
59 OPC_ANDI
= (0x0C << 26),
60 OPC_ORI
= (0x0D << 26),
61 OPC_XORI
= (0x0E << 26),
62 OPC_LUI
= (0x0F << 26),
63 /* arithmetic with immediate */
64 OPC_DADDI
= (0x18 << 26),
65 OPC_DADDIU
= (0x19 << 26),
66 /* Jump and branches */
68 OPC_JAL
= (0x03 << 26),
69 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
70 OPC_BEQL
= (0x14 << 26),
71 OPC_BNE
= (0x05 << 26),
72 OPC_BNEL
= (0x15 << 26),
73 OPC_BLEZ
= (0x06 << 26),
74 OPC_BLEZL
= (0x16 << 26),
75 OPC_BGTZ
= (0x07 << 26),
76 OPC_BGTZL
= (0x17 << 26),
77 OPC_JALX
= (0x1D << 26),
78 OPC_DAUI
= (0x1D << 26),
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_LWPC
= OPC_LW
| 0x5,
87 OPC_LBU
= (0x24 << 26),
88 OPC_LHU
= (0x25 << 26),
89 OPC_LWR
= (0x26 << 26),
90 OPC_LWU
= (0x27 << 26),
91 OPC_SB
= (0x28 << 26),
92 OPC_SH
= (0x29 << 26),
93 OPC_SWL
= (0x2A << 26),
94 OPC_SW
= (0x2B << 26),
95 OPC_SDL
= (0x2C << 26),
96 OPC_SDR
= (0x2D << 26),
97 OPC_SWR
= (0x2E << 26),
98 OPC_LL
= (0x30 << 26),
99 OPC_LLD
= (0x34 << 26),
100 OPC_LD
= (0x37 << 26),
101 OPC_LDPC
= OPC_LD
| 0x5,
102 OPC_SC
= (0x38 << 26),
103 OPC_SCD
= (0x3C << 26),
104 OPC_SD
= (0x3F << 26),
105 /* Floating point load/store */
106 OPC_LWC1
= (0x31 << 26),
107 OPC_LWC2
= (0x32 << 26),
108 OPC_LDC1
= (0x35 << 26),
109 OPC_LDC2
= (0x36 << 26),
110 OPC_SWC1
= (0x39 << 26),
111 OPC_SWC2
= (0x3A << 26),
112 OPC_SDC1
= (0x3D << 26),
113 OPC_SDC2
= (0x3E << 26),
114 /* Compact Branches */
115 OPC_BLEZALC
= (0x06 << 26),
116 OPC_BGEZALC
= (0x06 << 26),
117 OPC_BGEUC
= (0x06 << 26),
118 OPC_BGTZALC
= (0x07 << 26),
119 OPC_BLTZALC
= (0x07 << 26),
120 OPC_BLTUC
= (0x07 << 26),
121 OPC_BOVC
= (0x08 << 26),
122 OPC_BEQZALC
= (0x08 << 26),
123 OPC_BEQC
= (0x08 << 26),
124 OPC_BLEZC
= (0x16 << 26),
125 OPC_BGEZC
= (0x16 << 26),
126 OPC_BGEC
= (0x16 << 26),
127 OPC_BGTZC
= (0x17 << 26),
128 OPC_BLTZC
= (0x17 << 26),
129 OPC_BLTC
= (0x17 << 26),
130 OPC_BNVC
= (0x18 << 26),
131 OPC_BNEZALC
= (0x18 << 26),
132 OPC_BNEC
= (0x18 << 26),
133 OPC_BC
= (0x32 << 26),
134 OPC_BEQZC
= (0x36 << 26),
135 OPC_JIC
= (0x36 << 26),
136 OPC_BALC
= (0x3A << 26),
137 OPC_BNEZC
= (0x3E << 26),
138 OPC_JIALC
= (0x3E << 26),
139 /* MDMX ASE specific */
140 OPC_MDMX
= (0x1E << 26),
141 /* MSA ASE, same as MDMX */
143 /* Cache and prefetch */
144 OPC_CACHE
= (0x2F << 26),
145 OPC_PREF
= (0x33 << 26),
146 /* PC-relative address computation / loads */
147 OPC_PCREL
= (0x3B << 26),
150 /* PC-relative address computation / loads */
151 #define MASK_OPC_PCREL_TOP2BITS(op) (MASK_OP_MAJOR(op) | (op & (3 << 19)))
152 #define MASK_OPC_PCREL_TOP5BITS(op) (MASK_OP_MAJOR(op) | (op & (0x1f << 16)))
154 /* Instructions determined by bits 19 and 20 */
155 OPC_ADDIUPC
= OPC_PCREL
| (0 << 19),
156 R6_OPC_LWPC
= OPC_PCREL
| (1 << 19),
157 OPC_LWUPC
= OPC_PCREL
| (2 << 19),
159 /* Instructions determined by bits 16 ... 20 */
160 OPC_AUIPC
= OPC_PCREL
| (0x1e << 16),
161 OPC_ALUIPC
= OPC_PCREL
| (0x1f << 16),
164 R6_OPC_LDPC
= OPC_PCREL
| (6 << 18),
167 /* MIPS special opcodes */
168 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
172 OPC_SLL
= 0x00 | OPC_SPECIAL
,
173 /* NOP is SLL r0, r0, 0 */
174 /* SSNOP is SLL r0, r0, 1 */
175 /* EHB is SLL r0, r0, 3 */
176 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
177 OPC_ROTR
= OPC_SRL
| (1 << 21),
178 OPC_SRA
= 0x03 | OPC_SPECIAL
,
179 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
180 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
181 OPC_ROTRV
= OPC_SRLV
| (1 << 6),
182 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
183 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
184 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
185 OPC_DROTRV
= OPC_DSRLV
| (1 << 6),
186 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
187 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
188 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
189 OPC_DROTR
= OPC_DSRL
| (1 << 21),
190 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
191 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
192 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
193 OPC_DROTR32
= OPC_DSRL32
| (1 << 21),
194 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
195 /* Multiplication / division */
196 OPC_MULT
= 0x18 | OPC_SPECIAL
,
197 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
198 OPC_DIV
= 0x1A | OPC_SPECIAL
,
199 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
200 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
201 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
202 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
203 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
205 /* 2 registers arithmetic / logic */
206 OPC_ADD
= 0x20 | OPC_SPECIAL
,
207 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
208 OPC_SUB
= 0x22 | OPC_SPECIAL
,
209 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
210 OPC_AND
= 0x24 | OPC_SPECIAL
,
211 OPC_OR
= 0x25 | OPC_SPECIAL
,
212 OPC_XOR
= 0x26 | OPC_SPECIAL
,
213 OPC_NOR
= 0x27 | OPC_SPECIAL
,
214 OPC_SLT
= 0x2A | OPC_SPECIAL
,
215 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
216 OPC_DADD
= 0x2C | OPC_SPECIAL
,
217 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
218 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
219 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
221 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
222 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
224 OPC_TGE
= 0x30 | OPC_SPECIAL
,
225 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
226 OPC_TLT
= 0x32 | OPC_SPECIAL
,
227 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
228 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
229 OPC_TNE
= 0x36 | OPC_SPECIAL
,
230 /* HI / LO registers load & stores */
231 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
232 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
233 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
234 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
235 /* Conditional moves */
236 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
237 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
239 OPC_SELEQZ
= 0x35 | OPC_SPECIAL
,
240 OPC_SELNEZ
= 0x37 | OPC_SPECIAL
,
242 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
245 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* unofficial */
246 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
247 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
248 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
249 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
251 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
252 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
253 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
254 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
257 /* R6 Multiply and Divide instructions have the same Opcode
258 and function field as legacy OPC_MULT[U]/OPC_DIV[U] */
259 #define MASK_R6_MULDIV(op) (MASK_SPECIAL(op) | (op & (0x7ff)))
262 R6_OPC_MUL
= OPC_MULT
| (2 << 6),
263 R6_OPC_MUH
= OPC_MULT
| (3 << 6),
264 R6_OPC_MULU
= OPC_MULTU
| (2 << 6),
265 R6_OPC_MUHU
= OPC_MULTU
| (3 << 6),
266 R6_OPC_DIV
= OPC_DIV
| (2 << 6),
267 R6_OPC_MOD
= OPC_DIV
| (3 << 6),
268 R6_OPC_DIVU
= OPC_DIVU
| (2 << 6),
269 R6_OPC_MODU
= OPC_DIVU
| (3 << 6),
271 R6_OPC_DMUL
= OPC_DMULT
| (2 << 6),
272 R6_OPC_DMUH
= OPC_DMULT
| (3 << 6),
273 R6_OPC_DMULU
= OPC_DMULTU
| (2 << 6),
274 R6_OPC_DMUHU
= OPC_DMULTU
| (3 << 6),
275 R6_OPC_DDIV
= OPC_DDIV
| (2 << 6),
276 R6_OPC_DMOD
= OPC_DDIV
| (3 << 6),
277 R6_OPC_DDIVU
= OPC_DDIVU
| (2 << 6),
278 R6_OPC_DMODU
= OPC_DDIVU
| (3 << 6),
280 R6_OPC_CLZ
= 0x10 | OPC_SPECIAL
,
281 R6_OPC_CLO
= 0x11 | OPC_SPECIAL
,
282 R6_OPC_DCLZ
= 0x12 | OPC_SPECIAL
,
283 R6_OPC_DCLO
= 0x13 | OPC_SPECIAL
,
284 R6_OPC_SDBBP
= 0x0e | OPC_SPECIAL
,
286 OPC_LSA
= 0x05 | OPC_SPECIAL
,
287 OPC_DLSA
= 0x15 | OPC_SPECIAL
,
290 /* Multiplication variants of the vr54xx. */
291 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
294 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
295 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
296 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
297 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
298 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
299 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
300 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
301 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
302 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
303 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
304 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
305 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
306 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
307 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
310 /* REGIMM (rt field) opcodes */
311 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
314 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
315 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
316 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
317 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
318 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
319 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
320 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
321 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
322 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
323 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
324 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
325 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
326 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
327 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
328 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
330 OPC_DAHI
= (0x06 << 16) | OPC_REGIMM
,
331 OPC_DATI
= (0x1e << 16) | OPC_REGIMM
,
334 /* Special2 opcodes */
335 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
338 /* Multiply & xxx operations */
339 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
340 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
341 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
342 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
343 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
345 OPC_MULT_G_2F
= 0x10 | OPC_SPECIAL2
,
346 OPC_DMULT_G_2F
= 0x11 | OPC_SPECIAL2
,
347 OPC_MULTU_G_2F
= 0x12 | OPC_SPECIAL2
,
348 OPC_DMULTU_G_2F
= 0x13 | OPC_SPECIAL2
,
349 OPC_DIV_G_2F
= 0x14 | OPC_SPECIAL2
,
350 OPC_DDIV_G_2F
= 0x15 | OPC_SPECIAL2
,
351 OPC_DIVU_G_2F
= 0x16 | OPC_SPECIAL2
,
352 OPC_DDIVU_G_2F
= 0x17 | OPC_SPECIAL2
,
353 OPC_MOD_G_2F
= 0x1c | OPC_SPECIAL2
,
354 OPC_DMOD_G_2F
= 0x1d | OPC_SPECIAL2
,
355 OPC_MODU_G_2F
= 0x1e | OPC_SPECIAL2
,
356 OPC_DMODU_G_2F
= 0x1f | OPC_SPECIAL2
,
358 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
359 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
360 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
361 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
363 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
366 /* Special3 opcodes */
367 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
370 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
371 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
372 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
373 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
374 OPC_INS
= 0x04 | OPC_SPECIAL3
,
375 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
376 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
377 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
378 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
379 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
380 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
381 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
382 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
385 OPC_MULT_G_2E
= 0x18 | OPC_SPECIAL3
,
386 OPC_MULTU_G_2E
= 0x19 | OPC_SPECIAL3
,
387 OPC_DIV_G_2E
= 0x1A | OPC_SPECIAL3
,
388 OPC_DIVU_G_2E
= 0x1B | OPC_SPECIAL3
,
389 OPC_DMULT_G_2E
= 0x1C | OPC_SPECIAL3
,
390 OPC_DMULTU_G_2E
= 0x1D | OPC_SPECIAL3
,
391 OPC_DDIV_G_2E
= 0x1E | OPC_SPECIAL3
,
392 OPC_DDIVU_G_2E
= 0x1F | OPC_SPECIAL3
,
393 OPC_MOD_G_2E
= 0x22 | OPC_SPECIAL3
,
394 OPC_MODU_G_2E
= 0x23 | OPC_SPECIAL3
,
395 OPC_DMOD_G_2E
= 0x26 | OPC_SPECIAL3
,
396 OPC_DMODU_G_2E
= 0x27 | OPC_SPECIAL3
,
399 OPC_LX_DSP
= 0x0A | OPC_SPECIAL3
,
400 /* MIPS DSP Arithmetic */
401 OPC_ADDU_QB_DSP
= 0x10 | OPC_SPECIAL3
,
402 OPC_ADDU_OB_DSP
= 0x14 | OPC_SPECIAL3
,
403 OPC_ABSQ_S_PH_DSP
= 0x12 | OPC_SPECIAL3
,
404 OPC_ABSQ_S_QH_DSP
= 0x16 | OPC_SPECIAL3
,
405 /* OPC_ADDUH_QB_DSP is same as OPC_MULT_G_2E. */
406 /* OPC_ADDUH_QB_DSP = 0x18 | OPC_SPECIAL3, */
407 OPC_CMPU_EQ_QB_DSP
= 0x11 | OPC_SPECIAL3
,
408 OPC_CMPU_EQ_OB_DSP
= 0x15 | OPC_SPECIAL3
,
409 /* MIPS DSP GPR-Based Shift Sub-class */
410 OPC_SHLL_QB_DSP
= 0x13 | OPC_SPECIAL3
,
411 OPC_SHLL_OB_DSP
= 0x17 | OPC_SPECIAL3
,
412 /* MIPS DSP Multiply Sub-class insns */
413 /* OPC_MUL_PH_DSP is same as OPC_ADDUH_QB_DSP. */
414 /* OPC_MUL_PH_DSP = 0x18 | OPC_SPECIAL3, */
415 OPC_DPA_W_PH_DSP
= 0x30 | OPC_SPECIAL3
,
416 OPC_DPAQ_W_QH_DSP
= 0x34 | OPC_SPECIAL3
,
417 /* DSP Bit/Manipulation Sub-class */
418 OPC_INSV_DSP
= 0x0C | OPC_SPECIAL3
,
419 OPC_DINSV_DSP
= 0x0D | OPC_SPECIAL3
,
420 /* MIPS DSP Append Sub-class */
421 OPC_APPEND_DSP
= 0x31 | OPC_SPECIAL3
,
422 OPC_DAPPEND_DSP
= 0x35 | OPC_SPECIAL3
,
423 /* MIPS DSP Accumulator and DSPControl Access Sub-class */
424 OPC_EXTR_W_DSP
= 0x38 | OPC_SPECIAL3
,
425 OPC_DEXTR_W_DSP
= 0x3C | OPC_SPECIAL3
,
428 R6_OPC_PREF
= 0x35 | OPC_SPECIAL3
,
429 R6_OPC_CACHE
= 0x25 | OPC_SPECIAL3
,
430 R6_OPC_LL
= 0x36 | OPC_SPECIAL3
,
431 R6_OPC_SC
= 0x26 | OPC_SPECIAL3
,
432 R6_OPC_LLD
= 0x37 | OPC_SPECIAL3
,
433 R6_OPC_SCD
= 0x27 | OPC_SPECIAL3
,
437 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
440 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
441 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
442 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
443 OPC_ALIGN
= (0x08 << 6) | OPC_BSHFL
, /* 010.bp */
444 OPC_ALIGN_END
= (0x0B << 6) | OPC_BSHFL
, /* 010.00 to 010.11 */
445 OPC_BITSWAP
= (0x00 << 6) | OPC_BSHFL
/* 00000 */
449 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
452 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
453 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
454 OPC_DALIGN
= (0x08 << 6) | OPC_DBSHFL
, /* 01.bp */
455 OPC_DALIGN_END
= (0x0F << 6) | OPC_DBSHFL
, /* 01.000 to 01.111 */
456 OPC_DBITSWAP
= (0x00 << 6) | OPC_DBSHFL
, /* 00000 */
459 /* MIPS DSP REGIMM opcodes */
461 OPC_BPOSGE32
= (0x1C << 16) | OPC_REGIMM
,
462 OPC_BPOSGE64
= (0x1D << 16) | OPC_REGIMM
,
465 #define MASK_LX(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
468 OPC_LBUX
= (0x06 << 6) | OPC_LX_DSP
,
469 OPC_LHX
= (0x04 << 6) | OPC_LX_DSP
,
470 OPC_LWX
= (0x00 << 6) | OPC_LX_DSP
,
471 OPC_LDX
= (0x08 << 6) | OPC_LX_DSP
,
474 #define MASK_ADDU_QB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
476 /* MIPS DSP Arithmetic Sub-class */
477 OPC_ADDQ_PH
= (0x0A << 6) | OPC_ADDU_QB_DSP
,
478 OPC_ADDQ_S_PH
= (0x0E << 6) | OPC_ADDU_QB_DSP
,
479 OPC_ADDQ_S_W
= (0x16 << 6) | OPC_ADDU_QB_DSP
,
480 OPC_ADDU_QB
= (0x00 << 6) | OPC_ADDU_QB_DSP
,
481 OPC_ADDU_S_QB
= (0x04 << 6) | OPC_ADDU_QB_DSP
,
482 OPC_ADDU_PH
= (0x08 << 6) | OPC_ADDU_QB_DSP
,
483 OPC_ADDU_S_PH
= (0x0C << 6) | OPC_ADDU_QB_DSP
,
484 OPC_SUBQ_PH
= (0x0B << 6) | OPC_ADDU_QB_DSP
,
485 OPC_SUBQ_S_PH
= (0x0F << 6) | OPC_ADDU_QB_DSP
,
486 OPC_SUBQ_S_W
= (0x17 << 6) | OPC_ADDU_QB_DSP
,
487 OPC_SUBU_QB
= (0x01 << 6) | OPC_ADDU_QB_DSP
,
488 OPC_SUBU_S_QB
= (0x05 << 6) | OPC_ADDU_QB_DSP
,
489 OPC_SUBU_PH
= (0x09 << 6) | OPC_ADDU_QB_DSP
,
490 OPC_SUBU_S_PH
= (0x0D << 6) | OPC_ADDU_QB_DSP
,
491 OPC_ADDSC
= (0x10 << 6) | OPC_ADDU_QB_DSP
,
492 OPC_ADDWC
= (0x11 << 6) | OPC_ADDU_QB_DSP
,
493 OPC_MODSUB
= (0x12 << 6) | OPC_ADDU_QB_DSP
,
494 OPC_RADDU_W_QB
= (0x14 << 6) | OPC_ADDU_QB_DSP
,
495 /* MIPS DSP Multiply Sub-class insns */
496 OPC_MULEU_S_PH_QBL
= (0x06 << 6) | OPC_ADDU_QB_DSP
,
497 OPC_MULEU_S_PH_QBR
= (0x07 << 6) | OPC_ADDU_QB_DSP
,
498 OPC_MULQ_RS_PH
= (0x1F << 6) | OPC_ADDU_QB_DSP
,
499 OPC_MULEQ_S_W_PHL
= (0x1C << 6) | OPC_ADDU_QB_DSP
,
500 OPC_MULEQ_S_W_PHR
= (0x1D << 6) | OPC_ADDU_QB_DSP
,
501 OPC_MULQ_S_PH
= (0x1E << 6) | OPC_ADDU_QB_DSP
,
504 #define OPC_ADDUH_QB_DSP OPC_MULT_G_2E
505 #define MASK_ADDUH_QB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
507 /* MIPS DSP Arithmetic Sub-class */
508 OPC_ADDUH_QB
= (0x00 << 6) | OPC_ADDUH_QB_DSP
,
509 OPC_ADDUH_R_QB
= (0x02 << 6) | OPC_ADDUH_QB_DSP
,
510 OPC_ADDQH_PH
= (0x08 << 6) | OPC_ADDUH_QB_DSP
,
511 OPC_ADDQH_R_PH
= (0x0A << 6) | OPC_ADDUH_QB_DSP
,
512 OPC_ADDQH_W
= (0x10 << 6) | OPC_ADDUH_QB_DSP
,
513 OPC_ADDQH_R_W
= (0x12 << 6) | OPC_ADDUH_QB_DSP
,
514 OPC_SUBUH_QB
= (0x01 << 6) | OPC_ADDUH_QB_DSP
,
515 OPC_SUBUH_R_QB
= (0x03 << 6) | OPC_ADDUH_QB_DSP
,
516 OPC_SUBQH_PH
= (0x09 << 6) | OPC_ADDUH_QB_DSP
,
517 OPC_SUBQH_R_PH
= (0x0B << 6) | OPC_ADDUH_QB_DSP
,
518 OPC_SUBQH_W
= (0x11 << 6) | OPC_ADDUH_QB_DSP
,
519 OPC_SUBQH_R_W
= (0x13 << 6) | OPC_ADDUH_QB_DSP
,
520 /* MIPS DSP Multiply Sub-class insns */
521 OPC_MUL_PH
= (0x0C << 6) | OPC_ADDUH_QB_DSP
,
522 OPC_MUL_S_PH
= (0x0E << 6) | OPC_ADDUH_QB_DSP
,
523 OPC_MULQ_S_W
= (0x16 << 6) | OPC_ADDUH_QB_DSP
,
524 OPC_MULQ_RS_W
= (0x17 << 6) | OPC_ADDUH_QB_DSP
,
527 #define MASK_ABSQ_S_PH(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
529 /* MIPS DSP Arithmetic Sub-class */
530 OPC_ABSQ_S_QB
= (0x01 << 6) | OPC_ABSQ_S_PH_DSP
,
531 OPC_ABSQ_S_PH
= (0x09 << 6) | OPC_ABSQ_S_PH_DSP
,
532 OPC_ABSQ_S_W
= (0x11 << 6) | OPC_ABSQ_S_PH_DSP
,
533 OPC_PRECEQ_W_PHL
= (0x0C << 6) | OPC_ABSQ_S_PH_DSP
,
534 OPC_PRECEQ_W_PHR
= (0x0D << 6) | OPC_ABSQ_S_PH_DSP
,
535 OPC_PRECEQU_PH_QBL
= (0x04 << 6) | OPC_ABSQ_S_PH_DSP
,
536 OPC_PRECEQU_PH_QBR
= (0x05 << 6) | OPC_ABSQ_S_PH_DSP
,
537 OPC_PRECEQU_PH_QBLA
= (0x06 << 6) | OPC_ABSQ_S_PH_DSP
,
538 OPC_PRECEQU_PH_QBRA
= (0x07 << 6) | OPC_ABSQ_S_PH_DSP
,
539 OPC_PRECEU_PH_QBL
= (0x1C << 6) | OPC_ABSQ_S_PH_DSP
,
540 OPC_PRECEU_PH_QBR
= (0x1D << 6) | OPC_ABSQ_S_PH_DSP
,
541 OPC_PRECEU_PH_QBLA
= (0x1E << 6) | OPC_ABSQ_S_PH_DSP
,
542 OPC_PRECEU_PH_QBRA
= (0x1F << 6) | OPC_ABSQ_S_PH_DSP
,
543 /* DSP Bit/Manipulation Sub-class */
544 OPC_BITREV
= (0x1B << 6) | OPC_ABSQ_S_PH_DSP
,
545 OPC_REPL_QB
= (0x02 << 6) | OPC_ABSQ_S_PH_DSP
,
546 OPC_REPLV_QB
= (0x03 << 6) | OPC_ABSQ_S_PH_DSP
,
547 OPC_REPL_PH
= (0x0A << 6) | OPC_ABSQ_S_PH_DSP
,
548 OPC_REPLV_PH
= (0x0B << 6) | OPC_ABSQ_S_PH_DSP
,
551 #define MASK_CMPU_EQ_QB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
553 /* MIPS DSP Arithmetic Sub-class */
554 OPC_PRECR_QB_PH
= (0x0D << 6) | OPC_CMPU_EQ_QB_DSP
,
555 OPC_PRECRQ_QB_PH
= (0x0C << 6) | OPC_CMPU_EQ_QB_DSP
,
556 OPC_PRECR_SRA_PH_W
= (0x1E << 6) | OPC_CMPU_EQ_QB_DSP
,
557 OPC_PRECR_SRA_R_PH_W
= (0x1F << 6) | OPC_CMPU_EQ_QB_DSP
,
558 OPC_PRECRQ_PH_W
= (0x14 << 6) | OPC_CMPU_EQ_QB_DSP
,
559 OPC_PRECRQ_RS_PH_W
= (0x15 << 6) | OPC_CMPU_EQ_QB_DSP
,
560 OPC_PRECRQU_S_QB_PH
= (0x0F << 6) | OPC_CMPU_EQ_QB_DSP
,
561 /* DSP Compare-Pick Sub-class */
562 OPC_CMPU_EQ_QB
= (0x00 << 6) | OPC_CMPU_EQ_QB_DSP
,
563 OPC_CMPU_LT_QB
= (0x01 << 6) | OPC_CMPU_EQ_QB_DSP
,
564 OPC_CMPU_LE_QB
= (0x02 << 6) | OPC_CMPU_EQ_QB_DSP
,
565 OPC_CMPGU_EQ_QB
= (0x04 << 6) | OPC_CMPU_EQ_QB_DSP
,
566 OPC_CMPGU_LT_QB
= (0x05 << 6) | OPC_CMPU_EQ_QB_DSP
,
567 OPC_CMPGU_LE_QB
= (0x06 << 6) | OPC_CMPU_EQ_QB_DSP
,
568 OPC_CMPGDU_EQ_QB
= (0x18 << 6) | OPC_CMPU_EQ_QB_DSP
,
569 OPC_CMPGDU_LT_QB
= (0x19 << 6) | OPC_CMPU_EQ_QB_DSP
,
570 OPC_CMPGDU_LE_QB
= (0x1A << 6) | OPC_CMPU_EQ_QB_DSP
,
571 OPC_CMP_EQ_PH
= (0x08 << 6) | OPC_CMPU_EQ_QB_DSP
,
572 OPC_CMP_LT_PH
= (0x09 << 6) | OPC_CMPU_EQ_QB_DSP
,
573 OPC_CMP_LE_PH
= (0x0A << 6) | OPC_CMPU_EQ_QB_DSP
,
574 OPC_PICK_QB
= (0x03 << 6) | OPC_CMPU_EQ_QB_DSP
,
575 OPC_PICK_PH
= (0x0B << 6) | OPC_CMPU_EQ_QB_DSP
,
576 OPC_PACKRL_PH
= (0x0E << 6) | OPC_CMPU_EQ_QB_DSP
,
579 #define MASK_SHLL_QB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
581 /* MIPS DSP GPR-Based Shift Sub-class */
582 OPC_SHLL_QB
= (0x00 << 6) | OPC_SHLL_QB_DSP
,
583 OPC_SHLLV_QB
= (0x02 << 6) | OPC_SHLL_QB_DSP
,
584 OPC_SHLL_PH
= (0x08 << 6) | OPC_SHLL_QB_DSP
,
585 OPC_SHLLV_PH
= (0x0A << 6) | OPC_SHLL_QB_DSP
,
586 OPC_SHLL_S_PH
= (0x0C << 6) | OPC_SHLL_QB_DSP
,
587 OPC_SHLLV_S_PH
= (0x0E << 6) | OPC_SHLL_QB_DSP
,
588 OPC_SHLL_S_W
= (0x14 << 6) | OPC_SHLL_QB_DSP
,
589 OPC_SHLLV_S_W
= (0x16 << 6) | OPC_SHLL_QB_DSP
,
590 OPC_SHRL_QB
= (0x01 << 6) | OPC_SHLL_QB_DSP
,
591 OPC_SHRLV_QB
= (0x03 << 6) | OPC_SHLL_QB_DSP
,
592 OPC_SHRL_PH
= (0x19 << 6) | OPC_SHLL_QB_DSP
,
593 OPC_SHRLV_PH
= (0x1B << 6) | OPC_SHLL_QB_DSP
,
594 OPC_SHRA_QB
= (0x04 << 6) | OPC_SHLL_QB_DSP
,
595 OPC_SHRA_R_QB
= (0x05 << 6) | OPC_SHLL_QB_DSP
,
596 OPC_SHRAV_QB
= (0x06 << 6) | OPC_SHLL_QB_DSP
,
597 OPC_SHRAV_R_QB
= (0x07 << 6) | OPC_SHLL_QB_DSP
,
598 OPC_SHRA_PH
= (0x09 << 6) | OPC_SHLL_QB_DSP
,
599 OPC_SHRAV_PH
= (0x0B << 6) | OPC_SHLL_QB_DSP
,
600 OPC_SHRA_R_PH
= (0x0D << 6) | OPC_SHLL_QB_DSP
,
601 OPC_SHRAV_R_PH
= (0x0F << 6) | OPC_SHLL_QB_DSP
,
602 OPC_SHRA_R_W
= (0x15 << 6) | OPC_SHLL_QB_DSP
,
603 OPC_SHRAV_R_W
= (0x17 << 6) | OPC_SHLL_QB_DSP
,
606 #define MASK_DPA_W_PH(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
608 /* MIPS DSP Multiply Sub-class insns */
609 OPC_DPAU_H_QBL
= (0x03 << 6) | OPC_DPA_W_PH_DSP
,
610 OPC_DPAU_H_QBR
= (0x07 << 6) | OPC_DPA_W_PH_DSP
,
611 OPC_DPSU_H_QBL
= (0x0B << 6) | OPC_DPA_W_PH_DSP
,
612 OPC_DPSU_H_QBR
= (0x0F << 6) | OPC_DPA_W_PH_DSP
,
613 OPC_DPA_W_PH
= (0x00 << 6) | OPC_DPA_W_PH_DSP
,
614 OPC_DPAX_W_PH
= (0x08 << 6) | OPC_DPA_W_PH_DSP
,
615 OPC_DPAQ_S_W_PH
= (0x04 << 6) | OPC_DPA_W_PH_DSP
,
616 OPC_DPAQX_S_W_PH
= (0x18 << 6) | OPC_DPA_W_PH_DSP
,
617 OPC_DPAQX_SA_W_PH
= (0x1A << 6) | OPC_DPA_W_PH_DSP
,
618 OPC_DPS_W_PH
= (0x01 << 6) | OPC_DPA_W_PH_DSP
,
619 OPC_DPSX_W_PH
= (0x09 << 6) | OPC_DPA_W_PH_DSP
,
620 OPC_DPSQ_S_W_PH
= (0x05 << 6) | OPC_DPA_W_PH_DSP
,
621 OPC_DPSQX_S_W_PH
= (0x19 << 6) | OPC_DPA_W_PH_DSP
,
622 OPC_DPSQX_SA_W_PH
= (0x1B << 6) | OPC_DPA_W_PH_DSP
,
623 OPC_MULSAQ_S_W_PH
= (0x06 << 6) | OPC_DPA_W_PH_DSP
,
624 OPC_DPAQ_SA_L_W
= (0x0C << 6) | OPC_DPA_W_PH_DSP
,
625 OPC_DPSQ_SA_L_W
= (0x0D << 6) | OPC_DPA_W_PH_DSP
,
626 OPC_MAQ_S_W_PHL
= (0x14 << 6) | OPC_DPA_W_PH_DSP
,
627 OPC_MAQ_S_W_PHR
= (0x16 << 6) | OPC_DPA_W_PH_DSP
,
628 OPC_MAQ_SA_W_PHL
= (0x10 << 6) | OPC_DPA_W_PH_DSP
,
629 OPC_MAQ_SA_W_PHR
= (0x12 << 6) | OPC_DPA_W_PH_DSP
,
630 OPC_MULSA_W_PH
= (0x02 << 6) | OPC_DPA_W_PH_DSP
,
633 #define MASK_INSV(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
635 /* DSP Bit/Manipulation Sub-class */
636 OPC_INSV
= (0x00 << 6) | OPC_INSV_DSP
,
639 #define MASK_APPEND(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
641 /* MIPS DSP Append Sub-class */
642 OPC_APPEND
= (0x00 << 6) | OPC_APPEND_DSP
,
643 OPC_PREPEND
= (0x01 << 6) | OPC_APPEND_DSP
,
644 OPC_BALIGN
= (0x10 << 6) | OPC_APPEND_DSP
,
647 #define MASK_EXTR_W(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
649 /* MIPS DSP Accumulator and DSPControl Access Sub-class */
650 OPC_EXTR_W
= (0x00 << 6) | OPC_EXTR_W_DSP
,
651 OPC_EXTR_R_W
= (0x04 << 6) | OPC_EXTR_W_DSP
,
652 OPC_EXTR_RS_W
= (0x06 << 6) | OPC_EXTR_W_DSP
,
653 OPC_EXTR_S_H
= (0x0E << 6) | OPC_EXTR_W_DSP
,
654 OPC_EXTRV_S_H
= (0x0F << 6) | OPC_EXTR_W_DSP
,
655 OPC_EXTRV_W
= (0x01 << 6) | OPC_EXTR_W_DSP
,
656 OPC_EXTRV_R_W
= (0x05 << 6) | OPC_EXTR_W_DSP
,
657 OPC_EXTRV_RS_W
= (0x07 << 6) | OPC_EXTR_W_DSP
,
658 OPC_EXTP
= (0x02 << 6) | OPC_EXTR_W_DSP
,
659 OPC_EXTPV
= (0x03 << 6) | OPC_EXTR_W_DSP
,
660 OPC_EXTPDP
= (0x0A << 6) | OPC_EXTR_W_DSP
,
661 OPC_EXTPDPV
= (0x0B << 6) | OPC_EXTR_W_DSP
,
662 OPC_SHILO
= (0x1A << 6) | OPC_EXTR_W_DSP
,
663 OPC_SHILOV
= (0x1B << 6) | OPC_EXTR_W_DSP
,
664 OPC_MTHLIP
= (0x1F << 6) | OPC_EXTR_W_DSP
,
665 OPC_WRDSP
= (0x13 << 6) | OPC_EXTR_W_DSP
,
666 OPC_RDDSP
= (0x12 << 6) | OPC_EXTR_W_DSP
,
669 #define MASK_ABSQ_S_QH(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
671 /* MIPS DSP Arithmetic Sub-class */
672 OPC_PRECEQ_L_PWL
= (0x14 << 6) | OPC_ABSQ_S_QH_DSP
,
673 OPC_PRECEQ_L_PWR
= (0x15 << 6) | OPC_ABSQ_S_QH_DSP
,
674 OPC_PRECEQ_PW_QHL
= (0x0C << 6) | OPC_ABSQ_S_QH_DSP
,
675 OPC_PRECEQ_PW_QHR
= (0x0D << 6) | OPC_ABSQ_S_QH_DSP
,
676 OPC_PRECEQ_PW_QHLA
= (0x0E << 6) | OPC_ABSQ_S_QH_DSP
,
677 OPC_PRECEQ_PW_QHRA
= (0x0F << 6) | OPC_ABSQ_S_QH_DSP
,
678 OPC_PRECEQU_QH_OBL
= (0x04 << 6) | OPC_ABSQ_S_QH_DSP
,
679 OPC_PRECEQU_QH_OBR
= (0x05 << 6) | OPC_ABSQ_S_QH_DSP
,
680 OPC_PRECEQU_QH_OBLA
= (0x06 << 6) | OPC_ABSQ_S_QH_DSP
,
681 OPC_PRECEQU_QH_OBRA
= (0x07 << 6) | OPC_ABSQ_S_QH_DSP
,
682 OPC_PRECEU_QH_OBL
= (0x1C << 6) | OPC_ABSQ_S_QH_DSP
,
683 OPC_PRECEU_QH_OBR
= (0x1D << 6) | OPC_ABSQ_S_QH_DSP
,
684 OPC_PRECEU_QH_OBLA
= (0x1E << 6) | OPC_ABSQ_S_QH_DSP
,
685 OPC_PRECEU_QH_OBRA
= (0x1F << 6) | OPC_ABSQ_S_QH_DSP
,
686 OPC_ABSQ_S_OB
= (0x01 << 6) | OPC_ABSQ_S_QH_DSP
,
687 OPC_ABSQ_S_PW
= (0x11 << 6) | OPC_ABSQ_S_QH_DSP
,
688 OPC_ABSQ_S_QH
= (0x09 << 6) | OPC_ABSQ_S_QH_DSP
,
689 /* DSP Bit/Manipulation Sub-class */
690 OPC_REPL_OB
= (0x02 << 6) | OPC_ABSQ_S_QH_DSP
,
691 OPC_REPL_PW
= (0x12 << 6) | OPC_ABSQ_S_QH_DSP
,
692 OPC_REPL_QH
= (0x0A << 6) | OPC_ABSQ_S_QH_DSP
,
693 OPC_REPLV_OB
= (0x03 << 6) | OPC_ABSQ_S_QH_DSP
,
694 OPC_REPLV_PW
= (0x13 << 6) | OPC_ABSQ_S_QH_DSP
,
695 OPC_REPLV_QH
= (0x0B << 6) | OPC_ABSQ_S_QH_DSP
,
698 #define MASK_ADDU_OB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
700 /* MIPS DSP Multiply Sub-class insns */
701 OPC_MULEQ_S_PW_QHL
= (0x1C << 6) | OPC_ADDU_OB_DSP
,
702 OPC_MULEQ_S_PW_QHR
= (0x1D << 6) | OPC_ADDU_OB_DSP
,
703 OPC_MULEU_S_QH_OBL
= (0x06 << 6) | OPC_ADDU_OB_DSP
,
704 OPC_MULEU_S_QH_OBR
= (0x07 << 6) | OPC_ADDU_OB_DSP
,
705 OPC_MULQ_RS_QH
= (0x1F << 6) | OPC_ADDU_OB_DSP
,
706 /* MIPS DSP Arithmetic Sub-class */
707 OPC_RADDU_L_OB
= (0x14 << 6) | OPC_ADDU_OB_DSP
,
708 OPC_SUBQ_PW
= (0x13 << 6) | OPC_ADDU_OB_DSP
,
709 OPC_SUBQ_S_PW
= (0x17 << 6) | OPC_ADDU_OB_DSP
,
710 OPC_SUBQ_QH
= (0x0B << 6) | OPC_ADDU_OB_DSP
,
711 OPC_SUBQ_S_QH
= (0x0F << 6) | OPC_ADDU_OB_DSP
,
712 OPC_SUBU_OB
= (0x01 << 6) | OPC_ADDU_OB_DSP
,
713 OPC_SUBU_S_OB
= (0x05 << 6) | OPC_ADDU_OB_DSP
,
714 OPC_SUBU_QH
= (0x09 << 6) | OPC_ADDU_OB_DSP
,
715 OPC_SUBU_S_QH
= (0x0D << 6) | OPC_ADDU_OB_DSP
,
716 OPC_SUBUH_OB
= (0x19 << 6) | OPC_ADDU_OB_DSP
,
717 OPC_SUBUH_R_OB
= (0x1B << 6) | OPC_ADDU_OB_DSP
,
718 OPC_ADDQ_PW
= (0x12 << 6) | OPC_ADDU_OB_DSP
,
719 OPC_ADDQ_S_PW
= (0x16 << 6) | OPC_ADDU_OB_DSP
,
720 OPC_ADDQ_QH
= (0x0A << 6) | OPC_ADDU_OB_DSP
,
721 OPC_ADDQ_S_QH
= (0x0E << 6) | OPC_ADDU_OB_DSP
,
722 OPC_ADDU_OB
= (0x00 << 6) | OPC_ADDU_OB_DSP
,
723 OPC_ADDU_S_OB
= (0x04 << 6) | OPC_ADDU_OB_DSP
,
724 OPC_ADDU_QH
= (0x08 << 6) | OPC_ADDU_OB_DSP
,
725 OPC_ADDU_S_QH
= (0x0C << 6) | OPC_ADDU_OB_DSP
,
726 OPC_ADDUH_OB
= (0x18 << 6) | OPC_ADDU_OB_DSP
,
727 OPC_ADDUH_R_OB
= (0x1A << 6) | OPC_ADDU_OB_DSP
,
730 #define MASK_CMPU_EQ_OB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
732 /* DSP Compare-Pick Sub-class */
733 OPC_CMP_EQ_PW
= (0x10 << 6) | OPC_CMPU_EQ_OB_DSP
,
734 OPC_CMP_LT_PW
= (0x11 << 6) | OPC_CMPU_EQ_OB_DSP
,
735 OPC_CMP_LE_PW
= (0x12 << 6) | OPC_CMPU_EQ_OB_DSP
,
736 OPC_CMP_EQ_QH
= (0x08 << 6) | OPC_CMPU_EQ_OB_DSP
,
737 OPC_CMP_LT_QH
= (0x09 << 6) | OPC_CMPU_EQ_OB_DSP
,
738 OPC_CMP_LE_QH
= (0x0A << 6) | OPC_CMPU_EQ_OB_DSP
,
739 OPC_CMPGDU_EQ_OB
= (0x18 << 6) | OPC_CMPU_EQ_OB_DSP
,
740 OPC_CMPGDU_LT_OB
= (0x19 << 6) | OPC_CMPU_EQ_OB_DSP
,
741 OPC_CMPGDU_LE_OB
= (0x1A << 6) | OPC_CMPU_EQ_OB_DSP
,
742 OPC_CMPGU_EQ_OB
= (0x04 << 6) | OPC_CMPU_EQ_OB_DSP
,
743 OPC_CMPGU_LT_OB
= (0x05 << 6) | OPC_CMPU_EQ_OB_DSP
,
744 OPC_CMPGU_LE_OB
= (0x06 << 6) | OPC_CMPU_EQ_OB_DSP
,
745 OPC_CMPU_EQ_OB
= (0x00 << 6) | OPC_CMPU_EQ_OB_DSP
,
746 OPC_CMPU_LT_OB
= (0x01 << 6) | OPC_CMPU_EQ_OB_DSP
,
747 OPC_CMPU_LE_OB
= (0x02 << 6) | OPC_CMPU_EQ_OB_DSP
,
748 OPC_PACKRL_PW
= (0x0E << 6) | OPC_CMPU_EQ_OB_DSP
,
749 OPC_PICK_OB
= (0x03 << 6) | OPC_CMPU_EQ_OB_DSP
,
750 OPC_PICK_PW
= (0x13 << 6) | OPC_CMPU_EQ_OB_DSP
,
751 OPC_PICK_QH
= (0x0B << 6) | OPC_CMPU_EQ_OB_DSP
,
752 /* MIPS DSP Arithmetic Sub-class */
753 OPC_PRECR_OB_QH
= (0x0D << 6) | OPC_CMPU_EQ_OB_DSP
,
754 OPC_PRECR_SRA_QH_PW
= (0x1E << 6) | OPC_CMPU_EQ_OB_DSP
,
755 OPC_PRECR_SRA_R_QH_PW
= (0x1F << 6) | OPC_CMPU_EQ_OB_DSP
,
756 OPC_PRECRQ_OB_QH
= (0x0C << 6) | OPC_CMPU_EQ_OB_DSP
,
757 OPC_PRECRQ_PW_L
= (0x1C << 6) | OPC_CMPU_EQ_OB_DSP
,
758 OPC_PRECRQ_QH_PW
= (0x14 << 6) | OPC_CMPU_EQ_OB_DSP
,
759 OPC_PRECRQ_RS_QH_PW
= (0x15 << 6) | OPC_CMPU_EQ_OB_DSP
,
760 OPC_PRECRQU_S_OB_QH
= (0x0F << 6) | OPC_CMPU_EQ_OB_DSP
,
763 #define MASK_DAPPEND(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
765 /* DSP Append Sub-class */
766 OPC_DAPPEND
= (0x00 << 6) | OPC_DAPPEND_DSP
,
767 OPC_PREPENDD
= (0x03 << 6) | OPC_DAPPEND_DSP
,
768 OPC_PREPENDW
= (0x01 << 6) | OPC_DAPPEND_DSP
,
769 OPC_DBALIGN
= (0x10 << 6) | OPC_DAPPEND_DSP
,
772 #define MASK_DEXTR_W(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
774 /* MIPS DSP Accumulator and DSPControl Access Sub-class */
775 OPC_DMTHLIP
= (0x1F << 6) | OPC_DEXTR_W_DSP
,
776 OPC_DSHILO
= (0x1A << 6) | OPC_DEXTR_W_DSP
,
777 OPC_DEXTP
= (0x02 << 6) | OPC_DEXTR_W_DSP
,
778 OPC_DEXTPDP
= (0x0A << 6) | OPC_DEXTR_W_DSP
,
779 OPC_DEXTPDPV
= (0x0B << 6) | OPC_DEXTR_W_DSP
,
780 OPC_DEXTPV
= (0x03 << 6) | OPC_DEXTR_W_DSP
,
781 OPC_DEXTR_L
= (0x10 << 6) | OPC_DEXTR_W_DSP
,
782 OPC_DEXTR_R_L
= (0x14 << 6) | OPC_DEXTR_W_DSP
,
783 OPC_DEXTR_RS_L
= (0x16 << 6) | OPC_DEXTR_W_DSP
,
784 OPC_DEXTR_W
= (0x00 << 6) | OPC_DEXTR_W_DSP
,
785 OPC_DEXTR_R_W
= (0x04 << 6) | OPC_DEXTR_W_DSP
,
786 OPC_DEXTR_RS_W
= (0x06 << 6) | OPC_DEXTR_W_DSP
,
787 OPC_DEXTR_S_H
= (0x0E << 6) | OPC_DEXTR_W_DSP
,
788 OPC_DEXTRV_L
= (0x11 << 6) | OPC_DEXTR_W_DSP
,
789 OPC_DEXTRV_R_L
= (0x15 << 6) | OPC_DEXTR_W_DSP
,
790 OPC_DEXTRV_RS_L
= (0x17 << 6) | OPC_DEXTR_W_DSP
,
791 OPC_DEXTRV_S_H
= (0x0F << 6) | OPC_DEXTR_W_DSP
,
792 OPC_DEXTRV_W
= (0x01 << 6) | OPC_DEXTR_W_DSP
,
793 OPC_DEXTRV_R_W
= (0x05 << 6) | OPC_DEXTR_W_DSP
,
794 OPC_DEXTRV_RS_W
= (0x07 << 6) | OPC_DEXTR_W_DSP
,
795 OPC_DSHILOV
= (0x1B << 6) | OPC_DEXTR_W_DSP
,
798 #define MASK_DINSV(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
800 /* DSP Bit/Manipulation Sub-class */
801 OPC_DINSV
= (0x00 << 6) | OPC_DINSV_DSP
,
804 #define MASK_DPAQ_W_QH(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
806 /* MIPS DSP Multiply Sub-class insns */
807 OPC_DMADD
= (0x19 << 6) | OPC_DPAQ_W_QH_DSP
,
808 OPC_DMADDU
= (0x1D << 6) | OPC_DPAQ_W_QH_DSP
,
809 OPC_DMSUB
= (0x1B << 6) | OPC_DPAQ_W_QH_DSP
,
810 OPC_DMSUBU
= (0x1F << 6) | OPC_DPAQ_W_QH_DSP
,
811 OPC_DPA_W_QH
= (0x00 << 6) | OPC_DPAQ_W_QH_DSP
,
812 OPC_DPAQ_S_W_QH
= (0x04 << 6) | OPC_DPAQ_W_QH_DSP
,
813 OPC_DPAQ_SA_L_PW
= (0x0C << 6) | OPC_DPAQ_W_QH_DSP
,
814 OPC_DPAU_H_OBL
= (0x03 << 6) | OPC_DPAQ_W_QH_DSP
,
815 OPC_DPAU_H_OBR
= (0x07 << 6) | OPC_DPAQ_W_QH_DSP
,
816 OPC_DPS_W_QH
= (0x01 << 6) | OPC_DPAQ_W_QH_DSP
,
817 OPC_DPSQ_S_W_QH
= (0x05 << 6) | OPC_DPAQ_W_QH_DSP
,
818 OPC_DPSQ_SA_L_PW
= (0x0D << 6) | OPC_DPAQ_W_QH_DSP
,
819 OPC_DPSU_H_OBL
= (0x0B << 6) | OPC_DPAQ_W_QH_DSP
,
820 OPC_DPSU_H_OBR
= (0x0F << 6) | OPC_DPAQ_W_QH_DSP
,
821 OPC_MAQ_S_L_PWL
= (0x1C << 6) | OPC_DPAQ_W_QH_DSP
,
822 OPC_MAQ_S_L_PWR
= (0x1E << 6) | OPC_DPAQ_W_QH_DSP
,
823 OPC_MAQ_S_W_QHLL
= (0x14 << 6) | OPC_DPAQ_W_QH_DSP
,
824 OPC_MAQ_SA_W_QHLL
= (0x10 << 6) | OPC_DPAQ_W_QH_DSP
,
825 OPC_MAQ_S_W_QHLR
= (0x15 << 6) | OPC_DPAQ_W_QH_DSP
,
826 OPC_MAQ_SA_W_QHLR
= (0x11 << 6) | OPC_DPAQ_W_QH_DSP
,
827 OPC_MAQ_S_W_QHRL
= (0x16 << 6) | OPC_DPAQ_W_QH_DSP
,
828 OPC_MAQ_SA_W_QHRL
= (0x12 << 6) | OPC_DPAQ_W_QH_DSP
,
829 OPC_MAQ_S_W_QHRR
= (0x17 << 6) | OPC_DPAQ_W_QH_DSP
,
830 OPC_MAQ_SA_W_QHRR
= (0x13 << 6) | OPC_DPAQ_W_QH_DSP
,
831 OPC_MULSAQ_S_L_PW
= (0x0E << 6) | OPC_DPAQ_W_QH_DSP
,
832 OPC_MULSAQ_S_W_QH
= (0x06 << 6) | OPC_DPAQ_W_QH_DSP
,
835 #define MASK_SHLL_OB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
837 /* MIPS DSP GPR-Based Shift Sub-class */
838 OPC_SHLL_PW
= (0x10 << 6) | OPC_SHLL_OB_DSP
,
839 OPC_SHLL_S_PW
= (0x14 << 6) | OPC_SHLL_OB_DSP
,
840 OPC_SHLLV_OB
= (0x02 << 6) | OPC_SHLL_OB_DSP
,
841 OPC_SHLLV_PW
= (0x12 << 6) | OPC_SHLL_OB_DSP
,
842 OPC_SHLLV_S_PW
= (0x16 << 6) | OPC_SHLL_OB_DSP
,
843 OPC_SHLLV_QH
= (0x0A << 6) | OPC_SHLL_OB_DSP
,
844 OPC_SHLLV_S_QH
= (0x0E << 6) | OPC_SHLL_OB_DSP
,
845 OPC_SHRA_PW
= (0x11 << 6) | OPC_SHLL_OB_DSP
,
846 OPC_SHRA_R_PW
= (0x15 << 6) | OPC_SHLL_OB_DSP
,
847 OPC_SHRAV_OB
= (0x06 << 6) | OPC_SHLL_OB_DSP
,
848 OPC_SHRAV_R_OB
= (0x07 << 6) | OPC_SHLL_OB_DSP
,
849 OPC_SHRAV_PW
= (0x13 << 6) | OPC_SHLL_OB_DSP
,
850 OPC_SHRAV_R_PW
= (0x17 << 6) | OPC_SHLL_OB_DSP
,
851 OPC_SHRAV_QH
= (0x0B << 6) | OPC_SHLL_OB_DSP
,
852 OPC_SHRAV_R_QH
= (0x0F << 6) | OPC_SHLL_OB_DSP
,
853 OPC_SHRLV_OB
= (0x03 << 6) | OPC_SHLL_OB_DSP
,
854 OPC_SHRLV_QH
= (0x1B << 6) | OPC_SHLL_OB_DSP
,
855 OPC_SHLL_OB
= (0x00 << 6) | OPC_SHLL_OB_DSP
,
856 OPC_SHLL_QH
= (0x08 << 6) | OPC_SHLL_OB_DSP
,
857 OPC_SHLL_S_QH
= (0x0C << 6) | OPC_SHLL_OB_DSP
,
858 OPC_SHRA_OB
= (0x04 << 6) | OPC_SHLL_OB_DSP
,
859 OPC_SHRA_R_OB
= (0x05 << 6) | OPC_SHLL_OB_DSP
,
860 OPC_SHRA_QH
= (0x09 << 6) | OPC_SHLL_OB_DSP
,
861 OPC_SHRA_R_QH
= (0x0D << 6) | OPC_SHLL_OB_DSP
,
862 OPC_SHRL_OB
= (0x01 << 6) | OPC_SHLL_OB_DSP
,
863 OPC_SHRL_QH
= (0x19 << 6) | OPC_SHLL_OB_DSP
,
866 /* Coprocessor 0 (rs field) */
867 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
870 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
871 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
872 OPC_MFHC0
= (0x02 << 21) | OPC_CP0
,
873 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
874 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
875 OPC_MTHC0
= (0x06 << 21) | OPC_CP0
,
876 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
877 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
878 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
879 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
880 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
881 OPC_C0
= (0x10 << 21) | OPC_CP0
,
882 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
883 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
887 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
890 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
891 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
892 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
893 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
894 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
895 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
898 /* Coprocessor 0 (with rs == C0) */
899 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
902 OPC_TLBR
= 0x01 | OPC_C0
,
903 OPC_TLBWI
= 0x02 | OPC_C0
,
904 OPC_TLBINV
= 0x03 | OPC_C0
,
905 OPC_TLBINVF
= 0x04 | OPC_C0
,
906 OPC_TLBWR
= 0x06 | OPC_C0
,
907 OPC_TLBP
= 0x08 | OPC_C0
,
908 OPC_RFE
= 0x10 | OPC_C0
,
909 OPC_ERET
= 0x18 | OPC_C0
,
910 OPC_DERET
= 0x1F | OPC_C0
,
911 OPC_WAIT
= 0x20 | OPC_C0
,
914 /* Coprocessor 1 (rs field) */
915 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
917 /* Values for the fmt field in FP instructions */
919 /* 0 - 15 are reserved */
920 FMT_S
= 16, /* single fp */
921 FMT_D
= 17, /* double fp */
922 FMT_E
= 18, /* extended fp */
923 FMT_Q
= 19, /* quad fp */
924 FMT_W
= 20, /* 32-bit fixed */
925 FMT_L
= 21, /* 64-bit fixed */
926 FMT_PS
= 22, /* paired single fp */
927 /* 23 - 31 are reserved */
931 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
932 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
933 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
934 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
935 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
936 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
937 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
938 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
939 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
940 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
941 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
942 OPC_BZ_V
= (0x0B << 21) | OPC_CP1
,
943 OPC_BNZ_V
= (0x0F << 21) | OPC_CP1
,
944 OPC_S_FMT
= (FMT_S
<< 21) | OPC_CP1
,
945 OPC_D_FMT
= (FMT_D
<< 21) | OPC_CP1
,
946 OPC_E_FMT
= (FMT_E
<< 21) | OPC_CP1
,
947 OPC_Q_FMT
= (FMT_Q
<< 21) | OPC_CP1
,
948 OPC_W_FMT
= (FMT_W
<< 21) | OPC_CP1
,
949 OPC_L_FMT
= (FMT_L
<< 21) | OPC_CP1
,
950 OPC_PS_FMT
= (FMT_PS
<< 21) | OPC_CP1
,
951 OPC_BC1EQZ
= (0x09 << 21) | OPC_CP1
,
952 OPC_BC1NEZ
= (0x0D << 21) | OPC_CP1
,
953 OPC_BZ_B
= (0x18 << 21) | OPC_CP1
,
954 OPC_BZ_H
= (0x19 << 21) | OPC_CP1
,
955 OPC_BZ_W
= (0x1A << 21) | OPC_CP1
,
956 OPC_BZ_D
= (0x1B << 21) | OPC_CP1
,
957 OPC_BNZ_B
= (0x1C << 21) | OPC_CP1
,
958 OPC_BNZ_H
= (0x1D << 21) | OPC_CP1
,
959 OPC_BNZ_W
= (0x1E << 21) | OPC_CP1
,
960 OPC_BNZ_D
= (0x1F << 21) | OPC_CP1
,
963 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
964 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
967 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
968 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
969 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
970 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
974 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
975 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
979 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
980 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
983 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
986 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
987 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
988 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
989 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
990 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
991 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
992 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
993 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
994 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
995 OPC_BC2EQZ
= (0x09 << 21) | OPC_CP2
,
996 OPC_BC2NEZ
= (0x0D << 21) | OPC_CP2
,
999 #define MASK_LMI(op) (MASK_OP_MAJOR(op) | (op & (0x1F << 21)) | (op & 0x1F))
1002 OPC_PADDSH
= (24 << 21) | (0x00) | OPC_CP2
,
1003 OPC_PADDUSH
= (25 << 21) | (0x00) | OPC_CP2
,
1004 OPC_PADDH
= (26 << 21) | (0x00) | OPC_CP2
,
1005 OPC_PADDW
= (27 << 21) | (0x00) | OPC_CP2
,
1006 OPC_PADDSB
= (28 << 21) | (0x00) | OPC_CP2
,
1007 OPC_PADDUSB
= (29 << 21) | (0x00) | OPC_CP2
,
1008 OPC_PADDB
= (30 << 21) | (0x00) | OPC_CP2
,
1009 OPC_PADDD
= (31 << 21) | (0x00) | OPC_CP2
,
1011 OPC_PSUBSH
= (24 << 21) | (0x01) | OPC_CP2
,
1012 OPC_PSUBUSH
= (25 << 21) | (0x01) | OPC_CP2
,
1013 OPC_PSUBH
= (26 << 21) | (0x01) | OPC_CP2
,
1014 OPC_PSUBW
= (27 << 21) | (0x01) | OPC_CP2
,
1015 OPC_PSUBSB
= (28 << 21) | (0x01) | OPC_CP2
,
1016 OPC_PSUBUSB
= (29 << 21) | (0x01) | OPC_CP2
,
1017 OPC_PSUBB
= (30 << 21) | (0x01) | OPC_CP2
,
1018 OPC_PSUBD
= (31 << 21) | (0x01) | OPC_CP2
,
1020 OPC_PSHUFH
= (24 << 21) | (0x02) | OPC_CP2
,
1021 OPC_PACKSSWH
= (25 << 21) | (0x02) | OPC_CP2
,
1022 OPC_PACKSSHB
= (26 << 21) | (0x02) | OPC_CP2
,
1023 OPC_PACKUSHB
= (27 << 21) | (0x02) | OPC_CP2
,
1024 OPC_XOR_CP2
= (28 << 21) | (0x02) | OPC_CP2
,
1025 OPC_NOR_CP2
= (29 << 21) | (0x02) | OPC_CP2
,
1026 OPC_AND_CP2
= (30 << 21) | (0x02) | OPC_CP2
,
1027 OPC_PANDN
= (31 << 21) | (0x02) | OPC_CP2
,
1029 OPC_PUNPCKLHW
= (24 << 21) | (0x03) | OPC_CP2
,
1030 OPC_PUNPCKHHW
= (25 << 21) | (0x03) | OPC_CP2
,
1031 OPC_PUNPCKLBH
= (26 << 21) | (0x03) | OPC_CP2
,
1032 OPC_PUNPCKHBH
= (27 << 21) | (0x03) | OPC_CP2
,
1033 OPC_PINSRH_0
= (28 << 21) | (0x03) | OPC_CP2
,
1034 OPC_PINSRH_1
= (29 << 21) | (0x03) | OPC_CP2
,
1035 OPC_PINSRH_2
= (30 << 21) | (0x03) | OPC_CP2
,
1036 OPC_PINSRH_3
= (31 << 21) | (0x03) | OPC_CP2
,
1038 OPC_PAVGH
= (24 << 21) | (0x08) | OPC_CP2
,
1039 OPC_PAVGB
= (25 << 21) | (0x08) | OPC_CP2
,
1040 OPC_PMAXSH
= (26 << 21) | (0x08) | OPC_CP2
,
1041 OPC_PMINSH
= (27 << 21) | (0x08) | OPC_CP2
,
1042 OPC_PMAXUB
= (28 << 21) | (0x08) | OPC_CP2
,
1043 OPC_PMINUB
= (29 << 21) | (0x08) | OPC_CP2
,
1045 OPC_PCMPEQW
= (24 << 21) | (0x09) | OPC_CP2
,
1046 OPC_PCMPGTW
= (25 << 21) | (0x09) | OPC_CP2
,
1047 OPC_PCMPEQH
= (26 << 21) | (0x09) | OPC_CP2
,
1048 OPC_PCMPGTH
= (27 << 21) | (0x09) | OPC_CP2
,
1049 OPC_PCMPEQB
= (28 << 21) | (0x09) | OPC_CP2
,
1050 OPC_PCMPGTB
= (29 << 21) | (0x09) | OPC_CP2
,
1052 OPC_PSLLW
= (24 << 21) | (0x0A) | OPC_CP2
,
1053 OPC_PSLLH
= (25 << 21) | (0x0A) | OPC_CP2
,
1054 OPC_PMULLH
= (26 << 21) | (0x0A) | OPC_CP2
,
1055 OPC_PMULHH
= (27 << 21) | (0x0A) | OPC_CP2
,
1056 OPC_PMULUW
= (28 << 21) | (0x0A) | OPC_CP2
,
1057 OPC_PMULHUH
= (29 << 21) | (0x0A) | OPC_CP2
,
1059 OPC_PSRLW
= (24 << 21) | (0x0B) | OPC_CP2
,
1060 OPC_PSRLH
= (25 << 21) | (0x0B) | OPC_CP2
,
1061 OPC_PSRAW
= (26 << 21) | (0x0B) | OPC_CP2
,
1062 OPC_PSRAH
= (27 << 21) | (0x0B) | OPC_CP2
,
1063 OPC_PUNPCKLWD
= (28 << 21) | (0x0B) | OPC_CP2
,
1064 OPC_PUNPCKHWD
= (29 << 21) | (0x0B) | OPC_CP2
,
1066 OPC_ADDU_CP2
= (24 << 21) | (0x0C) | OPC_CP2
,
1067 OPC_OR_CP2
= (25 << 21) | (0x0C) | OPC_CP2
,
1068 OPC_ADD_CP2
= (26 << 21) | (0x0C) | OPC_CP2
,
1069 OPC_DADD_CP2
= (27 << 21) | (0x0C) | OPC_CP2
,
1070 OPC_SEQU_CP2
= (28 << 21) | (0x0C) | OPC_CP2
,
1071 OPC_SEQ_CP2
= (29 << 21) | (0x0C) | OPC_CP2
,
1073 OPC_SUBU_CP2
= (24 << 21) | (0x0D) | OPC_CP2
,
1074 OPC_PASUBUB
= (25 << 21) | (0x0D) | OPC_CP2
,
1075 OPC_SUB_CP2
= (26 << 21) | (0x0D) | OPC_CP2
,
1076 OPC_DSUB_CP2
= (27 << 21) | (0x0D) | OPC_CP2
,
1077 OPC_SLTU_CP2
= (28 << 21) | (0x0D) | OPC_CP2
,
1078 OPC_SLT_CP2
= (29 << 21) | (0x0D) | OPC_CP2
,
1080 OPC_SLL_CP2
= (24 << 21) | (0x0E) | OPC_CP2
,
1081 OPC_DSLL_CP2
= (25 << 21) | (0x0E) | OPC_CP2
,
1082 OPC_PEXTRH
= (26 << 21) | (0x0E) | OPC_CP2
,
1083 OPC_PMADDHW
= (27 << 21) | (0x0E) | OPC_CP2
,
1084 OPC_SLEU_CP2
= (28 << 21) | (0x0E) | OPC_CP2
,
1085 OPC_SLE_CP2
= (29 << 21) | (0x0E) | OPC_CP2
,
1087 OPC_SRL_CP2
= (24 << 21) | (0x0F) | OPC_CP2
,
1088 OPC_DSRL_CP2
= (25 << 21) | (0x0F) | OPC_CP2
,
1089 OPC_SRA_CP2
= (26 << 21) | (0x0F) | OPC_CP2
,
1090 OPC_DSRA_CP2
= (27 << 21) | (0x0F) | OPC_CP2
,
1091 OPC_BIADD
= (28 << 21) | (0x0F) | OPC_CP2
,
1092 OPC_PMOVMSKB
= (29 << 21) | (0x0F) | OPC_CP2
,
1096 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
1099 OPC_LWXC1
= 0x00 | OPC_CP3
,
1100 OPC_LDXC1
= 0x01 | OPC_CP3
,
1101 OPC_LUXC1
= 0x05 | OPC_CP3
,
1102 OPC_SWXC1
= 0x08 | OPC_CP3
,
1103 OPC_SDXC1
= 0x09 | OPC_CP3
,
1104 OPC_SUXC1
= 0x0D | OPC_CP3
,
1105 OPC_PREFX
= 0x0F | OPC_CP3
,
1106 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
1107 OPC_MADD_S
= 0x20 | OPC_CP3
,
1108 OPC_MADD_D
= 0x21 | OPC_CP3
,
1109 OPC_MADD_PS
= 0x26 | OPC_CP3
,
1110 OPC_MSUB_S
= 0x28 | OPC_CP3
,
1111 OPC_MSUB_D
= 0x29 | OPC_CP3
,
1112 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
1113 OPC_NMADD_S
= 0x30 | OPC_CP3
,
1114 OPC_NMADD_D
= 0x31 | OPC_CP3
,
1115 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
1116 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
1117 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
1118 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
1122 #define MASK_MSA_MINOR(op) (MASK_OP_MAJOR(op) | (op & 0x3F))
1124 OPC_MSA_I8_00
= 0x00 | OPC_MSA
,
1125 OPC_MSA_I8_01
= 0x01 | OPC_MSA
,
1126 OPC_MSA_I8_02
= 0x02 | OPC_MSA
,
1127 OPC_MSA_I5_06
= 0x06 | OPC_MSA
,
1128 OPC_MSA_I5_07
= 0x07 | OPC_MSA
,
1129 OPC_MSA_BIT_09
= 0x09 | OPC_MSA
,
1130 OPC_MSA_BIT_0A
= 0x0A | OPC_MSA
,
1131 OPC_MSA_3R_0D
= 0x0D | OPC_MSA
,
1132 OPC_MSA_3R_0E
= 0x0E | OPC_MSA
,
1133 OPC_MSA_3R_0F
= 0x0F | OPC_MSA
,
1134 OPC_MSA_3R_10
= 0x10 | OPC_MSA
,
1135 OPC_MSA_3R_11
= 0x11 | OPC_MSA
,
1136 OPC_MSA_3R_12
= 0x12 | OPC_MSA
,
1137 OPC_MSA_3R_13
= 0x13 | OPC_MSA
,
1138 OPC_MSA_3R_14
= 0x14 | OPC_MSA
,
1139 OPC_MSA_3R_15
= 0x15 | OPC_MSA
,
1140 OPC_MSA_ELM
= 0x19 | OPC_MSA
,
1141 OPC_MSA_3RF_1A
= 0x1A | OPC_MSA
,
1142 OPC_MSA_3RF_1B
= 0x1B | OPC_MSA
,
1143 OPC_MSA_3RF_1C
= 0x1C | OPC_MSA
,
1144 OPC_MSA_VEC
= 0x1E | OPC_MSA
,
1146 /* MI10 instruction */
1147 OPC_LD_B
= (0x20) | OPC_MSA
,
1148 OPC_LD_H
= (0x21) | OPC_MSA
,
1149 OPC_LD_W
= (0x22) | OPC_MSA
,
1150 OPC_LD_D
= (0x23) | OPC_MSA
,
1151 OPC_ST_B
= (0x24) | OPC_MSA
,
1152 OPC_ST_H
= (0x25) | OPC_MSA
,
1153 OPC_ST_W
= (0x26) | OPC_MSA
,
1154 OPC_ST_D
= (0x27) | OPC_MSA
,
1158 /* I5 instruction df(bits 22..21) = _b, _h, _w, _d */
1159 OPC_ADDVI_df
= (0x0 << 23) | OPC_MSA_I5_06
,
1160 OPC_CEQI_df
= (0x0 << 23) | OPC_MSA_I5_07
,
1161 OPC_SUBVI_df
= (0x1 << 23) | OPC_MSA_I5_06
,
1162 OPC_MAXI_S_df
= (0x2 << 23) | OPC_MSA_I5_06
,
1163 OPC_CLTI_S_df
= (0x2 << 23) | OPC_MSA_I5_07
,
1164 OPC_MAXI_U_df
= (0x3 << 23) | OPC_MSA_I5_06
,
1165 OPC_CLTI_U_df
= (0x3 << 23) | OPC_MSA_I5_07
,
1166 OPC_MINI_S_df
= (0x4 << 23) | OPC_MSA_I5_06
,
1167 OPC_CLEI_S_df
= (0x4 << 23) | OPC_MSA_I5_07
,
1168 OPC_MINI_U_df
= (0x5 << 23) | OPC_MSA_I5_06
,
1169 OPC_CLEI_U_df
= (0x5 << 23) | OPC_MSA_I5_07
,
1170 OPC_LDI_df
= (0x6 << 23) | OPC_MSA_I5_07
,
1172 /* I8 instruction */
1173 OPC_ANDI_B
= (0x0 << 24) | OPC_MSA_I8_00
,
1174 OPC_BMNZI_B
= (0x0 << 24) | OPC_MSA_I8_01
,
1175 OPC_SHF_B
= (0x0 << 24) | OPC_MSA_I8_02
,
1176 OPC_ORI_B
= (0x1 << 24) | OPC_MSA_I8_00
,
1177 OPC_BMZI_B
= (0x1 << 24) | OPC_MSA_I8_01
,
1178 OPC_SHF_H
= (0x1 << 24) | OPC_MSA_I8_02
,
1179 OPC_NORI_B
= (0x2 << 24) | OPC_MSA_I8_00
,
1180 OPC_BSELI_B
= (0x2 << 24) | OPC_MSA_I8_01
,
1181 OPC_SHF_W
= (0x2 << 24) | OPC_MSA_I8_02
,
1182 OPC_XORI_B
= (0x3 << 24) | OPC_MSA_I8_00
,
1184 /* VEC/2R/2RF instruction */
1185 OPC_AND_V
= (0x00 << 21) | OPC_MSA_VEC
,
1186 OPC_OR_V
= (0x01 << 21) | OPC_MSA_VEC
,
1187 OPC_NOR_V
= (0x02 << 21) | OPC_MSA_VEC
,
1188 OPC_XOR_V
= (0x03 << 21) | OPC_MSA_VEC
,
1189 OPC_BMNZ_V
= (0x04 << 21) | OPC_MSA_VEC
,
1190 OPC_BMZ_V
= (0x05 << 21) | OPC_MSA_VEC
,
1191 OPC_BSEL_V
= (0x06 << 21) | OPC_MSA_VEC
,
1193 OPC_MSA_2R
= (0x18 << 21) | OPC_MSA_VEC
,
1194 OPC_MSA_2RF
= (0x19 << 21) | OPC_MSA_VEC
,
1196 /* 2R instruction df(bits 17..16) = _b, _h, _w, _d */
1197 OPC_FILL_df
= (0x00 << 18) | OPC_MSA_2R
,
1198 OPC_PCNT_df
= (0x01 << 18) | OPC_MSA_2R
,
1199 OPC_NLOC_df
= (0x02 << 18) | OPC_MSA_2R
,
1200 OPC_NLZC_df
= (0x03 << 18) | OPC_MSA_2R
,
1202 /* 2RF instruction df(bit 16) = _w, _d */
1203 OPC_FCLASS_df
= (0x00 << 17) | OPC_MSA_2RF
,
1204 OPC_FTRUNC_S_df
= (0x01 << 17) | OPC_MSA_2RF
,
1205 OPC_FTRUNC_U_df
= (0x02 << 17) | OPC_MSA_2RF
,
1206 OPC_FSQRT_df
= (0x03 << 17) | OPC_MSA_2RF
,
1207 OPC_FRSQRT_df
= (0x04 << 17) | OPC_MSA_2RF
,
1208 OPC_FRCP_df
= (0x05 << 17) | OPC_MSA_2RF
,
1209 OPC_FRINT_df
= (0x06 << 17) | OPC_MSA_2RF
,
1210 OPC_FLOG2_df
= (0x07 << 17) | OPC_MSA_2RF
,
1211 OPC_FEXUPL_df
= (0x08 << 17) | OPC_MSA_2RF
,
1212 OPC_FEXUPR_df
= (0x09 << 17) | OPC_MSA_2RF
,
1213 OPC_FFQL_df
= (0x0A << 17) | OPC_MSA_2RF
,
1214 OPC_FFQR_df
= (0x0B << 17) | OPC_MSA_2RF
,
1215 OPC_FTINT_S_df
= (0x0C << 17) | OPC_MSA_2RF
,
1216 OPC_FTINT_U_df
= (0x0D << 17) | OPC_MSA_2RF
,
1217 OPC_FFINT_S_df
= (0x0E << 17) | OPC_MSA_2RF
,
1218 OPC_FFINT_U_df
= (0x0F << 17) | OPC_MSA_2RF
,
1220 /* 3R instruction df(bits 22..21) = _b, _h, _w, d */
1221 OPC_SLL_df
= (0x0 << 23) | OPC_MSA_3R_0D
,
1222 OPC_ADDV_df
= (0x0 << 23) | OPC_MSA_3R_0E
,
1223 OPC_CEQ_df
= (0x0 << 23) | OPC_MSA_3R_0F
,
1224 OPC_ADD_A_df
= (0x0 << 23) | OPC_MSA_3R_10
,
1225 OPC_SUBS_S_df
= (0x0 << 23) | OPC_MSA_3R_11
,
1226 OPC_MULV_df
= (0x0 << 23) | OPC_MSA_3R_12
,
1227 OPC_DOTP_S_df
= (0x0 << 23) | OPC_MSA_3R_13
,
1228 OPC_SLD_df
= (0x0 << 23) | OPC_MSA_3R_14
,
1229 OPC_VSHF_df
= (0x0 << 23) | OPC_MSA_3R_15
,
1230 OPC_SRA_df
= (0x1 << 23) | OPC_MSA_3R_0D
,
1231 OPC_SUBV_df
= (0x1 << 23) | OPC_MSA_3R_0E
,
1232 OPC_ADDS_A_df
= (0x1 << 23) | OPC_MSA_3R_10
,
1233 OPC_SUBS_U_df
= (0x1 << 23) | OPC_MSA_3R_11
,
1234 OPC_MADDV_df
= (0x1 << 23) | OPC_MSA_3R_12
,
1235 OPC_DOTP_U_df
= (0x1 << 23) | OPC_MSA_3R_13
,
1236 OPC_SPLAT_df
= (0x1 << 23) | OPC_MSA_3R_14
,
1237 OPC_SRAR_df
= (0x1 << 23) | OPC_MSA_3R_15
,
1238 OPC_SRL_df
= (0x2 << 23) | OPC_MSA_3R_0D
,
1239 OPC_MAX_S_df
= (0x2 << 23) | OPC_MSA_3R_0E
,
1240 OPC_CLT_S_df
= (0x2 << 23) | OPC_MSA_3R_0F
,
1241 OPC_ADDS_S_df
= (0x2 << 23) | OPC_MSA_3R_10
,
1242 OPC_SUBSUS_U_df
= (0x2 << 23) | OPC_MSA_3R_11
,
1243 OPC_MSUBV_df
= (0x2 << 23) | OPC_MSA_3R_12
,
1244 OPC_DPADD_S_df
= (0x2 << 23) | OPC_MSA_3R_13
,
1245 OPC_PCKEV_df
= (0x2 << 23) | OPC_MSA_3R_14
,
1246 OPC_SRLR_df
= (0x2 << 23) | OPC_MSA_3R_15
,
1247 OPC_BCLR_df
= (0x3 << 23) | OPC_MSA_3R_0D
,
1248 OPC_MAX_U_df
= (0x3 << 23) | OPC_MSA_3R_0E
,
1249 OPC_CLT_U_df
= (0x3 << 23) | OPC_MSA_3R_0F
,
1250 OPC_ADDS_U_df
= (0x3 << 23) | OPC_MSA_3R_10
,
1251 OPC_SUBSUU_S_df
= (0x3 << 23) | OPC_MSA_3R_11
,
1252 OPC_DPADD_U_df
= (0x3 << 23) | OPC_MSA_3R_13
,
1253 OPC_PCKOD_df
= (0x3 << 23) | OPC_MSA_3R_14
,
1254 OPC_BSET_df
= (0x4 << 23) | OPC_MSA_3R_0D
,
1255 OPC_MIN_S_df
= (0x4 << 23) | OPC_MSA_3R_0E
,
1256 OPC_CLE_S_df
= (0x4 << 23) | OPC_MSA_3R_0F
,
1257 OPC_AVE_S_df
= (0x4 << 23) | OPC_MSA_3R_10
,
1258 OPC_ASUB_S_df
= (0x4 << 23) | OPC_MSA_3R_11
,
1259 OPC_DIV_S_df
= (0x4 << 23) | OPC_MSA_3R_12
,
1260 OPC_DPSUB_S_df
= (0x4 << 23) | OPC_MSA_3R_13
,
1261 OPC_ILVL_df
= (0x4 << 23) | OPC_MSA_3R_14
,
1262 OPC_HADD_S_df
= (0x4 << 23) | OPC_MSA_3R_15
,
1263 OPC_BNEG_df
= (0x5 << 23) | OPC_MSA_3R_0D
,
1264 OPC_MIN_U_df
= (0x5 << 23) | OPC_MSA_3R_0E
,
1265 OPC_CLE_U_df
= (0x5 << 23) | OPC_MSA_3R_0F
,
1266 OPC_AVE_U_df
= (0x5 << 23) | OPC_MSA_3R_10
,
1267 OPC_ASUB_U_df
= (0x5 << 23) | OPC_MSA_3R_11
,
1268 OPC_DIV_U_df
= (0x5 << 23) | OPC_MSA_3R_12
,
1269 OPC_DPSUB_U_df
= (0x5 << 23) | OPC_MSA_3R_13
,
1270 OPC_ILVR_df
= (0x5 << 23) | OPC_MSA_3R_14
,
1271 OPC_HADD_U_df
= (0x5 << 23) | OPC_MSA_3R_15
,
1272 OPC_BINSL_df
= (0x6 << 23) | OPC_MSA_3R_0D
,
1273 OPC_MAX_A_df
= (0x6 << 23) | OPC_MSA_3R_0E
,
1274 OPC_AVER_S_df
= (0x6 << 23) | OPC_MSA_3R_10
,
1275 OPC_MOD_S_df
= (0x6 << 23) | OPC_MSA_3R_12
,
1276 OPC_ILVEV_df
= (0x6 << 23) | OPC_MSA_3R_14
,
1277 OPC_HSUB_S_df
= (0x6 << 23) | OPC_MSA_3R_15
,
1278 OPC_BINSR_df
= (0x7 << 23) | OPC_MSA_3R_0D
,
1279 OPC_MIN_A_df
= (0x7 << 23) | OPC_MSA_3R_0E
,
1280 OPC_AVER_U_df
= (0x7 << 23) | OPC_MSA_3R_10
,
1281 OPC_MOD_U_df
= (0x7 << 23) | OPC_MSA_3R_12
,
1282 OPC_ILVOD_df
= (0x7 << 23) | OPC_MSA_3R_14
,
1283 OPC_HSUB_U_df
= (0x7 << 23) | OPC_MSA_3R_15
,
1285 /* ELM instructions df(bits 21..16) = _b, _h, _w, _d */
1286 OPC_SLDI_df
= (0x0 << 22) | (0x00 << 16) | OPC_MSA_ELM
,
1287 OPC_CTCMSA
= (0x0 << 22) | (0x3E << 16) | OPC_MSA_ELM
,
1288 OPC_SPLATI_df
= (0x1 << 22) | (0x00 << 16) | OPC_MSA_ELM
,
1289 OPC_CFCMSA
= (0x1 << 22) | (0x3E << 16) | OPC_MSA_ELM
,
1290 OPC_COPY_S_df
= (0x2 << 22) | (0x00 << 16) | OPC_MSA_ELM
,
1291 OPC_MOVE_V
= (0x2 << 22) | (0x3E << 16) | OPC_MSA_ELM
,
1292 OPC_COPY_U_df
= (0x3 << 22) | (0x00 << 16) | OPC_MSA_ELM
,
1293 OPC_INSERT_df
= (0x4 << 22) | (0x00 << 16) | OPC_MSA_ELM
,
1294 OPC_INSVE_df
= (0x5 << 22) | (0x00 << 16) | OPC_MSA_ELM
,
1296 /* 3RF instruction _df(bit 21) = _w, _d */
1297 OPC_FCAF_df
= (0x0 << 22) | OPC_MSA_3RF_1A
,
1298 OPC_FADD_df
= (0x0 << 22) | OPC_MSA_3RF_1B
,
1299 OPC_FCUN_df
= (0x1 << 22) | OPC_MSA_3RF_1A
,
1300 OPC_FSUB_df
= (0x1 << 22) | OPC_MSA_3RF_1B
,
1301 OPC_FCOR_df
= (0x1 << 22) | OPC_MSA_3RF_1C
,
1302 OPC_FCEQ_df
= (0x2 << 22) | OPC_MSA_3RF_1A
,
1303 OPC_FMUL_df
= (0x2 << 22) | OPC_MSA_3RF_1B
,
1304 OPC_FCUNE_df
= (0x2 << 22) | OPC_MSA_3RF_1C
,
1305 OPC_FCUEQ_df
= (0x3 << 22) | OPC_MSA_3RF_1A
,
1306 OPC_FDIV_df
= (0x3 << 22) | OPC_MSA_3RF_1B
,
1307 OPC_FCNE_df
= (0x3 << 22) | OPC_MSA_3RF_1C
,
1308 OPC_FCLT_df
= (0x4 << 22) | OPC_MSA_3RF_1A
,
1309 OPC_FMADD_df
= (0x4 << 22) | OPC_MSA_3RF_1B
,
1310 OPC_MUL_Q_df
= (0x4 << 22) | OPC_MSA_3RF_1C
,
1311 OPC_FCULT_df
= (0x5 << 22) | OPC_MSA_3RF_1A
,
1312 OPC_FMSUB_df
= (0x5 << 22) | OPC_MSA_3RF_1B
,
1313 OPC_MADD_Q_df
= (0x5 << 22) | OPC_MSA_3RF_1C
,
1314 OPC_FCLE_df
= (0x6 << 22) | OPC_MSA_3RF_1A
,
1315 OPC_MSUB_Q_df
= (0x6 << 22) | OPC_MSA_3RF_1C
,
1316 OPC_FCULE_df
= (0x7 << 22) | OPC_MSA_3RF_1A
,
1317 OPC_FEXP2_df
= (0x7 << 22) | OPC_MSA_3RF_1B
,
1318 OPC_FSAF_df
= (0x8 << 22) | OPC_MSA_3RF_1A
,
1319 OPC_FEXDO_df
= (0x8 << 22) | OPC_MSA_3RF_1B
,
1320 OPC_FSUN_df
= (0x9 << 22) | OPC_MSA_3RF_1A
,
1321 OPC_FSOR_df
= (0x9 << 22) | OPC_MSA_3RF_1C
,
1322 OPC_FSEQ_df
= (0xA << 22) | OPC_MSA_3RF_1A
,
1323 OPC_FTQ_df
= (0xA << 22) | OPC_MSA_3RF_1B
,
1324 OPC_FSUNE_df
= (0xA << 22) | OPC_MSA_3RF_1C
,
1325 OPC_FSUEQ_df
= (0xB << 22) | OPC_MSA_3RF_1A
,
1326 OPC_FSNE_df
= (0xB << 22) | OPC_MSA_3RF_1C
,
1327 OPC_FSLT_df
= (0xC << 22) | OPC_MSA_3RF_1A
,
1328 OPC_FMIN_df
= (0xC << 22) | OPC_MSA_3RF_1B
,
1329 OPC_MULR_Q_df
= (0xC << 22) | OPC_MSA_3RF_1C
,
1330 OPC_FSULT_df
= (0xD << 22) | OPC_MSA_3RF_1A
,
1331 OPC_FMIN_A_df
= (0xD << 22) | OPC_MSA_3RF_1B
,
1332 OPC_MADDR_Q_df
= (0xD << 22) | OPC_MSA_3RF_1C
,
1333 OPC_FSLE_df
= (0xE << 22) | OPC_MSA_3RF_1A
,
1334 OPC_FMAX_df
= (0xE << 22) | OPC_MSA_3RF_1B
,
1335 OPC_MSUBR_Q_df
= (0xE << 22) | OPC_MSA_3RF_1C
,
1336 OPC_FSULE_df
= (0xF << 22) | OPC_MSA_3RF_1A
,
1337 OPC_FMAX_A_df
= (0xF << 22) | OPC_MSA_3RF_1B
,
1339 /* BIT instruction df(bits 22..16) = _B _H _W _D */
1340 OPC_SLLI_df
= (0x0 << 23) | OPC_MSA_BIT_09
,
1341 OPC_SAT_S_df
= (0x0 << 23) | OPC_MSA_BIT_0A
,
1342 OPC_SRAI_df
= (0x1 << 23) | OPC_MSA_BIT_09
,
1343 OPC_SAT_U_df
= (0x1 << 23) | OPC_MSA_BIT_0A
,
1344 OPC_SRLI_df
= (0x2 << 23) | OPC_MSA_BIT_09
,
1345 OPC_SRARI_df
= (0x2 << 23) | OPC_MSA_BIT_0A
,
1346 OPC_BCLRI_df
= (0x3 << 23) | OPC_MSA_BIT_09
,
1347 OPC_SRLRI_df
= (0x3 << 23) | OPC_MSA_BIT_0A
,
1348 OPC_BSETI_df
= (0x4 << 23) | OPC_MSA_BIT_09
,
1349 OPC_BNEGI_df
= (0x5 << 23) | OPC_MSA_BIT_09
,
1350 OPC_BINSLI_df
= (0x6 << 23) | OPC_MSA_BIT_09
,
1351 OPC_BINSRI_df
= (0x7 << 23) | OPC_MSA_BIT_09
,
1354 /* global register indices */
1355 static TCGv_ptr cpu_env
;
1356 static TCGv cpu_gpr
[32], cpu_PC
;
1357 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
];
1358 static TCGv cpu_dspctrl
, btarget
, bcond
;
1359 static TCGv_i32 hflags
;
1360 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
1361 static TCGv_i64 fpu_f64
[32];
1362 static TCGv_i64 msa_wr_d
[64];
1364 static uint32_t gen_opc_hflags
[OPC_BUF_SIZE
];
1365 static target_ulong gen_opc_btarget
[OPC_BUF_SIZE
];
1367 #include "exec/gen-icount.h"
1369 #define gen_helper_0e0i(name, arg) do { \
1370 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
1371 gen_helper_##name(cpu_env, helper_tmp); \
1372 tcg_temp_free_i32(helper_tmp); \
1375 #define gen_helper_0e1i(name, arg1, arg2) do { \
1376 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
1377 gen_helper_##name(cpu_env, arg1, helper_tmp); \
1378 tcg_temp_free_i32(helper_tmp); \
1381 #define gen_helper_1e0i(name, ret, arg1) do { \
1382 TCGv_i32 helper_tmp = tcg_const_i32(arg1); \
1383 gen_helper_##name(ret, cpu_env, helper_tmp); \
1384 tcg_temp_free_i32(helper_tmp); \
1387 #define gen_helper_1e1i(name, ret, arg1, arg2) do { \
1388 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
1389 gen_helper_##name(ret, cpu_env, arg1, helper_tmp); \
1390 tcg_temp_free_i32(helper_tmp); \
1393 #define gen_helper_0e2i(name, arg1, arg2, arg3) do { \
1394 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
1395 gen_helper_##name(cpu_env, arg1, arg2, helper_tmp); \
1396 tcg_temp_free_i32(helper_tmp); \
1399 #define gen_helper_1e2i(name, ret, arg1, arg2, arg3) do { \
1400 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
1401 gen_helper_##name(ret, cpu_env, arg1, arg2, helper_tmp); \
1402 tcg_temp_free_i32(helper_tmp); \
1405 #define gen_helper_0e3i(name, arg1, arg2, arg3, arg4) do { \
1406 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
1407 gen_helper_##name(cpu_env, arg1, arg2, arg3, helper_tmp); \
1408 tcg_temp_free_i32(helper_tmp); \
1411 typedef struct DisasContext
{
1412 struct TranslationBlock
*tb
;
1413 target_ulong pc
, saved_pc
;
1415 int singlestep_enabled
;
1417 int32_t CP0_Config1
;
1418 /* Routine used to access memory */
1420 TCGMemOp default_tcg_memop_mask
;
1421 uint32_t hflags
, saved_hflags
;
1423 target_ulong btarget
;
1432 int CP0_LLAddr_shift
;
1437 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
1438 * exception condition */
1439 BS_STOP
= 1, /* We want to stop translation for any reason */
1440 BS_BRANCH
= 2, /* We reached a branch condition */
1441 BS_EXCP
= 3, /* We reached an exception condition */
1444 static const char * const regnames
[] = {
1445 "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
1446 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
1447 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
1448 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
1451 static const char * const regnames_HI
[] = {
1452 "HI0", "HI1", "HI2", "HI3",
1455 static const char * const regnames_LO
[] = {
1456 "LO0", "LO1", "LO2", "LO3",
1459 static const char * const fregnames
[] = {
1460 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
1461 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
1462 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
1463 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
1466 static const char * const msaregnames
[] = {
1467 "w0.d0", "w0.d1", "w1.d0", "w1.d1",
1468 "w2.d0", "w2.d1", "w3.d0", "w3.d1",
1469 "w4.d0", "w4.d1", "w5.d0", "w5.d1",
1470 "w6.d0", "w6.d1", "w7.d0", "w7.d1",
1471 "w8.d0", "w8.d1", "w9.d0", "w9.d1",
1472 "w10.d0", "w10.d1", "w11.d0", "w11.d1",
1473 "w12.d0", "w12.d1", "w13.d0", "w13.d1",
1474 "w14.d0", "w14.d1", "w15.d0", "w15.d1",
1475 "w16.d0", "w16.d1", "w17.d0", "w17.d1",
1476 "w18.d0", "w18.d1", "w19.d0", "w19.d1",
1477 "w20.d0", "w20.d1", "w21.d0", "w21.d1",
1478 "w22.d0", "w22.d1", "w23.d0", "w23.d1",
1479 "w24.d0", "w24.d1", "w25.d0", "w25.d1",
1480 "w26.d0", "w26.d1", "w27.d0", "w27.d1",
1481 "w28.d0", "w28.d1", "w29.d0", "w29.d1",
1482 "w30.d0", "w30.d1", "w31.d0", "w31.d1",
1485 #define MIPS_DEBUG(fmt, ...) \
1487 if (MIPS_DEBUG_DISAS) { \
1488 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
1489 TARGET_FMT_lx ": %08x " fmt "\n", \
1490 ctx->pc, ctx->opcode , ## __VA_ARGS__); \
1494 #define LOG_DISAS(...) \
1496 if (MIPS_DEBUG_DISAS) { \
1497 qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \
1501 #define MIPS_INVAL(op) \
1502 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
1503 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F))
1505 /* General purpose registers moves. */
1506 static inline void gen_load_gpr (TCGv t
, int reg
)
1509 tcg_gen_movi_tl(t
, 0);
1511 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
1514 static inline void gen_store_gpr (TCGv t
, int reg
)
1517 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
1520 /* Moves to/from shadow registers. */
1521 static inline void gen_load_srsgpr (int from
, int to
)
1523 TCGv t0
= tcg_temp_new();
1526 tcg_gen_movi_tl(t0
, 0);
1528 TCGv_i32 t2
= tcg_temp_new_i32();
1529 TCGv_ptr addr
= tcg_temp_new_ptr();
1531 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
1532 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
1533 tcg_gen_andi_i32(t2
, t2
, 0xf);
1534 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
1535 tcg_gen_ext_i32_ptr(addr
, t2
);
1536 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
1538 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
1539 tcg_temp_free_ptr(addr
);
1540 tcg_temp_free_i32(t2
);
1542 gen_store_gpr(t0
, to
);
1546 static inline void gen_store_srsgpr (int from
, int to
)
1549 TCGv t0
= tcg_temp_new();
1550 TCGv_i32 t2
= tcg_temp_new_i32();
1551 TCGv_ptr addr
= tcg_temp_new_ptr();
1553 gen_load_gpr(t0
, from
);
1554 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
1555 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
1556 tcg_gen_andi_i32(t2
, t2
, 0xf);
1557 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
1558 tcg_gen_ext_i32_ptr(addr
, t2
);
1559 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
1561 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
1562 tcg_temp_free_ptr(addr
);
1563 tcg_temp_free_i32(t2
);
1569 static inline void gen_save_pc(target_ulong pc
)
1571 tcg_gen_movi_tl(cpu_PC
, pc
);
1574 static inline void save_cpu_state(DisasContext
*ctx
, int do_save_pc
)
1576 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
1577 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
1578 gen_save_pc(ctx
->pc
);
1579 ctx
->saved_pc
= ctx
->pc
;
1581 if (ctx
->hflags
!= ctx
->saved_hflags
) {
1582 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
1583 ctx
->saved_hflags
= ctx
->hflags
;
1584 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
1590 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
1596 static inline void restore_cpu_state(CPUMIPSState
*env
, DisasContext
*ctx
)
1598 ctx
->saved_hflags
= ctx
->hflags
;
1599 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
1605 ctx
->btarget
= env
->btarget
;
1610 static inline void generate_exception_err(DisasContext
*ctx
, int excp
, int err
)
1612 TCGv_i32 texcp
= tcg_const_i32(excp
);
1613 TCGv_i32 terr
= tcg_const_i32(err
);
1614 save_cpu_state(ctx
, 1);
1615 gen_helper_raise_exception_err(cpu_env
, texcp
, terr
);
1616 tcg_temp_free_i32(terr
);
1617 tcg_temp_free_i32(texcp
);
1620 static inline void generate_exception(DisasContext
*ctx
, int excp
)
1622 save_cpu_state(ctx
, 1);
1623 gen_helper_0e0i(raise_exception
, excp
);
1626 /* Floating point register moves. */
1627 static void gen_load_fpr32(DisasContext
*ctx
, TCGv_i32 t
, int reg
)
1629 if (ctx
->hflags
& MIPS_HFLAG_FRE
) {
1630 generate_exception(ctx
, EXCP_RI
);
1632 tcg_gen_trunc_i64_i32(t
, fpu_f64
[reg
]);
1635 static void gen_store_fpr32(DisasContext
*ctx
, TCGv_i32 t
, int reg
)
1638 if (ctx
->hflags
& MIPS_HFLAG_FRE
) {
1639 generate_exception(ctx
, EXCP_RI
);
1641 t64
= tcg_temp_new_i64();
1642 tcg_gen_extu_i32_i64(t64
, t
);
1643 tcg_gen_deposit_i64(fpu_f64
[reg
], fpu_f64
[reg
], t64
, 0, 32);
1644 tcg_temp_free_i64(t64
);
1647 static void gen_load_fpr32h(DisasContext
*ctx
, TCGv_i32 t
, int reg
)
1649 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
1650 TCGv_i64 t64
= tcg_temp_new_i64();
1651 tcg_gen_shri_i64(t64
, fpu_f64
[reg
], 32);
1652 tcg_gen_trunc_i64_i32(t
, t64
);
1653 tcg_temp_free_i64(t64
);
1655 gen_load_fpr32(ctx
, t
, reg
| 1);
1659 static void gen_store_fpr32h(DisasContext
*ctx
, TCGv_i32 t
, int reg
)
1661 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
1662 TCGv_i64 t64
= tcg_temp_new_i64();
1663 tcg_gen_extu_i32_i64(t64
, t
);
1664 tcg_gen_deposit_i64(fpu_f64
[reg
], fpu_f64
[reg
], t64
, 32, 32);
1665 tcg_temp_free_i64(t64
);
1667 gen_store_fpr32(ctx
, t
, reg
| 1);
1671 static void gen_load_fpr64(DisasContext
*ctx
, TCGv_i64 t
, int reg
)
1673 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
1674 tcg_gen_mov_i64(t
, fpu_f64
[reg
]);
1676 tcg_gen_concat32_i64(t
, fpu_f64
[reg
& ~1], fpu_f64
[reg
| 1]);
1680 static void gen_store_fpr64(DisasContext
*ctx
, TCGv_i64 t
, int reg
)
1682 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
1683 tcg_gen_mov_i64(fpu_f64
[reg
], t
);
1686 tcg_gen_deposit_i64(fpu_f64
[reg
& ~1], fpu_f64
[reg
& ~1], t
, 0, 32);
1687 t0
= tcg_temp_new_i64();
1688 tcg_gen_shri_i64(t0
, t
, 32);
1689 tcg_gen_deposit_i64(fpu_f64
[reg
| 1], fpu_f64
[reg
| 1], t0
, 0, 32);
1690 tcg_temp_free_i64(t0
);
1694 static inline int get_fp_bit (int cc
)
1702 /* Addresses computation */
1703 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
1705 tcg_gen_add_tl(ret
, arg0
, arg1
);
1707 #if defined(TARGET_MIPS64)
1708 if (ctx
->hflags
& MIPS_HFLAG_AWRAP
) {
1709 tcg_gen_ext32s_i64(ret
, ret
);
1714 /* Addresses computation (translation time) */
1715 static target_long
addr_add(DisasContext
*ctx
, target_long base
,
1718 target_long sum
= base
+ offset
;
1720 #if defined(TARGET_MIPS64)
1721 if (ctx
->hflags
& MIPS_HFLAG_AWRAP
) {
1728 static inline void gen_move_low32(TCGv ret
, TCGv_i64 arg
)
1730 #if defined(TARGET_MIPS64)
1731 tcg_gen_ext32s_tl(ret
, arg
);
1733 tcg_gen_trunc_i64_tl(ret
, arg
);
1737 static inline void check_cp0_enabled(DisasContext
*ctx
)
1739 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
1740 generate_exception_err(ctx
, EXCP_CpU
, 0);
1743 static inline void check_cp1_enabled(DisasContext
*ctx
)
1745 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
1746 generate_exception_err(ctx
, EXCP_CpU
, 1);
1749 /* Verify that the processor is running with COP1X instructions enabled.
1750 This is associated with the nabla symbol in the MIPS32 and MIPS64
1753 static inline void check_cop1x(DisasContext
*ctx
)
1755 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
1756 generate_exception(ctx
, EXCP_RI
);
1759 /* Verify that the processor is running with 64-bit floating-point
1760 operations enabled. */
1762 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
1764 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
1765 generate_exception(ctx
, EXCP_RI
);
1769 * Verify if floating point register is valid; an operation is not defined
1770 * if bit 0 of any register specification is set and the FR bit in the
1771 * Status register equals zero, since the register numbers specify an
1772 * even-odd pair of adjacent coprocessor general registers. When the FR bit
1773 * in the Status register equals one, both even and odd register numbers
1774 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
1776 * Multiple 64 bit wide registers can be checked by calling
1777 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
1779 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
1781 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
1782 generate_exception(ctx
, EXCP_RI
);
1785 /* Verify that the processor is running with DSP instructions enabled.
1786 This is enabled by CP0 Status register MX(24) bit.
1789 static inline void check_dsp(DisasContext
*ctx
)
1791 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_DSP
))) {
1792 if (ctx
->insn_flags
& ASE_DSP
) {
1793 generate_exception(ctx
, EXCP_DSPDIS
);
1795 generate_exception(ctx
, EXCP_RI
);
1800 static inline void check_dspr2(DisasContext
*ctx
)
1802 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_DSPR2
))) {
1803 if (ctx
->insn_flags
& ASE_DSP
) {
1804 generate_exception(ctx
, EXCP_DSPDIS
);
1806 generate_exception(ctx
, EXCP_RI
);
1811 /* This code generates a "reserved instruction" exception if the
1812 CPU does not support the instruction set corresponding to flags. */
1813 static inline void check_insn(DisasContext
*ctx
, int flags
)
1815 if (unlikely(!(ctx
->insn_flags
& flags
))) {
1816 generate_exception(ctx
, EXCP_RI
);
1820 /* This code generates a "reserved instruction" exception if the
1821 CPU has corresponding flag set which indicates that the instruction
1822 has been removed. */
1823 static inline void check_insn_opc_removed(DisasContext
*ctx
, int flags
)
1825 if (unlikely(ctx
->insn_flags
& flags
)) {
1826 generate_exception(ctx
, EXCP_RI
);
1830 /* This code generates a "reserved instruction" exception if the
1831 CPU does not support 64-bit paired-single (PS) floating point data type */
1832 static inline void check_ps(DisasContext
*ctx
)
1834 if (unlikely(!ctx
->ps
)) {
1835 generate_exception(ctx
, EXCP_RI
);
1837 check_cp1_64bitmode(ctx
);
1840 #ifdef TARGET_MIPS64
1841 /* This code generates a "reserved instruction" exception if 64-bit
1842 instructions are not enabled. */
1843 static inline void check_mips_64(DisasContext
*ctx
)
1845 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
1846 generate_exception(ctx
, EXCP_RI
);
1850 #ifndef CONFIG_USER_ONLY
1851 static inline void check_mvh(DisasContext
*ctx
)
1853 if (unlikely(!ctx
->mvh
)) {
1854 generate_exception(ctx
, EXCP_RI
);
1859 /* Define small wrappers for gen_load_fpr* so that we have a uniform
1860 calling interface for 32 and 64-bit FPRs. No sense in changing
1861 all callers for gen_load_fpr32 when we need the CTX parameter for
1863 #define gen_ldcmp_fpr32(ctx, x, y) gen_load_fpr32(ctx, x, y)
1864 #define gen_ldcmp_fpr64(ctx, x, y) gen_load_fpr64(ctx, x, y)
1865 #define FOP_CONDS(type, abs, fmt, ifmt, bits) \
1866 static inline void gen_cmp ## type ## _ ## fmt(DisasContext *ctx, int n, \
1867 int ft, int fs, int cc) \
1869 TCGv_i##bits fp0 = tcg_temp_new_i##bits (); \
1870 TCGv_i##bits fp1 = tcg_temp_new_i##bits (); \
1879 check_cp1_registers(ctx, fs | ft); \
1887 gen_ldcmp_fpr##bits (ctx, fp0, fs); \
1888 gen_ldcmp_fpr##bits (ctx, fp1, ft); \
1890 case 0: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _f, fp0, fp1, cc); break;\
1891 case 1: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _un, fp0, fp1, cc); break;\
1892 case 2: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _eq, fp0, fp1, cc); break;\
1893 case 3: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ueq, fp0, fp1, cc); break;\
1894 case 4: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _olt, fp0, fp1, cc); break;\
1895 case 5: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ult, fp0, fp1, cc); break;\
1896 case 6: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ole, fp0, fp1, cc); break;\
1897 case 7: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ule, fp0, fp1, cc); break;\
1898 case 8: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _sf, fp0, fp1, cc); break;\
1899 case 9: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngle, fp0, fp1, cc); break;\
1900 case 10: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _seq, fp0, fp1, cc); break;\
1901 case 11: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngl, fp0, fp1, cc); break;\
1902 case 12: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _lt, fp0, fp1, cc); break;\
1903 case 13: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _nge, fp0, fp1, cc); break;\
1904 case 14: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _le, fp0, fp1, cc); break;\
1905 case 15: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngt, fp0, fp1, cc); break;\
1908 tcg_temp_free_i##bits (fp0); \
1909 tcg_temp_free_i##bits (fp1); \
1912 FOP_CONDS(, 0, d
, FMT_D
, 64)
1913 FOP_CONDS(abs
, 1, d
, FMT_D
, 64)
1914 FOP_CONDS(, 0, s
, FMT_S
, 32)
1915 FOP_CONDS(abs
, 1, s
, FMT_S
, 32)
1916 FOP_CONDS(, 0, ps
, FMT_PS
, 64)
1917 FOP_CONDS(abs
, 1, ps
, FMT_PS
, 64)
1920 #define FOP_CONDNS(fmt, ifmt, bits, STORE) \
1921 static inline void gen_r6_cmp_ ## fmt(DisasContext * ctx, int n, \
1922 int ft, int fs, int fd) \
1924 TCGv_i ## bits fp0 = tcg_temp_new_i ## bits(); \
1925 TCGv_i ## bits fp1 = tcg_temp_new_i ## bits(); \
1926 if (ifmt == FMT_D) { \
1927 check_cp1_registers(ctx, fs | ft | fd); \
1929 gen_ldcmp_fpr ## bits(ctx, fp0, fs); \
1930 gen_ldcmp_fpr ## bits(ctx, fp1, ft); \
1933 gen_helper_r6_cmp_ ## fmt ## _af(fp0, cpu_env, fp0, fp1); \
1936 gen_helper_r6_cmp_ ## fmt ## _un(fp0, cpu_env, fp0, fp1); \
1939 gen_helper_r6_cmp_ ## fmt ## _eq(fp0, cpu_env, fp0, fp1); \
1942 gen_helper_r6_cmp_ ## fmt ## _ueq(fp0, cpu_env, fp0, fp1); \
1945 gen_helper_r6_cmp_ ## fmt ## _lt(fp0, cpu_env, fp0, fp1); \
1948 gen_helper_r6_cmp_ ## fmt ## _ult(fp0, cpu_env, fp0, fp1); \
1951 gen_helper_r6_cmp_ ## fmt ## _le(fp0, cpu_env, fp0, fp1); \
1954 gen_helper_r6_cmp_ ## fmt ## _ule(fp0, cpu_env, fp0, fp1); \
1957 gen_helper_r6_cmp_ ## fmt ## _saf(fp0, cpu_env, fp0, fp1); \
1960 gen_helper_r6_cmp_ ## fmt ## _sun(fp0, cpu_env, fp0, fp1); \
1963 gen_helper_r6_cmp_ ## fmt ## _seq(fp0, cpu_env, fp0, fp1); \
1966 gen_helper_r6_cmp_ ## fmt ## _sueq(fp0, cpu_env, fp0, fp1); \
1969 gen_helper_r6_cmp_ ## fmt ## _slt(fp0, cpu_env, fp0, fp1); \
1972 gen_helper_r6_cmp_ ## fmt ## _sult(fp0, cpu_env, fp0, fp1); \
1975 gen_helper_r6_cmp_ ## fmt ## _sle(fp0, cpu_env, fp0, fp1); \
1978 gen_helper_r6_cmp_ ## fmt ## _sule(fp0, cpu_env, fp0, fp1); \
1981 gen_helper_r6_cmp_ ## fmt ## _or(fp0, cpu_env, fp0, fp1); \
1984 gen_helper_r6_cmp_ ## fmt ## _une(fp0, cpu_env, fp0, fp1); \
1987 gen_helper_r6_cmp_ ## fmt ## _ne(fp0, cpu_env, fp0, fp1); \
1990 gen_helper_r6_cmp_ ## fmt ## _sor(fp0, cpu_env, fp0, fp1); \
1993 gen_helper_r6_cmp_ ## fmt ## _sune(fp0, cpu_env, fp0, fp1); \
1996 gen_helper_r6_cmp_ ## fmt ## _sne(fp0, cpu_env, fp0, fp1); \
2002 tcg_temp_free_i ## bits (fp0); \
2003 tcg_temp_free_i ## bits (fp1); \
2006 FOP_CONDNS(d
, FMT_D
, 64, gen_store_fpr64(ctx
, fp0
, fd
))
2007 FOP_CONDNS(s
, FMT_S
, 32, gen_store_fpr32(ctx
, fp0
, fd
))
2009 #undef gen_ldcmp_fpr32
2010 #undef gen_ldcmp_fpr64
2012 /* load/store instructions. */
2013 #ifdef CONFIG_USER_ONLY
2014 #define OP_LD_ATOMIC(insn,fname) \
2015 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
2017 TCGv t0 = tcg_temp_new(); \
2018 tcg_gen_mov_tl(t0, arg1); \
2019 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
2020 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUMIPSState, lladdr)); \
2021 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUMIPSState, llval)); \
2022 tcg_temp_free(t0); \
2025 #define OP_LD_ATOMIC(insn,fname) \
2026 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
2028 gen_helper_1e1i(insn, ret, arg1, ctx->mem_idx); \
2031 OP_LD_ATOMIC(ll
,ld32s
);
2032 #if defined(TARGET_MIPS64)
2033 OP_LD_ATOMIC(lld
,ld64
);
2037 #ifdef CONFIG_USER_ONLY
2038 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
2039 static inline void op_st_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
2041 TCGv t0 = tcg_temp_new(); \
2042 TCGLabel *l1 = gen_new_label(); \
2043 TCGLabel *l2 = gen_new_label(); \
2045 tcg_gen_andi_tl(t0, arg2, almask); \
2046 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
2047 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUMIPSState, CP0_BadVAddr)); \
2048 generate_exception(ctx, EXCP_AdES); \
2049 gen_set_label(l1); \
2050 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUMIPSState, lladdr)); \
2051 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
2052 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
2053 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUMIPSState, llreg)); \
2054 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUMIPSState, llnewval)); \
2055 gen_helper_0e0i(raise_exception, EXCP_SC); \
2056 gen_set_label(l2); \
2057 tcg_gen_movi_tl(t0, 0); \
2058 gen_store_gpr(t0, rt); \
2059 tcg_temp_free(t0); \
2062 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
2063 static inline void op_st_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
2065 TCGv t0 = tcg_temp_new(); \
2066 gen_helper_1e2i(insn, t0, arg1, arg2, ctx->mem_idx); \
2067 gen_store_gpr(t0, rt); \
2068 tcg_temp_free(t0); \
2071 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
2072 #if defined(TARGET_MIPS64)
2073 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
2077 static void gen_base_offset_addr (DisasContext
*ctx
, TCGv addr
,
2078 int base
, int16_t offset
)
2081 tcg_gen_movi_tl(addr
, offset
);
2082 } else if (offset
== 0) {
2083 gen_load_gpr(addr
, base
);
2085 tcg_gen_movi_tl(addr
, offset
);
2086 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
2090 static target_ulong
pc_relative_pc (DisasContext
*ctx
)
2092 target_ulong pc
= ctx
->pc
;
2094 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2095 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
2100 pc
&= ~(target_ulong
)3;
2105 static void gen_ld(DisasContext
*ctx
, uint32_t opc
,
2106 int rt
, int base
, int16_t offset
)
2108 const char *opn
= "ld";
2111 if (rt
== 0 && ctx
->insn_flags
& (INSN_LOONGSON2E
| INSN_LOONGSON2F
)) {
2112 /* Loongson CPU uses a load to zero register for prefetch.
2113 We emulate it as a NOP. On other CPU we must perform the
2114 actual memory access. */
2119 t0
= tcg_temp_new();
2120 gen_base_offset_addr(ctx
, t0
, base
, offset
);
2123 #if defined(TARGET_MIPS64)
2125 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEUL
|
2126 ctx
->default_tcg_memop_mask
);
2127 gen_store_gpr(t0
, rt
);
2131 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEQ
|
2132 ctx
->default_tcg_memop_mask
);
2133 gen_store_gpr(t0
, rt
);
2138 save_cpu_state(ctx
, 1);
2139 op_ld_lld(t0
, t0
, ctx
);
2140 gen_store_gpr(t0
, rt
);
2144 t1
= tcg_temp_new();
2145 tcg_gen_andi_tl(t1
, t0
, 7);
2146 #ifndef TARGET_WORDS_BIGENDIAN
2147 tcg_gen_xori_tl(t1
, t1
, 7);
2149 tcg_gen_shli_tl(t1
, t1
, 3);
2150 tcg_gen_andi_tl(t0
, t0
, ~7);
2151 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEQ
);
2152 tcg_gen_shl_tl(t0
, t0
, t1
);
2153 tcg_gen_xori_tl(t1
, t1
, 63);
2154 t2
= tcg_const_tl(0x7fffffffffffffffull
);
2155 tcg_gen_shr_tl(t2
, t2
, t1
);
2156 gen_load_gpr(t1
, rt
);
2157 tcg_gen_and_tl(t1
, t1
, t2
);
2159 tcg_gen_or_tl(t0
, t0
, t1
);
2161 gen_store_gpr(t0
, rt
);
2165 t1
= tcg_temp_new();
2166 tcg_gen_andi_tl(t1
, t0
, 7);
2167 #ifdef TARGET_WORDS_BIGENDIAN
2168 tcg_gen_xori_tl(t1
, t1
, 7);
2170 tcg_gen_shli_tl(t1
, t1
, 3);
2171 tcg_gen_andi_tl(t0
, t0
, ~7);
2172 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEQ
);
2173 tcg_gen_shr_tl(t0
, t0
, t1
);
2174 tcg_gen_xori_tl(t1
, t1
, 63);
2175 t2
= tcg_const_tl(0xfffffffffffffffeull
);
2176 tcg_gen_shl_tl(t2
, t2
, t1
);
2177 gen_load_gpr(t1
, rt
);
2178 tcg_gen_and_tl(t1
, t1
, t2
);
2180 tcg_gen_or_tl(t0
, t0
, t1
);
2182 gen_store_gpr(t0
, rt
);
2186 t1
= tcg_const_tl(pc_relative_pc(ctx
));
2187 gen_op_addr_add(ctx
, t0
, t0
, t1
);
2189 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEQ
);
2190 gen_store_gpr(t0
, rt
);
2195 t1
= tcg_const_tl(pc_relative_pc(ctx
));
2196 gen_op_addr_add(ctx
, t0
, t0
, t1
);
2198 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TESL
);
2199 gen_store_gpr(t0
, rt
);
2203 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TESL
|
2204 ctx
->default_tcg_memop_mask
);
2205 gen_store_gpr(t0
, rt
);
2209 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TESW
|
2210 ctx
->default_tcg_memop_mask
);
2211 gen_store_gpr(t0
, rt
);
2215 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEUW
|
2216 ctx
->default_tcg_memop_mask
);
2217 gen_store_gpr(t0
, rt
);
2221 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_SB
);
2222 gen_store_gpr(t0
, rt
);
2226 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_UB
);
2227 gen_store_gpr(t0
, rt
);
2231 t1
= tcg_temp_new();
2232 tcg_gen_andi_tl(t1
, t0
, 3);
2233 #ifndef TARGET_WORDS_BIGENDIAN
2234 tcg_gen_xori_tl(t1
, t1
, 3);
2236 tcg_gen_shli_tl(t1
, t1
, 3);
2237 tcg_gen_andi_tl(t0
, t0
, ~3);
2238 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEUL
);
2239 tcg_gen_shl_tl(t0
, t0
, t1
);
2240 tcg_gen_xori_tl(t1
, t1
, 31);
2241 t2
= tcg_const_tl(0x7fffffffull
);
2242 tcg_gen_shr_tl(t2
, t2
, t1
);
2243 gen_load_gpr(t1
, rt
);
2244 tcg_gen_and_tl(t1
, t1
, t2
);
2246 tcg_gen_or_tl(t0
, t0
, t1
);
2248 tcg_gen_ext32s_tl(t0
, t0
);
2249 gen_store_gpr(t0
, rt
);
2253 t1
= tcg_temp_new();
2254 tcg_gen_andi_tl(t1
, t0
, 3);
2255 #ifdef TARGET_WORDS_BIGENDIAN
2256 tcg_gen_xori_tl(t1
, t1
, 3);
2258 tcg_gen_shli_tl(t1
, t1
, 3);
2259 tcg_gen_andi_tl(t0
, t0
, ~3);
2260 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEUL
);
2261 tcg_gen_shr_tl(t0
, t0
, t1
);
2262 tcg_gen_xori_tl(t1
, t1
, 31);
2263 t2
= tcg_const_tl(0xfffffffeull
);
2264 tcg_gen_shl_tl(t2
, t2
, t1
);
2265 gen_load_gpr(t1
, rt
);
2266 tcg_gen_and_tl(t1
, t1
, t2
);
2268 tcg_gen_or_tl(t0
, t0
, t1
);
2270 tcg_gen_ext32s_tl(t0
, t0
);
2271 gen_store_gpr(t0
, rt
);
2276 save_cpu_state(ctx
, 1);
2277 op_ld_ll(t0
, t0
, ctx
);
2278 gen_store_gpr(t0
, rt
);
2282 (void)opn
; /* avoid a compiler warning */
2283 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
2288 static void gen_st (DisasContext
*ctx
, uint32_t opc
, int rt
,
2289 int base
, int16_t offset
)
2291 const char *opn
= "st";
2292 TCGv t0
= tcg_temp_new();
2293 TCGv t1
= tcg_temp_new();
2295 gen_base_offset_addr(ctx
, t0
, base
, offset
);
2296 gen_load_gpr(t1
, rt
);
2298 #if defined(TARGET_MIPS64)
2300 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEQ
|
2301 ctx
->default_tcg_memop_mask
);
2305 save_cpu_state(ctx
, 1);
2306 gen_helper_0e2i(sdl
, t1
, t0
, ctx
->mem_idx
);
2310 save_cpu_state(ctx
, 1);
2311 gen_helper_0e2i(sdr
, t1
, t0
, ctx
->mem_idx
);
2316 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEUL
|
2317 ctx
->default_tcg_memop_mask
);
2321 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEUW
|
2322 ctx
->default_tcg_memop_mask
);
2326 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_8
);
2330 save_cpu_state(ctx
, 1);
2331 gen_helper_0e2i(swl
, t1
, t0
, ctx
->mem_idx
);
2335 save_cpu_state(ctx
, 1);
2336 gen_helper_0e2i(swr
, t1
, t0
, ctx
->mem_idx
);
2340 (void)opn
; /* avoid a compiler warning */
2341 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
2347 /* Store conditional */
2348 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
2349 int base
, int16_t offset
)
2351 const char *opn
= "st_cond";
2354 #ifdef CONFIG_USER_ONLY
2355 t0
= tcg_temp_local_new();
2356 t1
= tcg_temp_local_new();
2358 t0
= tcg_temp_new();
2359 t1
= tcg_temp_new();
2361 gen_base_offset_addr(ctx
, t0
, base
, offset
);
2362 gen_load_gpr(t1
, rt
);
2364 #if defined(TARGET_MIPS64)
2367 save_cpu_state(ctx
, 1);
2368 op_st_scd(t1
, t0
, rt
, ctx
);
2374 save_cpu_state(ctx
, 1);
2375 op_st_sc(t1
, t0
, rt
, ctx
);
2379 (void)opn
; /* avoid a compiler warning */
2380 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
2385 /* Load and store */
2386 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
2387 int base
, int16_t offset
)
2389 const char *opn
= "flt_ldst";
2390 TCGv t0
= tcg_temp_new();
2392 gen_base_offset_addr(ctx
, t0
, base
, offset
);
2393 /* Don't do NOP if destination is zero: we must perform the actual
2398 TCGv_i32 fp0
= tcg_temp_new_i32();
2399 tcg_gen_qemu_ld_i32(fp0
, t0
, ctx
->mem_idx
, MO_TESL
|
2400 ctx
->default_tcg_memop_mask
);
2401 gen_store_fpr32(ctx
, fp0
, ft
);
2402 tcg_temp_free_i32(fp0
);
2408 TCGv_i32 fp0
= tcg_temp_new_i32();
2409 gen_load_fpr32(ctx
, fp0
, ft
);
2410 tcg_gen_qemu_st_i32(fp0
, t0
, ctx
->mem_idx
, MO_TEUL
|
2411 ctx
->default_tcg_memop_mask
);
2412 tcg_temp_free_i32(fp0
);
2418 TCGv_i64 fp0
= tcg_temp_new_i64();
2419 tcg_gen_qemu_ld_i64(fp0
, t0
, ctx
->mem_idx
, MO_TEQ
|
2420 ctx
->default_tcg_memop_mask
);
2421 gen_store_fpr64(ctx
, fp0
, ft
);
2422 tcg_temp_free_i64(fp0
);
2428 TCGv_i64 fp0
= tcg_temp_new_i64();
2429 gen_load_fpr64(ctx
, fp0
, ft
);
2430 tcg_gen_qemu_st_i64(fp0
, t0
, ctx
->mem_idx
, MO_TEQ
|
2431 ctx
->default_tcg_memop_mask
);
2432 tcg_temp_free_i64(fp0
);
2438 generate_exception(ctx
, EXCP_RI
);
2441 (void)opn
; /* avoid a compiler warning */
2442 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
2447 static void gen_cop1_ldst(DisasContext
*ctx
, uint32_t op
, int rt
,
2448 int rs
, int16_t imm
)
2450 if (ctx
->CP0_Config1
& (1 << CP0C1_FP
)) {
2451 check_cp1_enabled(ctx
);
2455 check_insn(ctx
, ISA_MIPS2
);
2458 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
2461 generate_exception_err(ctx
, EXCP_CpU
, 1);
2465 /* Arithmetic with immediate operand */
2466 static void gen_arith_imm(DisasContext
*ctx
, uint32_t opc
,
2467 int rt
, int rs
, int16_t imm
)
2469 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
2470 const char *opn
= "imm arith";
2472 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
2473 /* If no destination, treat it as a NOP.
2474 For addi, we must generate the overflow exception when needed. */
2481 TCGv t0
= tcg_temp_local_new();
2482 TCGv t1
= tcg_temp_new();
2483 TCGv t2
= tcg_temp_new();
2484 TCGLabel
*l1
= gen_new_label();
2486 gen_load_gpr(t1
, rs
);
2487 tcg_gen_addi_tl(t0
, t1
, uimm
);
2488 tcg_gen_ext32s_tl(t0
, t0
);
2490 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
2491 tcg_gen_xori_tl(t2
, t0
, uimm
);
2492 tcg_gen_and_tl(t1
, t1
, t2
);
2494 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2496 /* operands of same sign, result different sign */
2497 generate_exception(ctx
, EXCP_OVERFLOW
);
2499 tcg_gen_ext32s_tl(t0
, t0
);
2500 gen_store_gpr(t0
, rt
);
2507 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2508 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
2510 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
2514 #if defined(TARGET_MIPS64)
2517 TCGv t0
= tcg_temp_local_new();
2518 TCGv t1
= tcg_temp_new();
2519 TCGv t2
= tcg_temp_new();
2520 TCGLabel
*l1
= gen_new_label();
2522 gen_load_gpr(t1
, rs
);
2523 tcg_gen_addi_tl(t0
, t1
, uimm
);
2525 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
2526 tcg_gen_xori_tl(t2
, t0
, uimm
);
2527 tcg_gen_and_tl(t1
, t1
, t2
);
2529 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2531 /* operands of same sign, result different sign */
2532 generate_exception(ctx
, EXCP_OVERFLOW
);
2534 gen_store_gpr(t0
, rt
);
2541 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2543 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
2549 (void)opn
; /* avoid a compiler warning */
2550 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
2553 /* Logic with immediate operand */
2554 static void gen_logic_imm(DisasContext
*ctx
, uint32_t opc
,
2555 int rt
, int rs
, int16_t imm
)
2560 /* If no destination, treat it as a NOP. */
2564 uimm
= (uint16_t)imm
;
2567 if (likely(rs
!= 0))
2568 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2570 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
2571 MIPS_DEBUG("andi %s, %s, " TARGET_FMT_lx
, regnames
[rt
],
2572 regnames
[rs
], uimm
);
2576 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2578 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
2579 MIPS_DEBUG("ori %s, %s, " TARGET_FMT_lx
, regnames
[rt
],
2580 regnames
[rs
], uimm
);
2583 if (likely(rs
!= 0))
2584 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2586 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
2587 MIPS_DEBUG("xori %s, %s, " TARGET_FMT_lx
, regnames
[rt
],
2588 regnames
[rs
], uimm
);
2591 if (rs
!= 0 && (ctx
->insn_flags
& ISA_MIPS32R6
)) {
2593 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], imm
<< 16);
2594 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
2595 MIPS_DEBUG("aui %s, %s, %04x", regnames
[rt
], regnames
[rs
], imm
);
2597 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
2598 MIPS_DEBUG("lui %s, " TARGET_FMT_lx
, regnames
[rt
], uimm
);
2603 MIPS_DEBUG("Unknown logical immediate opcode %08x", opc
);
2608 /* Set on less than with immediate operand */
2609 static void gen_slt_imm(DisasContext
*ctx
, uint32_t opc
,
2610 int rt
, int rs
, int16_t imm
)
2612 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
2613 const char *opn
= "imm arith";
2617 /* If no destination, treat it as a NOP. */
2621 t0
= tcg_temp_new();
2622 gen_load_gpr(t0
, rs
);
2625 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
2629 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
2633 (void)opn
; /* avoid a compiler warning */
2634 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
2638 /* Shifts with immediate operand */
2639 static void gen_shift_imm(DisasContext
*ctx
, uint32_t opc
,
2640 int rt
, int rs
, int16_t imm
)
2642 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
2643 const char *opn
= "imm shift";
2647 /* If no destination, treat it as a NOP. */
2652 t0
= tcg_temp_new();
2653 gen_load_gpr(t0
, rs
);
2656 tcg_gen_shli_tl(t0
, t0
, uimm
);
2657 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
2661 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
2666 tcg_gen_ext32u_tl(t0
, t0
);
2667 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
2669 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
2675 TCGv_i32 t1
= tcg_temp_new_i32();
2677 tcg_gen_trunc_tl_i32(t1
, t0
);
2678 tcg_gen_rotri_i32(t1
, t1
, uimm
);
2679 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
2680 tcg_temp_free_i32(t1
);
2682 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
2686 #if defined(TARGET_MIPS64)
2688 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
2692 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
2696 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
2701 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
2703 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
2708 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
2712 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
2716 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
2720 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
2725 (void)opn
; /* avoid a compiler warning */
2726 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
2731 static void gen_arith(DisasContext
*ctx
, uint32_t opc
,
2732 int rd
, int rs
, int rt
)
2734 const char *opn
= "arith";
2736 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
2737 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
2738 /* If no destination, treat it as a NOP.
2739 For add & sub, we must generate the overflow exception when needed. */
2747 TCGv t0
= tcg_temp_local_new();
2748 TCGv t1
= tcg_temp_new();
2749 TCGv t2
= tcg_temp_new();
2750 TCGLabel
*l1
= gen_new_label();
2752 gen_load_gpr(t1
, rs
);
2753 gen_load_gpr(t2
, rt
);
2754 tcg_gen_add_tl(t0
, t1
, t2
);
2755 tcg_gen_ext32s_tl(t0
, t0
);
2756 tcg_gen_xor_tl(t1
, t1
, t2
);
2757 tcg_gen_xor_tl(t2
, t0
, t2
);
2758 tcg_gen_andc_tl(t1
, t2
, t1
);
2760 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2762 /* operands of same sign, result different sign */
2763 generate_exception(ctx
, EXCP_OVERFLOW
);
2765 gen_store_gpr(t0
, rd
);
2771 if (rs
!= 0 && rt
!= 0) {
2772 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2773 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2774 } else if (rs
== 0 && rt
!= 0) {
2775 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2776 } else if (rs
!= 0 && rt
== 0) {
2777 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2779 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2785 TCGv t0
= tcg_temp_local_new();
2786 TCGv t1
= tcg_temp_new();
2787 TCGv t2
= tcg_temp_new();
2788 TCGLabel
*l1
= gen_new_label();
2790 gen_load_gpr(t1
, rs
);
2791 gen_load_gpr(t2
, rt
);
2792 tcg_gen_sub_tl(t0
, t1
, t2
);
2793 tcg_gen_ext32s_tl(t0
, t0
);
2794 tcg_gen_xor_tl(t2
, t1
, t2
);
2795 tcg_gen_xor_tl(t1
, t0
, t1
);
2796 tcg_gen_and_tl(t1
, t1
, t2
);
2798 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2800 /* operands of different sign, first operand and result different sign */
2801 generate_exception(ctx
, EXCP_OVERFLOW
);
2803 gen_store_gpr(t0
, rd
);
2809 if (rs
!= 0 && rt
!= 0) {
2810 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2811 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2812 } else if (rs
== 0 && rt
!= 0) {
2813 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2814 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2815 } else if (rs
!= 0 && rt
== 0) {
2816 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2818 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2822 #if defined(TARGET_MIPS64)
2825 TCGv t0
= tcg_temp_local_new();
2826 TCGv t1
= tcg_temp_new();
2827 TCGv t2
= tcg_temp_new();
2828 TCGLabel
*l1
= gen_new_label();
2830 gen_load_gpr(t1
, rs
);
2831 gen_load_gpr(t2
, rt
);
2832 tcg_gen_add_tl(t0
, t1
, t2
);
2833 tcg_gen_xor_tl(t1
, t1
, t2
);
2834 tcg_gen_xor_tl(t2
, t0
, t2
);
2835 tcg_gen_andc_tl(t1
, t2
, t1
);
2837 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2839 /* operands of same sign, result different sign */
2840 generate_exception(ctx
, EXCP_OVERFLOW
);
2842 gen_store_gpr(t0
, rd
);
2848 if (rs
!= 0 && rt
!= 0) {
2849 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2850 } else if (rs
== 0 && rt
!= 0) {
2851 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2852 } else if (rs
!= 0 && rt
== 0) {
2853 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2855 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2861 TCGv t0
= tcg_temp_local_new();
2862 TCGv t1
= tcg_temp_new();
2863 TCGv t2
= tcg_temp_new();
2864 TCGLabel
*l1
= gen_new_label();
2866 gen_load_gpr(t1
, rs
);
2867 gen_load_gpr(t2
, rt
);
2868 tcg_gen_sub_tl(t0
, t1
, t2
);
2869 tcg_gen_xor_tl(t2
, t1
, t2
);
2870 tcg_gen_xor_tl(t1
, t0
, t1
);
2871 tcg_gen_and_tl(t1
, t1
, t2
);
2873 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2875 /* operands of different sign, first operand and result different sign */
2876 generate_exception(ctx
, EXCP_OVERFLOW
);
2878 gen_store_gpr(t0
, rd
);
2884 if (rs
!= 0 && rt
!= 0) {
2885 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2886 } else if (rs
== 0 && rt
!= 0) {
2887 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2888 } else if (rs
!= 0 && rt
== 0) {
2889 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2891 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2897 if (likely(rs
!= 0 && rt
!= 0)) {
2898 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2899 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2901 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2906 (void)opn
; /* avoid a compiler warning */
2907 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2910 /* Conditional move */
2911 static void gen_cond_move(DisasContext
*ctx
, uint32_t opc
,
2912 int rd
, int rs
, int rt
)
2914 const char *opn
= "cond move";
2918 /* If no destination, treat it as a NOP. */
2923 t0
= tcg_temp_new();
2924 gen_load_gpr(t0
, rt
);
2925 t1
= tcg_const_tl(0);
2926 t2
= tcg_temp_new();
2927 gen_load_gpr(t2
, rs
);
2930 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rd
], t0
, t1
, t2
, cpu_gpr
[rd
]);
2934 tcg_gen_movcond_tl(TCG_COND_EQ
, cpu_gpr
[rd
], t0
, t1
, t2
, cpu_gpr
[rd
]);
2938 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rd
], t0
, t1
, t2
, t1
);
2942 tcg_gen_movcond_tl(TCG_COND_EQ
, cpu_gpr
[rd
], t0
, t1
, t2
, t1
);
2950 (void)opn
; /* avoid a compiler warning */
2951 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2955 static void gen_logic(DisasContext
*ctx
, uint32_t opc
,
2956 int rd
, int rs
, int rt
)
2958 const char *opn
= "logic";
2961 /* If no destination, treat it as a NOP. */
2968 if (likely(rs
!= 0 && rt
!= 0)) {
2969 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2971 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2976 if (rs
!= 0 && rt
!= 0) {
2977 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2978 } else if (rs
== 0 && rt
!= 0) {
2979 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2980 } else if (rs
!= 0 && rt
== 0) {
2981 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2983 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
2988 if (likely(rs
!= 0 && rt
!= 0)) {
2989 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2990 } else if (rs
== 0 && rt
!= 0) {
2991 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2992 } else if (rs
!= 0 && rt
== 0) {
2993 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2995 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3000 if (likely(rs
!= 0 && rt
!= 0)) {
3001 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
3002 } else if (rs
== 0 && rt
!= 0) {
3003 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
3004 } else if (rs
!= 0 && rt
== 0) {
3005 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
3007 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3012 (void)opn
; /* avoid a compiler warning */
3013 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
3016 /* Set on lower than */
3017 static void gen_slt(DisasContext
*ctx
, uint32_t opc
,
3018 int rd
, int rs
, int rt
)
3020 const char *opn
= "slt";
3024 /* If no destination, treat it as a NOP. */
3029 t0
= tcg_temp_new();
3030 t1
= tcg_temp_new();
3031 gen_load_gpr(t0
, rs
);
3032 gen_load_gpr(t1
, rt
);
3035 tcg_gen_setcond_tl(TCG_COND_LT
, cpu_gpr
[rd
], t0
, t1
);
3039 tcg_gen_setcond_tl(TCG_COND_LTU
, cpu_gpr
[rd
], t0
, t1
);
3043 (void)opn
; /* avoid a compiler warning */
3044 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
3050 static void gen_shift(DisasContext
*ctx
, uint32_t opc
,
3051 int rd
, int rs
, int rt
)
3053 const char *opn
= "shifts";
3057 /* If no destination, treat it as a NOP.
3058 For add & sub, we must generate the overflow exception when needed. */
3063 t0
= tcg_temp_new();
3064 t1
= tcg_temp_new();
3065 gen_load_gpr(t0
, rs
);
3066 gen_load_gpr(t1
, rt
);
3069 tcg_gen_andi_tl(t0
, t0
, 0x1f);
3070 tcg_gen_shl_tl(t0
, t1
, t0
);
3071 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
3075 tcg_gen_andi_tl(t0
, t0
, 0x1f);
3076 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
3080 tcg_gen_ext32u_tl(t1
, t1
);
3081 tcg_gen_andi_tl(t0
, t0
, 0x1f);
3082 tcg_gen_shr_tl(t0
, t1
, t0
);
3083 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
3088 TCGv_i32 t2
= tcg_temp_new_i32();
3089 TCGv_i32 t3
= tcg_temp_new_i32();
3091 tcg_gen_trunc_tl_i32(t2
, t0
);
3092 tcg_gen_trunc_tl_i32(t3
, t1
);
3093 tcg_gen_andi_i32(t2
, t2
, 0x1f);
3094 tcg_gen_rotr_i32(t2
, t3
, t2
);
3095 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
3096 tcg_temp_free_i32(t2
);
3097 tcg_temp_free_i32(t3
);
3101 #if defined(TARGET_MIPS64)
3103 tcg_gen_andi_tl(t0
, t0
, 0x3f);
3104 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
3108 tcg_gen_andi_tl(t0
, t0
, 0x3f);
3109 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
3113 tcg_gen_andi_tl(t0
, t0
, 0x3f);
3114 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
3118 tcg_gen_andi_tl(t0
, t0
, 0x3f);
3119 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
3124 (void)opn
; /* avoid a compiler warning */
3125 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
3130 /* Arithmetic on HI/LO registers */
3131 static void gen_HILO(DisasContext
*ctx
, uint32_t opc
, int acc
, int reg
)
3133 const char *opn
= "hilo";
3135 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
3147 #if defined(TARGET_MIPS64)
3149 tcg_gen_ext32s_tl(cpu_gpr
[reg
], cpu_HI
[acc
]);
3153 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[acc
]);
3158 #if defined(TARGET_MIPS64)
3160 tcg_gen_ext32s_tl(cpu_gpr
[reg
], cpu_LO
[acc
]);
3164 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[acc
]);
3170 #if defined(TARGET_MIPS64)
3172 tcg_gen_ext32s_tl(cpu_HI
[acc
], cpu_gpr
[reg
]);
3176 tcg_gen_mov_tl(cpu_HI
[acc
], cpu_gpr
[reg
]);
3179 tcg_gen_movi_tl(cpu_HI
[acc
], 0);
3185 #if defined(TARGET_MIPS64)
3187 tcg_gen_ext32s_tl(cpu_LO
[acc
], cpu_gpr
[reg
]);
3191 tcg_gen_mov_tl(cpu_LO
[acc
], cpu_gpr
[reg
]);
3194 tcg_gen_movi_tl(cpu_LO
[acc
], 0);
3199 (void)opn
; /* avoid a compiler warning */
3200 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
3203 static inline void gen_r6_ld(target_long addr
, int reg
, int memidx
,
3206 TCGv t0
= tcg_const_tl(addr
);
3207 tcg_gen_qemu_ld_tl(t0
, t0
, memidx
, memop
);
3208 gen_store_gpr(t0
, reg
);
3212 static inline void gen_pcrel(DisasContext
*ctx
, int opc
, target_ulong pc
,
3218 switch (MASK_OPC_PCREL_TOP2BITS(opc
)) {
3221 offset
= sextract32(ctx
->opcode
<< 2, 0, 21);
3222 addr
= addr_add(ctx
, pc
, offset
);
3223 tcg_gen_movi_tl(cpu_gpr
[rs
], addr
);
3227 offset
= sextract32(ctx
->opcode
<< 2, 0, 21);
3228 addr
= addr_add(ctx
, pc
, offset
);
3229 gen_r6_ld(addr
, rs
, ctx
->mem_idx
, MO_TESL
);
3231 #if defined(TARGET_MIPS64)
3234 offset
= sextract32(ctx
->opcode
<< 2, 0, 21);
3235 addr
= addr_add(ctx
, pc
, offset
);
3236 gen_r6_ld(addr
, rs
, ctx
->mem_idx
, MO_TEUL
);
3240 switch (MASK_OPC_PCREL_TOP5BITS(opc
)) {
3243 offset
= sextract32(ctx
->opcode
, 0, 16) << 16;
3244 addr
= addr_add(ctx
, pc
, offset
);
3245 tcg_gen_movi_tl(cpu_gpr
[rs
], addr
);
3250 offset
= sextract32(ctx
->opcode
, 0, 16) << 16;
3251 addr
= ~0xFFFF & addr_add(ctx
, pc
, offset
);
3252 tcg_gen_movi_tl(cpu_gpr
[rs
], addr
);
3255 #if defined(TARGET_MIPS64)
3256 case R6_OPC_LDPC
: /* bits 16 and 17 are part of immediate */
3257 case R6_OPC_LDPC
+ (1 << 16):
3258 case R6_OPC_LDPC
+ (2 << 16):
3259 case R6_OPC_LDPC
+ (3 << 16):
3261 offset
= sextract32(ctx
->opcode
<< 3, 0, 21);
3262 addr
= addr_add(ctx
, (pc
& ~0x7), offset
);
3263 gen_r6_ld(addr
, rs
, ctx
->mem_idx
, MO_TEQ
);
3267 MIPS_INVAL("OPC_PCREL");
3268 generate_exception(ctx
, EXCP_RI
);
3275 static void gen_r6_muldiv(DisasContext
*ctx
, int opc
, int rd
, int rs
, int rt
)
3277 const char *opn
= "r6 mul/div";
3286 t0
= tcg_temp_new();
3287 t1
= tcg_temp_new();
3289 gen_load_gpr(t0
, rs
);
3290 gen_load_gpr(t1
, rt
);
3295 TCGv t2
= tcg_temp_new();
3296 TCGv t3
= tcg_temp_new();
3297 tcg_gen_ext32s_tl(t0
, t0
);
3298 tcg_gen_ext32s_tl(t1
, t1
);
3299 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
3300 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1);
3301 tcg_gen_and_tl(t2
, t2
, t3
);
3302 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3303 tcg_gen_or_tl(t2
, t2
, t3
);
3304 tcg_gen_movi_tl(t3
, 0);
3305 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
3306 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
3307 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3315 TCGv t2
= tcg_temp_new();
3316 TCGv t3
= tcg_temp_new();
3317 tcg_gen_ext32s_tl(t0
, t0
);
3318 tcg_gen_ext32s_tl(t1
, t1
);
3319 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
3320 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1);
3321 tcg_gen_and_tl(t2
, t2
, t3
);
3322 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3323 tcg_gen_or_tl(t2
, t2
, t3
);
3324 tcg_gen_movi_tl(t3
, 0);
3325 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
3326 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
3327 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3335 TCGv t2
= tcg_const_tl(0);
3336 TCGv t3
= tcg_const_tl(1);
3337 tcg_gen_ext32u_tl(t0
, t0
);
3338 tcg_gen_ext32u_tl(t1
, t1
);
3339 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
, t2
, t3
, t1
);
3340 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
3341 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3349 TCGv t2
= tcg_const_tl(0);
3350 TCGv t3
= tcg_const_tl(1);
3351 tcg_gen_ext32u_tl(t0
, t0
);
3352 tcg_gen_ext32u_tl(t1
, t1
);
3353 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
, t2
, t3
, t1
);
3354 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
3355 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3363 TCGv_i32 t2
= tcg_temp_new_i32();
3364 TCGv_i32 t3
= tcg_temp_new_i32();
3365 tcg_gen_trunc_tl_i32(t2
, t0
);
3366 tcg_gen_trunc_tl_i32(t3
, t1
);
3367 tcg_gen_mul_i32(t2
, t2
, t3
);
3368 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
3369 tcg_temp_free_i32(t2
);
3370 tcg_temp_free_i32(t3
);
3376 TCGv_i32 t2
= tcg_temp_new_i32();
3377 TCGv_i32 t3
= tcg_temp_new_i32();
3378 tcg_gen_trunc_tl_i32(t2
, t0
);
3379 tcg_gen_trunc_tl_i32(t3
, t1
);
3380 tcg_gen_muls2_i32(t2
, t3
, t2
, t3
);
3381 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t3
);
3382 tcg_temp_free_i32(t2
);
3383 tcg_temp_free_i32(t3
);
3389 TCGv_i32 t2
= tcg_temp_new_i32();
3390 TCGv_i32 t3
= tcg_temp_new_i32();
3391 tcg_gen_trunc_tl_i32(t2
, t0
);
3392 tcg_gen_trunc_tl_i32(t3
, t1
);
3393 tcg_gen_mul_i32(t2
, t2
, t3
);
3394 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
3395 tcg_temp_free_i32(t2
);
3396 tcg_temp_free_i32(t3
);
3402 TCGv_i32 t2
= tcg_temp_new_i32();
3403 TCGv_i32 t3
= tcg_temp_new_i32();
3404 tcg_gen_trunc_tl_i32(t2
, t0
);
3405 tcg_gen_trunc_tl_i32(t3
, t1
);
3406 tcg_gen_mulu2_i32(t2
, t3
, t2
, t3
);
3407 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t3
);
3408 tcg_temp_free_i32(t2
);
3409 tcg_temp_free_i32(t3
);
3413 #if defined(TARGET_MIPS64)
3416 TCGv t2
= tcg_temp_new();
3417 TCGv t3
= tcg_temp_new();
3418 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, -1LL << 63);
3419 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1LL);
3420 tcg_gen_and_tl(t2
, t2
, t3
);
3421 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3422 tcg_gen_or_tl(t2
, t2
, t3
);
3423 tcg_gen_movi_tl(t3
, 0);
3424 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
3425 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
3433 TCGv t2
= tcg_temp_new();
3434 TCGv t3
= tcg_temp_new();
3435 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, -1LL << 63);
3436 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1LL);
3437 tcg_gen_and_tl(t2
, t2
, t3
);
3438 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3439 tcg_gen_or_tl(t2
, t2
, t3
);
3440 tcg_gen_movi_tl(t3
, 0);
3441 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
3442 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
3450 TCGv t2
= tcg_const_tl(0);
3451 TCGv t3
= tcg_const_tl(1);
3452 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
, t2
, t3
, t1
);
3453 tcg_gen_divu_i64(cpu_gpr
[rd
], t0
, t1
);
3461 TCGv t2
= tcg_const_tl(0);
3462 TCGv t3
= tcg_const_tl(1);
3463 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
, t2
, t3
, t1
);
3464 tcg_gen_remu_i64(cpu_gpr
[rd
], t0
, t1
);
3471 tcg_gen_mul_i64(cpu_gpr
[rd
], t0
, t1
);
3476 TCGv t2
= tcg_temp_new();
3477 tcg_gen_muls2_i64(t2
, cpu_gpr
[rd
], t0
, t1
);
3483 tcg_gen_mul_i64(cpu_gpr
[rd
], t0
, t1
);
3488 TCGv t2
= tcg_temp_new();
3489 tcg_gen_mulu2_i64(t2
, cpu_gpr
[rd
], t0
, t1
);
3497 generate_exception(ctx
, EXCP_RI
);
3500 (void)opn
; /* avoid a compiler warning */
3501 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
3507 static void gen_muldiv(DisasContext
*ctx
, uint32_t opc
,
3508 int acc
, int rs
, int rt
)
3510 const char *opn
= "mul/div";
3513 t0
= tcg_temp_new();
3514 t1
= tcg_temp_new();
3516 gen_load_gpr(t0
, rs
);
3517 gen_load_gpr(t1
, rt
);
3526 TCGv t2
= tcg_temp_new();
3527 TCGv t3
= tcg_temp_new();
3528 tcg_gen_ext32s_tl(t0
, t0
);
3529 tcg_gen_ext32s_tl(t1
, t1
);
3530 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
3531 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1);
3532 tcg_gen_and_tl(t2
, t2
, t3
);
3533 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3534 tcg_gen_or_tl(t2
, t2
, t3
);
3535 tcg_gen_movi_tl(t3
, 0);
3536 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
3537 tcg_gen_div_tl(cpu_LO
[acc
], t0
, t1
);
3538 tcg_gen_rem_tl(cpu_HI
[acc
], t0
, t1
);
3539 tcg_gen_ext32s_tl(cpu_LO
[acc
], cpu_LO
[acc
]);
3540 tcg_gen_ext32s_tl(cpu_HI
[acc
], cpu_HI
[acc
]);
3548 TCGv t2
= tcg_const_tl(0);
3549 TCGv t3
= tcg_const_tl(1);
3550 tcg_gen_ext32u_tl(t0
, t0
);
3551 tcg_gen_ext32u_tl(t1
, t1
);
3552 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
, t2
, t3
, t1
);
3553 tcg_gen_divu_tl(cpu_LO
[acc
], t0
, t1
);
3554 tcg_gen_remu_tl(cpu_HI
[acc
], t0
, t1
);
3555 tcg_gen_ext32s_tl(cpu_LO
[acc
], cpu_LO
[acc
]);
3556 tcg_gen_ext32s_tl(cpu_HI
[acc
], cpu_HI
[acc
]);
3564 TCGv_i32 t2
= tcg_temp_new_i32();
3565 TCGv_i32 t3
= tcg_temp_new_i32();
3566 tcg_gen_trunc_tl_i32(t2
, t0
);
3567 tcg_gen_trunc_tl_i32(t3
, t1
);
3568 tcg_gen_muls2_i32(t2
, t3
, t2
, t3
);
3569 tcg_gen_ext_i32_tl(cpu_LO
[acc
], t2
);
3570 tcg_gen_ext_i32_tl(cpu_HI
[acc
], t3
);
3571 tcg_temp_free_i32(t2
);
3572 tcg_temp_free_i32(t3
);
3578 TCGv_i32 t2
= tcg_temp_new_i32();
3579 TCGv_i32 t3
= tcg_temp_new_i32();
3580 tcg_gen_trunc_tl_i32(t2
, t0
);
3581 tcg_gen_trunc_tl_i32(t3
, t1
);
3582 tcg_gen_mulu2_i32(t2
, t3
, t2
, t3
);
3583 tcg_gen_ext_i32_tl(cpu_LO
[acc
], t2
);
3584 tcg_gen_ext_i32_tl(cpu_HI
[acc
], t3
);
3585 tcg_temp_free_i32(t2
);
3586 tcg_temp_free_i32(t3
);
3590 #if defined(TARGET_MIPS64)
3593 TCGv t2
= tcg_temp_new();
3594 TCGv t3
= tcg_temp_new();
3595 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, -1LL << 63);
3596 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1LL);
3597 tcg_gen_and_tl(t2
, t2
, t3
);
3598 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3599 tcg_gen_or_tl(t2
, t2
, t3
);
3600 tcg_gen_movi_tl(t3
, 0);
3601 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
3602 tcg_gen_div_tl(cpu_LO
[acc
], t0
, t1
);
3603 tcg_gen_rem_tl(cpu_HI
[acc
], t0
, t1
);
3611 TCGv t2
= tcg_const_tl(0);
3612 TCGv t3
= tcg_const_tl(1);
3613 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
, t2
, t3
, t1
);
3614 tcg_gen_divu_i64(cpu_LO
[acc
], t0
, t1
);
3615 tcg_gen_remu_i64(cpu_HI
[acc
], t0
, t1
);
3622 tcg_gen_muls2_i64(cpu_LO
[acc
], cpu_HI
[acc
], t0
, t1
);
3626 tcg_gen_mulu2_i64(cpu_LO
[acc
], cpu_HI
[acc
], t0
, t1
);
3632 TCGv_i64 t2
= tcg_temp_new_i64();
3633 TCGv_i64 t3
= tcg_temp_new_i64();
3635 tcg_gen_ext_tl_i64(t2
, t0
);
3636 tcg_gen_ext_tl_i64(t3
, t1
);
3637 tcg_gen_mul_i64(t2
, t2
, t3
);
3638 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3639 tcg_gen_add_i64(t2
, t2
, t3
);
3640 tcg_temp_free_i64(t3
);
3641 tcg_gen_trunc_i64_tl(t0
, t2
);
3642 tcg_gen_shri_i64(t2
, t2
, 32);
3643 tcg_gen_trunc_i64_tl(t1
, t2
);
3644 tcg_temp_free_i64(t2
);
3645 tcg_gen_ext32s_tl(cpu_LO
[acc
], t0
);
3646 tcg_gen_ext32s_tl(cpu_HI
[acc
], t1
);
3652 TCGv_i64 t2
= tcg_temp_new_i64();
3653 TCGv_i64 t3
= tcg_temp_new_i64();
3655 tcg_gen_ext32u_tl(t0
, t0
);
3656 tcg_gen_ext32u_tl(t1
, t1
);
3657 tcg_gen_extu_tl_i64(t2
, t0
);
3658 tcg_gen_extu_tl_i64(t3
, t1
);
3659 tcg_gen_mul_i64(t2
, t2
, t3
);
3660 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3661 tcg_gen_add_i64(t2
, t2
, t3
);
3662 tcg_temp_free_i64(t3
);
3663 tcg_gen_trunc_i64_tl(t0
, t2
);
3664 tcg_gen_shri_i64(t2
, t2
, 32);
3665 tcg_gen_trunc_i64_tl(t1
, t2
);
3666 tcg_temp_free_i64(t2
);
3667 tcg_gen_ext32s_tl(cpu_LO
[acc
], t0
);
3668 tcg_gen_ext32s_tl(cpu_HI
[acc
], t1
);
3674 TCGv_i64 t2
= tcg_temp_new_i64();
3675 TCGv_i64 t3
= tcg_temp_new_i64();
3677 tcg_gen_ext_tl_i64(t2
, t0
);
3678 tcg_gen_ext_tl_i64(t3
, t1
);
3679 tcg_gen_mul_i64(t2
, t2
, t3
);
3680 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3681 tcg_gen_sub_i64(t2
, t3
, t2
);
3682 tcg_temp_free_i64(t3
);
3683 tcg_gen_trunc_i64_tl(t0
, t2
);
3684 tcg_gen_shri_i64(t2
, t2
, 32);
3685 tcg_gen_trunc_i64_tl(t1
, t2
);
3686 tcg_temp_free_i64(t2
);
3687 tcg_gen_ext32s_tl(cpu_LO
[acc
], t0
);
3688 tcg_gen_ext32s_tl(cpu_HI
[acc
], t1
);
3694 TCGv_i64 t2
= tcg_temp_new_i64();
3695 TCGv_i64 t3
= tcg_temp_new_i64();
3697 tcg_gen_ext32u_tl(t0
, t0
);
3698 tcg_gen_ext32u_tl(t1
, t1
);
3699 tcg_gen_extu_tl_i64(t2
, t0
);
3700 tcg_gen_extu_tl_i64(t3
, t1
);
3701 tcg_gen_mul_i64(t2
, t2
, t3
);
3702 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3703 tcg_gen_sub_i64(t2
, t3
, t2
);
3704 tcg_temp_free_i64(t3
);
3705 tcg_gen_trunc_i64_tl(t0
, t2
);
3706 tcg_gen_shri_i64(t2
, t2
, 32);
3707 tcg_gen_trunc_i64_tl(t1
, t2
);
3708 tcg_temp_free_i64(t2
);
3709 tcg_gen_ext32s_tl(cpu_LO
[acc
], t0
);
3710 tcg_gen_ext32s_tl(cpu_HI
[acc
], t1
);
3716 generate_exception(ctx
, EXCP_RI
);
3719 (void)opn
; /* avoid a compiler warning */
3720 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
3726 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
3727 int rd
, int rs
, int rt
)
3729 const char *opn
= "mul vr54xx";
3730 TCGv t0
= tcg_temp_new();
3731 TCGv t1
= tcg_temp_new();
3733 gen_load_gpr(t0
, rs
);
3734 gen_load_gpr(t1
, rt
);
3737 case OPC_VR54XX_MULS
:
3738 gen_helper_muls(t0
, cpu_env
, t0
, t1
);
3741 case OPC_VR54XX_MULSU
:
3742 gen_helper_mulsu(t0
, cpu_env
, t0
, t1
);
3745 case OPC_VR54XX_MACC
:
3746 gen_helper_macc(t0
, cpu_env
, t0
, t1
);
3749 case OPC_VR54XX_MACCU
:
3750 gen_helper_maccu(t0
, cpu_env
, t0
, t1
);
3753 case OPC_VR54XX_MSAC
:
3754 gen_helper_msac(t0
, cpu_env
, t0
, t1
);
3757 case OPC_VR54XX_MSACU
:
3758 gen_helper_msacu(t0
, cpu_env
, t0
, t1
);
3761 case OPC_VR54XX_MULHI
:
3762 gen_helper_mulhi(t0
, cpu_env
, t0
, t1
);
3765 case OPC_VR54XX_MULHIU
:
3766 gen_helper_mulhiu(t0
, cpu_env
, t0
, t1
);
3769 case OPC_VR54XX_MULSHI
:
3770 gen_helper_mulshi(t0
, cpu_env
, t0
, t1
);
3773 case OPC_VR54XX_MULSHIU
:
3774 gen_helper_mulshiu(t0
, cpu_env
, t0
, t1
);
3777 case OPC_VR54XX_MACCHI
:
3778 gen_helper_macchi(t0
, cpu_env
, t0
, t1
);
3781 case OPC_VR54XX_MACCHIU
:
3782 gen_helper_macchiu(t0
, cpu_env
, t0
, t1
);
3785 case OPC_VR54XX_MSACHI
:
3786 gen_helper_msachi(t0
, cpu_env
, t0
, t1
);
3789 case OPC_VR54XX_MSACHIU
:
3790 gen_helper_msachiu(t0
, cpu_env
, t0
, t1
);
3794 MIPS_INVAL("mul vr54xx");
3795 generate_exception(ctx
, EXCP_RI
);
3798 gen_store_gpr(t0
, rd
);
3799 (void)opn
; /* avoid a compiler warning */
3800 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
3807 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
3810 const char *opn
= "CLx";
3818 t0
= tcg_temp_new();
3819 gen_load_gpr(t0
, rs
);
3823 gen_helper_clo(cpu_gpr
[rd
], t0
);
3828 gen_helper_clz(cpu_gpr
[rd
], t0
);
3831 #if defined(TARGET_MIPS64)
3834 gen_helper_dclo(cpu_gpr
[rd
], t0
);
3839 gen_helper_dclz(cpu_gpr
[rd
], t0
);
3844 (void)opn
; /* avoid a compiler warning */
3845 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
3849 /* Godson integer instructions */
3850 static void gen_loongson_integer(DisasContext
*ctx
, uint32_t opc
,
3851 int rd
, int rs
, int rt
)
3853 const char *opn
= "loongson";
3865 case OPC_MULTU_G_2E
:
3866 case OPC_MULTU_G_2F
:
3867 #if defined(TARGET_MIPS64)
3868 case OPC_DMULT_G_2E
:
3869 case OPC_DMULT_G_2F
:
3870 case OPC_DMULTU_G_2E
:
3871 case OPC_DMULTU_G_2F
:
3873 t0
= tcg_temp_new();
3874 t1
= tcg_temp_new();
3877 t0
= tcg_temp_local_new();
3878 t1
= tcg_temp_local_new();
3882 gen_load_gpr(t0
, rs
);
3883 gen_load_gpr(t1
, rt
);
3888 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
3889 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3892 case OPC_MULTU_G_2E
:
3893 case OPC_MULTU_G_2F
:
3894 tcg_gen_ext32u_tl(t0
, t0
);
3895 tcg_gen_ext32u_tl(t1
, t1
);
3896 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
3897 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3903 TCGLabel
*l1
= gen_new_label();
3904 TCGLabel
*l2
= gen_new_label();
3905 TCGLabel
*l3
= gen_new_label();
3906 tcg_gen_ext32s_tl(t0
, t0
);
3907 tcg_gen_ext32s_tl(t1
, t1
);
3908 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3909 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3912 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
3913 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
3914 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
3917 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
3918 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3926 TCGLabel
*l1
= gen_new_label();
3927 TCGLabel
*l2
= gen_new_label();
3928 tcg_gen_ext32u_tl(t0
, t0
);
3929 tcg_gen_ext32u_tl(t1
, t1
);
3930 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3931 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3934 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
3935 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3943 TCGLabel
*l1
= gen_new_label();
3944 TCGLabel
*l2
= gen_new_label();
3945 TCGLabel
*l3
= gen_new_label();
3946 tcg_gen_ext32u_tl(t0
, t0
);
3947 tcg_gen_ext32u_tl(t1
, t1
);
3948 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
3949 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
3950 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
3952 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3955 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
3956 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3964 TCGLabel
*l1
= gen_new_label();
3965 TCGLabel
*l2
= gen_new_label();
3966 tcg_gen_ext32u_tl(t0
, t0
);
3967 tcg_gen_ext32u_tl(t1
, t1
);
3968 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3969 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3972 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
3973 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3978 #if defined(TARGET_MIPS64)
3979 case OPC_DMULT_G_2E
:
3980 case OPC_DMULT_G_2F
:
3981 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
3984 case OPC_DMULTU_G_2E
:
3985 case OPC_DMULTU_G_2F
:
3986 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
3992 TCGLabel
*l1
= gen_new_label();
3993 TCGLabel
*l2
= gen_new_label();
3994 TCGLabel
*l3
= gen_new_label();
3995 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3996 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3999 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
4000 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
4001 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
4004 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
4009 case OPC_DDIVU_G_2E
:
4010 case OPC_DDIVU_G_2F
:
4012 TCGLabel
*l1
= gen_new_label();
4013 TCGLabel
*l2
= gen_new_label();
4014 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
4015 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
4018 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
4026 TCGLabel
*l1
= gen_new_label();
4027 TCGLabel
*l2
= gen_new_label();
4028 TCGLabel
*l3
= gen_new_label();
4029 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4030 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
4031 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
4033 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
4036 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
4041 case OPC_DMODU_G_2E
:
4042 case OPC_DMODU_G_2F
:
4044 TCGLabel
*l1
= gen_new_label();
4045 TCGLabel
*l2
= gen_new_label();
4046 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
4047 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
4050 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
4058 (void)opn
; /* avoid a compiler warning */
4059 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
4064 /* Loongson multimedia instructions */
4065 static void gen_loongson_multimedia(DisasContext
*ctx
, int rd
, int rs
, int rt
)
4067 const char *opn
= "loongson_cp2";
4068 uint32_t opc
, shift_max
;
4071 opc
= MASK_LMI(ctx
->opcode
);
4077 t0
= tcg_temp_local_new_i64();
4078 t1
= tcg_temp_local_new_i64();
4081 t0
= tcg_temp_new_i64();
4082 t1
= tcg_temp_new_i64();
4086 gen_load_fpr64(ctx
, t0
, rs
);
4087 gen_load_fpr64(ctx
, t1
, rt
);
4089 #define LMI_HELPER(UP, LO) \
4090 case OPC_##UP: gen_helper_##LO(t0, t0, t1); opn = #LO; break
4091 #define LMI_HELPER_1(UP, LO) \
4092 case OPC_##UP: gen_helper_##LO(t0, t0); opn = #LO; break
4093 #define LMI_DIRECT(UP, LO, OP) \
4094 case OPC_##UP: tcg_gen_##OP##_i64(t0, t0, t1); opn = #LO; break
4097 LMI_HELPER(PADDSH
, paddsh
);
4098 LMI_HELPER(PADDUSH
, paddush
);
4099 LMI_HELPER(PADDH
, paddh
);
4100 LMI_HELPER(PADDW
, paddw
);
4101 LMI_HELPER(PADDSB
, paddsb
);
4102 LMI_HELPER(PADDUSB
, paddusb
);
4103 LMI_HELPER(PADDB
, paddb
);
4105 LMI_HELPER(PSUBSH
, psubsh
);
4106 LMI_HELPER(PSUBUSH
, psubush
);
4107 LMI_HELPER(PSUBH
, psubh
);
4108 LMI_HELPER(PSUBW
, psubw
);
4109 LMI_HELPER(PSUBSB
, psubsb
);
4110 LMI_HELPER(PSUBUSB
, psubusb
);
4111 LMI_HELPER(PSUBB
, psubb
);
4113 LMI_HELPER(PSHUFH
, pshufh
);
4114 LMI_HELPER(PACKSSWH
, packsswh
);
4115 LMI_HELPER(PACKSSHB
, packsshb
);
4116 LMI_HELPER(PACKUSHB
, packushb
);
4118 LMI_HELPER(PUNPCKLHW
, punpcklhw
);
4119 LMI_HELPER(PUNPCKHHW
, punpckhhw
);
4120 LMI_HELPER(PUNPCKLBH
, punpcklbh
);
4121 LMI_HELPER(PUNPCKHBH
, punpckhbh
);
4122 LMI_HELPER(PUNPCKLWD
, punpcklwd
);
4123 LMI_HELPER(PUNPCKHWD
, punpckhwd
);
4125 LMI_HELPER(PAVGH
, pavgh
);
4126 LMI_HELPER(PAVGB
, pavgb
);
4127 LMI_HELPER(PMAXSH
, pmaxsh
);
4128 LMI_HELPER(PMINSH
, pminsh
);
4129 LMI_HELPER(PMAXUB
, pmaxub
);
4130 LMI_HELPER(PMINUB
, pminub
);
4132 LMI_HELPER(PCMPEQW
, pcmpeqw
);
4133 LMI_HELPER(PCMPGTW
, pcmpgtw
);
4134 LMI_HELPER(PCMPEQH
, pcmpeqh
);
4135 LMI_HELPER(PCMPGTH
, pcmpgth
);
4136 LMI_HELPER(PCMPEQB
, pcmpeqb
);
4137 LMI_HELPER(PCMPGTB
, pcmpgtb
);
4139 LMI_HELPER(PSLLW
, psllw
);
4140 LMI_HELPER(PSLLH
, psllh
);
4141 LMI_HELPER(PSRLW
, psrlw
);
4142 LMI_HELPER(PSRLH
, psrlh
);
4143 LMI_HELPER(PSRAW
, psraw
);
4144 LMI_HELPER(PSRAH
, psrah
);
4146 LMI_HELPER(PMULLH
, pmullh
);
4147 LMI_HELPER(PMULHH
, pmulhh
);
4148 LMI_HELPER(PMULHUH
, pmulhuh
);
4149 LMI_HELPER(PMADDHW
, pmaddhw
);
4151 LMI_HELPER(PASUBUB
, pasubub
);
4152 LMI_HELPER_1(BIADD
, biadd
);
4153 LMI_HELPER_1(PMOVMSKB
, pmovmskb
);
4155 LMI_DIRECT(PADDD
, paddd
, add
);
4156 LMI_DIRECT(PSUBD
, psubd
, sub
);
4157 LMI_DIRECT(XOR_CP2
, xor, xor);
4158 LMI_DIRECT(NOR_CP2
, nor
, nor
);
4159 LMI_DIRECT(AND_CP2
, and, and);
4160 LMI_DIRECT(PANDN
, pandn
, andc
);
4161 LMI_DIRECT(OR
, or, or);
4164 tcg_gen_deposit_i64(t0
, t0
, t1
, 0, 16);
4168 tcg_gen_deposit_i64(t0
, t0
, t1
, 16, 16);
4172 tcg_gen_deposit_i64(t0
, t0
, t1
, 32, 16);
4176 tcg_gen_deposit_i64(t0
, t0
, t1
, 48, 16);
4181 tcg_gen_andi_i64(t1
, t1
, 3);
4182 tcg_gen_shli_i64(t1
, t1
, 4);
4183 tcg_gen_shr_i64(t0
, t0
, t1
);
4184 tcg_gen_ext16u_i64(t0
, t0
);
4189 tcg_gen_add_i64(t0
, t0
, t1
);
4190 tcg_gen_ext32s_i64(t0
, t0
);
4194 tcg_gen_sub_i64(t0
, t0
, t1
);
4195 tcg_gen_ext32s_i64(t0
, t0
);
4224 /* Make sure shift count isn't TCG undefined behaviour. */
4225 tcg_gen_andi_i64(t1
, t1
, shift_max
- 1);
4230 tcg_gen_shl_i64(t0
, t0
, t1
);
4234 /* Since SRA is UndefinedResult without sign-extended inputs,
4235 we can treat SRA and DSRA the same. */
4236 tcg_gen_sar_i64(t0
, t0
, t1
);
4239 /* We want to shift in zeros for SRL; zero-extend first. */
4240 tcg_gen_ext32u_i64(t0
, t0
);
4243 tcg_gen_shr_i64(t0
, t0
, t1
);
4247 if (shift_max
== 32) {
4248 tcg_gen_ext32s_i64(t0
, t0
);
4251 /* Shifts larger than MAX produce zero. */
4252 tcg_gen_setcondi_i64(TCG_COND_LTU
, t1
, t1
, shift_max
);
4253 tcg_gen_neg_i64(t1
, t1
);
4254 tcg_gen_and_i64(t0
, t0
, t1
);
4260 TCGv_i64 t2
= tcg_temp_new_i64();
4261 TCGLabel
*lab
= gen_new_label();
4263 tcg_gen_mov_i64(t2
, t0
);
4264 tcg_gen_add_i64(t0
, t1
, t2
);
4265 if (opc
== OPC_ADD_CP2
) {
4266 tcg_gen_ext32s_i64(t0
, t0
);
4268 tcg_gen_xor_i64(t1
, t1
, t2
);
4269 tcg_gen_xor_i64(t2
, t2
, t0
);
4270 tcg_gen_andc_i64(t1
, t2
, t1
);
4271 tcg_temp_free_i64(t2
);
4272 tcg_gen_brcondi_i64(TCG_COND_GE
, t1
, 0, lab
);
4273 generate_exception(ctx
, EXCP_OVERFLOW
);
4276 opn
= (opc
== OPC_ADD_CP2
? "add" : "dadd");
4283 TCGv_i64 t2
= tcg_temp_new_i64();
4284 TCGLabel
*lab
= gen_new_label();
4286 tcg_gen_mov_i64(t2
, t0
);
4287 tcg_gen_sub_i64(t0
, t1
, t2
);
4288 if (opc
== OPC_SUB_CP2
) {
4289 tcg_gen_ext32s_i64(t0
, t0
);
4291 tcg_gen_xor_i64(t1
, t1
, t2
);
4292 tcg_gen_xor_i64(t2
, t2
, t0
);
4293 tcg_gen_and_i64(t1
, t1
, t2
);
4294 tcg_temp_free_i64(t2
);
4295 tcg_gen_brcondi_i64(TCG_COND_GE
, t1
, 0, lab
);
4296 generate_exception(ctx
, EXCP_OVERFLOW
);
4299 opn
= (opc
== OPC_SUB_CP2
? "sub" : "dsub");
4304 tcg_gen_ext32u_i64(t0
, t0
);
4305 tcg_gen_ext32u_i64(t1
, t1
);
4306 tcg_gen_mul_i64(t0
, t0
, t1
);
4316 /* ??? Document is unclear: Set FCC[CC]. Does that mean the
4317 FD field is the CC field? */
4320 generate_exception(ctx
, EXCP_RI
);
4327 gen_store_fpr64(ctx
, t0
, rd
);
4329 (void)opn
; /* avoid a compiler warning */
4330 MIPS_DEBUG("%s %s, %s, %s", opn
,
4331 fregnames
[rd
], fregnames
[rs
], fregnames
[rt
]);
4332 tcg_temp_free_i64(t0
);
4333 tcg_temp_free_i64(t1
);
4337 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
4338 int rs
, int rt
, int16_t imm
)
4341 TCGv t0
= tcg_temp_new();
4342 TCGv t1
= tcg_temp_new();
4345 /* Load needed operands */
4353 /* Compare two registers */
4355 gen_load_gpr(t0
, rs
);
4356 gen_load_gpr(t1
, rt
);
4366 /* Compare register to immediate */
4367 if (rs
!= 0 || imm
!= 0) {
4368 gen_load_gpr(t0
, rs
);
4369 tcg_gen_movi_tl(t1
, (int32_t)imm
);
4376 case OPC_TEQ
: /* rs == rs */
4377 case OPC_TEQI
: /* r0 == 0 */
4378 case OPC_TGE
: /* rs >= rs */
4379 case OPC_TGEI
: /* r0 >= 0 */
4380 case OPC_TGEU
: /* rs >= rs unsigned */
4381 case OPC_TGEIU
: /* r0 >= 0 unsigned */
4383 generate_exception(ctx
, EXCP_TRAP
);
4385 case OPC_TLT
: /* rs < rs */
4386 case OPC_TLTI
: /* r0 < 0 */
4387 case OPC_TLTU
: /* rs < rs unsigned */
4388 case OPC_TLTIU
: /* r0 < 0 unsigned */
4389 case OPC_TNE
: /* rs != rs */
4390 case OPC_TNEI
: /* r0 != 0 */
4391 /* Never trap: treat as NOP. */
4395 TCGLabel
*l1
= gen_new_label();
4400 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
4404 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
4408 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
4412 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4416 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
4420 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
4423 generate_exception(ctx
, EXCP_TRAP
);
4430 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
4432 TranslationBlock
*tb
;
4434 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
4435 likely(!ctx
->singlestep_enabled
)) {
4438 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
4441 if (ctx
->singlestep_enabled
) {
4442 save_cpu_state(ctx
, 0);
4443 gen_helper_0e0i(raise_exception
, EXCP_DEBUG
);
4449 /* Branches (before delay slot) */
4450 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
4452 int rs
, int rt
, int32_t offset
,
4455 target_ulong btgt
= -1;
4457 int bcond_compute
= 0;
4458 TCGv t0
= tcg_temp_new();
4459 TCGv t1
= tcg_temp_new();
4461 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
4462 #ifdef MIPS_DEBUG_DISAS
4463 LOG_DISAS("Branch in delay / forbidden slot at PC 0x"
4464 TARGET_FMT_lx
"\n", ctx
->pc
);
4466 generate_exception(ctx
, EXCP_RI
);
4470 /* Load needed operands */
4476 /* Compare two registers */
4478 gen_load_gpr(t0
, rs
);
4479 gen_load_gpr(t1
, rt
);
4482 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
4496 /* Compare to zero */
4498 gen_load_gpr(t0
, rs
);
4501 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
4504 #if defined(TARGET_MIPS64)
4506 tcg_gen_andi_tl(t0
, cpu_dspctrl
, 0x7F);
4508 tcg_gen_andi_tl(t0
, cpu_dspctrl
, 0x3F);
4511 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
4516 /* Jump to immediate */
4517 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
4521 /* Jump to register */
4522 if (offset
!= 0 && offset
!= 16) {
4523 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
4524 others are reserved. */
4525 MIPS_INVAL("jump hint");
4526 generate_exception(ctx
, EXCP_RI
);
4529 gen_load_gpr(btarget
, rs
);
4532 MIPS_INVAL("branch/jump");
4533 generate_exception(ctx
, EXCP_RI
);
4536 if (bcond_compute
== 0) {
4537 /* No condition to be computed */
4539 case OPC_BEQ
: /* rx == rx */
4540 case OPC_BEQL
: /* rx == rx likely */
4541 case OPC_BGEZ
: /* 0 >= 0 */
4542 case OPC_BGEZL
: /* 0 >= 0 likely */
4543 case OPC_BLEZ
: /* 0 <= 0 */
4544 case OPC_BLEZL
: /* 0 <= 0 likely */
4546 ctx
->hflags
|= MIPS_HFLAG_B
;
4547 MIPS_DEBUG("balways");
4549 case OPC_BGEZAL
: /* 0 >= 0 */
4550 case OPC_BGEZALL
: /* 0 >= 0 likely */
4551 /* Always take and link */
4553 ctx
->hflags
|= MIPS_HFLAG_B
;
4554 MIPS_DEBUG("balways and link");
4556 case OPC_BNE
: /* rx != rx */
4557 case OPC_BGTZ
: /* 0 > 0 */
4558 case OPC_BLTZ
: /* 0 < 0 */
4560 MIPS_DEBUG("bnever (NOP)");
4562 case OPC_BLTZAL
: /* 0 < 0 */
4563 /* Handle as an unconditional branch to get correct delay
4566 btgt
= ctx
->pc
+ insn_bytes
+ delayslot_size
;
4567 ctx
->hflags
|= MIPS_HFLAG_B
;
4568 MIPS_DEBUG("bnever and link");
4570 case OPC_BLTZALL
: /* 0 < 0 likely */
4571 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
4572 /* Skip the instruction in the delay slot */
4573 MIPS_DEBUG("bnever, link and skip");
4576 case OPC_BNEL
: /* rx != rx likely */
4577 case OPC_BGTZL
: /* 0 > 0 likely */
4578 case OPC_BLTZL
: /* 0 < 0 likely */
4579 /* Skip the instruction in the delay slot */
4580 MIPS_DEBUG("bnever and skip");
4584 ctx
->hflags
|= MIPS_HFLAG_B
;
4585 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
4588 ctx
->hflags
|= MIPS_HFLAG_BX
;
4592 ctx
->hflags
|= MIPS_HFLAG_B
;
4593 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
4596 ctx
->hflags
|= MIPS_HFLAG_BR
;
4597 MIPS_DEBUG("jr %s", regnames
[rs
]);
4601 ctx
->hflags
|= MIPS_HFLAG_BR
;
4602 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
4605 MIPS_INVAL("branch/jump");
4606 generate_exception(ctx
, EXCP_RI
);
4612 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
4613 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
4614 regnames
[rs
], regnames
[rt
], btgt
);
4617 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
4618 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
4619 regnames
[rs
], regnames
[rt
], btgt
);
4622 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
4623 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
4624 regnames
[rs
], regnames
[rt
], btgt
);
4627 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
4628 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
4629 regnames
[rs
], regnames
[rt
], btgt
);
4632 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
4633 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4636 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
4637 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4640 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
4641 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4645 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
4647 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4650 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
4651 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4654 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
4655 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4658 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
4659 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4662 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
4663 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4666 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
4667 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4670 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
4671 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4674 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 32);
4675 MIPS_DEBUG("bposge32 " TARGET_FMT_lx
, btgt
);
4677 #if defined(TARGET_MIPS64)
4679 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 64);
4680 MIPS_DEBUG("bposge64 " TARGET_FMT_lx
, btgt
);
4684 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
4686 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4688 ctx
->hflags
|= MIPS_HFLAG_BC
;
4691 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
4693 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
4695 ctx
->hflags
|= MIPS_HFLAG_BL
;
4698 MIPS_INVAL("conditional branch/jump");
4699 generate_exception(ctx
, EXCP_RI
);
4703 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
4704 blink
, ctx
->hflags
, btgt
);
4706 ctx
->btarget
= btgt
;
4708 switch (delayslot_size
) {
4710 ctx
->hflags
|= MIPS_HFLAG_BDS16
;
4713 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
4718 int post_delay
= insn_bytes
+ delayslot_size
;
4719 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
4721 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ post_delay
+ lowbit
);
4725 if (insn_bytes
== 2)
4726 ctx
->hflags
|= MIPS_HFLAG_B16
;
4731 /* special3 bitfield operations */
4732 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
4733 int rs
, int lsb
, int msb
)
4735 TCGv t0
= tcg_temp_new();
4736 TCGv t1
= tcg_temp_new();
4738 gen_load_gpr(t1
, rs
);
4743 tcg_gen_shri_tl(t0
, t1
, lsb
);
4745 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
4747 tcg_gen_ext32s_tl(t0
, t0
);
4750 #if defined(TARGET_MIPS64)
4752 tcg_gen_shri_tl(t0
, t1
, lsb
);
4754 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
4758 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
4759 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
4762 tcg_gen_shri_tl(t0
, t1
, lsb
);
4763 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
4769 gen_load_gpr(t0
, rt
);
4770 tcg_gen_deposit_tl(t0
, t0
, t1
, lsb
, msb
- lsb
+ 1);
4771 tcg_gen_ext32s_tl(t0
, t0
);
4773 #if defined(TARGET_MIPS64)
4775 gen_load_gpr(t0
, rt
);
4776 tcg_gen_deposit_tl(t0
, t0
, t1
, lsb
, msb
+ 32 - lsb
+ 1);
4779 gen_load_gpr(t0
, rt
);
4780 tcg_gen_deposit_tl(t0
, t0
, t1
, lsb
+ 32, msb
- lsb
+ 1);
4783 gen_load_gpr(t0
, rt
);
4784 tcg_gen_deposit_tl(t0
, t0
, t1
, lsb
, msb
- lsb
+ 1);
4789 MIPS_INVAL("bitops");
4790 generate_exception(ctx
, EXCP_RI
);
4795 gen_store_gpr(t0
, rt
);
4800 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
4805 /* If no destination, treat it as a NOP. */
4810 t0
= tcg_temp_new();
4811 gen_load_gpr(t0
, rt
);
4815 TCGv t1
= tcg_temp_new();
4817 tcg_gen_shri_tl(t1
, t0
, 8);
4818 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
4819 tcg_gen_shli_tl(t0
, t0
, 8);
4820 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
4821 tcg_gen_or_tl(t0
, t0
, t1
);
4823 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
4827 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
4830 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
4832 #if defined(TARGET_MIPS64)
4835 TCGv t1
= tcg_temp_new();
4837 tcg_gen_shri_tl(t1
, t0
, 8);
4838 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
4839 tcg_gen_shli_tl(t0
, t0
, 8);
4840 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
4841 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
4847 TCGv t1
= tcg_temp_new();
4849 tcg_gen_shri_tl(t1
, t0
, 16);
4850 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
4851 tcg_gen_shli_tl(t0
, t0
, 16);
4852 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
4853 tcg_gen_or_tl(t0
, t0
, t1
);
4854 tcg_gen_shri_tl(t1
, t0
, 32);
4855 tcg_gen_shli_tl(t0
, t0
, 32);
4856 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
4862 MIPS_INVAL("bsfhl");
4863 generate_exception(ctx
, EXCP_RI
);
4870 static void gen_lsa(DisasContext
*ctx
, int opc
, int rd
, int rs
, int rt
,
4879 t0
= tcg_temp_new();
4880 t1
= tcg_temp_new();
4881 gen_load_gpr(t0
, rs
);
4882 gen_load_gpr(t1
, rt
);
4883 tcg_gen_shli_tl(t0
, t0
, imm2
+ 1);
4884 tcg_gen_add_tl(cpu_gpr
[rd
], t0
, t1
);
4885 if (opc
== OPC_LSA
) {
4886 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
4895 static void gen_align(DisasContext
*ctx
, int opc
, int rd
, int rs
, int rt
,
4903 t0
= tcg_temp_new();
4904 gen_load_gpr(t0
, rt
);
4906 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
4908 TCGv t1
= tcg_temp_new();
4909 gen_load_gpr(t1
, rs
);
4913 TCGv_i64 t2
= tcg_temp_new_i64();
4914 tcg_gen_concat_tl_i64(t2
, t1
, t0
);
4915 tcg_gen_shri_i64(t2
, t2
, 8 * (4 - bp
));
4916 gen_move_low32(cpu_gpr
[rd
], t2
);
4917 tcg_temp_free_i64(t2
);
4920 #if defined(TARGET_MIPS64)
4922 tcg_gen_shli_tl(t0
, t0
, 8 * bp
);
4923 tcg_gen_shri_tl(t1
, t1
, 8 * (8 - bp
));
4924 tcg_gen_or_tl(cpu_gpr
[rd
], t1
, t0
);
4934 static void gen_bitswap(DisasContext
*ctx
, int opc
, int rd
, int rt
)
4941 t0
= tcg_temp_new();
4942 gen_load_gpr(t0
, rt
);
4945 gen_helper_bitswap(cpu_gpr
[rd
], t0
);
4947 #if defined(TARGET_MIPS64)
4949 gen_helper_dbitswap(cpu_gpr
[rd
], t0
);
4956 #ifndef CONFIG_USER_ONLY
4957 /* CP0 (MMU and control) */
4958 static inline void gen_mthc0_entrylo(TCGv arg
, target_ulong off
)
4960 TCGv_i64 t0
= tcg_temp_new_i64();
4961 TCGv_i64 t1
= tcg_temp_new_i64();
4963 tcg_gen_ext_tl_i64(t0
, arg
);
4964 tcg_gen_ld_i64(t1
, cpu_env
, off
);
4965 #if defined(TARGET_MIPS64)
4966 tcg_gen_deposit_i64(t1
, t1
, t0
, 30, 32);
4968 tcg_gen_concat32_i64(t1
, t1
, t0
);
4970 tcg_gen_st_i64(t1
, cpu_env
, off
);
4971 tcg_temp_free_i64(t1
);
4972 tcg_temp_free_i64(t0
);
4975 static inline void gen_mthc0_store64(TCGv arg
, target_ulong off
)
4977 TCGv_i64 t0
= tcg_temp_new_i64();
4978 TCGv_i64 t1
= tcg_temp_new_i64();
4980 tcg_gen_ext_tl_i64(t0
, arg
);
4981 tcg_gen_ld_i64(t1
, cpu_env
, off
);
4982 tcg_gen_concat32_i64(t1
, t1
, t0
);
4983 tcg_gen_st_i64(t1
, cpu_env
, off
);
4984 tcg_temp_free_i64(t1
);
4985 tcg_temp_free_i64(t0
);
4988 static inline void gen_mfhc0_entrylo(TCGv arg
, target_ulong off
)
4990 TCGv_i64 t0
= tcg_temp_new_i64();
4992 tcg_gen_ld_i64(t0
, cpu_env
, off
);
4993 #if defined(TARGET_MIPS64)
4994 tcg_gen_shri_i64(t0
, t0
, 30);
4996 tcg_gen_shri_i64(t0
, t0
, 32);
4998 gen_move_low32(arg
, t0
);
4999 tcg_temp_free_i64(t0
);
5002 static inline void gen_mfhc0_load64(TCGv arg
, target_ulong off
, int shift
)
5004 TCGv_i64 t0
= tcg_temp_new_i64();
5006 tcg_gen_ld_i64(t0
, cpu_env
, off
);
5007 tcg_gen_shri_i64(t0
, t0
, 32 + shift
);
5008 gen_move_low32(arg
, t0
);
5009 tcg_temp_free_i64(t0
);
5012 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
5014 TCGv_i32 t0
= tcg_temp_new_i32();
5016 tcg_gen_ld_i32(t0
, cpu_env
, off
);
5017 tcg_gen_ext_i32_tl(arg
, t0
);
5018 tcg_temp_free_i32(t0
);
5021 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
5023 tcg_gen_ld_tl(arg
, cpu_env
, off
);
5024 tcg_gen_ext32s_tl(arg
, arg
);
5027 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
5029 TCGv_i32 t0
= tcg_temp_new_i32();
5031 tcg_gen_trunc_tl_i32(t0
, arg
);
5032 tcg_gen_st_i32(t0
, cpu_env
, off
);
5033 tcg_temp_free_i32(t0
);
5036 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
5038 tcg_gen_ext32s_tl(arg
, arg
);
5039 tcg_gen_st_tl(arg
, cpu_env
, off
);
5042 static void gen_mfhc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
5044 const char *rn
= "invalid";
5046 if (!(ctx
->hflags
& MIPS_HFLAG_ELPA
)) {
5047 goto mfhc0_read_zero
;
5054 gen_mfhc0_entrylo(arg
, offsetof(CPUMIPSState
, CP0_EntryLo0
));
5058 goto mfhc0_read_zero
;
5064 gen_mfhc0_entrylo(arg
, offsetof(CPUMIPSState
, CP0_EntryLo1
));
5068 goto mfhc0_read_zero
;
5074 gen_mfhc0_load64(arg
, offsetof(CPUMIPSState
, lladdr
),
5075 ctx
->CP0_LLAddr_shift
);
5079 goto mfhc0_read_zero
;
5088 gen_mfhc0_load64(arg
, offsetof(CPUMIPSState
, CP0_TagLo
), 0);
5092 goto mfhc0_read_zero
;
5096 goto mfhc0_read_zero
;
5099 (void)rn
; /* avoid a compiler warning */
5100 LOG_DISAS("mfhc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5104 LOG_DISAS("mfhc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5105 tcg_gen_movi_tl(arg
, 0);
5108 static void gen_mthc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
5110 const char *rn
= "invalid";
5111 uint64_t mask
= ctx
->PAMask
>> 36;
5113 if (!(ctx
->hflags
& MIPS_HFLAG_ELPA
)) {
5121 tcg_gen_andi_tl(arg
, arg
, mask
);
5122 gen_mthc0_entrylo(arg
, offsetof(CPUMIPSState
, CP0_EntryLo0
));
5132 tcg_gen_andi_tl(arg
, arg
, mask
);
5133 gen_mthc0_entrylo(arg
, offsetof(CPUMIPSState
, CP0_EntryLo1
));
5143 /* LLAddr is read-only (the only exception is bit 0 if LLB is
5144 supported); the CP0_LLAddr_rw_bitmask does not seem to be
5145 relevant for modern MIPS cores supporting MTHC0, therefore
5146 treating MTHC0 to LLAddr as NOP. */
5159 tcg_gen_andi_tl(arg
, arg
, mask
);
5160 gen_mthc0_store64(arg
, offsetof(CPUMIPSState
, CP0_TagLo
));
5171 (void)rn
; /* avoid a compiler warning */
5173 LOG_DISAS("mthc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5176 static inline void gen_mfc0_unimplemented(DisasContext
*ctx
, TCGv arg
)
5178 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
5179 tcg_gen_movi_tl(arg
, 0);
5181 tcg_gen_movi_tl(arg
, ~0);
5185 #define CP0_CHECK(c) \
5188 goto cp0_unimplemented; \
5192 static void gen_mfc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
5194 const char *rn
= "invalid";
5197 check_insn(ctx
, ISA_MIPS32
);
5203 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Index
));
5207 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5208 gen_helper_mfc0_mvpcontrol(arg
, cpu_env
);
5212 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5213 gen_helper_mfc0_mvpconf0(arg
, cpu_env
);
5217 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5218 gen_helper_mfc0_mvpconf1(arg
, cpu_env
);
5222 goto cp0_unimplemented
;
5228 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS32R6
));
5229 gen_helper_mfc0_random(arg
, cpu_env
);
5233 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5234 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEControl
));
5238 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5239 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf0
));
5243 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5244 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf1
));
5248 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5249 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_YQMask
));
5253 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5254 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
5258 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5259 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
5260 rn
= "VPEScheFBack";
5263 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5264 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEOpt
));
5268 goto cp0_unimplemented
;
5275 TCGv_i64 tmp
= tcg_temp_new_i64();
5276 tcg_gen_ld_i64(tmp
, cpu_env
,
5277 offsetof(CPUMIPSState
, CP0_EntryLo0
));
5278 #if defined(TARGET_MIPS64)
5280 /* Move RI/XI fields to bits 31:30 */
5281 tcg_gen_shri_tl(arg
, tmp
, CP0EnLo_XI
);
5282 tcg_gen_deposit_tl(tmp
, tmp
, arg
, 30, 2);
5285 gen_move_low32(arg
, tmp
);
5286 tcg_temp_free_i64(tmp
);
5291 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5292 gen_helper_mfc0_tcstatus(arg
, cpu_env
);
5296 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5297 gen_helper_mfc0_tcbind(arg
, cpu_env
);
5301 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5302 gen_helper_mfc0_tcrestart(arg
, cpu_env
);
5306 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5307 gen_helper_mfc0_tchalt(arg
, cpu_env
);
5311 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5312 gen_helper_mfc0_tccontext(arg
, cpu_env
);
5316 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5317 gen_helper_mfc0_tcschedule(arg
, cpu_env
);
5321 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5322 gen_helper_mfc0_tcschefback(arg
, cpu_env
);
5326 goto cp0_unimplemented
;
5333 TCGv_i64 tmp
= tcg_temp_new_i64();
5334 tcg_gen_ld_i64(tmp
, cpu_env
,
5335 offsetof(CPUMIPSState
, CP0_EntryLo1
));
5336 #if defined(TARGET_MIPS64)
5338 /* Move RI/XI fields to bits 31:30 */
5339 tcg_gen_shri_tl(arg
, tmp
, CP0EnLo_XI
);
5340 tcg_gen_deposit_tl(tmp
, tmp
, arg
, 30, 2);
5343 gen_move_low32(arg
, tmp
);
5344 tcg_temp_free_i64(tmp
);
5349 goto cp0_unimplemented
;
5355 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_Context
));
5356 tcg_gen_ext32s_tl(arg
, arg
);
5360 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
5361 rn
= "ContextConfig";
5362 goto cp0_unimplemented
;
5365 CP0_CHECK(ctx
->ulri
);
5366 tcg_gen_ld32s_tl(arg
, cpu_env
,
5367 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
5371 goto cp0_unimplemented
;
5377 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageMask
));
5381 check_insn(ctx
, ISA_MIPS32R2
);
5382 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageGrain
));
5386 goto cp0_unimplemented
;
5392 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Wired
));
5396 check_insn(ctx
, ISA_MIPS32R2
);
5397 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf0
));
5401 check_insn(ctx
, ISA_MIPS32R2
);
5402 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf1
));
5406 check_insn(ctx
, ISA_MIPS32R2
);
5407 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf2
));
5411 check_insn(ctx
, ISA_MIPS32R2
);
5412 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf3
));
5416 check_insn(ctx
, ISA_MIPS32R2
);
5417 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf4
));
5421 goto cp0_unimplemented
;
5427 check_insn(ctx
, ISA_MIPS32R2
);
5428 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_HWREna
));
5432 goto cp0_unimplemented
;
5438 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_BadVAddr
));
5439 tcg_gen_ext32s_tl(arg
, arg
);
5444 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstr
));
5449 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstrP
));
5453 goto cp0_unimplemented
;
5459 /* Mark as an IO operation because we read the time. */
5460 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
5463 gen_helper_mfc0_count(arg
, cpu_env
);
5464 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
5467 /* Break the TB to be able to take timer interrupts immediately
5468 after reading count. */
5469 ctx
->bstate
= BS_STOP
;
5472 /* 6,7 are implementation dependent */
5474 goto cp0_unimplemented
;
5480 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryHi
));
5481 tcg_gen_ext32s_tl(arg
, arg
);
5485 goto cp0_unimplemented
;
5491 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Compare
));
5494 /* 6,7 are implementation dependent */
5496 goto cp0_unimplemented
;
5502 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Status
));
5506 check_insn(ctx
, ISA_MIPS32R2
);
5507 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_IntCtl
));
5511 check_insn(ctx
, ISA_MIPS32R2
);
5512 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
5516 check_insn(ctx
, ISA_MIPS32R2
);
5517 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
5521 goto cp0_unimplemented
;
5527 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Cause
));
5531 goto cp0_unimplemented
;
5537 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EPC
));
5538 tcg_gen_ext32s_tl(arg
, arg
);
5542 goto cp0_unimplemented
;
5548 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PRid
));
5552 check_insn(ctx
, ISA_MIPS32R2
);
5553 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_EBase
));
5557 goto cp0_unimplemented
;
5563 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config0
));
5567 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config1
));
5571 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config2
));
5575 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config3
));
5579 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config4
));
5583 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config5
));
5586 /* 6,7 are implementation dependent */
5588 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config6
));
5592 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config7
));
5596 goto cp0_unimplemented
;
5602 gen_helper_mfc0_lladdr(arg
, cpu_env
);
5606 goto cp0_unimplemented
;
5612 gen_helper_1e0i(mfc0_watchlo
, arg
, sel
);
5616 goto cp0_unimplemented
;
5622 gen_helper_1e0i(mfc0_watchhi
, arg
, sel
);
5626 goto cp0_unimplemented
;
5632 #if defined(TARGET_MIPS64)
5633 check_insn(ctx
, ISA_MIPS3
);
5634 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_XContext
));
5635 tcg_gen_ext32s_tl(arg
, arg
);
5640 goto cp0_unimplemented
;
5644 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5645 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS32R6
));
5648 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Framemask
));
5652 goto cp0_unimplemented
;
5656 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
5657 rn
= "'Diagnostic"; /* implementation dependent */
5662 gen_helper_mfc0_debug(arg
, cpu_env
); /* EJTAG support */
5666 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
5667 rn
= "TraceControl";
5670 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
5671 rn
= "TraceControl2";
5674 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
5675 rn
= "UserTraceData";
5678 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
5682 goto cp0_unimplemented
;
5689 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
5690 tcg_gen_ext32s_tl(arg
, arg
);
5694 goto cp0_unimplemented
;
5700 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Performance0
));
5701 rn
= "Performance0";
5704 // gen_helper_mfc0_performance1(arg);
5705 rn
= "Performance1";
5708 // gen_helper_mfc0_performance2(arg);
5709 rn
= "Performance2";
5712 // gen_helper_mfc0_performance3(arg);
5713 rn
= "Performance3";
5716 // gen_helper_mfc0_performance4(arg);
5717 rn
= "Performance4";
5720 // gen_helper_mfc0_performance5(arg);
5721 rn
= "Performance5";
5724 // gen_helper_mfc0_performance6(arg);
5725 rn
= "Performance6";
5728 // gen_helper_mfc0_performance7(arg);
5729 rn
= "Performance7";
5732 goto cp0_unimplemented
;
5736 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
5742 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
5746 goto cp0_unimplemented
;
5756 TCGv_i64 tmp
= tcg_temp_new_i64();
5757 tcg_gen_ld_i64(tmp
, cpu_env
, offsetof(CPUMIPSState
, CP0_TagLo
));
5758 gen_move_low32(arg
, tmp
);
5759 tcg_temp_free_i64(tmp
);
5767 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataLo
));
5771 goto cp0_unimplemented
;
5780 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagHi
));
5787 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataHi
));
5791 goto cp0_unimplemented
;
5797 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
5798 tcg_gen_ext32s_tl(arg
, arg
);
5802 goto cp0_unimplemented
;
5809 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
5813 CP0_CHECK(ctx
->kscrexist
& (1 << sel
));
5814 tcg_gen_ld_tl(arg
, cpu_env
,
5815 offsetof(CPUMIPSState
, CP0_KScratch
[sel
-2]));
5816 tcg_gen_ext32s_tl(arg
, arg
);
5820 goto cp0_unimplemented
;
5824 goto cp0_unimplemented
;
5826 (void)rn
; /* avoid a compiler warning */
5827 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5831 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5832 gen_mfc0_unimplemented(ctx
, arg
);
5835 static void gen_mtc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
5837 const char *rn
= "invalid";
5840 check_insn(ctx
, ISA_MIPS32
);
5842 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
5850 gen_helper_mtc0_index(cpu_env
, arg
);
5854 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5855 gen_helper_mtc0_mvpcontrol(cpu_env
, arg
);
5859 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5864 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5869 goto cp0_unimplemented
;
5879 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5880 gen_helper_mtc0_vpecontrol(cpu_env
, arg
);
5884 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5885 gen_helper_mtc0_vpeconf0(cpu_env
, arg
);
5889 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5890 gen_helper_mtc0_vpeconf1(cpu_env
, arg
);
5894 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5895 gen_helper_mtc0_yqmask(cpu_env
, arg
);
5899 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5900 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
5904 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5905 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
5906 rn
= "VPEScheFBack";
5909 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5910 gen_helper_mtc0_vpeopt(cpu_env
, arg
);
5914 goto cp0_unimplemented
;
5920 gen_helper_mtc0_entrylo0(cpu_env
, arg
);
5924 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5925 gen_helper_mtc0_tcstatus(cpu_env
, arg
);
5929 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5930 gen_helper_mtc0_tcbind(cpu_env
, arg
);
5934 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5935 gen_helper_mtc0_tcrestart(cpu_env
, arg
);
5939 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5940 gen_helper_mtc0_tchalt(cpu_env
, arg
);
5944 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5945 gen_helper_mtc0_tccontext(cpu_env
, arg
);
5949 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5950 gen_helper_mtc0_tcschedule(cpu_env
, arg
);
5954 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5955 gen_helper_mtc0_tcschefback(cpu_env
, arg
);
5959 goto cp0_unimplemented
;
5965 gen_helper_mtc0_entrylo1(cpu_env
, arg
);
5969 goto cp0_unimplemented
;
5975 gen_helper_mtc0_context(cpu_env
, arg
);
5979 // gen_helper_mtc0_contextconfig(cpu_env, arg); /* SmartMIPS ASE */
5980 rn
= "ContextConfig";
5981 goto cp0_unimplemented
;
5984 CP0_CHECK(ctx
->ulri
);
5985 tcg_gen_st_tl(arg
, cpu_env
,
5986 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
5990 goto cp0_unimplemented
;
5996 gen_helper_mtc0_pagemask(cpu_env
, arg
);
6000 check_insn(ctx
, ISA_MIPS32R2
);
6001 gen_helper_mtc0_pagegrain(cpu_env
, arg
);
6003 ctx
->bstate
= BS_STOP
;
6006 goto cp0_unimplemented
;
6012 gen_helper_mtc0_wired(cpu_env
, arg
);
6016 check_insn(ctx
, ISA_MIPS32R2
);
6017 gen_helper_mtc0_srsconf0(cpu_env
, arg
);
6021 check_insn(ctx
, ISA_MIPS32R2
);
6022 gen_helper_mtc0_srsconf1(cpu_env
, arg
);
6026 check_insn(ctx
, ISA_MIPS32R2
);
6027 gen_helper_mtc0_srsconf2(cpu_env
, arg
);
6031 check_insn(ctx
, ISA_MIPS32R2
);
6032 gen_helper_mtc0_srsconf3(cpu_env
, arg
);
6036 check_insn(ctx
, ISA_MIPS32R2
);
6037 gen_helper_mtc0_srsconf4(cpu_env
, arg
);
6041 goto cp0_unimplemented
;
6047 check_insn(ctx
, ISA_MIPS32R2
);
6048 gen_helper_mtc0_hwrena(cpu_env
, arg
);
6049 ctx
->bstate
= BS_STOP
;
6053 goto cp0_unimplemented
;
6071 goto cp0_unimplemented
;
6077 gen_helper_mtc0_count(cpu_env
, arg
);
6080 /* 6,7 are implementation dependent */
6082 goto cp0_unimplemented
;
6088 gen_helper_mtc0_entryhi(cpu_env
, arg
);
6092 goto cp0_unimplemented
;
6098 gen_helper_mtc0_compare(cpu_env
, arg
);
6101 /* 6,7 are implementation dependent */
6103 goto cp0_unimplemented
;
6109 save_cpu_state(ctx
, 1);
6110 gen_helper_mtc0_status(cpu_env
, arg
);
6111 /* BS_STOP isn't good enough here, hflags may have changed. */
6112 gen_save_pc(ctx
->pc
+ 4);
6113 ctx
->bstate
= BS_EXCP
;
6117 check_insn(ctx
, ISA_MIPS32R2
);
6118 gen_helper_mtc0_intctl(cpu_env
, arg
);
6119 /* Stop translation as we may have switched the execution mode */
6120 ctx
->bstate
= BS_STOP
;
6124 check_insn(ctx
, ISA_MIPS32R2
);
6125 gen_helper_mtc0_srsctl(cpu_env
, arg
);
6126 /* Stop translation as we may have switched the execution mode */
6127 ctx
->bstate
= BS_STOP
;
6131 check_insn(ctx
, ISA_MIPS32R2
);
6132 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
6133 /* Stop translation as we may have switched the execution mode */
6134 ctx
->bstate
= BS_STOP
;
6138 goto cp0_unimplemented
;
6144 save_cpu_state(ctx
, 1);
6145 gen_helper_mtc0_cause(cpu_env
, arg
);
6149 goto cp0_unimplemented
;
6155 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_EPC
));
6159 goto cp0_unimplemented
;
6169 check_insn(ctx
, ISA_MIPS32R2
);
6170 gen_helper_mtc0_ebase(cpu_env
, arg
);
6174 goto cp0_unimplemented
;
6180 gen_helper_mtc0_config0(cpu_env
, arg
);
6182 /* Stop translation as we may have switched the execution mode */
6183 ctx
->bstate
= BS_STOP
;
6186 /* ignored, read only */
6190 gen_helper_mtc0_config2(cpu_env
, arg
);
6192 /* Stop translation as we may have switched the execution mode */
6193 ctx
->bstate
= BS_STOP
;
6196 gen_helper_mtc0_config3(cpu_env
, arg
);
6198 /* Stop translation as we may have switched the execution mode */
6199 ctx
->bstate
= BS_STOP
;
6202 gen_helper_mtc0_config4(cpu_env
, arg
);
6204 ctx
->bstate
= BS_STOP
;
6207 gen_helper_mtc0_config5(cpu_env
, arg
);
6209 /* Stop translation as we may have switched the execution mode */
6210 ctx
->bstate
= BS_STOP
;
6212 /* 6,7 are implementation dependent */
6222 rn
= "Invalid config selector";
6223 goto cp0_unimplemented
;
6229 gen_helper_mtc0_lladdr(cpu_env
, arg
);
6233 goto cp0_unimplemented
;
6239 gen_helper_0e1i(mtc0_watchlo
, arg
, sel
);
6243 goto cp0_unimplemented
;
6249 gen_helper_0e1i(mtc0_watchhi
, arg
, sel
);
6253 goto cp0_unimplemented
;
6259 #if defined(TARGET_MIPS64)
6260 check_insn(ctx
, ISA_MIPS3
);
6261 gen_helper_mtc0_xcontext(cpu_env
, arg
);
6266 goto cp0_unimplemented
;
6270 /* Officially reserved, but sel 0 is used for R1x000 framemask */
6271 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS32R6
));
6274 gen_helper_mtc0_framemask(cpu_env
, arg
);
6278 goto cp0_unimplemented
;
6283 rn
= "Diagnostic"; /* implementation dependent */
6288 gen_helper_mtc0_debug(cpu_env
, arg
); /* EJTAG support */
6289 /* BS_STOP isn't good enough here, hflags may have changed. */
6290 gen_save_pc(ctx
->pc
+ 4);
6291 ctx
->bstate
= BS_EXCP
;
6295 // gen_helper_mtc0_tracecontrol(cpu_env, arg); /* PDtrace support */
6296 rn
= "TraceControl";
6297 /* Stop translation as we may have switched the execution mode */
6298 ctx
->bstate
= BS_STOP
;
6301 // gen_helper_mtc0_tracecontrol2(cpu_env, arg); /* PDtrace support */
6302 rn
= "TraceControl2";
6303 /* Stop translation as we may have switched the execution mode */
6304 ctx
->bstate
= BS_STOP
;
6307 /* Stop translation as we may have switched the execution mode */
6308 ctx
->bstate
= BS_STOP
;
6309 // gen_helper_mtc0_usertracedata(cpu_env, arg); /* PDtrace support */
6310 rn
= "UserTraceData";
6311 /* Stop translation as we may have switched the execution mode */
6312 ctx
->bstate
= BS_STOP
;
6315 // gen_helper_mtc0_tracebpc(cpu_env, arg); /* PDtrace support */
6316 /* Stop translation as we may have switched the execution mode */
6317 ctx
->bstate
= BS_STOP
;
6321 goto cp0_unimplemented
;
6328 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_DEPC
));
6332 goto cp0_unimplemented
;
6338 gen_helper_mtc0_performance0(cpu_env
, arg
);
6339 rn
= "Performance0";
6342 // gen_helper_mtc0_performance1(arg);
6343 rn
= "Performance1";
6346 // gen_helper_mtc0_performance2(arg);
6347 rn
= "Performance2";
6350 // gen_helper_mtc0_performance3(arg);
6351 rn
= "Performance3";
6354 // gen_helper_mtc0_performance4(arg);
6355 rn
= "Performance4";
6358 // gen_helper_mtc0_performance5(arg);
6359 rn
= "Performance5";
6362 // gen_helper_mtc0_performance6(arg);
6363 rn
= "Performance6";
6366 // gen_helper_mtc0_performance7(arg);
6367 rn
= "Performance7";
6370 goto cp0_unimplemented
;
6384 goto cp0_unimplemented
;
6393 gen_helper_mtc0_taglo(cpu_env
, arg
);
6400 gen_helper_mtc0_datalo(cpu_env
, arg
);
6404 goto cp0_unimplemented
;
6413 gen_helper_mtc0_taghi(cpu_env
, arg
);
6420 gen_helper_mtc0_datahi(cpu_env
, arg
);
6425 goto cp0_unimplemented
;
6431 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
6435 goto cp0_unimplemented
;
6442 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
6446 CP0_CHECK(ctx
->kscrexist
& (1 << sel
));
6447 tcg_gen_st_tl(arg
, cpu_env
,
6448 offsetof(CPUMIPSState
, CP0_KScratch
[sel
-2]));
6452 goto cp0_unimplemented
;
6454 /* Stop translation as we may have switched the execution mode */
6455 ctx
->bstate
= BS_STOP
;
6458 goto cp0_unimplemented
;
6460 (void)rn
; /* avoid a compiler warning */
6461 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
6462 /* For simplicity assume that all writes can cause interrupts. */
6463 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
6465 ctx
->bstate
= BS_STOP
;
6470 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
6473 #if defined(TARGET_MIPS64)
6474 static void gen_dmfc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
6476 const char *rn
= "invalid";
6479 check_insn(ctx
, ISA_MIPS64
);
6485 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Index
));
6489 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6490 gen_helper_mfc0_mvpcontrol(arg
, cpu_env
);
6494 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6495 gen_helper_mfc0_mvpconf0(arg
, cpu_env
);
6499 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6500 gen_helper_mfc0_mvpconf1(arg
, cpu_env
);
6504 goto cp0_unimplemented
;
6510 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS32R6
));
6511 gen_helper_mfc0_random(arg
, cpu_env
);
6515 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6516 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEControl
));
6520 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6521 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf0
));
6525 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6526 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf1
));
6530 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6531 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_YQMask
));
6535 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6536 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
6540 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6541 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
6542 rn
= "VPEScheFBack";
6545 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6546 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEOpt
));
6550 goto cp0_unimplemented
;
6556 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryLo0
));
6560 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6561 gen_helper_mfc0_tcstatus(arg
, cpu_env
);
6565 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6566 gen_helper_mfc0_tcbind(arg
, cpu_env
);
6570 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6571 gen_helper_dmfc0_tcrestart(arg
, cpu_env
);
6575 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6576 gen_helper_dmfc0_tchalt(arg
, cpu_env
);
6580 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6581 gen_helper_dmfc0_tccontext(arg
, cpu_env
);
6585 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6586 gen_helper_dmfc0_tcschedule(arg
, cpu_env
);
6590 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6591 gen_helper_dmfc0_tcschefback(arg
, cpu_env
);
6595 goto cp0_unimplemented
;
6601 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryLo1
));
6605 goto cp0_unimplemented
;
6611 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_Context
));
6615 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
6616 rn
= "ContextConfig";
6617 goto cp0_unimplemented
;
6620 CP0_CHECK(ctx
->ulri
);
6621 tcg_gen_ld_tl(arg
, cpu_env
,
6622 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
6626 goto cp0_unimplemented
;
6632 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageMask
));
6636 check_insn(ctx
, ISA_MIPS32R2
);
6637 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageGrain
));
6641 goto cp0_unimplemented
;
6647 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Wired
));
6651 check_insn(ctx
, ISA_MIPS32R2
);
6652 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf0
));
6656 check_insn(ctx
, ISA_MIPS32R2
);
6657 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf1
));
6661 check_insn(ctx
, ISA_MIPS32R2
);
6662 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf2
));
6666 check_insn(ctx
, ISA_MIPS32R2
);
6667 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf3
));
6671 check_insn(ctx
, ISA_MIPS32R2
);
6672 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf4
));
6676 goto cp0_unimplemented
;
6682 check_insn(ctx
, ISA_MIPS32R2
);
6683 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_HWREna
));
6687 goto cp0_unimplemented
;
6693 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_BadVAddr
));
6698 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstr
));
6703 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstrP
));
6707 goto cp0_unimplemented
;
6713 /* Mark as an IO operation because we read the time. */
6714 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
6717 gen_helper_mfc0_count(arg
, cpu_env
);
6718 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
6721 /* Break the TB to be able to take timer interrupts immediately
6722 after reading count. */
6723 ctx
->bstate
= BS_STOP
;
6726 /* 6,7 are implementation dependent */
6728 goto cp0_unimplemented
;
6734 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryHi
));
6738 goto cp0_unimplemented
;
6744 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Compare
));
6747 /* 6,7 are implementation dependent */
6749 goto cp0_unimplemented
;
6755 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Status
));
6759 check_insn(ctx
, ISA_MIPS32R2
);
6760 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_IntCtl
));
6764 check_insn(ctx
, ISA_MIPS32R2
);
6765 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
6769 check_insn(ctx
, ISA_MIPS32R2
);
6770 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
6774 goto cp0_unimplemented
;
6780 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Cause
));
6784 goto cp0_unimplemented
;
6790 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EPC
));
6794 goto cp0_unimplemented
;
6800 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PRid
));
6804 check_insn(ctx
, ISA_MIPS32R2
);
6805 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_EBase
));
6809 goto cp0_unimplemented
;
6815 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config0
));
6819 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config1
));
6823 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config2
));
6827 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config3
));
6831 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config4
));
6835 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config5
));
6838 /* 6,7 are implementation dependent */
6840 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config6
));
6844 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config7
));
6848 goto cp0_unimplemented
;
6854 gen_helper_dmfc0_lladdr(arg
, cpu_env
);
6858 goto cp0_unimplemented
;
6864 gen_helper_1e0i(dmfc0_watchlo
, arg
, sel
);
6868 goto cp0_unimplemented
;
6874 gen_helper_1e0i(mfc0_watchhi
, arg
, sel
);
6878 goto cp0_unimplemented
;
6884 check_insn(ctx
, ISA_MIPS3
);
6885 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_XContext
));
6889 goto cp0_unimplemented
;
6893 /* Officially reserved, but sel 0 is used for R1x000 framemask */
6894 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS32R6
));
6897 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Framemask
));
6901 goto cp0_unimplemented
;
6905 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
6906 rn
= "'Diagnostic"; /* implementation dependent */
6911 gen_helper_mfc0_debug(arg
, cpu_env
); /* EJTAG support */
6915 // gen_helper_dmfc0_tracecontrol(arg, cpu_env); /* PDtrace support */
6916 rn
= "TraceControl";
6919 // gen_helper_dmfc0_tracecontrol2(arg, cpu_env); /* PDtrace support */
6920 rn
= "TraceControl2";
6923 // gen_helper_dmfc0_usertracedata(arg, cpu_env); /* PDtrace support */
6924 rn
= "UserTraceData";
6927 // gen_helper_dmfc0_tracebpc(arg, cpu_env); /* PDtrace support */
6931 goto cp0_unimplemented
;
6938 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
6942 goto cp0_unimplemented
;
6948 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Performance0
));
6949 rn
= "Performance0";
6952 // gen_helper_dmfc0_performance1(arg);
6953 rn
= "Performance1";
6956 // gen_helper_dmfc0_performance2(arg);
6957 rn
= "Performance2";
6960 // gen_helper_dmfc0_performance3(arg);
6961 rn
= "Performance3";
6964 // gen_helper_dmfc0_performance4(arg);
6965 rn
= "Performance4";
6968 // gen_helper_dmfc0_performance5(arg);
6969 rn
= "Performance5";
6972 // gen_helper_dmfc0_performance6(arg);
6973 rn
= "Performance6";
6976 // gen_helper_dmfc0_performance7(arg);
6977 rn
= "Performance7";
6980 goto cp0_unimplemented
;
6984 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
6991 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
6995 goto cp0_unimplemented
;
7004 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagLo
));
7011 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataLo
));
7015 goto cp0_unimplemented
;
7024 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagHi
));
7031 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataHi
));
7035 goto cp0_unimplemented
;
7041 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
7045 goto cp0_unimplemented
;
7052 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
7056 CP0_CHECK(ctx
->kscrexist
& (1 << sel
));
7057 tcg_gen_ld_tl(arg
, cpu_env
,
7058 offsetof(CPUMIPSState
, CP0_KScratch
[sel
-2]));
7062 goto cp0_unimplemented
;
7066 goto cp0_unimplemented
;
7068 (void)rn
; /* avoid a compiler warning */
7069 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
7073 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
7074 gen_mfc0_unimplemented(ctx
, arg
);
7077 static void gen_dmtc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
7079 const char *rn
= "invalid";
7082 check_insn(ctx
, ISA_MIPS64
);
7084 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
7092 gen_helper_mtc0_index(cpu_env
, arg
);
7096 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7097 gen_helper_mtc0_mvpcontrol(cpu_env
, arg
);
7101 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7106 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7111 goto cp0_unimplemented
;
7121 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7122 gen_helper_mtc0_vpecontrol(cpu_env
, arg
);
7126 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7127 gen_helper_mtc0_vpeconf0(cpu_env
, arg
);
7131 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7132 gen_helper_mtc0_vpeconf1(cpu_env
, arg
);
7136 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7137 gen_helper_mtc0_yqmask(cpu_env
, arg
);
7141 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7142 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
7146 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7147 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
7148 rn
= "VPEScheFBack";
7151 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7152 gen_helper_mtc0_vpeopt(cpu_env
, arg
);
7156 goto cp0_unimplemented
;
7162 gen_helper_dmtc0_entrylo0(cpu_env
, arg
);
7166 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7167 gen_helper_mtc0_tcstatus(cpu_env
, arg
);
7171 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7172 gen_helper_mtc0_tcbind(cpu_env
, arg
);
7176 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7177 gen_helper_mtc0_tcrestart(cpu_env
, arg
);
7181 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7182 gen_helper_mtc0_tchalt(cpu_env
, arg
);
7186 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7187 gen_helper_mtc0_tccontext(cpu_env
, arg
);
7191 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7192 gen_helper_mtc0_tcschedule(cpu_env
, arg
);
7196 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7197 gen_helper_mtc0_tcschefback(cpu_env
, arg
);
7201 goto cp0_unimplemented
;
7207 gen_helper_dmtc0_entrylo1(cpu_env
, arg
);
7211 goto cp0_unimplemented
;
7217 gen_helper_mtc0_context(cpu_env
, arg
);
7221 // gen_helper_mtc0_contextconfig(cpu_env, arg); /* SmartMIPS ASE */
7222 rn
= "ContextConfig";
7223 goto cp0_unimplemented
;
7226 CP0_CHECK(ctx
->ulri
);
7227 tcg_gen_st_tl(arg
, cpu_env
,
7228 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
7232 goto cp0_unimplemented
;
7238 gen_helper_mtc0_pagemask(cpu_env
, arg
);
7242 check_insn(ctx
, ISA_MIPS32R2
);
7243 gen_helper_mtc0_pagegrain(cpu_env
, arg
);
7247 goto cp0_unimplemented
;
7253 gen_helper_mtc0_wired(cpu_env
, arg
);
7257 check_insn(ctx
, ISA_MIPS32R2
);
7258 gen_helper_mtc0_srsconf0(cpu_env
, arg
);
7262 check_insn(ctx
, ISA_MIPS32R2
);
7263 gen_helper_mtc0_srsconf1(cpu_env
, arg
);
7267 check_insn(ctx
, ISA_MIPS32R2
);
7268 gen_helper_mtc0_srsconf2(cpu_env
, arg
);
7272 check_insn(ctx
, ISA_MIPS32R2
);
7273 gen_helper_mtc0_srsconf3(cpu_env
, arg
);
7277 check_insn(ctx
, ISA_MIPS32R2
);
7278 gen_helper_mtc0_srsconf4(cpu_env
, arg
);
7282 goto cp0_unimplemented
;
7288 check_insn(ctx
, ISA_MIPS32R2
);
7289 gen_helper_mtc0_hwrena(cpu_env
, arg
);
7290 ctx
->bstate
= BS_STOP
;
7294 goto cp0_unimplemented
;
7312 goto cp0_unimplemented
;
7318 gen_helper_mtc0_count(cpu_env
, arg
);
7321 /* 6,7 are implementation dependent */
7323 goto cp0_unimplemented
;
7325 /* Stop translation as we may have switched the execution mode */
7326 ctx
->bstate
= BS_STOP
;
7331 gen_helper_mtc0_entryhi(cpu_env
, arg
);
7335 goto cp0_unimplemented
;
7341 gen_helper_mtc0_compare(cpu_env
, arg
);
7344 /* 6,7 are implementation dependent */
7346 goto cp0_unimplemented
;
7348 /* Stop translation as we may have switched the execution mode */
7349 ctx
->bstate
= BS_STOP
;
7354 save_cpu_state(ctx
, 1);
7355 gen_helper_mtc0_status(cpu_env
, arg
);
7356 /* BS_STOP isn't good enough here, hflags may have changed. */
7357 gen_save_pc(ctx
->pc
+ 4);
7358 ctx
->bstate
= BS_EXCP
;
7362 check_insn(ctx
, ISA_MIPS32R2
);
7363 gen_helper_mtc0_intctl(cpu_env
, arg
);
7364 /* Stop translation as we may have switched the execution mode */
7365 ctx
->bstate
= BS_STOP
;
7369 check_insn(ctx
, ISA_MIPS32R2
);
7370 gen_helper_mtc0_srsctl(cpu_env
, arg
);
7371 /* Stop translation as we may have switched the execution mode */
7372 ctx
->bstate
= BS_STOP
;
7376 check_insn(ctx
, ISA_MIPS32R2
);
7377 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
7378 /* Stop translation as we may have switched the execution mode */
7379 ctx
->bstate
= BS_STOP
;
7383 goto cp0_unimplemented
;
7389 save_cpu_state(ctx
, 1);
7390 /* Mark as an IO operation because we may trigger a software
7392 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
7395 gen_helper_mtc0_cause(cpu_env
, arg
);
7396 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
7399 /* Stop translation as we may have triggered an intetrupt */
7400 ctx
->bstate
= BS_STOP
;
7404 goto cp0_unimplemented
;
7410 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EPC
));
7414 goto cp0_unimplemented
;
7424 check_insn(ctx
, ISA_MIPS32R2
);
7425 gen_helper_mtc0_ebase(cpu_env
, arg
);
7429 goto cp0_unimplemented
;
7435 gen_helper_mtc0_config0(cpu_env
, arg
);
7437 /* Stop translation as we may have switched the execution mode */
7438 ctx
->bstate
= BS_STOP
;
7441 /* ignored, read only */
7445 gen_helper_mtc0_config2(cpu_env
, arg
);
7447 /* Stop translation as we may have switched the execution mode */
7448 ctx
->bstate
= BS_STOP
;
7451 gen_helper_mtc0_config3(cpu_env
, arg
);
7453 /* Stop translation as we may have switched the execution mode */
7454 ctx
->bstate
= BS_STOP
;
7457 /* currently ignored */
7461 gen_helper_mtc0_config5(cpu_env
, arg
);
7463 /* Stop translation as we may have switched the execution mode */
7464 ctx
->bstate
= BS_STOP
;
7466 /* 6,7 are implementation dependent */
7468 rn
= "Invalid config selector";
7469 goto cp0_unimplemented
;
7475 gen_helper_mtc0_lladdr(cpu_env
, arg
);
7479 goto cp0_unimplemented
;
7485 gen_helper_0e1i(mtc0_watchlo
, arg
, sel
);
7489 goto cp0_unimplemented
;
7495 gen_helper_0e1i(mtc0_watchhi
, arg
, sel
);
7499 goto cp0_unimplemented
;
7505 check_insn(ctx
, ISA_MIPS3
);
7506 gen_helper_mtc0_xcontext(cpu_env
, arg
);
7510 goto cp0_unimplemented
;
7514 /* Officially reserved, but sel 0 is used for R1x000 framemask */
7515 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS32R6
));
7518 gen_helper_mtc0_framemask(cpu_env
, arg
);
7522 goto cp0_unimplemented
;
7527 rn
= "Diagnostic"; /* implementation dependent */
7532 gen_helper_mtc0_debug(cpu_env
, arg
); /* EJTAG support */
7533 /* BS_STOP isn't good enough here, hflags may have changed. */
7534 gen_save_pc(ctx
->pc
+ 4);
7535 ctx
->bstate
= BS_EXCP
;
7539 // gen_helper_mtc0_tracecontrol(cpu_env, arg); /* PDtrace support */
7540 /* Stop translation as we may have switched the execution mode */
7541 ctx
->bstate
= BS_STOP
;
7542 rn
= "TraceControl";
7545 // gen_helper_mtc0_tracecontrol2(cpu_env, arg); /* PDtrace support */
7546 /* Stop translation as we may have switched the execution mode */
7547 ctx
->bstate
= BS_STOP
;
7548 rn
= "TraceControl2";
7551 // gen_helper_mtc0_usertracedata(cpu_env, arg); /* PDtrace support */
7552 /* Stop translation as we may have switched the execution mode */
7553 ctx
->bstate
= BS_STOP
;
7554 rn
= "UserTraceData";
7557 // gen_helper_mtc0_tracebpc(cpu_env, arg); /* PDtrace support */
7558 /* Stop translation as we may have switched the execution mode */
7559 ctx
->bstate
= BS_STOP
;
7563 goto cp0_unimplemented
;
7570 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
7574 goto cp0_unimplemented
;
7580 gen_helper_mtc0_performance0(cpu_env
, arg
);
7581 rn
= "Performance0";
7584 // gen_helper_mtc0_performance1(cpu_env, arg);
7585 rn
= "Performance1";
7588 // gen_helper_mtc0_performance2(cpu_env, arg);
7589 rn
= "Performance2";
7592 // gen_helper_mtc0_performance3(cpu_env, arg);
7593 rn
= "Performance3";
7596 // gen_helper_mtc0_performance4(cpu_env, arg);
7597 rn
= "Performance4";
7600 // gen_helper_mtc0_performance5(cpu_env, arg);
7601 rn
= "Performance5";
7604 // gen_helper_mtc0_performance6(cpu_env, arg);
7605 rn
= "Performance6";
7608 // gen_helper_mtc0_performance7(cpu_env, arg);
7609 rn
= "Performance7";
7612 goto cp0_unimplemented
;
7626 goto cp0_unimplemented
;
7635 gen_helper_mtc0_taglo(cpu_env
, arg
);
7642 gen_helper_mtc0_datalo(cpu_env
, arg
);
7646 goto cp0_unimplemented
;
7655 gen_helper_mtc0_taghi(cpu_env
, arg
);
7662 gen_helper_mtc0_datahi(cpu_env
, arg
);
7667 goto cp0_unimplemented
;
7673 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
7677 goto cp0_unimplemented
;
7684 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
7688 CP0_CHECK(ctx
->kscrexist
& (1 << sel
));
7689 tcg_gen_st_tl(arg
, cpu_env
,
7690 offsetof(CPUMIPSState
, CP0_KScratch
[sel
-2]));
7694 goto cp0_unimplemented
;
7696 /* Stop translation as we may have switched the execution mode */
7697 ctx
->bstate
= BS_STOP
;
7700 goto cp0_unimplemented
;
7702 (void)rn
; /* avoid a compiler warning */
7703 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
7704 /* For simplicity assume that all writes can cause interrupts. */
7705 if (ctx
->tb
->cflags
& CF_USE_ICOUNT
) {
7707 ctx
->bstate
= BS_STOP
;
7712 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
7714 #endif /* TARGET_MIPS64 */
7716 static void gen_mftr(CPUMIPSState
*env
, DisasContext
*ctx
, int rt
, int rd
,
7717 int u
, int sel
, int h
)
7719 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
7720 TCGv t0
= tcg_temp_local_new();
7722 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
7723 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
7724 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
7725 tcg_gen_movi_tl(t0
, -1);
7726 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
7727 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
7728 tcg_gen_movi_tl(t0
, -1);
7734 gen_helper_mftc0_vpecontrol(t0
, cpu_env
);
7737 gen_helper_mftc0_vpeconf0(t0
, cpu_env
);
7747 gen_helper_mftc0_tcstatus(t0
, cpu_env
);
7750 gen_helper_mftc0_tcbind(t0
, cpu_env
);
7753 gen_helper_mftc0_tcrestart(t0
, cpu_env
);
7756 gen_helper_mftc0_tchalt(t0
, cpu_env
);
7759 gen_helper_mftc0_tccontext(t0
, cpu_env
);
7762 gen_helper_mftc0_tcschedule(t0
, cpu_env
);
7765 gen_helper_mftc0_tcschefback(t0
, cpu_env
);
7768 gen_mfc0(ctx
, t0
, rt
, sel
);
7775 gen_helper_mftc0_entryhi(t0
, cpu_env
);
7778 gen_mfc0(ctx
, t0
, rt
, sel
);
7784 gen_helper_mftc0_status(t0
, cpu_env
);
7787 gen_mfc0(ctx
, t0
, rt
, sel
);
7793 gen_helper_mftc0_cause(t0
, cpu_env
);
7803 gen_helper_mftc0_epc(t0
, cpu_env
);
7813 gen_helper_mftc0_ebase(t0
, cpu_env
);
7823 gen_helper_mftc0_configx(t0
, cpu_env
, tcg_const_tl(sel
));
7833 gen_helper_mftc0_debug(t0
, cpu_env
);
7836 gen_mfc0(ctx
, t0
, rt
, sel
);
7841 gen_mfc0(ctx
, t0
, rt
, sel
);
7843 } else switch (sel
) {
7844 /* GPR registers. */
7846 gen_helper_1e0i(mftgpr
, t0
, rt
);
7848 /* Auxiliary CPU registers */
7852 gen_helper_1e0i(mftlo
, t0
, 0);
7855 gen_helper_1e0i(mfthi
, t0
, 0);
7858 gen_helper_1e0i(mftacx
, t0
, 0);
7861 gen_helper_1e0i(mftlo
, t0
, 1);
7864 gen_helper_1e0i(mfthi
, t0
, 1);
7867 gen_helper_1e0i(mftacx
, t0
, 1);
7870 gen_helper_1e0i(mftlo
, t0
, 2);
7873 gen_helper_1e0i(mfthi
, t0
, 2);
7876 gen_helper_1e0i(mftacx
, t0
, 2);
7879 gen_helper_1e0i(mftlo
, t0
, 3);
7882 gen_helper_1e0i(mfthi
, t0
, 3);
7885 gen_helper_1e0i(mftacx
, t0
, 3);
7888 gen_helper_mftdsp(t0
, cpu_env
);
7894 /* Floating point (COP1). */
7896 /* XXX: For now we support only a single FPU context. */
7898 TCGv_i32 fp0
= tcg_temp_new_i32();
7900 gen_load_fpr32(ctx
, fp0
, rt
);
7901 tcg_gen_ext_i32_tl(t0
, fp0
);
7902 tcg_temp_free_i32(fp0
);
7904 TCGv_i32 fp0
= tcg_temp_new_i32();
7906 gen_load_fpr32h(ctx
, fp0
, rt
);
7907 tcg_gen_ext_i32_tl(t0
, fp0
);
7908 tcg_temp_free_i32(fp0
);
7912 /* XXX: For now we support only a single FPU context. */
7913 gen_helper_1e0i(cfc1
, t0
, rt
);
7915 /* COP2: Not implemented. */
7922 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
7923 gen_store_gpr(t0
, rd
);
7929 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
7930 generate_exception(ctx
, EXCP_RI
);
7933 static void gen_mttr(CPUMIPSState
*env
, DisasContext
*ctx
, int rd
, int rt
,
7934 int u
, int sel
, int h
)
7936 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
7937 TCGv t0
= tcg_temp_local_new();
7939 gen_load_gpr(t0
, rt
);
7940 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
7941 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
7942 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
7944 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
7945 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
7952 gen_helper_mttc0_vpecontrol(cpu_env
, t0
);
7955 gen_helper_mttc0_vpeconf0(cpu_env
, t0
);
7965 gen_helper_mttc0_tcstatus(cpu_env
, t0
);
7968 gen_helper_mttc0_tcbind(cpu_env
, t0
);
7971 gen_helper_mttc0_tcrestart(cpu_env
, t0
);
7974 gen_helper_mttc0_tchalt(cpu_env
, t0
);
7977 gen_helper_mttc0_tccontext(cpu_env
, t0
);
7980 gen_helper_mttc0_tcschedule(cpu_env
, t0
);
7983 gen_helper_mttc0_tcschefback(cpu_env
, t0
);
7986 gen_mtc0(ctx
, t0
, rd
, sel
);
7993 gen_helper_mttc0_entryhi(cpu_env
, t0
);
7996 gen_mtc0(ctx
, t0
, rd
, sel
);
8002 gen_helper_mttc0_status(cpu_env
, t0
);
8005 gen_mtc0(ctx
, t0
, rd
, sel
);
8011 gen_helper_mttc0_cause(cpu_env
, t0
);
8021 gen_helper_mttc0_ebase(cpu_env
, t0
);
8031 gen_helper_mttc0_debug(cpu_env
, t0
);
8034 gen_mtc0(ctx
, t0
, rd
, sel
);
8039 gen_mtc0(ctx
, t0
, rd
, sel
);
8041 } else switch (sel
) {
8042 /* GPR registers. */
8044 gen_helper_0e1i(mttgpr
, t0
, rd
);
8046 /* Auxiliary CPU registers */
8050 gen_helper_0e1i(mttlo
, t0
, 0);
8053 gen_helper_0e1i(mtthi
, t0
, 0);
8056 gen_helper_0e1i(mttacx
, t0
, 0);
8059 gen_helper_0e1i(mttlo
, t0
, 1);
8062 gen_helper_0e1i(mtthi
, t0
, 1);
8065 gen_helper_0e1i(mttacx
, t0
, 1);
8068 gen_helper_0e1i(mttlo
, t0
, 2);
8071 gen_helper_0e1i(mtthi
, t0
, 2);
8074 gen_helper_0e1i(mttacx
, t0
, 2);
8077 gen_helper_0e1i(mttlo
, t0
, 3);
8080 gen_helper_0e1i(mtthi
, t0
, 3);
8083 gen_helper_0e1i(mttacx
, t0
, 3);
8086 gen_helper_mttdsp(cpu_env
, t0
);
8092 /* Floating point (COP1). */
8094 /* XXX: For now we support only a single FPU context. */
8096 TCGv_i32 fp0
= tcg_temp_new_i32();
8098 tcg_gen_trunc_tl_i32(fp0
, t0
);
8099 gen_store_fpr32(ctx
, fp0
, rd
);
8100 tcg_temp_free_i32(fp0
);
8102 TCGv_i32 fp0
= tcg_temp_new_i32();
8104 tcg_gen_trunc_tl_i32(fp0
, t0
);
8105 gen_store_fpr32h(ctx
, fp0
, rd
);
8106 tcg_temp_free_i32(fp0
);
8110 /* XXX: For now we support only a single FPU context. */
8111 save_cpu_state(ctx
, 1);
8113 TCGv_i32 fs_tmp
= tcg_const_i32(rd
);
8115 gen_helper_0e2i(ctc1
, t0
, fs_tmp
, rt
);
8116 tcg_temp_free_i32(fs_tmp
);
8118 /* Stop translation as we may have changed hflags */
8119 ctx
->bstate
= BS_STOP
;
8121 /* COP2: Not implemented. */
8128 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
8134 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
8135 generate_exception(ctx
, EXCP_RI
);
8138 static void gen_cp0 (CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
8140 const char *opn
= "ldst";
8142 check_cp0_enabled(ctx
);
8149 gen_mfc0(ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
8154 TCGv t0
= tcg_temp_new();
8156 gen_load_gpr(t0
, rt
);
8157 gen_mtc0(ctx
, t0
, rd
, ctx
->opcode
& 0x7);
8162 #if defined(TARGET_MIPS64)
8164 check_insn(ctx
, ISA_MIPS3
);
8169 gen_dmfc0(ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
8173 check_insn(ctx
, ISA_MIPS3
);
8175 TCGv t0
= tcg_temp_new();
8177 gen_load_gpr(t0
, rt
);
8178 gen_dmtc0(ctx
, t0
, rd
, ctx
->opcode
& 0x7);
8190 gen_mfhc0(ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
8196 TCGv t0
= tcg_temp_new();
8197 gen_load_gpr(t0
, rt
);
8198 gen_mthc0(ctx
, t0
, rd
, ctx
->opcode
& 0x7);
8204 check_insn(ctx
, ASE_MT
);
8209 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
8210 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
8214 check_insn(ctx
, ASE_MT
);
8215 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
8216 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
8221 if (!env
->tlb
->helper_tlbwi
)
8223 gen_helper_tlbwi(cpu_env
);
8228 if (!env
->tlb
->helper_tlbinv
) {
8231 gen_helper_tlbinv(cpu_env
);
8232 } /* treat as nop if TLBINV not supported */
8237 if (!env
->tlb
->helper_tlbinvf
) {
8240 gen_helper_tlbinvf(cpu_env
);
8241 } /* treat as nop if TLBINV not supported */
8245 if (!env
->tlb
->helper_tlbwr
)
8247 gen_helper_tlbwr(cpu_env
);
8251 if (!env
->tlb
->helper_tlbp
)
8253 gen_helper_tlbp(cpu_env
);
8257 if (!env
->tlb
->helper_tlbr
)
8259 gen_helper_tlbr(cpu_env
);
8261 case OPC_ERET
: /* OPC_ERETNC */
8262 if ((ctx
->insn_flags
& ISA_MIPS32R6
) &&
8263 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8264 MIPS_DEBUG("CTI in delay / forbidden slot");
8267 int bit_shift
= (ctx
->hflags
& MIPS_HFLAG_M16
) ? 16 : 6;
8268 if (ctx
->opcode
& (1 << bit_shift
)) {
8271 check_insn(ctx
, ISA_MIPS32R5
);
8272 gen_helper_eretnc(cpu_env
);
8276 check_insn(ctx
, ISA_MIPS2
);
8277 gen_helper_eret(cpu_env
);
8279 ctx
->bstate
= BS_EXCP
;
8284 check_insn(ctx
, ISA_MIPS32
);
8285 if ((ctx
->insn_flags
& ISA_MIPS32R6
) &&
8286 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8287 MIPS_DEBUG("CTI in delay / forbidden slot");
8290 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8292 generate_exception(ctx
, EXCP_RI
);
8294 gen_helper_deret(cpu_env
);
8295 ctx
->bstate
= BS_EXCP
;
8300 check_insn(ctx
, ISA_MIPS3
| ISA_MIPS32
);
8301 if ((ctx
->insn_flags
& ISA_MIPS32R6
) &&
8302 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8303 MIPS_DEBUG("CTI in delay / forbidden slot");
8306 /* If we get an exception, we want to restart at next instruction */
8308 save_cpu_state(ctx
, 1);
8310 gen_helper_wait(cpu_env
);
8311 ctx
->bstate
= BS_EXCP
;
8316 generate_exception(ctx
, EXCP_RI
);
8319 (void)opn
; /* avoid a compiler warning */
8320 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
8322 #endif /* !CONFIG_USER_ONLY */
8324 /* CP1 Branches (before delay slot) */
8325 static void gen_compute_branch1(DisasContext
*ctx
, uint32_t op
,
8326 int32_t cc
, int32_t offset
)
8328 target_ulong btarget
;
8329 const char *opn
= "cp1 cond branch";
8330 TCGv_i32 t0
= tcg_temp_new_i32();
8332 if ((ctx
->insn_flags
& ISA_MIPS32R6
) && (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8333 MIPS_DEBUG("CTI in delay / forbidden slot");
8334 generate_exception(ctx
, EXCP_RI
);
8339 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS32
);
8341 btarget
= ctx
->pc
+ 4 + offset
;
8345 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8346 tcg_gen_not_i32(t0
, t0
);
8347 tcg_gen_andi_i32(t0
, t0
, 1);
8348 tcg_gen_extu_i32_tl(bcond
, t0
);
8352 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8353 tcg_gen_not_i32(t0
, t0
);
8354 tcg_gen_andi_i32(t0
, t0
, 1);
8355 tcg_gen_extu_i32_tl(bcond
, t0
);
8359 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8360 tcg_gen_andi_i32(t0
, t0
, 1);
8361 tcg_gen_extu_i32_tl(bcond
, t0
);
8365 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8366 tcg_gen_andi_i32(t0
, t0
, 1);
8367 tcg_gen_extu_i32_tl(bcond
, t0
);
8370 ctx
->hflags
|= MIPS_HFLAG_BL
;
8374 TCGv_i32 t1
= tcg_temp_new_i32();
8375 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8376 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
8377 tcg_gen_nand_i32(t0
, t0
, t1
);
8378 tcg_temp_free_i32(t1
);
8379 tcg_gen_andi_i32(t0
, t0
, 1);
8380 tcg_gen_extu_i32_tl(bcond
, t0
);
8386 TCGv_i32 t1
= tcg_temp_new_i32();
8387 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8388 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
8389 tcg_gen_or_i32(t0
, t0
, t1
);
8390 tcg_temp_free_i32(t1
);
8391 tcg_gen_andi_i32(t0
, t0
, 1);
8392 tcg_gen_extu_i32_tl(bcond
, t0
);
8398 TCGv_i32 t1
= tcg_temp_new_i32();
8399 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8400 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
8401 tcg_gen_and_i32(t0
, t0
, t1
);
8402 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
8403 tcg_gen_and_i32(t0
, t0
, t1
);
8404 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
8405 tcg_gen_nand_i32(t0
, t0
, t1
);
8406 tcg_temp_free_i32(t1
);
8407 tcg_gen_andi_i32(t0
, t0
, 1);
8408 tcg_gen_extu_i32_tl(bcond
, t0
);
8414 TCGv_i32 t1
= tcg_temp_new_i32();
8415 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8416 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
8417 tcg_gen_or_i32(t0
, t0
, t1
);
8418 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
8419 tcg_gen_or_i32(t0
, t0
, t1
);
8420 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
8421 tcg_gen_or_i32(t0
, t0
, t1
);
8422 tcg_temp_free_i32(t1
);
8423 tcg_gen_andi_i32(t0
, t0
, 1);
8424 tcg_gen_extu_i32_tl(bcond
, t0
);
8428 ctx
->hflags
|= MIPS_HFLAG_BC
;
8432 generate_exception (ctx
, EXCP_RI
);
8435 (void)opn
; /* avoid a compiler warning */
8436 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
8437 ctx
->hflags
, btarget
);
8438 ctx
->btarget
= btarget
;
8439 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
8441 tcg_temp_free_i32(t0
);
8444 /* R6 CP1 Branches */
8445 static void gen_compute_branch1_r6(DisasContext
*ctx
, uint32_t op
,
8446 int32_t ft
, int32_t offset
,
8449 target_ulong btarget
;
8450 const char *opn
= "cp1 cond branch";
8451 TCGv_i64 t0
= tcg_temp_new_i64();
8453 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8454 #ifdef MIPS_DEBUG_DISAS
8455 LOG_DISAS("Branch in delay / forbidden slot at PC 0x" TARGET_FMT_lx
8458 generate_exception(ctx
, EXCP_RI
);
8462 gen_load_fpr64(ctx
, t0
, ft
);
8463 tcg_gen_andi_i64(t0
, t0
, 1);
8465 btarget
= addr_add(ctx
, ctx
->pc
+ 4, offset
);
8469 tcg_gen_xori_i64(t0
, t0
, 1);
8471 ctx
->hflags
|= MIPS_HFLAG_BC
;
8474 /* t0 already set */
8476 ctx
->hflags
|= MIPS_HFLAG_BC
;
8480 generate_exception(ctx
, EXCP_RI
);
8484 tcg_gen_trunc_i64_tl(bcond
, t0
);
8486 (void)opn
; /* avoid a compiler warning */
8487 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
8488 ctx
->hflags
, btarget
);
8489 ctx
->btarget
= btarget
;
8491 switch (delayslot_size
) {
8493 ctx
->hflags
|= MIPS_HFLAG_BDS16
;
8496 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
8501 tcg_temp_free_i64(t0
);
8504 /* Coprocessor 1 (FPU) */
8506 #define FOP(func, fmt) (((fmt) << 21) | (func))
8509 OPC_ADD_S
= FOP(0, FMT_S
),
8510 OPC_SUB_S
= FOP(1, FMT_S
),
8511 OPC_MUL_S
= FOP(2, FMT_S
),
8512 OPC_DIV_S
= FOP(3, FMT_S
),
8513 OPC_SQRT_S
= FOP(4, FMT_S
),
8514 OPC_ABS_S
= FOP(5, FMT_S
),
8515 OPC_MOV_S
= FOP(6, FMT_S
),
8516 OPC_NEG_S
= FOP(7, FMT_S
),
8517 OPC_ROUND_L_S
= FOP(8, FMT_S
),
8518 OPC_TRUNC_L_S
= FOP(9, FMT_S
),
8519 OPC_CEIL_L_S
= FOP(10, FMT_S
),
8520 OPC_FLOOR_L_S
= FOP(11, FMT_S
),
8521 OPC_ROUND_W_S
= FOP(12, FMT_S
),
8522 OPC_TRUNC_W_S
= FOP(13, FMT_S
),
8523 OPC_CEIL_W_S
= FOP(14, FMT_S
),
8524 OPC_FLOOR_W_S
= FOP(15, FMT_S
),
8525 OPC_SEL_S
= FOP(16, FMT_S
),
8526 OPC_MOVCF_S
= FOP(17, FMT_S
),
8527 OPC_MOVZ_S
= FOP(18, FMT_S
),
8528 OPC_MOVN_S
= FOP(19, FMT_S
),
8529 OPC_SELEQZ_S
= FOP(20, FMT_S
),
8530 OPC_RECIP_S
= FOP(21, FMT_S
),
8531 OPC_RSQRT_S
= FOP(22, FMT_S
),
8532 OPC_SELNEZ_S
= FOP(23, FMT_S
),
8533 OPC_MADDF_S
= FOP(24, FMT_S
),
8534 OPC_MSUBF_S
= FOP(25, FMT_S
),
8535 OPC_RINT_S
= FOP(26, FMT_S
),
8536 OPC_CLASS_S
= FOP(27, FMT_S
),
8537 OPC_MIN_S
= FOP(28, FMT_S
),
8538 OPC_RECIP2_S
= FOP(28, FMT_S
),
8539 OPC_MINA_S
= FOP(29, FMT_S
),
8540 OPC_RECIP1_S
= FOP(29, FMT_S
),
8541 OPC_MAX_S
= FOP(30, FMT_S
),
8542 OPC_RSQRT1_S
= FOP(30, FMT_S
),
8543 OPC_MAXA_S
= FOP(31, FMT_S
),
8544 OPC_RSQRT2_S
= FOP(31, FMT_S
),
8545 OPC_CVT_D_S
= FOP(33, FMT_S
),
8546 OPC_CVT_W_S
= FOP(36, FMT_S
),
8547 OPC_CVT_L_S
= FOP(37, FMT_S
),
8548 OPC_CVT_PS_S
= FOP(38, FMT_S
),
8549 OPC_CMP_F_S
= FOP (48, FMT_S
),
8550 OPC_CMP_UN_S
= FOP (49, FMT_S
),
8551 OPC_CMP_EQ_S
= FOP (50, FMT_S
),
8552 OPC_CMP_UEQ_S
= FOP (51, FMT_S
),
8553 OPC_CMP_OLT_S
= FOP (52, FMT_S
),
8554 OPC_CMP_ULT_S
= FOP (53, FMT_S
),
8555 OPC_CMP_OLE_S
= FOP (54, FMT_S
),
8556 OPC_CMP_ULE_S
= FOP (55, FMT_S
),
8557 OPC_CMP_SF_S
= FOP (56, FMT_S
),
8558 OPC_CMP_NGLE_S
= FOP (57, FMT_S
),
8559 OPC_CMP_SEQ_S
= FOP (58, FMT_S
),
8560 OPC_CMP_NGL_S
= FOP (59, FMT_S
),
8561 OPC_CMP_LT_S
= FOP (60, FMT_S
),
8562 OPC_CMP_NGE_S
= FOP (61, FMT_S
),
8563 OPC_CMP_LE_S
= FOP (62, FMT_S
),
8564 OPC_CMP_NGT_S
= FOP (63, FMT_S
),
8566 OPC_ADD_D
= FOP(0, FMT_D
),
8567 OPC_SUB_D
= FOP(1, FMT_D
),
8568 OPC_MUL_D
= FOP(2, FMT_D
),
8569 OPC_DIV_D
= FOP(3, FMT_D
),
8570 OPC_SQRT_D
= FOP(4, FMT_D
),
8571 OPC_ABS_D
= FOP(5, FMT_D
),
8572 OPC_MOV_D
= FOP(6, FMT_D
),
8573 OPC_NEG_D
= FOP(7, FMT_D
),
8574 OPC_ROUND_L_D
= FOP(8, FMT_D
),
8575 OPC_TRUNC_L_D
= FOP(9, FMT_D
),
8576 OPC_CEIL_L_D
= FOP(10, FMT_D
),
8577 OPC_FLOOR_L_D
= FOP(11, FMT_D
),
8578 OPC_ROUND_W_D
= FOP(12, FMT_D
),
8579 OPC_TRUNC_W_D
= FOP(13, FMT_D
),
8580 OPC_CEIL_W_D
= FOP(14, FMT_D
),
8581 OPC_FLOOR_W_D
= FOP(15, FMT_D
),
8582 OPC_SEL_D
= FOP(16, FMT_D
),
8583 OPC_MOVCF_D
= FOP(17, FMT_D
),
8584 OPC_MOVZ_D
= FOP(18, FMT_D
),
8585 OPC_MOVN_D
= FOP(19, FMT_D
),
8586 OPC_SELEQZ_D
= FOP(20, FMT_D
),
8587 OPC_RECIP_D
= FOP(21, FMT_D
),
8588 OPC_RSQRT_D
= FOP(22, FMT_D
),
8589 OPC_SELNEZ_D
= FOP(23, FMT_D
),
8590 OPC_MADDF_D
= FOP(24, FMT_D
),
8591 OPC_MSUBF_D
= FOP(25, FMT_D
),
8592 OPC_RINT_D
= FOP(26, FMT_D
),
8593 OPC_CLASS_D
= FOP(27, FMT_D
),
8594 OPC_MIN_D
= FOP(28, FMT_D
),
8595 OPC_RECIP2_D
= FOP(28, FMT_D
),
8596 OPC_MINA_D
= FOP(29, FMT_D
),
8597 OPC_RECIP1_D
= FOP(29, FMT_D
),
8598 OPC_MAX_D
= FOP(30, FMT_D
),
8599 OPC_RSQRT1_D
= FOP(30, FMT_D
),
8600 OPC_MAXA_D
= FOP(31, FMT_D
),
8601 OPC_RSQRT2_D
= FOP(31, FMT_D
),
8602 OPC_CVT_S_D
= FOP(32, FMT_D
),
8603 OPC_CVT_W_D
= FOP(36, FMT_D
),
8604 OPC_CVT_L_D
= FOP(37, FMT_D
),
8605 OPC_CMP_F_D
= FOP (48, FMT_D
),
8606 OPC_CMP_UN_D
= FOP (49, FMT_D
),
8607 OPC_CMP_EQ_D
= FOP (50, FMT_D
),
8608 OPC_CMP_UEQ_D
= FOP (51, FMT_D
),
8609 OPC_CMP_OLT_D
= FOP (52, FMT_D
),
8610 OPC_CMP_ULT_D
= FOP (53, FMT_D
),
8611 OPC_CMP_OLE_D
= FOP (54, FMT_D
),
8612 OPC_CMP_ULE_D
= FOP (55, FMT_D
),
8613 OPC_CMP_SF_D
= FOP (56, FMT_D
),
8614 OPC_CMP_NGLE_D
= FOP (57, FMT_D
),
8615 OPC_CMP_SEQ_D
= FOP (58, FMT_D
),
8616 OPC_CMP_NGL_D
= FOP (59, FMT_D
),
8617 OPC_CMP_LT_D
= FOP (60, FMT_D
),
8618 OPC_CMP_NGE_D
= FOP (61, FMT_D
),
8619 OPC_CMP_LE_D
= FOP (62, FMT_D
),
8620 OPC_CMP_NGT_D
= FOP (63, FMT_D
),
8622 OPC_CVT_S_W
= FOP(32, FMT_W
),
8623 OPC_CVT_D_W
= FOP(33, FMT_W
),
8624 OPC_CVT_S_L
= FOP(32, FMT_L
),
8625 OPC_CVT_D_L
= FOP(33, FMT_L
),
8626 OPC_CVT_PS_PW
= FOP(38, FMT_W
),
8628 OPC_ADD_PS
= FOP(0, FMT_PS
),
8629 OPC_SUB_PS
= FOP(1, FMT_PS
),
8630 OPC_MUL_PS
= FOP(2, FMT_PS
),
8631 OPC_DIV_PS
= FOP(3, FMT_PS
),
8632 OPC_ABS_PS
= FOP(5, FMT_PS
),
8633 OPC_MOV_PS
= FOP(6, FMT_PS
),
8634 OPC_NEG_PS
= FOP(7, FMT_PS
),
8635 OPC_MOVCF_PS
= FOP(17, FMT_PS
),
8636 OPC_MOVZ_PS
= FOP(18, FMT_PS
),
8637 OPC_MOVN_PS
= FOP(19, FMT_PS
),
8638 OPC_ADDR_PS
= FOP(24, FMT_PS
),
8639 OPC_MULR_PS
= FOP(26, FMT_PS
),
8640 OPC_RECIP2_PS
= FOP(28, FMT_PS
),
8641 OPC_RECIP1_PS
= FOP(29, FMT_PS
),
8642 OPC_RSQRT1_PS
= FOP(30, FMT_PS
),
8643 OPC_RSQRT2_PS
= FOP(31, FMT_PS
),
8645 OPC_CVT_S_PU
= FOP(32, FMT_PS
),
8646 OPC_CVT_PW_PS
= FOP(36, FMT_PS
),
8647 OPC_CVT_S_PL
= FOP(40, FMT_PS
),
8648 OPC_PLL_PS
= FOP(44, FMT_PS
),
8649 OPC_PLU_PS
= FOP(45, FMT_PS
),
8650 OPC_PUL_PS
= FOP(46, FMT_PS
),
8651 OPC_PUU_PS
= FOP(47, FMT_PS
),
8652 OPC_CMP_F_PS
= FOP (48, FMT_PS
),
8653 OPC_CMP_UN_PS
= FOP (49, FMT_PS
),
8654 OPC_CMP_EQ_PS
= FOP (50, FMT_PS
),
8655 OPC_CMP_UEQ_PS
= FOP (51, FMT_PS
),
8656 OPC_CMP_OLT_PS
= FOP (52, FMT_PS
),
8657 OPC_CMP_ULT_PS
= FOP (53, FMT_PS
),
8658 OPC_CMP_OLE_PS
= FOP (54, FMT_PS
),
8659 OPC_CMP_ULE_PS
= FOP (55, FMT_PS
),
8660 OPC_CMP_SF_PS
= FOP (56, FMT_PS
),
8661 OPC_CMP_NGLE_PS
= FOP (57, FMT_PS
),
8662 OPC_CMP_SEQ_PS
= FOP (58, FMT_PS
),
8663 OPC_CMP_NGL_PS
= FOP (59, FMT_PS
),
8664 OPC_CMP_LT_PS
= FOP (60, FMT_PS
),
8665 OPC_CMP_NGE_PS
= FOP (61, FMT_PS
),
8666 OPC_CMP_LE_PS
= FOP (62, FMT_PS
),
8667 OPC_CMP_NGT_PS
= FOP (63, FMT_PS
),
8671 R6_OPC_CMP_AF_S
= FOP(0, FMT_W
),
8672 R6_OPC_CMP_UN_S
= FOP(1, FMT_W
),
8673 R6_OPC_CMP_EQ_S
= FOP(2, FMT_W
),
8674 R6_OPC_CMP_UEQ_S
= FOP(3, FMT_W
),
8675 R6_OPC_CMP_LT_S
= FOP(4, FMT_W
),
8676 R6_OPC_CMP_ULT_S
= FOP(5, FMT_W
),
8677 R6_OPC_CMP_LE_S
= FOP(6, FMT_W
),
8678 R6_OPC_CMP_ULE_S
= FOP(7, FMT_W
),
8679 R6_OPC_CMP_SAF_S
= FOP(8, FMT_W
),
8680 R6_OPC_CMP_SUN_S
= FOP(9, FMT_W
),
8681 R6_OPC_CMP_SEQ_S
= FOP(10, FMT_W
),
8682 R6_OPC_CMP_SEUQ_S
= FOP(11, FMT_W
),
8683 R6_OPC_CMP_SLT_S
= FOP(12, FMT_W
),
8684 R6_OPC_CMP_SULT_S
= FOP(13, FMT_W
),
8685 R6_OPC_CMP_SLE_S
= FOP(14, FMT_W
),
8686 R6_OPC_CMP_SULE_S
= FOP(15, FMT_W
),
8687 R6_OPC_CMP_OR_S
= FOP(17, FMT_W
),
8688 R6_OPC_CMP_UNE_S
= FOP(18, FMT_W
),
8689 R6_OPC_CMP_NE_S
= FOP(19, FMT_W
),
8690 R6_OPC_CMP_SOR_S
= FOP(25, FMT_W
),
8691 R6_OPC_CMP_SUNE_S
= FOP(26, FMT_W
),
8692 R6_OPC_CMP_SNE_S
= FOP(27, FMT_W
),
8694 R6_OPC_CMP_AF_D
= FOP(0, FMT_L
),
8695 R6_OPC_CMP_UN_D
= FOP(1, FMT_L
),
8696 R6_OPC_CMP_EQ_D
= FOP(2, FMT_L
),
8697 R6_OPC_CMP_UEQ_D
= FOP(3, FMT_L
),
8698 R6_OPC_CMP_LT_D
= FOP(4, FMT_L
),
8699 R6_OPC_CMP_ULT_D
= FOP(5, FMT_L
),
8700 R6_OPC_CMP_LE_D
= FOP(6, FMT_L
),
8701 R6_OPC_CMP_ULE_D
= FOP(7, FMT_L
),
8702 R6_OPC_CMP_SAF_D
= FOP(8, FMT_L
),
8703 R6_OPC_CMP_SUN_D
= FOP(9, FMT_L
),
8704 R6_OPC_CMP_SEQ_D
= FOP(10, FMT_L
),
8705 R6_OPC_CMP_SEUQ_D
= FOP(11, FMT_L
),
8706 R6_OPC_CMP_SLT_D
= FOP(12, FMT_L
),
8707 R6_OPC_CMP_SULT_D
= FOP(13, FMT_L
),
8708 R6_OPC_CMP_SLE_D
= FOP(14, FMT_L
),
8709 R6_OPC_CMP_SULE_D
= FOP(15, FMT_L
),
8710 R6_OPC_CMP_OR_D
= FOP(17, FMT_L
),
8711 R6_OPC_CMP_UNE_D
= FOP(18, FMT_L
),
8712 R6_OPC_CMP_NE_D
= FOP(19, FMT_L
),
8713 R6_OPC_CMP_SOR_D
= FOP(25, FMT_L
),
8714 R6_OPC_CMP_SUNE_D
= FOP(26, FMT_L
),
8715 R6_OPC_CMP_SNE_D
= FOP(27, FMT_L
),
8717 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
8719 const char *opn
= "cp1 move";
8720 TCGv t0
= tcg_temp_new();
8725 TCGv_i32 fp0
= tcg_temp_new_i32();
8727 gen_load_fpr32(ctx
, fp0
, fs
);
8728 tcg_gen_ext_i32_tl(t0
, fp0
);
8729 tcg_temp_free_i32(fp0
);
8731 gen_store_gpr(t0
, rt
);
8735 gen_load_gpr(t0
, rt
);
8737 TCGv_i32 fp0
= tcg_temp_new_i32();
8739 tcg_gen_trunc_tl_i32(fp0
, t0
);
8740 gen_store_fpr32(ctx
, fp0
, fs
);
8741 tcg_temp_free_i32(fp0
);
8746 gen_helper_1e0i(cfc1
, t0
, fs
);
8747 gen_store_gpr(t0
, rt
);
8751 gen_load_gpr(t0
, rt
);
8752 save_cpu_state(ctx
, 1);
8754 TCGv_i32 fs_tmp
= tcg_const_i32(fs
);
8756 gen_helper_0e2i(ctc1
, t0
, fs_tmp
, rt
);
8757 tcg_temp_free_i32(fs_tmp
);
8759 /* Stop translation as we may have changed hflags */
8760 ctx
->bstate
= BS_STOP
;
8763 #if defined(TARGET_MIPS64)
8765 gen_load_fpr64(ctx
, t0
, fs
);
8766 gen_store_gpr(t0
, rt
);
8770 gen_load_gpr(t0
, rt
);
8771 gen_store_fpr64(ctx
, t0
, fs
);
8777 TCGv_i32 fp0
= tcg_temp_new_i32();
8779 gen_load_fpr32h(ctx
, fp0
, fs
);
8780 tcg_gen_ext_i32_tl(t0
, fp0
);
8781 tcg_temp_free_i32(fp0
);
8783 gen_store_gpr(t0
, rt
);
8787 gen_load_gpr(t0
, rt
);
8789 TCGv_i32 fp0
= tcg_temp_new_i32();
8791 tcg_gen_trunc_tl_i32(fp0
, t0
);
8792 gen_store_fpr32h(ctx
, fp0
, fs
);
8793 tcg_temp_free_i32(fp0
);
8799 generate_exception (ctx
, EXCP_RI
);
8802 (void)opn
; /* avoid a compiler warning */
8803 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
8809 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
8825 l1
= gen_new_label();
8826 t0
= tcg_temp_new_i32();
8827 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
8828 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
8829 tcg_temp_free_i32(t0
);
8831 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
8833 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
8838 static inline void gen_movcf_s(DisasContext
*ctx
, int fs
, int fd
, int cc
,
8842 TCGv_i32 t0
= tcg_temp_new_i32();
8843 TCGLabel
*l1
= gen_new_label();
8850 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
8851 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
8852 gen_load_fpr32(ctx
, t0
, fs
);
8853 gen_store_fpr32(ctx
, t0
, fd
);
8855 tcg_temp_free_i32(t0
);
8858 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
8861 TCGv_i32 t0
= tcg_temp_new_i32();
8863 TCGLabel
*l1
= gen_new_label();
8870 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
8871 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
8872 tcg_temp_free_i32(t0
);
8873 fp0
= tcg_temp_new_i64();
8874 gen_load_fpr64(ctx
, fp0
, fs
);
8875 gen_store_fpr64(ctx
, fp0
, fd
);
8876 tcg_temp_free_i64(fp0
);
8880 static inline void gen_movcf_ps(DisasContext
*ctx
, int fs
, int fd
,
8884 TCGv_i32 t0
= tcg_temp_new_i32();
8885 TCGLabel
*l1
= gen_new_label();
8886 TCGLabel
*l2
= gen_new_label();
8893 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
8894 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
8895 gen_load_fpr32(ctx
, t0
, fs
);
8896 gen_store_fpr32(ctx
, t0
, fd
);
8899 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
8900 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
8901 gen_load_fpr32h(ctx
, t0
, fs
);
8902 gen_store_fpr32h(ctx
, t0
, fd
);
8903 tcg_temp_free_i32(t0
);
8907 static void gen_sel_s(DisasContext
*ctx
, enum fopcode op1
, int fd
, int ft
,
8910 TCGv_i32 t1
= tcg_const_i32(0);
8911 TCGv_i32 fp0
= tcg_temp_new_i32();
8912 TCGv_i32 fp1
= tcg_temp_new_i32();
8913 TCGv_i32 fp2
= tcg_temp_new_i32();
8914 gen_load_fpr32(ctx
, fp0
, fd
);
8915 gen_load_fpr32(ctx
, fp1
, ft
);
8916 gen_load_fpr32(ctx
, fp2
, fs
);
8920 tcg_gen_andi_i32(fp0
, fp0
, 1);
8921 tcg_gen_movcond_i32(TCG_COND_NE
, fp0
, fp0
, t1
, fp1
, fp2
);
8924 tcg_gen_andi_i32(fp1
, fp1
, 1);
8925 tcg_gen_movcond_i32(TCG_COND_EQ
, fp0
, fp1
, t1
, fp2
, t1
);
8928 tcg_gen_andi_i32(fp1
, fp1
, 1);
8929 tcg_gen_movcond_i32(TCG_COND_NE
, fp0
, fp1
, t1
, fp2
, t1
);
8932 MIPS_INVAL("gen_sel_s");
8933 generate_exception (ctx
, EXCP_RI
);
8937 gen_store_fpr32(ctx
, fp0
, fd
);
8938 tcg_temp_free_i32(fp2
);
8939 tcg_temp_free_i32(fp1
);
8940 tcg_temp_free_i32(fp0
);
8941 tcg_temp_free_i32(t1
);
8944 static void gen_sel_d(DisasContext
*ctx
, enum fopcode op1
, int fd
, int ft
,
8947 TCGv_i64 t1
= tcg_const_i64(0);
8948 TCGv_i64 fp0
= tcg_temp_new_i64();
8949 TCGv_i64 fp1
= tcg_temp_new_i64();
8950 TCGv_i64 fp2
= tcg_temp_new_i64();
8951 gen_load_fpr64(ctx
, fp0
, fd
);
8952 gen_load_fpr64(ctx
, fp1
, ft
);
8953 gen_load_fpr64(ctx
, fp2
, fs
);
8957 tcg_gen_andi_i64(fp0
, fp0
, 1);
8958 tcg_gen_movcond_i64(TCG_COND_NE
, fp0
, fp0
, t1
, fp1
, fp2
);
8961 tcg_gen_andi_i64(fp1
, fp1
, 1);
8962 tcg_gen_movcond_i64(TCG_COND_EQ
, fp0
, fp1
, t1
, fp2
, t1
);
8965 tcg_gen_andi_i64(fp1
, fp1
, 1);
8966 tcg_gen_movcond_i64(TCG_COND_NE
, fp0
, fp1
, t1
, fp2
, t1
);
8969 MIPS_INVAL("gen_sel_d");
8970 generate_exception (ctx
, EXCP_RI
);
8974 gen_store_fpr64(ctx
, fp0
, fd
);
8975 tcg_temp_free_i64(fp2
);
8976 tcg_temp_free_i64(fp1
);
8977 tcg_temp_free_i64(fp0
);
8978 tcg_temp_free_i64(t1
);
8981 static void gen_farith (DisasContext
*ctx
, enum fopcode op1
,
8982 int ft
, int fs
, int fd
, int cc
)
8984 const char *opn
= "farith";
8985 const char *condnames
[] = {
9003 const char *condnames_abs
[] = {
9021 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
9022 uint32_t func
= ctx
->opcode
& 0x3f;
9026 TCGv_i32 fp0
= tcg_temp_new_i32();
9027 TCGv_i32 fp1
= tcg_temp_new_i32();
9029 gen_load_fpr32(ctx
, fp0
, fs
);
9030 gen_load_fpr32(ctx
, fp1
, ft
);
9031 gen_helper_float_add_s(fp0
, cpu_env
, fp0
, fp1
);
9032 tcg_temp_free_i32(fp1
);
9033 gen_store_fpr32(ctx
, fp0
, fd
);
9034 tcg_temp_free_i32(fp0
);
9041 TCGv_i32 fp0
= tcg_temp_new_i32();
9042 TCGv_i32 fp1
= tcg_temp_new_i32();
9044 gen_load_fpr32(ctx
, fp0
, fs
);
9045 gen_load_fpr32(ctx
, fp1
, ft
);
9046 gen_helper_float_sub_s(fp0
, cpu_env
, fp0
, fp1
);
9047 tcg_temp_free_i32(fp1
);
9048 gen_store_fpr32(ctx
, fp0
, fd
);
9049 tcg_temp_free_i32(fp0
);
9056 TCGv_i32 fp0
= tcg_temp_new_i32();
9057 TCGv_i32 fp1
= tcg_temp_new_i32();
9059 gen_load_fpr32(ctx
, fp0
, fs
);
9060 gen_load_fpr32(ctx
, fp1
, ft
);
9061 gen_helper_float_mul_s(fp0
, cpu_env
, fp0
, fp1
);
9062 tcg_temp_free_i32(fp1
);
9063 gen_store_fpr32(ctx
, fp0
, fd
);
9064 tcg_temp_free_i32(fp0
);
9071 TCGv_i32 fp0
= tcg_temp_new_i32();
9072 TCGv_i32 fp1
= tcg_temp_new_i32();
9074 gen_load_fpr32(ctx
, fp0
, fs
);
9075 gen_load_fpr32(ctx
, fp1
, ft
);
9076 gen_helper_float_div_s(fp0
, cpu_env
, fp0
, fp1
);
9077 tcg_temp_free_i32(fp1
);
9078 gen_store_fpr32(ctx
, fp0
, fd
);
9079 tcg_temp_free_i32(fp0
);
9086 TCGv_i32 fp0
= tcg_temp_new_i32();
9088 gen_load_fpr32(ctx
, fp0
, fs
);
9089 gen_helper_float_sqrt_s(fp0
, cpu_env
, fp0
);
9090 gen_store_fpr32(ctx
, fp0
, fd
);
9091 tcg_temp_free_i32(fp0
);
9097 TCGv_i32 fp0
= tcg_temp_new_i32();
9099 gen_load_fpr32(ctx
, fp0
, fs
);
9100 gen_helper_float_abs_s(fp0
, fp0
);
9101 gen_store_fpr32(ctx
, fp0
, fd
);
9102 tcg_temp_free_i32(fp0
);
9108 TCGv_i32 fp0
= tcg_temp_new_i32();
9110 gen_load_fpr32(ctx
, fp0
, fs
);
9111 gen_store_fpr32(ctx
, fp0
, fd
);
9112 tcg_temp_free_i32(fp0
);
9118 TCGv_i32 fp0
= tcg_temp_new_i32();
9120 gen_load_fpr32(ctx
, fp0
, fs
);
9121 gen_helper_float_chs_s(fp0
, fp0
);
9122 gen_store_fpr32(ctx
, fp0
, fd
);
9123 tcg_temp_free_i32(fp0
);
9128 check_cp1_64bitmode(ctx
);
9130 TCGv_i32 fp32
= tcg_temp_new_i32();
9131 TCGv_i64 fp64
= tcg_temp_new_i64();
9133 gen_load_fpr32(ctx
, fp32
, fs
);
9134 gen_helper_float_roundl_s(fp64
, cpu_env
, fp32
);
9135 tcg_temp_free_i32(fp32
);
9136 gen_store_fpr64(ctx
, fp64
, fd
);
9137 tcg_temp_free_i64(fp64
);
9142 check_cp1_64bitmode(ctx
);
9144 TCGv_i32 fp32
= tcg_temp_new_i32();
9145 TCGv_i64 fp64
= tcg_temp_new_i64();
9147 gen_load_fpr32(ctx
, fp32
, fs
);
9148 gen_helper_float_truncl_s(fp64
, cpu_env
, fp32
);
9149 tcg_temp_free_i32(fp32
);
9150 gen_store_fpr64(ctx
, fp64
, fd
);
9151 tcg_temp_free_i64(fp64
);
9156 check_cp1_64bitmode(ctx
);
9158 TCGv_i32 fp32
= tcg_temp_new_i32();
9159 TCGv_i64 fp64
= tcg_temp_new_i64();
9161 gen_load_fpr32(ctx
, fp32
, fs
);
9162 gen_helper_float_ceill_s(fp64
, cpu_env
, fp32
);
9163 tcg_temp_free_i32(fp32
);
9164 gen_store_fpr64(ctx
, fp64
, fd
);
9165 tcg_temp_free_i64(fp64
);
9170 check_cp1_64bitmode(ctx
);
9172 TCGv_i32 fp32
= tcg_temp_new_i32();
9173 TCGv_i64 fp64
= tcg_temp_new_i64();
9175 gen_load_fpr32(ctx
, fp32
, fs
);
9176 gen_helper_float_floorl_s(fp64
, cpu_env
, fp32
);
9177 tcg_temp_free_i32(fp32
);
9178 gen_store_fpr64(ctx
, fp64
, fd
);
9179 tcg_temp_free_i64(fp64
);
9185 TCGv_i32 fp0
= tcg_temp_new_i32();
9187 gen_load_fpr32(ctx
, fp0
, fs
);
9188 gen_helper_float_roundw_s(fp0
, cpu_env
, fp0
);
9189 gen_store_fpr32(ctx
, fp0
, fd
);
9190 tcg_temp_free_i32(fp0
);
9196 TCGv_i32 fp0
= tcg_temp_new_i32();
9198 gen_load_fpr32(ctx
, fp0
, fs
);
9199 gen_helper_float_truncw_s(fp0
, cpu_env
, fp0
);
9200 gen_store_fpr32(ctx
, fp0
, fd
);
9201 tcg_temp_free_i32(fp0
);
9207 TCGv_i32 fp0
= tcg_temp_new_i32();
9209 gen_load_fpr32(ctx
, fp0
, fs
);
9210 gen_helper_float_ceilw_s(fp0
, cpu_env
, fp0
);
9211 gen_store_fpr32(ctx
, fp0
, fd
);
9212 tcg_temp_free_i32(fp0
);
9218 TCGv_i32 fp0
= tcg_temp_new_i32();
9220 gen_load_fpr32(ctx
, fp0
, fs
);
9221 gen_helper_float_floorw_s(fp0
, cpu_env
, fp0
);
9222 gen_store_fpr32(ctx
, fp0
, fd
);
9223 tcg_temp_free_i32(fp0
);
9228 check_insn(ctx
, ISA_MIPS32R6
);
9229 gen_sel_s(ctx
, op1
, fd
, ft
, fs
);
9233 check_insn(ctx
, ISA_MIPS32R6
);
9234 gen_sel_s(ctx
, op1
, fd
, ft
, fs
);
9238 check_insn(ctx
, ISA_MIPS32R6
);
9239 gen_sel_s(ctx
, op1
, fd
, ft
, fs
);
9243 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
9244 gen_movcf_s(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
9248 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
9250 TCGLabel
*l1
= gen_new_label();
9254 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
9256 fp0
= tcg_temp_new_i32();
9257 gen_load_fpr32(ctx
, fp0
, fs
);
9258 gen_store_fpr32(ctx
, fp0
, fd
);
9259 tcg_temp_free_i32(fp0
);
9265 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
9267 TCGLabel
*l1
= gen_new_label();
9271 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
9272 fp0
= tcg_temp_new_i32();
9273 gen_load_fpr32(ctx
, fp0
, fs
);
9274 gen_store_fpr32(ctx
, fp0
, fd
);
9275 tcg_temp_free_i32(fp0
);
9284 TCGv_i32 fp0
= tcg_temp_new_i32();
9286 gen_load_fpr32(ctx
, fp0
, fs
);
9287 gen_helper_float_recip_s(fp0
, cpu_env
, fp0
);
9288 gen_store_fpr32(ctx
, fp0
, fd
);
9289 tcg_temp_free_i32(fp0
);
9296 TCGv_i32 fp0
= tcg_temp_new_i32();
9298 gen_load_fpr32(ctx
, fp0
, fs
);
9299 gen_helper_float_rsqrt_s(fp0
, cpu_env
, fp0
);
9300 gen_store_fpr32(ctx
, fp0
, fd
);
9301 tcg_temp_free_i32(fp0
);
9306 check_insn(ctx
, ISA_MIPS32R6
);
9308 TCGv_i32 fp0
= tcg_temp_new_i32();
9309 TCGv_i32 fp1
= tcg_temp_new_i32();
9310 TCGv_i32 fp2
= tcg_temp_new_i32();
9311 gen_load_fpr32(ctx
, fp0
, fs
);
9312 gen_load_fpr32(ctx
, fp1
, ft
);
9313 gen_load_fpr32(ctx
, fp2
, fd
);
9314 gen_helper_float_maddf_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
9315 gen_store_fpr32(ctx
, fp2
, fd
);
9316 tcg_temp_free_i32(fp2
);
9317 tcg_temp_free_i32(fp1
);
9318 tcg_temp_free_i32(fp0
);
9323 check_insn(ctx
, ISA_MIPS32R6
);
9325 TCGv_i32 fp0
= tcg_temp_new_i32();
9326 TCGv_i32 fp1
= tcg_temp_new_i32();
9327 TCGv_i32 fp2
= tcg_temp_new_i32();
9328 gen_load_fpr32(ctx
, fp0
, fs
);
9329 gen_load_fpr32(ctx
, fp1
, ft
);
9330 gen_load_fpr32(ctx
, fp2
, fd
);
9331 gen_helper_float_msubf_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
9332 gen_store_fpr32(ctx
, fp2
, fd
);
9333 tcg_temp_free_i32(fp2
);
9334 tcg_temp_free_i32(fp1
);
9335 tcg_temp_free_i32(fp0
);
9340 check_insn(ctx
, ISA_MIPS32R6
);
9342 TCGv_i32 fp0
= tcg_temp_new_i32();
9343 gen_load_fpr32(ctx
, fp0
, fs
);
9344 gen_helper_float_rint_s(fp0
, cpu_env
, fp0
);
9345 gen_store_fpr32(ctx
, fp0
, fd
);
9346 tcg_temp_free_i32(fp0
);
9351 check_insn(ctx
, ISA_MIPS32R6
);
9353 TCGv_i32 fp0
= tcg_temp_new_i32();
9354 gen_load_fpr32(ctx
, fp0
, fs
);
9355 gen_helper_float_class_s(fp0
, fp0
);
9356 gen_store_fpr32(ctx
, fp0
, fd
);
9357 tcg_temp_free_i32(fp0
);
9361 case OPC_MIN_S
: /* OPC_RECIP2_S */
9362 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
9364 TCGv_i32 fp0
= tcg_temp_new_i32();
9365 TCGv_i32 fp1
= tcg_temp_new_i32();
9366 TCGv_i32 fp2
= tcg_temp_new_i32();
9367 gen_load_fpr32(ctx
, fp0
, fs
);
9368 gen_load_fpr32(ctx
, fp1
, ft
);
9369 gen_helper_float_min_s(fp2
, cpu_env
, fp0
, fp1
);
9370 gen_store_fpr32(ctx
, fp2
, fd
);
9371 tcg_temp_free_i32(fp2
);
9372 tcg_temp_free_i32(fp1
);
9373 tcg_temp_free_i32(fp0
);
9377 check_cp1_64bitmode(ctx
);
9379 TCGv_i32 fp0
= tcg_temp_new_i32();
9380 TCGv_i32 fp1
= tcg_temp_new_i32();
9382 gen_load_fpr32(ctx
, fp0
, fs
);
9383 gen_load_fpr32(ctx
, fp1
, ft
);
9384 gen_helper_float_recip2_s(fp0
, cpu_env
, fp0
, fp1
);
9385 tcg_temp_free_i32(fp1
);
9386 gen_store_fpr32(ctx
, fp0
, fd
);
9387 tcg_temp_free_i32(fp0
);
9392 case OPC_MINA_S
: /* OPC_RECIP1_S */
9393 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
9395 TCGv_i32 fp0
= tcg_temp_new_i32();
9396 TCGv_i32 fp1
= tcg_temp_new_i32();
9397 TCGv_i32 fp2
= tcg_temp_new_i32();
9398 gen_load_fpr32(ctx
, fp0
, fs
);
9399 gen_load_fpr32(ctx
, fp1
, ft
);
9400 gen_helper_float_mina_s(fp2
, cpu_env
, fp0
, fp1
);
9401 gen_store_fpr32(ctx
, fp2
, fd
);
9402 tcg_temp_free_i32(fp2
);
9403 tcg_temp_free_i32(fp1
);
9404 tcg_temp_free_i32(fp0
);
9408 check_cp1_64bitmode(ctx
);
9410 TCGv_i32 fp0
= tcg_temp_new_i32();
9412 gen_load_fpr32(ctx
, fp0
, fs
);
9413 gen_helper_float_recip1_s(fp0
, cpu_env
, fp0
);
9414 gen_store_fpr32(ctx
, fp0
, fd
);
9415 tcg_temp_free_i32(fp0
);
9420 case OPC_MAX_S
: /* OPC_RSQRT1_S */
9421 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
9423 TCGv_i32 fp0
= tcg_temp_new_i32();
9424 TCGv_i32 fp1
= tcg_temp_new_i32();
9425 gen_load_fpr32(ctx
, fp0
, fs
);
9426 gen_load_fpr32(ctx
, fp1
, ft
);
9427 gen_helper_float_max_s(fp1
, cpu_env
, fp0
, fp1
);
9428 gen_store_fpr32(ctx
, fp1
, fd
);
9429 tcg_temp_free_i32(fp1
);
9430 tcg_temp_free_i32(fp0
);
9434 check_cp1_64bitmode(ctx
);
9436 TCGv_i32 fp0
= tcg_temp_new_i32();
9438 gen_load_fpr32(ctx
, fp0
, fs
);
9439 gen_helper_float_rsqrt1_s(fp0
, cpu_env
, fp0
);
9440 gen_store_fpr32(ctx
, fp0
, fd
);
9441 tcg_temp_free_i32(fp0
);
9446 case OPC_MAXA_S
: /* OPC_RSQRT2_S */
9447 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
9449 TCGv_i32 fp0
= tcg_temp_new_i32();
9450 TCGv_i32 fp1
= tcg_temp_new_i32();
9451 gen_load_fpr32(ctx
, fp0
, fs
);
9452 gen_load_fpr32(ctx
, fp1
, ft
);
9453 gen_helper_float_maxa_s(fp1
, cpu_env
, fp0
, fp1
);
9454 gen_store_fpr32(ctx
, fp1
, fd
);
9455 tcg_temp_free_i32(fp1
);
9456 tcg_temp_free_i32(fp0
);
9460 check_cp1_64bitmode(ctx
);
9462 TCGv_i32 fp0
= tcg_temp_new_i32();
9463 TCGv_i32 fp1
= tcg_temp_new_i32();
9465 gen_load_fpr32(ctx
, fp0
, fs
);
9466 gen_load_fpr32(ctx
, fp1
, ft
);
9467 gen_helper_float_rsqrt2_s(fp0
, cpu_env
, fp0
, fp1
);
9468 tcg_temp_free_i32(fp1
);
9469 gen_store_fpr32(ctx
, fp0
, fd
);
9470 tcg_temp_free_i32(fp0
);
9476 check_cp1_registers(ctx
, fd
);
9478 TCGv_i32 fp32
= tcg_temp_new_i32();
9479 TCGv_i64 fp64
= tcg_temp_new_i64();
9481 gen_load_fpr32(ctx
, fp32
, fs
);
9482 gen_helper_float_cvtd_s(fp64
, cpu_env
, fp32
);
9483 tcg_temp_free_i32(fp32
);
9484 gen_store_fpr64(ctx
, fp64
, fd
);
9485 tcg_temp_free_i64(fp64
);
9491 TCGv_i32 fp0
= tcg_temp_new_i32();
9493 gen_load_fpr32(ctx
, fp0
, fs
);
9494 gen_helper_float_cvtw_s(fp0
, cpu_env
, fp0
);
9495 gen_store_fpr32(ctx
, fp0
, fd
);
9496 tcg_temp_free_i32(fp0
);
9501 check_cp1_64bitmode(ctx
);
9503 TCGv_i32 fp32
= tcg_temp_new_i32();
9504 TCGv_i64 fp64
= tcg_temp_new_i64();
9506 gen_load_fpr32(ctx
, fp32
, fs
);
9507 gen_helper_float_cvtl_s(fp64
, cpu_env
, fp32
);
9508 tcg_temp_free_i32(fp32
);
9509 gen_store_fpr64(ctx
, fp64
, fd
);
9510 tcg_temp_free_i64(fp64
);
9517 TCGv_i64 fp64
= tcg_temp_new_i64();
9518 TCGv_i32 fp32_0
= tcg_temp_new_i32();
9519 TCGv_i32 fp32_1
= tcg_temp_new_i32();
9521 gen_load_fpr32(ctx
, fp32_0
, fs
);
9522 gen_load_fpr32(ctx
, fp32_1
, ft
);
9523 tcg_gen_concat_i32_i64(fp64
, fp32_1
, fp32_0
);
9524 tcg_temp_free_i32(fp32_1
);
9525 tcg_temp_free_i32(fp32_0
);
9526 gen_store_fpr64(ctx
, fp64
, fd
);
9527 tcg_temp_free_i64(fp64
);
9540 case OPC_CMP_NGLE_S
:
9547 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
9548 if (ctx
->opcode
& (1 << 6)) {
9549 gen_cmpabs_s(ctx
, func
-48, ft
, fs
, cc
);
9550 opn
= condnames_abs
[func
-48];
9552 gen_cmp_s(ctx
, func
-48, ft
, fs
, cc
);
9553 opn
= condnames
[func
-48];
9557 check_cp1_registers(ctx
, fs
| ft
| fd
);
9559 TCGv_i64 fp0
= tcg_temp_new_i64();
9560 TCGv_i64 fp1
= tcg_temp_new_i64();
9562 gen_load_fpr64(ctx
, fp0
, fs
);
9563 gen_load_fpr64(ctx
, fp1
, ft
);
9564 gen_helper_float_add_d(fp0
, cpu_env
, fp0
, fp1
);
9565 tcg_temp_free_i64(fp1
);
9566 gen_store_fpr64(ctx
, fp0
, fd
);
9567 tcg_temp_free_i64(fp0
);
9573 check_cp1_registers(ctx
, fs
| ft
| fd
);
9575 TCGv_i64 fp0
= tcg_temp_new_i64();
9576 TCGv_i64 fp1
= tcg_temp_new_i64();
9578 gen_load_fpr64(ctx
, fp0
, fs
);
9579 gen_load_fpr64(ctx
, fp1
, ft
);
9580 gen_helper_float_sub_d(fp0
, cpu_env
, fp0
, fp1
);
9581 tcg_temp_free_i64(fp1
);
9582 gen_store_fpr64(ctx
, fp0
, fd
);
9583 tcg_temp_free_i64(fp0
);
9589 check_cp1_registers(ctx
, fs
| ft
| fd
);
9591 TCGv_i64 fp0
= tcg_temp_new_i64();
9592 TCGv_i64 fp1
= tcg_temp_new_i64();
9594 gen_load_fpr64(ctx
, fp0
, fs
);
9595 gen_load_fpr64(ctx
, fp1
, ft
);
9596 gen_helper_float_mul_d(fp0
, cpu_env
, fp0
, fp1
);
9597 tcg_temp_free_i64(fp1
);
9598 gen_store_fpr64(ctx
, fp0
, fd
);
9599 tcg_temp_free_i64(fp0
);
9605 check_cp1_registers(ctx
, fs
| ft
| fd
);
9607 TCGv_i64 fp0
= tcg_temp_new_i64();
9608 TCGv_i64 fp1
= tcg_temp_new_i64();
9610 gen_load_fpr64(ctx
, fp0
, fs
);
9611 gen_load_fpr64(ctx
, fp1
, ft
);
9612 gen_helper_float_div_d(fp0
, cpu_env
, fp0
, fp1
);
9613 tcg_temp_free_i64(fp1
);
9614 gen_store_fpr64(ctx
, fp0
, fd
);
9615 tcg_temp_free_i64(fp0
);
9621 check_cp1_registers(ctx
, fs
| fd
);
9623 TCGv_i64 fp0
= tcg_temp_new_i64();
9625 gen_load_fpr64(ctx
, fp0
, fs
);
9626 gen_helper_float_sqrt_d(fp0
, cpu_env
, fp0
);
9627 gen_store_fpr64(ctx
, fp0
, fd
);
9628 tcg_temp_free_i64(fp0
);
9633 check_cp1_registers(ctx
, fs
| fd
);
9635 TCGv_i64 fp0
= tcg_temp_new_i64();
9637 gen_load_fpr64(ctx
, fp0
, fs
);
9638 gen_helper_float_abs_d(fp0
, fp0
);
9639 gen_store_fpr64(ctx
, fp0
, fd
);
9640 tcg_temp_free_i64(fp0
);
9645 check_cp1_registers(ctx
, fs
| fd
);
9647 TCGv_i64 fp0
= tcg_temp_new_i64();
9649 gen_load_fpr64(ctx
, fp0
, fs
);
9650 gen_store_fpr64(ctx
, fp0
, fd
);
9651 tcg_temp_free_i64(fp0
);
9656 check_cp1_registers(ctx
, fs
| fd
);
9658 TCGv_i64 fp0
= tcg_temp_new_i64();
9660 gen_load_fpr64(ctx
, fp0
, fs
);
9661 gen_helper_float_chs_d(fp0
, fp0
);
9662 gen_store_fpr64(ctx
, fp0
, fd
);
9663 tcg_temp_free_i64(fp0
);
9668 check_cp1_64bitmode(ctx
);
9670 TCGv_i64 fp0
= tcg_temp_new_i64();
9672 gen_load_fpr64(ctx
, fp0
, fs
);
9673 gen_helper_float_roundl_d(fp0
, cpu_env
, fp0
);
9674 gen_store_fpr64(ctx
, fp0
, fd
);
9675 tcg_temp_free_i64(fp0
);
9680 check_cp1_64bitmode(ctx
);
9682 TCGv_i64 fp0
= tcg_temp_new_i64();
9684 gen_load_fpr64(ctx
, fp0
, fs
);
9685 gen_helper_float_truncl_d(fp0
, cpu_env
, fp0
);
9686 gen_store_fpr64(ctx
, fp0
, fd
);
9687 tcg_temp_free_i64(fp0
);
9692 check_cp1_64bitmode(ctx
);
9694 TCGv_i64 fp0
= tcg_temp_new_i64();
9696 gen_load_fpr64(ctx
, fp0
, fs
);
9697 gen_helper_float_ceill_d(fp0
, cpu_env
, fp0
);
9698 gen_store_fpr64(ctx
, fp0
, fd
);
9699 tcg_temp_free_i64(fp0
);
9704 check_cp1_64bitmode(ctx
);
9706 TCGv_i64 fp0
= tcg_temp_new_i64();
9708 gen_load_fpr64(ctx
, fp0
, fs
);
9709 gen_helper_float_floorl_d(fp0
, cpu_env
, fp0
);
9710 gen_store_fpr64(ctx
, fp0
, fd
);
9711 tcg_temp_free_i64(fp0
);
9716 check_cp1_registers(ctx
, fs
);
9718 TCGv_i32 fp32
= tcg_temp_new_i32();
9719 TCGv_i64 fp64
= tcg_temp_new_i64();
9721 gen_load_fpr64(ctx
, fp64
, fs
);
9722 gen_helper_float_roundw_d(fp32
, cpu_env
, fp64
);
9723 tcg_temp_free_i64(fp64
);
9724 gen_store_fpr32(ctx
, fp32
, fd
);
9725 tcg_temp_free_i32(fp32
);
9730 check_cp1_registers(ctx
, fs
);
9732 TCGv_i32 fp32
= tcg_temp_new_i32();
9733 TCGv_i64 fp64
= tcg_temp_new_i64();
9735 gen_load_fpr64(ctx
, fp64
, fs
);
9736 gen_helper_float_truncw_d(fp32
, cpu_env
, fp64
);
9737 tcg_temp_free_i64(fp64
);
9738 gen_store_fpr32(ctx
, fp32
, fd
);
9739 tcg_temp_free_i32(fp32
);
9744 check_cp1_registers(ctx
, fs
);
9746 TCGv_i32 fp32
= tcg_temp_new_i32();
9747 TCGv_i64 fp64
= tcg_temp_new_i64();
9749 gen_load_fpr64(ctx
, fp64
, fs
);
9750 gen_helper_float_ceilw_d(fp32
, cpu_env
, fp64
);
9751 tcg_temp_free_i64(fp64
);
9752 gen_store_fpr32(ctx
, fp32
, fd
);
9753 tcg_temp_free_i32(fp32
);
9758 check_cp1_registers(ctx
, fs
);
9760 TCGv_i32 fp32
= tcg_temp_new_i32();
9761 TCGv_i64 fp64
= tcg_temp_new_i64();
9763 gen_load_fpr64(ctx
, fp64
, fs
);
9764 gen_helper_float_floorw_d(fp32
, cpu_env
, fp64
);
9765 tcg_temp_free_i64(fp64
);
9766 gen_store_fpr32(ctx
, fp32
, fd
);
9767 tcg_temp_free_i32(fp32
);
9772 check_insn(ctx
, ISA_MIPS32R6
);
9773 gen_sel_d(ctx
, op1
, fd
, ft
, fs
);
9777 check_insn(ctx
, ISA_MIPS32R6
);
9778 gen_sel_d(ctx
, op1
, fd
, ft
, fs
);
9782 check_insn(ctx
, ISA_MIPS32R6
);
9783 gen_sel_d(ctx
, op1
, fd
, ft
, fs
);
9787 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
9788 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
9792 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
9794 TCGLabel
*l1
= gen_new_label();
9798 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
9800 fp0
= tcg_temp_new_i64();
9801 gen_load_fpr64(ctx
, fp0
, fs
);
9802 gen_store_fpr64(ctx
, fp0
, fd
);
9803 tcg_temp_free_i64(fp0
);
9809 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
9811 TCGLabel
*l1
= gen_new_label();
9815 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
9816 fp0
= tcg_temp_new_i64();
9817 gen_load_fpr64(ctx
, fp0
, fs
);
9818 gen_store_fpr64(ctx
, fp0
, fd
);
9819 tcg_temp_free_i64(fp0
);
9826 check_cp1_64bitmode(ctx
);
9828 TCGv_i64 fp0
= tcg_temp_new_i64();
9830 gen_load_fpr64(ctx
, fp0
, fs
);
9831 gen_helper_float_recip_d(fp0
, cpu_env
, fp0
);
9832 gen_store_fpr64(ctx
, fp0
, fd
);
9833 tcg_temp_free_i64(fp0
);
9838 check_cp1_64bitmode(ctx
);
9840 TCGv_i64 fp0
= tcg_temp_new_i64();
9842 gen_load_fpr64(ctx
, fp0
, fs
);
9843 gen_helper_float_rsqrt_d(fp0
, cpu_env
, fp0
);
9844 gen_store_fpr64(ctx
, fp0
, fd
);
9845 tcg_temp_free_i64(fp0
);
9850 check_insn(ctx
, ISA_MIPS32R6
);
9852 TCGv_i64 fp0
= tcg_temp_new_i64();
9853 TCGv_i64 fp1
= tcg_temp_new_i64();
9854 TCGv_i64 fp2
= tcg_temp_new_i64();
9855 gen_load_fpr64(ctx
, fp0
, fs
);
9856 gen_load_fpr64(ctx
, fp1
, ft
);
9857 gen_load_fpr64(ctx
, fp2
, fd
);
9858 gen_helper_float_maddf_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
9859 gen_store_fpr64(ctx
, fp2
, fd
);
9860 tcg_temp_free_i64(fp2
);
9861 tcg_temp_free_i64(fp1
);
9862 tcg_temp_free_i64(fp0
);
9867 check_insn(ctx
, ISA_MIPS32R6
);
9869 TCGv_i64 fp0
= tcg_temp_new_i64();
9870 TCGv_i64 fp1
= tcg_temp_new_i64();
9871 TCGv_i64 fp2
= tcg_temp_new_i64();
9872 gen_load_fpr64(ctx
, fp0
, fs
);
9873 gen_load_fpr64(ctx
, fp1
, ft
);
9874 gen_load_fpr64(ctx
, fp2
, fd
);
9875 gen_helper_float_msubf_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
9876 gen_store_fpr64(ctx
, fp2
, fd
);
9877 tcg_temp_free_i64(fp2
);
9878 tcg_temp_free_i64(fp1
);
9879 tcg_temp_free_i64(fp0
);
9884 check_insn(ctx
, ISA_MIPS32R6
);
9886 TCGv_i64 fp0
= tcg_temp_new_i64();
9887 gen_load_fpr64(ctx
, fp0
, fs
);
9888 gen_helper_float_rint_d(fp0
, cpu_env
, fp0
);
9889 gen_store_fpr64(ctx
, fp0
, fd
);
9890 tcg_temp_free_i64(fp0
);
9895 check_insn(ctx
, ISA_MIPS32R6
);
9897 TCGv_i64 fp0
= tcg_temp_new_i64();
9898 gen_load_fpr64(ctx
, fp0
, fs
);
9899 gen_helper_float_class_d(fp0
, fp0
);
9900 gen_store_fpr64(ctx
, fp0
, fd
);
9901 tcg_temp_free_i64(fp0
);
9905 case OPC_MIN_D
: /* OPC_RECIP2_D */
9906 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
9908 TCGv_i64 fp0
= tcg_temp_new_i64();
9909 TCGv_i64 fp1
= tcg_temp_new_i64();
9910 gen_load_fpr64(ctx
, fp0
, fs
);
9911 gen_load_fpr64(ctx
, fp1
, ft
);
9912 gen_helper_float_min_d(fp1
, cpu_env
, fp0
, fp1
);
9913 gen_store_fpr64(ctx
, fp1
, fd
);
9914 tcg_temp_free_i64(fp1
);
9915 tcg_temp_free_i64(fp0
);
9919 check_cp1_64bitmode(ctx
);
9921 TCGv_i64 fp0
= tcg_temp_new_i64();
9922 TCGv_i64 fp1
= tcg_temp_new_i64();
9924 gen_load_fpr64(ctx
, fp0
, fs
);
9925 gen_load_fpr64(ctx
, fp1
, ft
);
9926 gen_helper_float_recip2_d(fp0
, cpu_env
, fp0
, fp1
);
9927 tcg_temp_free_i64(fp1
);
9928 gen_store_fpr64(ctx
, fp0
, fd
);
9929 tcg_temp_free_i64(fp0
);
9934 case OPC_MINA_D
: /* OPC_RECIP1_D */
9935 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
9937 TCGv_i64 fp0
= tcg_temp_new_i64();
9938 TCGv_i64 fp1
= tcg_temp_new_i64();
9939 gen_load_fpr64(ctx
, fp0
, fs
);
9940 gen_load_fpr64(ctx
, fp1
, ft
);
9941 gen_helper_float_mina_d(fp1
, cpu_env
, fp0
, fp1
);
9942 gen_store_fpr64(ctx
, fp1
, fd
);
9943 tcg_temp_free_i64(fp1
);
9944 tcg_temp_free_i64(fp0
);
9948 check_cp1_64bitmode(ctx
);
9950 TCGv_i64 fp0
= tcg_temp_new_i64();
9952 gen_load_fpr64(ctx
, fp0
, fs
);
9953 gen_helper_float_recip1_d(fp0
, cpu_env
, fp0
);
9954 gen_store_fpr64(ctx
, fp0
, fd
);
9955 tcg_temp_free_i64(fp0
);
9960 case OPC_MAX_D
: /* OPC_RSQRT1_D */
9961 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
9963 TCGv_i64 fp0
= tcg_temp_new_i64();
9964 TCGv_i64 fp1
= tcg_temp_new_i64();
9965 gen_load_fpr64(ctx
, fp0
, fs
);
9966 gen_load_fpr64(ctx
, fp1
, ft
);
9967 gen_helper_float_max_d(fp1
, cpu_env
, fp0
, fp1
);
9968 gen_store_fpr64(ctx
, fp1
, fd
);
9969 tcg_temp_free_i64(fp1
);
9970 tcg_temp_free_i64(fp0
);
9974 check_cp1_64bitmode(ctx
);
9976 TCGv_i64 fp0
= tcg_temp_new_i64();
9978 gen_load_fpr64(ctx
, fp0
, fs
);
9979 gen_helper_float_rsqrt1_d(fp0
, cpu_env
, fp0
);
9980 gen_store_fpr64(ctx
, fp0
, fd
);
9981 tcg_temp_free_i64(fp0
);
9986 case OPC_MAXA_D
: /* OPC_RSQRT2_D */
9987 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
9989 TCGv_i64 fp0
= tcg_temp_new_i64();
9990 TCGv_i64 fp1
= tcg_temp_new_i64();
9991 gen_load_fpr64(ctx
, fp0
, fs
);
9992 gen_load_fpr64(ctx
, fp1
, ft
);
9993 gen_helper_float_maxa_d(fp1
, cpu_env
, fp0
, fp1
);
9994 gen_store_fpr64(ctx
, fp1
, fd
);
9995 tcg_temp_free_i64(fp1
);
9996 tcg_temp_free_i64(fp0
);
10000 check_cp1_64bitmode(ctx
);
10002 TCGv_i64 fp0
= tcg_temp_new_i64();
10003 TCGv_i64 fp1
= tcg_temp_new_i64();
10005 gen_load_fpr64(ctx
, fp0
, fs
);
10006 gen_load_fpr64(ctx
, fp1
, ft
);
10007 gen_helper_float_rsqrt2_d(fp0
, cpu_env
, fp0
, fp1
);
10008 tcg_temp_free_i64(fp1
);
10009 gen_store_fpr64(ctx
, fp0
, fd
);
10010 tcg_temp_free_i64(fp0
);
10018 case OPC_CMP_UEQ_D
:
10019 case OPC_CMP_OLT_D
:
10020 case OPC_CMP_ULT_D
:
10021 case OPC_CMP_OLE_D
:
10022 case OPC_CMP_ULE_D
:
10024 case OPC_CMP_NGLE_D
:
10025 case OPC_CMP_SEQ_D
:
10026 case OPC_CMP_NGL_D
:
10028 case OPC_CMP_NGE_D
:
10030 case OPC_CMP_NGT_D
:
10031 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
10032 if (ctx
->opcode
& (1 << 6)) {
10033 gen_cmpabs_d(ctx
, func
-48, ft
, fs
, cc
);
10034 opn
= condnames_abs
[func
-48];
10036 gen_cmp_d(ctx
, func
-48, ft
, fs
, cc
);
10037 opn
= condnames
[func
-48];
10041 check_cp1_registers(ctx
, fs
);
10043 TCGv_i32 fp32
= tcg_temp_new_i32();
10044 TCGv_i64 fp64
= tcg_temp_new_i64();
10046 gen_load_fpr64(ctx
, fp64
, fs
);
10047 gen_helper_float_cvts_d(fp32
, cpu_env
, fp64
);
10048 tcg_temp_free_i64(fp64
);
10049 gen_store_fpr32(ctx
, fp32
, fd
);
10050 tcg_temp_free_i32(fp32
);
10055 check_cp1_registers(ctx
, fs
);
10057 TCGv_i32 fp32
= tcg_temp_new_i32();
10058 TCGv_i64 fp64
= tcg_temp_new_i64();
10060 gen_load_fpr64(ctx
, fp64
, fs
);
10061 gen_helper_float_cvtw_d(fp32
, cpu_env
, fp64
);
10062 tcg_temp_free_i64(fp64
);
10063 gen_store_fpr32(ctx
, fp32
, fd
);
10064 tcg_temp_free_i32(fp32
);
10069 check_cp1_64bitmode(ctx
);
10071 TCGv_i64 fp0
= tcg_temp_new_i64();
10073 gen_load_fpr64(ctx
, fp0
, fs
);
10074 gen_helper_float_cvtl_d(fp0
, cpu_env
, fp0
);
10075 gen_store_fpr64(ctx
, fp0
, fd
);
10076 tcg_temp_free_i64(fp0
);
10082 TCGv_i32 fp0
= tcg_temp_new_i32();
10084 gen_load_fpr32(ctx
, fp0
, fs
);
10085 gen_helper_float_cvts_w(fp0
, cpu_env
, fp0
);
10086 gen_store_fpr32(ctx
, fp0
, fd
);
10087 tcg_temp_free_i32(fp0
);
10092 check_cp1_registers(ctx
, fd
);
10094 TCGv_i32 fp32
= tcg_temp_new_i32();
10095 TCGv_i64 fp64
= tcg_temp_new_i64();
10097 gen_load_fpr32(ctx
, fp32
, fs
);
10098 gen_helper_float_cvtd_w(fp64
, cpu_env
, fp32
);
10099 tcg_temp_free_i32(fp32
);
10100 gen_store_fpr64(ctx
, fp64
, fd
);
10101 tcg_temp_free_i64(fp64
);
10106 check_cp1_64bitmode(ctx
);
10108 TCGv_i32 fp32
= tcg_temp_new_i32();
10109 TCGv_i64 fp64
= tcg_temp_new_i64();
10111 gen_load_fpr64(ctx
, fp64
, fs
);
10112 gen_helper_float_cvts_l(fp32
, cpu_env
, fp64
);
10113 tcg_temp_free_i64(fp64
);
10114 gen_store_fpr32(ctx
, fp32
, fd
);
10115 tcg_temp_free_i32(fp32
);
10120 check_cp1_64bitmode(ctx
);
10122 TCGv_i64 fp0
= tcg_temp_new_i64();
10124 gen_load_fpr64(ctx
, fp0
, fs
);
10125 gen_helper_float_cvtd_l(fp0
, cpu_env
, fp0
);
10126 gen_store_fpr64(ctx
, fp0
, fd
);
10127 tcg_temp_free_i64(fp0
);
10131 case OPC_CVT_PS_PW
:
10134 TCGv_i64 fp0
= tcg_temp_new_i64();
10136 gen_load_fpr64(ctx
, fp0
, fs
);
10137 gen_helper_float_cvtps_pw(fp0
, cpu_env
, fp0
);
10138 gen_store_fpr64(ctx
, fp0
, fd
);
10139 tcg_temp_free_i64(fp0
);
10146 TCGv_i64 fp0
= tcg_temp_new_i64();
10147 TCGv_i64 fp1
= tcg_temp_new_i64();
10149 gen_load_fpr64(ctx
, fp0
, fs
);
10150 gen_load_fpr64(ctx
, fp1
, ft
);
10151 gen_helper_float_add_ps(fp0
, cpu_env
, fp0
, fp1
);
10152 tcg_temp_free_i64(fp1
);
10153 gen_store_fpr64(ctx
, fp0
, fd
);
10154 tcg_temp_free_i64(fp0
);
10161 TCGv_i64 fp0
= tcg_temp_new_i64();
10162 TCGv_i64 fp1
= tcg_temp_new_i64();
10164 gen_load_fpr64(ctx
, fp0
, fs
);
10165 gen_load_fpr64(ctx
, fp1
, ft
);
10166 gen_helper_float_sub_ps(fp0
, cpu_env
, fp0
, fp1
);
10167 tcg_temp_free_i64(fp1
);
10168 gen_store_fpr64(ctx
, fp0
, fd
);
10169 tcg_temp_free_i64(fp0
);
10176 TCGv_i64 fp0
= tcg_temp_new_i64();
10177 TCGv_i64 fp1
= tcg_temp_new_i64();
10179 gen_load_fpr64(ctx
, fp0
, fs
);
10180 gen_load_fpr64(ctx
, fp1
, ft
);
10181 gen_helper_float_mul_ps(fp0
, cpu_env
, fp0
, fp1
);
10182 tcg_temp_free_i64(fp1
);
10183 gen_store_fpr64(ctx
, fp0
, fd
);
10184 tcg_temp_free_i64(fp0
);
10191 TCGv_i64 fp0
= tcg_temp_new_i64();
10193 gen_load_fpr64(ctx
, fp0
, fs
);
10194 gen_helper_float_abs_ps(fp0
, fp0
);
10195 gen_store_fpr64(ctx
, fp0
, fd
);
10196 tcg_temp_free_i64(fp0
);
10203 TCGv_i64 fp0
= tcg_temp_new_i64();
10205 gen_load_fpr64(ctx
, fp0
, fs
);
10206 gen_store_fpr64(ctx
, fp0
, fd
);
10207 tcg_temp_free_i64(fp0
);
10214 TCGv_i64 fp0
= tcg_temp_new_i64();
10216 gen_load_fpr64(ctx
, fp0
, fs
);
10217 gen_helper_float_chs_ps(fp0
, fp0
);
10218 gen_store_fpr64(ctx
, fp0
, fd
);
10219 tcg_temp_free_i64(fp0
);
10225 gen_movcf_ps(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
10231 TCGLabel
*l1
= gen_new_label();
10235 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
10236 fp0
= tcg_temp_new_i64();
10237 gen_load_fpr64(ctx
, fp0
, fs
);
10238 gen_store_fpr64(ctx
, fp0
, fd
);
10239 tcg_temp_free_i64(fp0
);
10247 TCGLabel
*l1
= gen_new_label();
10251 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
10252 fp0
= tcg_temp_new_i64();
10253 gen_load_fpr64(ctx
, fp0
, fs
);
10254 gen_store_fpr64(ctx
, fp0
, fd
);
10255 tcg_temp_free_i64(fp0
);
10264 TCGv_i64 fp0
= tcg_temp_new_i64();
10265 TCGv_i64 fp1
= tcg_temp_new_i64();
10267 gen_load_fpr64(ctx
, fp0
, ft
);
10268 gen_load_fpr64(ctx
, fp1
, fs
);
10269 gen_helper_float_addr_ps(fp0
, cpu_env
, fp0
, fp1
);
10270 tcg_temp_free_i64(fp1
);
10271 gen_store_fpr64(ctx
, fp0
, fd
);
10272 tcg_temp_free_i64(fp0
);
10279 TCGv_i64 fp0
= tcg_temp_new_i64();
10280 TCGv_i64 fp1
= tcg_temp_new_i64();
10282 gen_load_fpr64(ctx
, fp0
, ft
);
10283 gen_load_fpr64(ctx
, fp1
, fs
);
10284 gen_helper_float_mulr_ps(fp0
, cpu_env
, fp0
, fp1
);
10285 tcg_temp_free_i64(fp1
);
10286 gen_store_fpr64(ctx
, fp0
, fd
);
10287 tcg_temp_free_i64(fp0
);
10291 case OPC_RECIP2_PS
:
10294 TCGv_i64 fp0
= tcg_temp_new_i64();
10295 TCGv_i64 fp1
= tcg_temp_new_i64();
10297 gen_load_fpr64(ctx
, fp0
, fs
);
10298 gen_load_fpr64(ctx
, fp1
, ft
);
10299 gen_helper_float_recip2_ps(fp0
, cpu_env
, fp0
, fp1
);
10300 tcg_temp_free_i64(fp1
);
10301 gen_store_fpr64(ctx
, fp0
, fd
);
10302 tcg_temp_free_i64(fp0
);
10306 case OPC_RECIP1_PS
:
10309 TCGv_i64 fp0
= tcg_temp_new_i64();
10311 gen_load_fpr64(ctx
, fp0
, fs
);
10312 gen_helper_float_recip1_ps(fp0
, cpu_env
, fp0
);
10313 gen_store_fpr64(ctx
, fp0
, fd
);
10314 tcg_temp_free_i64(fp0
);
10318 case OPC_RSQRT1_PS
:
10321 TCGv_i64 fp0
= tcg_temp_new_i64();
10323 gen_load_fpr64(ctx
, fp0
, fs
);
10324 gen_helper_float_rsqrt1_ps(fp0
, cpu_env
, fp0
);
10325 gen_store_fpr64(ctx
, fp0
, fd
);
10326 tcg_temp_free_i64(fp0
);
10330 case OPC_RSQRT2_PS
:
10333 TCGv_i64 fp0
= tcg_temp_new_i64();
10334 TCGv_i64 fp1
= tcg_temp_new_i64();
10336 gen_load_fpr64(ctx
, fp0
, fs
);
10337 gen_load_fpr64(ctx
, fp1
, ft
);
10338 gen_helper_float_rsqrt2_ps(fp0
, cpu_env
, fp0
, fp1
);
10339 tcg_temp_free_i64(fp1
);
10340 gen_store_fpr64(ctx
, fp0
, fd
);
10341 tcg_temp_free_i64(fp0
);
10346 check_cp1_64bitmode(ctx
);
10348 TCGv_i32 fp0
= tcg_temp_new_i32();
10350 gen_load_fpr32h(ctx
, fp0
, fs
);
10351 gen_helper_float_cvts_pu(fp0
, cpu_env
, fp0
);
10352 gen_store_fpr32(ctx
, fp0
, fd
);
10353 tcg_temp_free_i32(fp0
);
10357 case OPC_CVT_PW_PS
:
10360 TCGv_i64 fp0
= tcg_temp_new_i64();
10362 gen_load_fpr64(ctx
, fp0
, fs
);
10363 gen_helper_float_cvtpw_ps(fp0
, cpu_env
, fp0
);
10364 gen_store_fpr64(ctx
, fp0
, fd
);
10365 tcg_temp_free_i64(fp0
);
10370 check_cp1_64bitmode(ctx
);
10372 TCGv_i32 fp0
= tcg_temp_new_i32();
10374 gen_load_fpr32(ctx
, fp0
, fs
);
10375 gen_helper_float_cvts_pl(fp0
, cpu_env
, fp0
);
10376 gen_store_fpr32(ctx
, fp0
, fd
);
10377 tcg_temp_free_i32(fp0
);
10384 TCGv_i32 fp0
= tcg_temp_new_i32();
10385 TCGv_i32 fp1
= tcg_temp_new_i32();
10387 gen_load_fpr32(ctx
, fp0
, fs
);
10388 gen_load_fpr32(ctx
, fp1
, ft
);
10389 gen_store_fpr32h(ctx
, fp0
, fd
);
10390 gen_store_fpr32(ctx
, fp1
, fd
);
10391 tcg_temp_free_i32(fp0
);
10392 tcg_temp_free_i32(fp1
);
10399 TCGv_i32 fp0
= tcg_temp_new_i32();
10400 TCGv_i32 fp1
= tcg_temp_new_i32();
10402 gen_load_fpr32(ctx
, fp0
, fs
);
10403 gen_load_fpr32h(ctx
, fp1
, ft
);
10404 gen_store_fpr32(ctx
, fp1
, fd
);
10405 gen_store_fpr32h(ctx
, fp0
, fd
);
10406 tcg_temp_free_i32(fp0
);
10407 tcg_temp_free_i32(fp1
);
10414 TCGv_i32 fp0
= tcg_temp_new_i32();
10415 TCGv_i32 fp1
= tcg_temp_new_i32();
10417 gen_load_fpr32h(ctx
, fp0
, fs
);
10418 gen_load_fpr32(ctx
, fp1
, ft
);
10419 gen_store_fpr32(ctx
, fp1
, fd
);
10420 gen_store_fpr32h(ctx
, fp0
, fd
);
10421 tcg_temp_free_i32(fp0
);
10422 tcg_temp_free_i32(fp1
);
10429 TCGv_i32 fp0
= tcg_temp_new_i32();
10430 TCGv_i32 fp1
= tcg_temp_new_i32();
10432 gen_load_fpr32h(ctx
, fp0
, fs
);
10433 gen_load_fpr32h(ctx
, fp1
, ft
);
10434 gen_store_fpr32(ctx
, fp1
, fd
);
10435 gen_store_fpr32h(ctx
, fp0
, fd
);
10436 tcg_temp_free_i32(fp0
);
10437 tcg_temp_free_i32(fp1
);
10442 case OPC_CMP_UN_PS
:
10443 case OPC_CMP_EQ_PS
:
10444 case OPC_CMP_UEQ_PS
:
10445 case OPC_CMP_OLT_PS
:
10446 case OPC_CMP_ULT_PS
:
10447 case OPC_CMP_OLE_PS
:
10448 case OPC_CMP_ULE_PS
:
10449 case OPC_CMP_SF_PS
:
10450 case OPC_CMP_NGLE_PS
:
10451 case OPC_CMP_SEQ_PS
:
10452 case OPC_CMP_NGL_PS
:
10453 case OPC_CMP_LT_PS
:
10454 case OPC_CMP_NGE_PS
:
10455 case OPC_CMP_LE_PS
:
10456 case OPC_CMP_NGT_PS
:
10457 if (ctx
->opcode
& (1 << 6)) {
10458 gen_cmpabs_ps(ctx
, func
-48, ft
, fs
, cc
);
10459 opn
= condnames_abs
[func
-48];
10461 gen_cmp_ps(ctx
, func
-48, ft
, fs
, cc
);
10462 opn
= condnames
[func
-48];
10467 generate_exception (ctx
, EXCP_RI
);
10470 (void)opn
; /* avoid a compiler warning */
10473 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
10476 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
10479 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
10484 /* Coprocessor 3 (FPU) */
10485 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
10486 int fd
, int fs
, int base
, int index
)
10488 const char *opn
= "extended float load/store";
10490 TCGv t0
= tcg_temp_new();
10493 gen_load_gpr(t0
, index
);
10494 } else if (index
== 0) {
10495 gen_load_gpr(t0
, base
);
10497 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], cpu_gpr
[index
]);
10499 /* Don't do NOP if destination is zero: we must perform the actual
10505 TCGv_i32 fp0
= tcg_temp_new_i32();
10507 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TESL
);
10508 tcg_gen_trunc_tl_i32(fp0
, t0
);
10509 gen_store_fpr32(ctx
, fp0
, fd
);
10510 tcg_temp_free_i32(fp0
);
10516 check_cp1_registers(ctx
, fd
);
10518 TCGv_i64 fp0
= tcg_temp_new_i64();
10519 tcg_gen_qemu_ld_i64(fp0
, t0
, ctx
->mem_idx
, MO_TEQ
);
10520 gen_store_fpr64(ctx
, fp0
, fd
);
10521 tcg_temp_free_i64(fp0
);
10526 check_cp1_64bitmode(ctx
);
10527 tcg_gen_andi_tl(t0
, t0
, ~0x7);
10529 TCGv_i64 fp0
= tcg_temp_new_i64();
10531 tcg_gen_qemu_ld_i64(fp0
, t0
, ctx
->mem_idx
, MO_TEQ
);
10532 gen_store_fpr64(ctx
, fp0
, fd
);
10533 tcg_temp_free_i64(fp0
);
10540 TCGv_i32 fp0
= tcg_temp_new_i32();
10541 gen_load_fpr32(ctx
, fp0
, fs
);
10542 tcg_gen_qemu_st_i32(fp0
, t0
, ctx
->mem_idx
, MO_TEUL
);
10543 tcg_temp_free_i32(fp0
);
10550 check_cp1_registers(ctx
, fs
);
10552 TCGv_i64 fp0
= tcg_temp_new_i64();
10553 gen_load_fpr64(ctx
, fp0
, fs
);
10554 tcg_gen_qemu_st_i64(fp0
, t0
, ctx
->mem_idx
, MO_TEQ
);
10555 tcg_temp_free_i64(fp0
);
10561 check_cp1_64bitmode(ctx
);
10562 tcg_gen_andi_tl(t0
, t0
, ~0x7);
10564 TCGv_i64 fp0
= tcg_temp_new_i64();
10565 gen_load_fpr64(ctx
, fp0
, fs
);
10566 tcg_gen_qemu_st_i64(fp0
, t0
, ctx
->mem_idx
, MO_TEQ
);
10567 tcg_temp_free_i64(fp0
);
10574 (void)opn
; (void)store
; /* avoid compiler warnings */
10575 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
10576 regnames
[index
], regnames
[base
]);
10579 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
10580 int fd
, int fr
, int fs
, int ft
)
10582 const char *opn
= "flt3_arith";
10588 TCGv t0
= tcg_temp_local_new();
10589 TCGv_i32 fp
= tcg_temp_new_i32();
10590 TCGv_i32 fph
= tcg_temp_new_i32();
10591 TCGLabel
*l1
= gen_new_label();
10592 TCGLabel
*l2
= gen_new_label();
10594 gen_load_gpr(t0
, fr
);
10595 tcg_gen_andi_tl(t0
, t0
, 0x7);
10597 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
10598 gen_load_fpr32(ctx
, fp
, fs
);
10599 gen_load_fpr32h(ctx
, fph
, fs
);
10600 gen_store_fpr32(ctx
, fp
, fd
);
10601 gen_store_fpr32h(ctx
, fph
, fd
);
10604 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
10606 #ifdef TARGET_WORDS_BIGENDIAN
10607 gen_load_fpr32(ctx
, fp
, fs
);
10608 gen_load_fpr32h(ctx
, fph
, ft
);
10609 gen_store_fpr32h(ctx
, fp
, fd
);
10610 gen_store_fpr32(ctx
, fph
, fd
);
10612 gen_load_fpr32h(ctx
, fph
, fs
);
10613 gen_load_fpr32(ctx
, fp
, ft
);
10614 gen_store_fpr32(ctx
, fph
, fd
);
10615 gen_store_fpr32h(ctx
, fp
, fd
);
10618 tcg_temp_free_i32(fp
);
10619 tcg_temp_free_i32(fph
);
10626 TCGv_i32 fp0
= tcg_temp_new_i32();
10627 TCGv_i32 fp1
= tcg_temp_new_i32();
10628 TCGv_i32 fp2
= tcg_temp_new_i32();
10630 gen_load_fpr32(ctx
, fp0
, fs
);
10631 gen_load_fpr32(ctx
, fp1
, ft
);
10632 gen_load_fpr32(ctx
, fp2
, fr
);
10633 gen_helper_float_madd_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10634 tcg_temp_free_i32(fp0
);
10635 tcg_temp_free_i32(fp1
);
10636 gen_store_fpr32(ctx
, fp2
, fd
);
10637 tcg_temp_free_i32(fp2
);
10643 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
10645 TCGv_i64 fp0
= tcg_temp_new_i64();
10646 TCGv_i64 fp1
= tcg_temp_new_i64();
10647 TCGv_i64 fp2
= tcg_temp_new_i64();
10649 gen_load_fpr64(ctx
, fp0
, fs
);
10650 gen_load_fpr64(ctx
, fp1
, ft
);
10651 gen_load_fpr64(ctx
, fp2
, fr
);
10652 gen_helper_float_madd_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10653 tcg_temp_free_i64(fp0
);
10654 tcg_temp_free_i64(fp1
);
10655 gen_store_fpr64(ctx
, fp2
, fd
);
10656 tcg_temp_free_i64(fp2
);
10663 TCGv_i64 fp0
= tcg_temp_new_i64();
10664 TCGv_i64 fp1
= tcg_temp_new_i64();
10665 TCGv_i64 fp2
= tcg_temp_new_i64();
10667 gen_load_fpr64(ctx
, fp0
, fs
);
10668 gen_load_fpr64(ctx
, fp1
, ft
);
10669 gen_load_fpr64(ctx
, fp2
, fr
);
10670 gen_helper_float_madd_ps(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10671 tcg_temp_free_i64(fp0
);
10672 tcg_temp_free_i64(fp1
);
10673 gen_store_fpr64(ctx
, fp2
, fd
);
10674 tcg_temp_free_i64(fp2
);
10681 TCGv_i32 fp0
= tcg_temp_new_i32();
10682 TCGv_i32 fp1
= tcg_temp_new_i32();
10683 TCGv_i32 fp2
= tcg_temp_new_i32();
10685 gen_load_fpr32(ctx
, fp0
, fs
);
10686 gen_load_fpr32(ctx
, fp1
, ft
);
10687 gen_load_fpr32(ctx
, fp2
, fr
);
10688 gen_helper_float_msub_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10689 tcg_temp_free_i32(fp0
);
10690 tcg_temp_free_i32(fp1
);
10691 gen_store_fpr32(ctx
, fp2
, fd
);
10692 tcg_temp_free_i32(fp2
);
10698 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
10700 TCGv_i64 fp0
= tcg_temp_new_i64();
10701 TCGv_i64 fp1
= tcg_temp_new_i64();
10702 TCGv_i64 fp2
= tcg_temp_new_i64();
10704 gen_load_fpr64(ctx
, fp0
, fs
);
10705 gen_load_fpr64(ctx
, fp1
, ft
);
10706 gen_load_fpr64(ctx
, fp2
, fr
);
10707 gen_helper_float_msub_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10708 tcg_temp_free_i64(fp0
);
10709 tcg_temp_free_i64(fp1
);
10710 gen_store_fpr64(ctx
, fp2
, fd
);
10711 tcg_temp_free_i64(fp2
);
10718 TCGv_i64 fp0
= tcg_temp_new_i64();
10719 TCGv_i64 fp1
= tcg_temp_new_i64();
10720 TCGv_i64 fp2
= tcg_temp_new_i64();
10722 gen_load_fpr64(ctx
, fp0
, fs
);
10723 gen_load_fpr64(ctx
, fp1
, ft
);
10724 gen_load_fpr64(ctx
, fp2
, fr
);
10725 gen_helper_float_msub_ps(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10726 tcg_temp_free_i64(fp0
);
10727 tcg_temp_free_i64(fp1
);
10728 gen_store_fpr64(ctx
, fp2
, fd
);
10729 tcg_temp_free_i64(fp2
);
10736 TCGv_i32 fp0
= tcg_temp_new_i32();
10737 TCGv_i32 fp1
= tcg_temp_new_i32();
10738 TCGv_i32 fp2
= tcg_temp_new_i32();
10740 gen_load_fpr32(ctx
, fp0
, fs
);
10741 gen_load_fpr32(ctx
, fp1
, ft
);
10742 gen_load_fpr32(ctx
, fp2
, fr
);
10743 gen_helper_float_nmadd_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10744 tcg_temp_free_i32(fp0
);
10745 tcg_temp_free_i32(fp1
);
10746 gen_store_fpr32(ctx
, fp2
, fd
);
10747 tcg_temp_free_i32(fp2
);
10753 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
10755 TCGv_i64 fp0
= tcg_temp_new_i64();
10756 TCGv_i64 fp1
= tcg_temp_new_i64();
10757 TCGv_i64 fp2
= tcg_temp_new_i64();
10759 gen_load_fpr64(ctx
, fp0
, fs
);
10760 gen_load_fpr64(ctx
, fp1
, ft
);
10761 gen_load_fpr64(ctx
, fp2
, fr
);
10762 gen_helper_float_nmadd_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10763 tcg_temp_free_i64(fp0
);
10764 tcg_temp_free_i64(fp1
);
10765 gen_store_fpr64(ctx
, fp2
, fd
);
10766 tcg_temp_free_i64(fp2
);
10773 TCGv_i64 fp0
= tcg_temp_new_i64();
10774 TCGv_i64 fp1
= tcg_temp_new_i64();
10775 TCGv_i64 fp2
= tcg_temp_new_i64();
10777 gen_load_fpr64(ctx
, fp0
, fs
);
10778 gen_load_fpr64(ctx
, fp1
, ft
);
10779 gen_load_fpr64(ctx
, fp2
, fr
);
10780 gen_helper_float_nmadd_ps(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10781 tcg_temp_free_i64(fp0
);
10782 tcg_temp_free_i64(fp1
);
10783 gen_store_fpr64(ctx
, fp2
, fd
);
10784 tcg_temp_free_i64(fp2
);
10791 TCGv_i32 fp0
= tcg_temp_new_i32();
10792 TCGv_i32 fp1
= tcg_temp_new_i32();
10793 TCGv_i32 fp2
= tcg_temp_new_i32();
10795 gen_load_fpr32(ctx
, fp0
, fs
);
10796 gen_load_fpr32(ctx
, fp1
, ft
);
10797 gen_load_fpr32(ctx
, fp2
, fr
);
10798 gen_helper_float_nmsub_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10799 tcg_temp_free_i32(fp0
);
10800 tcg_temp_free_i32(fp1
);
10801 gen_store_fpr32(ctx
, fp2
, fd
);
10802 tcg_temp_free_i32(fp2
);
10808 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
10810 TCGv_i64 fp0
= tcg_temp_new_i64();
10811 TCGv_i64 fp1
= tcg_temp_new_i64();
10812 TCGv_i64 fp2
= tcg_temp_new_i64();
10814 gen_load_fpr64(ctx
, fp0
, fs
);
10815 gen_load_fpr64(ctx
, fp1
, ft
);
10816 gen_load_fpr64(ctx
, fp2
, fr
);
10817 gen_helper_float_nmsub_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10818 tcg_temp_free_i64(fp0
);
10819 tcg_temp_free_i64(fp1
);
10820 gen_store_fpr64(ctx
, fp2
, fd
);
10821 tcg_temp_free_i64(fp2
);
10828 TCGv_i64 fp0
= tcg_temp_new_i64();
10829 TCGv_i64 fp1
= tcg_temp_new_i64();
10830 TCGv_i64 fp2
= tcg_temp_new_i64();
10832 gen_load_fpr64(ctx
, fp0
, fs
);
10833 gen_load_fpr64(ctx
, fp1
, ft
);
10834 gen_load_fpr64(ctx
, fp2
, fr
);
10835 gen_helper_float_nmsub_ps(fp2
, cpu_env
, fp0
, fp1
, fp2
);
10836 tcg_temp_free_i64(fp0
);
10837 tcg_temp_free_i64(fp1
);
10838 gen_store_fpr64(ctx
, fp2
, fd
);
10839 tcg_temp_free_i64(fp2
);
10845 generate_exception (ctx
, EXCP_RI
);
10848 (void)opn
; /* avoid a compiler warning */
10849 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
10850 fregnames
[fs
], fregnames
[ft
]);
10853 static void gen_rdhwr(DisasContext
*ctx
, int rt
, int rd
)
10857 #if !defined(CONFIG_USER_ONLY)
10858 /* The Linux kernel will emulate rdhwr if it's not supported natively.
10859 Therefore only check the ISA in system mode. */
10860 check_insn(ctx
, ISA_MIPS32R2
);
10862 t0
= tcg_temp_new();
10866 save_cpu_state(ctx
, 1);
10867 gen_helper_rdhwr_cpunum(t0
, cpu_env
);
10868 gen_store_gpr(t0
, rt
);
10871 save_cpu_state(ctx
, 1);
10872 gen_helper_rdhwr_synci_step(t0
, cpu_env
);
10873 gen_store_gpr(t0
, rt
);
10876 save_cpu_state(ctx
, 1);
10877 gen_helper_rdhwr_cc(t0
, cpu_env
);
10878 gen_store_gpr(t0
, rt
);
10881 save_cpu_state(ctx
, 1);
10882 gen_helper_rdhwr_ccres(t0
, cpu_env
);
10883 gen_store_gpr(t0
, rt
);
10886 #if defined(CONFIG_USER_ONLY)
10887 tcg_gen_ld_tl(t0
, cpu_env
,
10888 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
10889 gen_store_gpr(t0
, rt
);
10892 if ((ctx
->hflags
& MIPS_HFLAG_CP0
) ||
10893 (ctx
->hflags
& MIPS_HFLAG_HWRENA_ULR
)) {
10894 tcg_gen_ld_tl(t0
, cpu_env
,
10895 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
10896 gen_store_gpr(t0
, rt
);
10898 generate_exception(ctx
, EXCP_RI
);
10902 default: /* Invalid */
10903 MIPS_INVAL("rdhwr");
10904 generate_exception(ctx
, EXCP_RI
);
10910 static inline void clear_branch_hflags(DisasContext
*ctx
)
10912 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
10913 if (ctx
->bstate
== BS_NONE
) {
10914 save_cpu_state(ctx
, 0);
10916 /* it is not safe to save ctx->hflags as hflags may be changed
10917 in execution time by the instruction in delay / forbidden slot. */
10918 tcg_gen_andi_i32(hflags
, hflags
, ~MIPS_HFLAG_BMASK
);
10922 static void gen_branch(DisasContext
*ctx
, int insn_bytes
)
10924 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
10925 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
10926 /* Branches completion */
10927 clear_branch_hflags(ctx
);
10928 ctx
->bstate
= BS_BRANCH
;
10929 /* FIXME: Need to clear can_do_io. */
10930 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
10931 case MIPS_HFLAG_FBNSLOT
:
10932 MIPS_DEBUG("forbidden slot");
10933 gen_goto_tb(ctx
, 0, ctx
->pc
+ insn_bytes
);
10936 /* unconditional branch */
10937 MIPS_DEBUG("unconditional branch");
10938 if (proc_hflags
& MIPS_HFLAG_BX
) {
10939 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
10941 gen_goto_tb(ctx
, 0, ctx
->btarget
);
10943 case MIPS_HFLAG_BL
:
10944 /* blikely taken case */
10945 MIPS_DEBUG("blikely branch taken");
10946 gen_goto_tb(ctx
, 0, ctx
->btarget
);
10948 case MIPS_HFLAG_BC
:
10949 /* Conditional branch */
10950 MIPS_DEBUG("conditional branch");
10952 TCGLabel
*l1
= gen_new_label();
10954 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
10955 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
10957 gen_goto_tb(ctx
, 0, ctx
->btarget
);
10960 case MIPS_HFLAG_BR
:
10961 /* unconditional branch to register */
10962 MIPS_DEBUG("branch to register");
10963 if (ctx
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
10964 TCGv t0
= tcg_temp_new();
10965 TCGv_i32 t1
= tcg_temp_new_i32();
10967 tcg_gen_andi_tl(t0
, btarget
, 0x1);
10968 tcg_gen_trunc_tl_i32(t1
, t0
);
10970 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
10971 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
10972 tcg_gen_or_i32(hflags
, hflags
, t1
);
10973 tcg_temp_free_i32(t1
);
10975 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
10977 tcg_gen_mov_tl(cpu_PC
, btarget
);
10979 if (ctx
->singlestep_enabled
) {
10980 save_cpu_state(ctx
, 0);
10981 gen_helper_0e0i(raise_exception
, EXCP_DEBUG
);
10983 tcg_gen_exit_tb(0);
10986 fprintf(stderr
, "unknown branch 0x%x\n", proc_hflags
);
10992 /* Compact Branches */
10993 static void gen_compute_compact_branch(DisasContext
*ctx
, uint32_t opc
,
10994 int rs
, int rt
, int32_t offset
)
10996 int bcond_compute
= 0;
10997 TCGv t0
= tcg_temp_new();
10998 TCGv t1
= tcg_temp_new();
10999 int m16_lowbit
= (ctx
->hflags
& MIPS_HFLAG_M16
) != 0;
11001 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
11002 #ifdef MIPS_DEBUG_DISAS
11003 LOG_DISAS("Branch in delay / forbidden slot at PC 0x" TARGET_FMT_lx
11006 generate_exception(ctx
, EXCP_RI
);
11010 /* Load needed operands and calculate btarget */
11012 /* compact branch */
11013 case OPC_BOVC
: /* OPC_BEQZALC, OPC_BEQC */
11014 case OPC_BNVC
: /* OPC_BNEZALC, OPC_BNEC */
11015 gen_load_gpr(t0
, rs
);
11016 gen_load_gpr(t1
, rt
);
11018 ctx
->btarget
= addr_add(ctx
, ctx
->pc
+ 4, offset
);
11019 if (rs
<= rt
&& rs
== 0) {
11020 /* OPC_BEQZALC, OPC_BNEZALC */
11021 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 4 + m16_lowbit
);
11024 case OPC_BLEZC
: /* OPC_BGEZC, OPC_BGEC */
11025 case OPC_BGTZC
: /* OPC_BLTZC, OPC_BLTC */
11026 gen_load_gpr(t0
, rs
);
11027 gen_load_gpr(t1
, rt
);
11029 ctx
->btarget
= addr_add(ctx
, ctx
->pc
+ 4, offset
);
11031 case OPC_BLEZALC
: /* OPC_BGEZALC, OPC_BGEUC */
11032 case OPC_BGTZALC
: /* OPC_BLTZALC, OPC_BLTUC */
11033 if (rs
== 0 || rs
== rt
) {
11034 /* OPC_BLEZALC, OPC_BGEZALC */
11035 /* OPC_BGTZALC, OPC_BLTZALC */
11036 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 4 + m16_lowbit
);
11038 gen_load_gpr(t0
, rs
);
11039 gen_load_gpr(t1
, rt
);
11041 ctx
->btarget
= addr_add(ctx
, ctx
->pc
+ 4, offset
);
11045 ctx
->btarget
= addr_add(ctx
, ctx
->pc
+ 4, offset
);
11050 /* OPC_BEQZC, OPC_BNEZC */
11051 gen_load_gpr(t0
, rs
);
11053 ctx
->btarget
= addr_add(ctx
, ctx
->pc
+ 4, offset
);
11055 /* OPC_JIC, OPC_JIALC */
11056 TCGv tbase
= tcg_temp_new();
11057 TCGv toffset
= tcg_temp_new();
11059 gen_load_gpr(tbase
, rt
);
11060 tcg_gen_movi_tl(toffset
, offset
);
11061 gen_op_addr_add(ctx
, btarget
, tbase
, toffset
);
11062 tcg_temp_free(tbase
);
11063 tcg_temp_free(toffset
);
11067 MIPS_INVAL("Compact branch/jump");
11068 generate_exception(ctx
, EXCP_RI
);
11072 if (bcond_compute
== 0) {
11073 /* Uncoditional compact branch */
11076 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 4 + m16_lowbit
);
11079 ctx
->hflags
|= MIPS_HFLAG_BR
;
11082 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 4 + m16_lowbit
);
11085 ctx
->hflags
|= MIPS_HFLAG_B
;
11088 MIPS_INVAL("Compact branch/jump");
11089 generate_exception(ctx
, EXCP_RI
);
11093 /* Generating branch here as compact branches don't have delay slot */
11094 gen_branch(ctx
, 4);
11096 /* Conditional compact branch */
11097 TCGLabel
*fs
= gen_new_label();
11098 save_cpu_state(ctx
, 0);
11101 case OPC_BLEZALC
: /* OPC_BGEZALC, OPC_BGEUC */
11102 if (rs
== 0 && rt
!= 0) {
11104 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LE
), t1
, 0, fs
);
11105 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
11107 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GE
), t1
, 0, fs
);
11110 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_GEU
), t0
, t1
, fs
);
11113 case OPC_BGTZALC
: /* OPC_BLTZALC, OPC_BLTUC */
11114 if (rs
== 0 && rt
!= 0) {
11116 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GT
), t1
, 0, fs
);
11117 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
11119 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LT
), t1
, 0, fs
);
11122 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_LTU
), t0
, t1
, fs
);
11125 case OPC_BLEZC
: /* OPC_BGEZC, OPC_BGEC */
11126 if (rs
== 0 && rt
!= 0) {
11128 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LE
), t1
, 0, fs
);
11129 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
11131 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GE
), t1
, 0, fs
);
11134 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_GE
), t0
, t1
, fs
);
11137 case OPC_BGTZC
: /* OPC_BLTZC, OPC_BLTC */
11138 if (rs
== 0 && rt
!= 0) {
11140 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GT
), t1
, 0, fs
);
11141 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
11143 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LT
), t1
, 0, fs
);
11146 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_LT
), t0
, t1
, fs
);
11149 case OPC_BOVC
: /* OPC_BEQZALC, OPC_BEQC */
11150 case OPC_BNVC
: /* OPC_BNEZALC, OPC_BNEC */
11152 /* OPC_BOVC, OPC_BNVC */
11153 TCGv t2
= tcg_temp_new();
11154 TCGv t3
= tcg_temp_new();
11155 TCGv t4
= tcg_temp_new();
11156 TCGv input_overflow
= tcg_temp_new();
11158 gen_load_gpr(t0
, rs
);
11159 gen_load_gpr(t1
, rt
);
11160 tcg_gen_ext32s_tl(t2
, t0
);
11161 tcg_gen_setcond_tl(TCG_COND_NE
, input_overflow
, t2
, t0
);
11162 tcg_gen_ext32s_tl(t3
, t1
);
11163 tcg_gen_setcond_tl(TCG_COND_NE
, t4
, t3
, t1
);
11164 tcg_gen_or_tl(input_overflow
, input_overflow
, t4
);
11166 tcg_gen_add_tl(t4
, t2
, t3
);
11167 tcg_gen_ext32s_tl(t4
, t4
);
11168 tcg_gen_xor_tl(t2
, t2
, t3
);
11169 tcg_gen_xor_tl(t3
, t4
, t3
);
11170 tcg_gen_andc_tl(t2
, t3
, t2
);
11171 tcg_gen_setcondi_tl(TCG_COND_LT
, t4
, t2
, 0);
11172 tcg_gen_or_tl(t4
, t4
, input_overflow
);
11173 if (opc
== OPC_BOVC
) {
11175 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_NE
), t4
, 0, fs
);
11178 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_EQ
), t4
, 0, fs
);
11180 tcg_temp_free(input_overflow
);
11184 } else if (rs
< rt
&& rs
== 0) {
11185 /* OPC_BEQZALC, OPC_BNEZALC */
11186 if (opc
== OPC_BEQZALC
) {
11188 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_EQ
), t1
, 0, fs
);
11191 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_NE
), t1
, 0, fs
);
11194 /* OPC_BEQC, OPC_BNEC */
11195 if (opc
== OPC_BEQC
) {
11197 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_EQ
), t0
, t1
, fs
);
11200 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_NE
), t0
, t1
, fs
);
11205 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_EQ
), t0
, 0, fs
);
11208 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_NE
), t0
, 0, fs
);
11211 MIPS_INVAL("Compact conditional branch/jump");
11212 generate_exception(ctx
, EXCP_RI
);
11216 /* Generating branch here as compact branches don't have delay slot */
11217 gen_goto_tb(ctx
, 1, ctx
->btarget
);
11220 ctx
->hflags
|= MIPS_HFLAG_FBNSLOT
;
11221 MIPS_DEBUG("Compact conditional branch");
11229 /* ISA extensions (ASEs) */
11230 /* MIPS16 extension to MIPS32 */
11232 /* MIPS16 major opcodes */
11234 M16_OPC_ADDIUSP
= 0x00,
11235 M16_OPC_ADDIUPC
= 0x01,
11237 M16_OPC_JAL
= 0x03,
11238 M16_OPC_BEQZ
= 0x04,
11239 M16_OPC_BNEQZ
= 0x05,
11240 M16_OPC_SHIFT
= 0x06,
11242 M16_OPC_RRIA
= 0x08,
11243 M16_OPC_ADDIU8
= 0x09,
11244 M16_OPC_SLTI
= 0x0a,
11245 M16_OPC_SLTIU
= 0x0b,
11248 M16_OPC_CMPI
= 0x0e,
11252 M16_OPC_LWSP
= 0x12,
11254 M16_OPC_LBU
= 0x14,
11255 M16_OPC_LHU
= 0x15,
11256 M16_OPC_LWPC
= 0x16,
11257 M16_OPC_LWU
= 0x17,
11260 M16_OPC_SWSP
= 0x1a,
11262 M16_OPC_RRR
= 0x1c,
11264 M16_OPC_EXTEND
= 0x1e,
11268 /* I8 funct field */
11287 /* RR funct field */
11321 /* I64 funct field */
11329 I64_DADDIUPC
= 0x6,
11333 /* RR ry field for CNVT */
11335 RR_RY_CNVT_ZEB
= 0x0,
11336 RR_RY_CNVT_ZEH
= 0x1,
11337 RR_RY_CNVT_ZEW
= 0x2,
11338 RR_RY_CNVT_SEB
= 0x4,
11339 RR_RY_CNVT_SEH
= 0x5,
11340 RR_RY_CNVT_SEW
= 0x6,
11343 static int xlat (int r
)
11345 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
11350 static void gen_mips16_save (DisasContext
*ctx
,
11351 int xsregs
, int aregs
,
11352 int do_ra
, int do_s0
, int do_s1
,
11355 TCGv t0
= tcg_temp_new();
11356 TCGv t1
= tcg_temp_new();
11357 TCGv t2
= tcg_temp_new();
11387 generate_exception(ctx
, EXCP_RI
);
11393 gen_base_offset_addr(ctx
, t0
, 29, 12);
11394 gen_load_gpr(t1
, 7);
11395 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEUL
);
11398 gen_base_offset_addr(ctx
, t0
, 29, 8);
11399 gen_load_gpr(t1
, 6);
11400 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEUL
);
11403 gen_base_offset_addr(ctx
, t0
, 29, 4);
11404 gen_load_gpr(t1
, 5);
11405 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEUL
);
11408 gen_base_offset_addr(ctx
, t0
, 29, 0);
11409 gen_load_gpr(t1
, 4);
11410 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEUL
);
11413 gen_load_gpr(t0
, 29);
11415 #define DECR_AND_STORE(reg) do { \
11416 tcg_gen_movi_tl(t2, -4); \
11417 gen_op_addr_add(ctx, t0, t0, t2); \
11418 gen_load_gpr(t1, reg); \
11419 tcg_gen_qemu_st_tl(t1, t0, ctx->mem_idx, MO_TEUL); \
11423 DECR_AND_STORE(31);
11428 DECR_AND_STORE(30);
11431 DECR_AND_STORE(23);
11434 DECR_AND_STORE(22);
11437 DECR_AND_STORE(21);
11440 DECR_AND_STORE(20);
11443 DECR_AND_STORE(19);
11446 DECR_AND_STORE(18);
11450 DECR_AND_STORE(17);
11453 DECR_AND_STORE(16);
11483 generate_exception(ctx
, EXCP_RI
);
11499 #undef DECR_AND_STORE
11501 tcg_gen_movi_tl(t2
, -framesize
);
11502 gen_op_addr_add(ctx
, cpu_gpr
[29], cpu_gpr
[29], t2
);
11508 static void gen_mips16_restore (DisasContext
*ctx
,
11509 int xsregs
, int aregs
,
11510 int do_ra
, int do_s0
, int do_s1
,
11514 TCGv t0
= tcg_temp_new();
11515 TCGv t1
= tcg_temp_new();
11516 TCGv t2
= tcg_temp_new();
11518 tcg_gen_movi_tl(t2
, framesize
);
11519 gen_op_addr_add(ctx
, t0
, cpu_gpr
[29], t2
);
11521 #define DECR_AND_LOAD(reg) do { \
11522 tcg_gen_movi_tl(t2, -4); \
11523 gen_op_addr_add(ctx, t0, t0, t2); \
11524 tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, MO_TESL); \
11525 gen_store_gpr(t1, reg); \
11589 generate_exception(ctx
, EXCP_RI
);
11605 #undef DECR_AND_LOAD
11607 tcg_gen_movi_tl(t2
, framesize
);
11608 gen_op_addr_add(ctx
, cpu_gpr
[29], cpu_gpr
[29], t2
);
11614 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
11615 int is_64_bit
, int extended
)
11619 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
11620 generate_exception(ctx
, EXCP_RI
);
11624 t0
= tcg_temp_new();
11626 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
11627 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
11629 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
11635 #if defined(TARGET_MIPS64)
11636 static void decode_i64_mips16 (DisasContext
*ctx
,
11637 int ry
, int funct
, int16_t offset
,
11642 check_insn(ctx
, ISA_MIPS3
);
11643 check_mips_64(ctx
);
11644 offset
= extended
? offset
: offset
<< 3;
11645 gen_ld(ctx
, OPC_LD
, ry
, 29, offset
);
11648 check_insn(ctx
, ISA_MIPS3
);
11649 check_mips_64(ctx
);
11650 offset
= extended
? offset
: offset
<< 3;
11651 gen_st(ctx
, OPC_SD
, ry
, 29, offset
);
11654 check_insn(ctx
, ISA_MIPS3
);
11655 check_mips_64(ctx
);
11656 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
11657 gen_st(ctx
, OPC_SD
, 31, 29, offset
);
11660 check_insn(ctx
, ISA_MIPS3
);
11661 check_mips_64(ctx
);
11662 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
11663 gen_arith_imm(ctx
, OPC_DADDIU
, 29, 29, offset
);
11666 check_insn(ctx
, ISA_MIPS3
);
11667 check_mips_64(ctx
);
11668 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
11669 generate_exception(ctx
, EXCP_RI
);
11671 offset
= extended
? offset
: offset
<< 3;
11672 gen_ld(ctx
, OPC_LDPC
, ry
, 0, offset
);
11676 check_insn(ctx
, ISA_MIPS3
);
11677 check_mips_64(ctx
);
11678 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
11679 gen_arith_imm(ctx
, OPC_DADDIU
, ry
, ry
, offset
);
11682 check_insn(ctx
, ISA_MIPS3
);
11683 check_mips_64(ctx
);
11684 offset
= extended
? offset
: offset
<< 2;
11685 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
11688 check_insn(ctx
, ISA_MIPS3
);
11689 check_mips_64(ctx
);
11690 offset
= extended
? offset
: offset
<< 2;
11691 gen_arith_imm(ctx
, OPC_DADDIU
, ry
, 29, offset
);
11697 static int decode_extended_mips16_opc (CPUMIPSState
*env
, DisasContext
*ctx
)
11699 int extend
= cpu_lduw_code(env
, ctx
->pc
+ 2);
11700 int op
, rx
, ry
, funct
, sa
;
11701 int16_t imm
, offset
;
11703 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
11704 op
= (ctx
->opcode
>> 11) & 0x1f;
11705 sa
= (ctx
->opcode
>> 22) & 0x1f;
11706 funct
= (ctx
->opcode
>> 8) & 0x7;
11707 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
11708 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
11709 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
11710 | ((ctx
->opcode
>> 21) & 0x3f) << 5
11711 | (ctx
->opcode
& 0x1f));
11713 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
11716 case M16_OPC_ADDIUSP
:
11717 gen_arith_imm(ctx
, OPC_ADDIU
, rx
, 29, imm
);
11719 case M16_OPC_ADDIUPC
:
11720 gen_addiupc(ctx
, rx
, imm
, 0, 1);
11723 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1, 0);
11724 /* No delay slot, so just process as a normal instruction */
11727 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1, 0);
11728 /* No delay slot, so just process as a normal instruction */
11730 case M16_OPC_BNEQZ
:
11731 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1, 0);
11732 /* No delay slot, so just process as a normal instruction */
11734 case M16_OPC_SHIFT
:
11735 switch (ctx
->opcode
& 0x3) {
11737 gen_shift_imm(ctx
, OPC_SLL
, rx
, ry
, sa
);
11740 #if defined(TARGET_MIPS64)
11741 check_mips_64(ctx
);
11742 gen_shift_imm(ctx
, OPC_DSLL
, rx
, ry
, sa
);
11744 generate_exception(ctx
, EXCP_RI
);
11748 gen_shift_imm(ctx
, OPC_SRL
, rx
, ry
, sa
);
11751 gen_shift_imm(ctx
, OPC_SRA
, rx
, ry
, sa
);
11755 #if defined(TARGET_MIPS64)
11757 check_insn(ctx
, ISA_MIPS3
);
11758 check_mips_64(ctx
);
11759 gen_ld(ctx
, OPC_LD
, ry
, rx
, offset
);
11763 imm
= ctx
->opcode
& 0xf;
11764 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
11765 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
11766 imm
= (int16_t) (imm
<< 1) >> 1;
11767 if ((ctx
->opcode
>> 4) & 0x1) {
11768 #if defined(TARGET_MIPS64)
11769 check_mips_64(ctx
);
11770 gen_arith_imm(ctx
, OPC_DADDIU
, ry
, rx
, imm
);
11772 generate_exception(ctx
, EXCP_RI
);
11775 gen_arith_imm(ctx
, OPC_ADDIU
, ry
, rx
, imm
);
11778 case M16_OPC_ADDIU8
:
11779 gen_arith_imm(ctx
, OPC_ADDIU
, rx
, rx
, imm
);
11782 gen_slt_imm(ctx
, OPC_SLTI
, 24, rx
, imm
);
11784 case M16_OPC_SLTIU
:
11785 gen_slt_imm(ctx
, OPC_SLTIU
, 24, rx
, imm
);
11790 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1, 0);
11793 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1, 0);
11796 gen_st(ctx
, OPC_SW
, 31, 29, imm
);
11799 gen_arith_imm(ctx
, OPC_ADDIU
, 29, 29, imm
);
11802 check_insn(ctx
, ISA_MIPS32
);
11804 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
11805 int aregs
= (ctx
->opcode
>> 16) & 0xf;
11806 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
11807 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
11808 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
11809 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
11810 | (ctx
->opcode
& 0xf)) << 3;
11812 if (ctx
->opcode
& (1 << 7)) {
11813 gen_mips16_save(ctx
, xsregs
, aregs
,
11814 do_ra
, do_s0
, do_s1
,
11817 gen_mips16_restore(ctx
, xsregs
, aregs
,
11818 do_ra
, do_s0
, do_s1
,
11824 generate_exception(ctx
, EXCP_RI
);
11829 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
11832 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
11834 #if defined(TARGET_MIPS64)
11836 check_insn(ctx
, ISA_MIPS3
);
11837 check_mips_64(ctx
);
11838 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
);
11842 gen_ld(ctx
, OPC_LB
, ry
, rx
, offset
);
11845 gen_ld(ctx
, OPC_LH
, ry
, rx
, offset
);
11848 gen_ld(ctx
, OPC_LW
, rx
, 29, offset
);
11851 gen_ld(ctx
, OPC_LW
, ry
, rx
, offset
);
11854 gen_ld(ctx
, OPC_LBU
, ry
, rx
, offset
);
11857 gen_ld(ctx
, OPC_LHU
, ry
, rx
, offset
);
11860 gen_ld(ctx
, OPC_LWPC
, rx
, 0, offset
);
11862 #if defined(TARGET_MIPS64)
11864 check_insn(ctx
, ISA_MIPS3
);
11865 check_mips_64(ctx
);
11866 gen_ld(ctx
, OPC_LWU
, ry
, rx
, offset
);
11870 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
11873 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
);
11876 gen_st(ctx
, OPC_SW
, rx
, 29, offset
);
11879 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
);
11881 #if defined(TARGET_MIPS64)
11883 decode_i64_mips16(ctx
, ry
, funct
, offset
, 1);
11887 generate_exception(ctx
, EXCP_RI
);
11894 static inline bool is_uhi(int sdbbp_code
)
11896 #ifdef CONFIG_USER_ONLY
11899 return semihosting_enabled() && sdbbp_code
== 1;
11903 static int decode_mips16_opc (CPUMIPSState
*env
, DisasContext
*ctx
)
11907 int op
, cnvt_op
, op1
, offset
;
11911 op
= (ctx
->opcode
>> 11) & 0x1f;
11912 sa
= (ctx
->opcode
>> 2) & 0x7;
11913 sa
= sa
== 0 ? 8 : sa
;
11914 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
11915 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
11916 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
11917 op1
= offset
= ctx
->opcode
& 0x1f;
11922 case M16_OPC_ADDIUSP
:
11924 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
11926 gen_arith_imm(ctx
, OPC_ADDIU
, rx
, 29, imm
);
11929 case M16_OPC_ADDIUPC
:
11930 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
11933 offset
= (ctx
->opcode
& 0x7ff) << 1;
11934 offset
= (int16_t)(offset
<< 4) >> 4;
11935 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
, 0);
11936 /* No delay slot, so just process as a normal instruction */
11939 offset
= cpu_lduw_code(env
, ctx
->pc
+ 2);
11940 offset
= (((ctx
->opcode
& 0x1f) << 21)
11941 | ((ctx
->opcode
>> 5) & 0x1f) << 16
11943 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALX
: OPC_JAL
;
11944 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
, 2);
11948 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0,
11949 ((int8_t)ctx
->opcode
) << 1, 0);
11950 /* No delay slot, so just process as a normal instruction */
11952 case M16_OPC_BNEQZ
:
11953 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0,
11954 ((int8_t)ctx
->opcode
) << 1, 0);
11955 /* No delay slot, so just process as a normal instruction */
11957 case M16_OPC_SHIFT
:
11958 switch (ctx
->opcode
& 0x3) {
11960 gen_shift_imm(ctx
, OPC_SLL
, rx
, ry
, sa
);
11963 #if defined(TARGET_MIPS64)
11964 check_insn(ctx
, ISA_MIPS3
);
11965 check_mips_64(ctx
);
11966 gen_shift_imm(ctx
, OPC_DSLL
, rx
, ry
, sa
);
11968 generate_exception(ctx
, EXCP_RI
);
11972 gen_shift_imm(ctx
, OPC_SRL
, rx
, ry
, sa
);
11975 gen_shift_imm(ctx
, OPC_SRA
, rx
, ry
, sa
);
11979 #if defined(TARGET_MIPS64)
11981 check_insn(ctx
, ISA_MIPS3
);
11982 check_mips_64(ctx
);
11983 gen_ld(ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
11988 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
11990 if ((ctx
->opcode
>> 4) & 1) {
11991 #if defined(TARGET_MIPS64)
11992 check_insn(ctx
, ISA_MIPS3
);
11993 check_mips_64(ctx
);
11994 gen_arith_imm(ctx
, OPC_DADDIU
, ry
, rx
, imm
);
11996 generate_exception(ctx
, EXCP_RI
);
11999 gen_arith_imm(ctx
, OPC_ADDIU
, ry
, rx
, imm
);
12003 case M16_OPC_ADDIU8
:
12005 int16_t imm
= (int8_t) ctx
->opcode
;
12007 gen_arith_imm(ctx
, OPC_ADDIU
, rx
, rx
, imm
);
12012 int16_t imm
= (uint8_t) ctx
->opcode
;
12013 gen_slt_imm(ctx
, OPC_SLTI
, 24, rx
, imm
);
12016 case M16_OPC_SLTIU
:
12018 int16_t imm
= (uint8_t) ctx
->opcode
;
12019 gen_slt_imm(ctx
, OPC_SLTIU
, 24, rx
, imm
);
12026 funct
= (ctx
->opcode
>> 8) & 0x7;
12029 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
12030 ((int8_t)ctx
->opcode
) << 1, 0);
12033 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
12034 ((int8_t)ctx
->opcode
) << 1, 0);
12037 gen_st(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
12040 gen_arith_imm(ctx
, OPC_ADDIU
, 29, 29,
12041 ((int8_t)ctx
->opcode
) << 3);
12044 check_insn(ctx
, ISA_MIPS32
);
12046 int do_ra
= ctx
->opcode
& (1 << 6);
12047 int do_s0
= ctx
->opcode
& (1 << 5);
12048 int do_s1
= ctx
->opcode
& (1 << 4);
12049 int framesize
= ctx
->opcode
& 0xf;
12051 if (framesize
== 0) {
12054 framesize
= framesize
<< 3;
12057 if (ctx
->opcode
& (1 << 7)) {
12058 gen_mips16_save(ctx
, 0, 0,
12059 do_ra
, do_s0
, do_s1
, framesize
);
12061 gen_mips16_restore(ctx
, 0, 0,
12062 do_ra
, do_s0
, do_s1
, framesize
);
12068 int rz
= xlat(ctx
->opcode
& 0x7);
12070 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
12071 ((ctx
->opcode
>> 5) & 0x7);
12072 gen_arith(ctx
, OPC_ADDU
, reg32
, rz
, 0);
12076 reg32
= ctx
->opcode
& 0x1f;
12077 gen_arith(ctx
, OPC_ADDU
, ry
, reg32
, 0);
12080 generate_exception(ctx
, EXCP_RI
);
12087 int16_t imm
= (uint8_t) ctx
->opcode
;
12089 gen_arith_imm(ctx
, OPC_ADDIU
, rx
, 0, imm
);
12094 int16_t imm
= (uint8_t) ctx
->opcode
;
12095 gen_logic_imm(ctx
, OPC_XORI
, 24, rx
, imm
);
12098 #if defined(TARGET_MIPS64)
12100 check_insn(ctx
, ISA_MIPS3
);
12101 check_mips_64(ctx
);
12102 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
12106 gen_ld(ctx
, OPC_LB
, ry
, rx
, offset
);
12109 gen_ld(ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
12112 gen_ld(ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
12115 gen_ld(ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
12118 gen_ld(ctx
, OPC_LBU
, ry
, rx
, offset
);
12121 gen_ld(ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
12124 gen_ld(ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
12126 #if defined (TARGET_MIPS64)
12128 check_insn(ctx
, ISA_MIPS3
);
12129 check_mips_64(ctx
);
12130 gen_ld(ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
12134 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
12137 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
12140 gen_st(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
12143 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
12147 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
12150 switch (ctx
->opcode
& 0x3) {
12152 mips32_op
= OPC_ADDU
;
12155 mips32_op
= OPC_SUBU
;
12157 #if defined(TARGET_MIPS64)
12159 mips32_op
= OPC_DADDU
;
12160 check_insn(ctx
, ISA_MIPS3
);
12161 check_mips_64(ctx
);
12164 mips32_op
= OPC_DSUBU
;
12165 check_insn(ctx
, ISA_MIPS3
);
12166 check_mips_64(ctx
);
12170 generate_exception(ctx
, EXCP_RI
);
12174 gen_arith(ctx
, mips32_op
, rz
, rx
, ry
);
12183 int nd
= (ctx
->opcode
>> 7) & 0x1;
12184 int link
= (ctx
->opcode
>> 6) & 0x1;
12185 int ra
= (ctx
->opcode
>> 5) & 0x1;
12188 check_insn(ctx
, ISA_MIPS32
);
12197 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0,
12202 if (is_uhi(extract32(ctx
->opcode
, 5, 6))) {
12203 gen_helper_do_semihosting(cpu_env
);
12205 /* XXX: not clear which exception should be raised
12206 * when in debug mode...
12208 check_insn(ctx
, ISA_MIPS32
);
12209 generate_exception(ctx
, EXCP_DBp
);
12213 gen_slt(ctx
, OPC_SLT
, 24, rx
, ry
);
12216 gen_slt(ctx
, OPC_SLTU
, 24, rx
, ry
);
12219 generate_exception(ctx
, EXCP_BREAK
);
12222 gen_shift(ctx
, OPC_SLLV
, ry
, rx
, ry
);
12225 gen_shift(ctx
, OPC_SRLV
, ry
, rx
, ry
);
12228 gen_shift(ctx
, OPC_SRAV
, ry
, rx
, ry
);
12230 #if defined (TARGET_MIPS64)
12232 check_insn(ctx
, ISA_MIPS3
);
12233 check_mips_64(ctx
);
12234 gen_shift_imm(ctx
, OPC_DSRL
, ry
, ry
, sa
);
12238 gen_logic(ctx
, OPC_XOR
, 24, rx
, ry
);
12241 gen_arith(ctx
, OPC_SUBU
, rx
, 0, ry
);
12244 gen_logic(ctx
, OPC_AND
, rx
, rx
, ry
);
12247 gen_logic(ctx
, OPC_OR
, rx
, rx
, ry
);
12250 gen_logic(ctx
, OPC_XOR
, rx
, rx
, ry
);
12253 gen_logic(ctx
, OPC_NOR
, rx
, ry
, 0);
12256 gen_HILO(ctx
, OPC_MFHI
, 0, rx
);
12259 check_insn(ctx
, ISA_MIPS32
);
12261 case RR_RY_CNVT_ZEB
:
12262 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
12264 case RR_RY_CNVT_ZEH
:
12265 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
12267 case RR_RY_CNVT_SEB
:
12268 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
12270 case RR_RY_CNVT_SEH
:
12271 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
12273 #if defined (TARGET_MIPS64)
12274 case RR_RY_CNVT_ZEW
:
12275 check_insn(ctx
, ISA_MIPS64
);
12276 check_mips_64(ctx
);
12277 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
12279 case RR_RY_CNVT_SEW
:
12280 check_insn(ctx
, ISA_MIPS64
);
12281 check_mips_64(ctx
);
12282 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
12286 generate_exception(ctx
, EXCP_RI
);
12291 gen_HILO(ctx
, OPC_MFLO
, 0, rx
);
12293 #if defined (TARGET_MIPS64)
12295 check_insn(ctx
, ISA_MIPS3
);
12296 check_mips_64(ctx
);
12297 gen_shift_imm(ctx
, OPC_DSRA
, ry
, ry
, sa
);
12300 check_insn(ctx
, ISA_MIPS3
);
12301 check_mips_64(ctx
);
12302 gen_shift(ctx
, OPC_DSLLV
, ry
, rx
, ry
);
12305 check_insn(ctx
, ISA_MIPS3
);
12306 check_mips_64(ctx
);
12307 gen_shift(ctx
, OPC_DSRLV
, ry
, rx
, ry
);
12310 check_insn(ctx
, ISA_MIPS3
);
12311 check_mips_64(ctx
);
12312 gen_shift(ctx
, OPC_DSRAV
, ry
, rx
, ry
);
12316 gen_muldiv(ctx
, OPC_MULT
, 0, rx
, ry
);
12319 gen_muldiv(ctx
, OPC_MULTU
, 0, rx
, ry
);
12322 gen_muldiv(ctx
, OPC_DIV
, 0, rx
, ry
);
12325 gen_muldiv(ctx
, OPC_DIVU
, 0, rx
, ry
);
12327 #if defined (TARGET_MIPS64)
12329 check_insn(ctx
, ISA_MIPS3
);
12330 check_mips_64(ctx
);
12331 gen_muldiv(ctx
, OPC_DMULT
, 0, rx
, ry
);
12334 check_insn(ctx
, ISA_MIPS3
);
12335 check_mips_64(ctx
);
12336 gen_muldiv(ctx
, OPC_DMULTU
, 0, rx
, ry
);
12339 check_insn(ctx
, ISA_MIPS3
);
12340 check_mips_64(ctx
);
12341 gen_muldiv(ctx
, OPC_DDIV
, 0, rx
, ry
);
12344 check_insn(ctx
, ISA_MIPS3
);
12345 check_mips_64(ctx
);
12346 gen_muldiv(ctx
, OPC_DDIVU
, 0, rx
, ry
);
12350 generate_exception(ctx
, EXCP_RI
);
12354 case M16_OPC_EXTEND
:
12355 decode_extended_mips16_opc(env
, ctx
);
12358 #if defined(TARGET_MIPS64)
12360 funct
= (ctx
->opcode
>> 8) & 0x7;
12361 decode_i64_mips16(ctx
, ry
, funct
, offset
, 0);
12365 generate_exception(ctx
, EXCP_RI
);
12372 /* microMIPS extension to MIPS32/MIPS64 */
12375 * microMIPS32/microMIPS64 major opcodes
12377 * 1. MIPS Architecture for Programmers Volume II-B:
12378 * The microMIPS32 Instruction Set (Revision 3.05)
12380 * Table 6.2 microMIPS32 Encoding of Major Opcode Field
12382 * 2. MIPS Architecture For Programmers Volume II-A:
12383 * The MIPS64 Instruction Set (Revision 3.51)
12413 POOL32S
= 0x16, /* MIPS64 */
12414 DADDIU32
= 0x17, /* MIPS64 */
12443 /* 0x29 is reserved */
12456 /* 0x31 is reserved */
12469 SD32
= 0x36, /* MIPS64 */
12470 LD32
= 0x37, /* MIPS64 */
12472 /* 0x39 is reserved */
12488 /* PCREL Instructions perform PC-Relative address calculation. bits 20..16 */
12498 /* POOL32A encoding of minor opcode field */
12501 /* These opcodes are distinguished only by bits 9..6; those bits are
12502 * what are recorded below. */
12538 /* The following can be distinguished by their lower 6 bits. */
12546 /* POOL32AXF encoding of minor opcode field extension */
12549 * 1. MIPS Architecture for Programmers Volume II-B:
12550 * The microMIPS32 Instruction Set (Revision 3.05)
12552 * Table 6.5 POOL32Axf Encoding of Minor Opcode Extension Field
12554 * 2. MIPS Architecture for Programmers VolumeIV-e:
12555 * The MIPS DSP Application-Specific Extension
12556 * to the microMIPS32 Architecture (Revision 2.34)
12558 * Table 5.5 POOL32Axf Encoding of Minor Opcode Extension Field
12573 /* begin of microMIPS32 DSP */
12575 /* bits 13..12 for 0x01 */
12581 /* bits 13..12 for 0x2a */
12587 /* bits 13..12 for 0x32 */
12591 /* end of microMIPS32 DSP */
12593 /* bits 15..12 for 0x2c */
12610 /* bits 15..12 for 0x34 */
12618 /* bits 15..12 for 0x3c */
12620 JR
= 0x0, /* alias */
12628 /* bits 15..12 for 0x05 */
12632 /* bits 15..12 for 0x0d */
12644 /* bits 15..12 for 0x15 */
12650 /* bits 15..12 for 0x1d */
12654 /* bits 15..12 for 0x2d */
12659 /* bits 15..12 for 0x35 */
12666 /* POOL32B encoding of minor opcode field (bits 15..12) */
12682 /* POOL32C encoding of minor opcode field (bits 15..12) */
12690 /* 0xa is reserved */
12697 /* 0x6 is reserved */
12703 /* POOL32F encoding of minor opcode field (bits 5..0) */
12706 /* These are the bit 7..6 values */
12715 /* These are the bit 8..6 values */
12740 MOVZ_FMT_05
= 0x05,
12774 CABS_COND_FMT
= 0x1c, /* MIPS3D */
12781 /* POOL32Fxf encoding of minor opcode extension field */
12819 /* POOL32I encoding of minor opcode field (bits 25..21) */
12849 /* These overlap and are distinguished by bit16 of the instruction */
12858 /* POOL16A encoding of minor opcode field */
12865 /* POOL16B encoding of minor opcode field */
12872 /* POOL16C encoding of minor opcode field */
12892 /* R6 POOL16C encoding of minor opcode field (bits 0..5) */
12912 /* POOL16D encoding of minor opcode field */
12919 /* POOL16E encoding of minor opcode field */
12926 static int mmreg (int r
)
12928 static const int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
12933 /* Used for 16-bit store instructions. */
12934 static int mmreg2 (int r
)
12936 static const int map
[] = { 0, 17, 2, 3, 4, 5, 6, 7 };
12941 #define uMIPS_RD(op) ((op >> 7) & 0x7)
12942 #define uMIPS_RS(op) ((op >> 4) & 0x7)
12943 #define uMIPS_RS2(op) uMIPS_RS(op)
12944 #define uMIPS_RS1(op) ((op >> 1) & 0x7)
12945 #define uMIPS_RD5(op) ((op >> 5) & 0x1f)
12946 #define uMIPS_RS5(op) (op & 0x1f)
12948 /* Signed immediate */
12949 #define SIMM(op, start, width) \
12950 ((int32_t)(((op >> start) & ((~0U) >> (32-width))) \
12953 /* Zero-extended immediate */
12954 #define ZIMM(op, start, width) ((op >> start) & ((~0U) >> (32-width)))
12956 static void gen_addiur1sp(DisasContext
*ctx
)
12958 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
12960 gen_arith_imm(ctx
, OPC_ADDIU
, rd
, 29, ((ctx
->opcode
>> 1) & 0x3f) << 2);
12963 static void gen_addiur2(DisasContext
*ctx
)
12965 static const int decoded_imm
[] = { 1, 4, 8, 12, 16, 20, 24, -1 };
12966 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
12967 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
12969 gen_arith_imm(ctx
, OPC_ADDIU
, rd
, rs
, decoded_imm
[ZIMM(ctx
->opcode
, 1, 3)]);
12972 static void gen_addiusp(DisasContext
*ctx
)
12974 int encoded
= ZIMM(ctx
->opcode
, 1, 9);
12977 if (encoded
<= 1) {
12978 decoded
= 256 + encoded
;
12979 } else if (encoded
<= 255) {
12981 } else if (encoded
<= 509) {
12982 decoded
= encoded
- 512;
12984 decoded
= encoded
- 768;
12987 gen_arith_imm(ctx
, OPC_ADDIU
, 29, 29, decoded
<< 2);
12990 static void gen_addius5(DisasContext
*ctx
)
12992 int imm
= SIMM(ctx
->opcode
, 1, 4);
12993 int rd
= (ctx
->opcode
>> 5) & 0x1f;
12995 gen_arith_imm(ctx
, OPC_ADDIU
, rd
, rd
, imm
);
12998 static void gen_andi16(DisasContext
*ctx
)
13000 static const int decoded_imm
[] = { 128, 1, 2, 3, 4, 7, 8, 15, 16,
13001 31, 32, 63, 64, 255, 32768, 65535 };
13002 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
13003 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
13004 int encoded
= ZIMM(ctx
->opcode
, 0, 4);
13006 gen_logic_imm(ctx
, OPC_ANDI
, rd
, rs
, decoded_imm
[encoded
]);
13009 static void gen_ldst_multiple (DisasContext
*ctx
, uint32_t opc
, int reglist
,
13010 int base
, int16_t offset
)
13012 const char *opn
= "ldst_multiple";
13016 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
13017 generate_exception(ctx
, EXCP_RI
);
13021 t0
= tcg_temp_new();
13023 gen_base_offset_addr(ctx
, t0
, base
, offset
);
13025 t1
= tcg_const_tl(reglist
);
13026 t2
= tcg_const_i32(ctx
->mem_idx
);
13028 save_cpu_state(ctx
, 1);
13031 gen_helper_lwm(cpu_env
, t0
, t1
, t2
);
13035 gen_helper_swm(cpu_env
, t0
, t1
, t2
);
13038 #ifdef TARGET_MIPS64
13040 gen_helper_ldm(cpu_env
, t0
, t1
, t2
);
13044 gen_helper_sdm(cpu_env
, t0
, t1
, t2
);
13050 MIPS_DEBUG("%s, %x, %d(%s)", opn
, reglist
, offset
, regnames
[base
]);
13053 tcg_temp_free_i32(t2
);
13057 static void gen_pool16c_insn(DisasContext
*ctx
)
13059 int rd
= mmreg((ctx
->opcode
>> 3) & 0x7);
13060 int rs
= mmreg(ctx
->opcode
& 0x7);
13062 switch (((ctx
->opcode
) >> 4) & 0x3f) {
13067 gen_logic(ctx
, OPC_NOR
, rd
, rs
, 0);
13073 gen_logic(ctx
, OPC_XOR
, rd
, rd
, rs
);
13079 gen_logic(ctx
, OPC_AND
, rd
, rd
, rs
);
13085 gen_logic(ctx
, OPC_OR
, rd
, rd
, rs
);
13092 static const int lwm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
13093 int offset
= ZIMM(ctx
->opcode
, 0, 4);
13095 gen_ldst_multiple(ctx
, LWM32
, lwm_convert
[(ctx
->opcode
>> 4) & 0x3],
13104 static const int swm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
13105 int offset
= ZIMM(ctx
->opcode
, 0, 4);
13107 gen_ldst_multiple(ctx
, SWM32
, swm_convert
[(ctx
->opcode
>> 4) & 0x3],
13114 int reg
= ctx
->opcode
& 0x1f;
13116 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0, 4);
13122 int reg
= ctx
->opcode
& 0x1f;
13123 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0, 0);
13124 /* Let normal delay slot handling in our caller take us
13125 to the branch target. */
13130 gen_compute_branch(ctx
, OPC_JALR
, 2, ctx
->opcode
& 0x1f, 31, 0, 4);
13131 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
13135 gen_compute_branch(ctx
, OPC_JALR
, 2, ctx
->opcode
& 0x1f, 31, 0, 2);
13136 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
13140 gen_HILO(ctx
, OPC_MFHI
, 0, uMIPS_RS5(ctx
->opcode
));
13144 gen_HILO(ctx
, OPC_MFLO
, 0, uMIPS_RS5(ctx
->opcode
));
13147 generate_exception(ctx
, EXCP_BREAK
);
13150 if (is_uhi(extract32(ctx
->opcode
, 0, 4))) {
13151 gen_helper_do_semihosting(cpu_env
);
13153 /* XXX: not clear which exception should be raised
13154 * when in debug mode...
13156 check_insn(ctx
, ISA_MIPS32
);
13157 generate_exception(ctx
, EXCP_DBp
);
13160 case JRADDIUSP
+ 0:
13161 case JRADDIUSP
+ 1:
13163 int imm
= ZIMM(ctx
->opcode
, 0, 5);
13164 gen_compute_branch(ctx
, OPC_JR
, 2, 31, 0, 0, 0);
13165 gen_arith_imm(ctx
, OPC_ADDIU
, 29, 29, imm
<< 2);
13166 /* Let normal delay slot handling in our caller take us
13167 to the branch target. */
13171 generate_exception(ctx
, EXCP_RI
);
13176 static inline void gen_movep(DisasContext
*ctx
, int enc_dest
, int enc_rt
,
13179 int rd
, rs
, re
, rt
;
13180 static const int rd_enc
[] = { 5, 5, 6, 4, 4, 4, 4, 4 };
13181 static const int re_enc
[] = { 6, 7, 7, 21, 22, 5, 6, 7 };
13182 static const int rs_rt_enc
[] = { 0, 17, 2, 3, 16, 18, 19, 20 };
13183 rd
= rd_enc
[enc_dest
];
13184 re
= re_enc
[enc_dest
];
13185 rs
= rs_rt_enc
[enc_rs
];
13186 rt
= rs_rt_enc
[enc_rt
];
13188 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
13190 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
13193 tcg_gen_mov_tl(cpu_gpr
[re
], cpu_gpr
[rt
]);
13195 tcg_gen_movi_tl(cpu_gpr
[re
], 0);
13199 static void gen_pool16c_r6_insn(DisasContext
*ctx
)
13201 int rt
= mmreg((ctx
->opcode
>> 7) & 0x7);
13202 int rs
= mmreg((ctx
->opcode
>> 4) & 0x7);
13204 switch (ctx
->opcode
& 0xf) {
13206 gen_logic(ctx
, OPC_NOR
, rt
, rs
, 0);
13209 gen_logic(ctx
, OPC_AND
, rt
, rt
, rs
);
13213 int lwm_converted
= 0x11 + extract32(ctx
->opcode
, 8, 2);
13214 int offset
= extract32(ctx
->opcode
, 4, 4);
13215 gen_ldst_multiple(ctx
, LWM32
, lwm_converted
, 29, offset
<< 2);
13218 case R6_JRC16
: /* JRCADDIUSP */
13219 if ((ctx
->opcode
>> 4) & 1) {
13221 int imm
= extract32(ctx
->opcode
, 5, 5);
13222 gen_compute_branch(ctx
, OPC_JR
, 2, 31, 0, 0, 0);
13223 gen_arith_imm(ctx
, OPC_ADDIU
, 29, 29, imm
<< 2);
13226 int rs
= extract32(ctx
->opcode
, 5, 5);
13227 gen_compute_branch(ctx
, OPC_JR
, 2, rs
, 0, 0, 0);
13230 case MOVEP
... MOVEP_07
:
13231 case MOVEP_0C
... MOVEP_0F
:
13233 int enc_dest
= uMIPS_RD(ctx
->opcode
);
13234 int enc_rt
= uMIPS_RS2(ctx
->opcode
);
13235 int enc_rs
= (ctx
->opcode
& 3) | ((ctx
->opcode
>> 1) & 4);
13236 gen_movep(ctx
, enc_dest
, enc_rt
, enc_rs
);
13240 gen_logic(ctx
, OPC_XOR
, rt
, rt
, rs
);
13243 gen_logic(ctx
, OPC_OR
, rt
, rt
, rs
);
13247 int swm_converted
= 0x11 + extract32(ctx
->opcode
, 8, 2);
13248 int offset
= extract32(ctx
->opcode
, 4, 4);
13249 gen_ldst_multiple(ctx
, SWM32
, swm_converted
, 29, offset
<< 2);
13252 case JALRC16
: /* BREAK16, SDBBP16 */
13253 switch (ctx
->opcode
& 0x3f) {
13255 case JALRC16
+ 0x20:
13257 gen_compute_branch(ctx
, OPC_JALR
, 2, (ctx
->opcode
>> 5) & 0x1f,
13262 generate_exception(ctx
, EXCP_BREAK
);
13266 if (ctx
->hflags
& MIPS_HFLAG_SBRI
) {
13267 generate_exception(ctx
, EXCP_RI
);
13269 generate_exception(ctx
, EXCP_DBp
);
13275 generate_exception(ctx
, EXCP_RI
);
13280 static void gen_ldxs (DisasContext
*ctx
, int base
, int index
, int rd
)
13282 TCGv t0
= tcg_temp_new();
13283 TCGv t1
= tcg_temp_new();
13285 gen_load_gpr(t0
, base
);
13288 gen_load_gpr(t1
, index
);
13289 tcg_gen_shli_tl(t1
, t1
, 2);
13290 gen_op_addr_add(ctx
, t0
, t1
, t0
);
13293 tcg_gen_qemu_ld_tl(t1
, t0
, ctx
->mem_idx
, MO_TESL
);
13294 gen_store_gpr(t1
, rd
);
13300 static void gen_ldst_pair (DisasContext
*ctx
, uint32_t opc
, int rd
,
13301 int base
, int16_t offset
)
13303 const char *opn
= "ldst_pair";
13306 if (ctx
->hflags
& MIPS_HFLAG_BMASK
|| rd
== 31) {
13307 generate_exception(ctx
, EXCP_RI
);
13311 t0
= tcg_temp_new();
13312 t1
= tcg_temp_new();
13314 gen_base_offset_addr(ctx
, t0
, base
, offset
);
13319 generate_exception(ctx
, EXCP_RI
);
13322 tcg_gen_qemu_ld_tl(t1
, t0
, ctx
->mem_idx
, MO_TESL
);
13323 gen_store_gpr(t1
, rd
);
13324 tcg_gen_movi_tl(t1
, 4);
13325 gen_op_addr_add(ctx
, t0
, t0
, t1
);
13326 tcg_gen_qemu_ld_tl(t1
, t0
, ctx
->mem_idx
, MO_TESL
);
13327 gen_store_gpr(t1
, rd
+1);
13331 gen_load_gpr(t1
, rd
);
13332 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEUL
);
13333 tcg_gen_movi_tl(t1
, 4);
13334 gen_op_addr_add(ctx
, t0
, t0
, t1
);
13335 gen_load_gpr(t1
, rd
+1);
13336 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEUL
);
13339 #ifdef TARGET_MIPS64
13342 generate_exception(ctx
, EXCP_RI
);
13345 tcg_gen_qemu_ld_tl(t1
, t0
, ctx
->mem_idx
, MO_TEQ
);
13346 gen_store_gpr(t1
, rd
);
13347 tcg_gen_movi_tl(t1
, 8);
13348 gen_op_addr_add(ctx
, t0
, t0
, t1
);
13349 tcg_gen_qemu_ld_tl(t1
, t0
, ctx
->mem_idx
, MO_TEQ
);
13350 gen_store_gpr(t1
, rd
+1);
13354 gen_load_gpr(t1
, rd
);
13355 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEQ
);
13356 tcg_gen_movi_tl(t1
, 8);
13357 gen_op_addr_add(ctx
, t0
, t0
, t1
);
13358 gen_load_gpr(t1
, rd
+1);
13359 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_TEQ
);
13364 (void)opn
; /* avoid a compiler warning */
13365 MIPS_DEBUG("%s, %s, %d(%s)", opn
, regnames
[rd
], offset
, regnames
[base
]);
13370 static void gen_pool32axf (CPUMIPSState
*env
, DisasContext
*ctx
, int rt
, int rs
)
13372 int extension
= (ctx
->opcode
>> 6) & 0x3f;
13373 int minor
= (ctx
->opcode
>> 12) & 0xf;
13374 uint32_t mips32_op
;
13376 switch (extension
) {
13378 mips32_op
= OPC_TEQ
;
13381 mips32_op
= OPC_TGE
;
13384 mips32_op
= OPC_TGEU
;
13387 mips32_op
= OPC_TLT
;
13390 mips32_op
= OPC_TLTU
;
13393 mips32_op
= OPC_TNE
;
13395 gen_trap(ctx
, mips32_op
, rs
, rt
, -1);
13397 #ifndef CONFIG_USER_ONLY
13400 check_cp0_enabled(ctx
);
13402 /* Treat as NOP. */
13405 gen_mfc0(ctx
, cpu_gpr
[rt
], rs
, (ctx
->opcode
>> 11) & 0x7);
13409 check_cp0_enabled(ctx
);
13411 TCGv t0
= tcg_temp_new();
13413 gen_load_gpr(t0
, rt
);
13414 gen_mtc0(ctx
, t0
, rs
, (ctx
->opcode
>> 11) & 0x7);
13420 switch (minor
& 3) {
13422 gen_muldiv(ctx
, OPC_MADD
, (ctx
->opcode
>> 14) & 3, rs
, rt
);
13425 gen_muldiv(ctx
, OPC_MADDU
, (ctx
->opcode
>> 14) & 3, rs
, rt
);
13428 gen_muldiv(ctx
, OPC_MSUB
, (ctx
->opcode
>> 14) & 3, rs
, rt
);
13431 gen_muldiv(ctx
, OPC_MSUBU
, (ctx
->opcode
>> 14) & 3, rs
, rt
);
13434 goto pool32axf_invalid
;
13438 switch (minor
& 3) {
13440 gen_muldiv(ctx
, OPC_MULT
, (ctx
->opcode
>> 14) & 3, rs
, rt
);
13443 gen_muldiv(ctx
, OPC_MULTU
, (ctx
->opcode
>> 14) & 3, rs
, rt
);
13446 goto pool32axf_invalid
;
13452 check_insn(ctx
, ISA_MIPS32R6
);
13453 gen_bitswap(ctx
, OPC_BITSWAP
, rs
, rt
);
13456 gen_bshfl(ctx
, OPC_SEB
, rs
, rt
);
13459 gen_bshfl(ctx
, OPC_SEH
, rs
, rt
);
13462 mips32_op
= OPC_CLO
;
13465 mips32_op
= OPC_CLZ
;
13467 check_insn(ctx
, ISA_MIPS32
);
13468 gen_cl(ctx
, mips32_op
, rt
, rs
);
13471 gen_rdhwr(ctx
, rt
, rs
);
13474 gen_bshfl(ctx
, OPC_WSBH
, rs
, rt
);
13477 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13478 mips32_op
= OPC_MULT
;
13481 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13482 mips32_op
= OPC_MULTU
;
13485 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13486 mips32_op
= OPC_DIV
;
13489 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13490 mips32_op
= OPC_DIVU
;
13493 check_insn(ctx
, ISA_MIPS32
);
13494 gen_muldiv(ctx
, mips32_op
, 0, rs
, rt
);
13497 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13498 mips32_op
= OPC_MADD
;
13501 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13502 mips32_op
= OPC_MADDU
;
13505 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13506 mips32_op
= OPC_MSUB
;
13509 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13510 mips32_op
= OPC_MSUBU
;
13512 check_insn(ctx
, ISA_MIPS32
);
13513 gen_muldiv(ctx
, mips32_op
, 0, rs
, rt
);
13516 goto pool32axf_invalid
;
13527 generate_exception_err(ctx
, EXCP_CpU
, 2);
13530 goto pool32axf_invalid
;
13535 case JALR
: /* JALRC */
13536 case JALR_HB
: /* JALRC_HB */
13537 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
13538 /* JALRC, JALRC_HB */
13539 gen_compute_branch(ctx
, OPC_JALR
, 4, rs
, rt
, 0, 0);
13541 /* JALR, JALR_HB */
13542 gen_compute_branch(ctx
, OPC_JALR
, 4, rs
, rt
, 0, 4);
13543 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
13548 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13549 gen_compute_branch(ctx
, OPC_JALR
, 4, rs
, rt
, 0, 2);
13550 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
13553 goto pool32axf_invalid
;
13559 check_cp0_enabled(ctx
);
13560 check_insn(ctx
, ISA_MIPS32R2
);
13561 gen_load_srsgpr(rs
, rt
);
13564 check_cp0_enabled(ctx
);
13565 check_insn(ctx
, ISA_MIPS32R2
);
13566 gen_store_srsgpr(rs
, rt
);
13569 goto pool32axf_invalid
;
13572 #ifndef CONFIG_USER_ONLY
13576 mips32_op
= OPC_TLBP
;
13579 mips32_op
= OPC_TLBR
;
13582 mips32_op
= OPC_TLBWI
;
13585 mips32_op
= OPC_TLBWR
;
13588 mips32_op
= OPC_TLBINV
;
13591 mips32_op
= OPC_TLBINVF
;
13594 mips32_op
= OPC_WAIT
;
13597 mips32_op
= OPC_DERET
;
13600 mips32_op
= OPC_ERET
;
13602 gen_cp0(env
, ctx
, mips32_op
, rt
, rs
);
13605 goto pool32axf_invalid
;
13611 check_cp0_enabled(ctx
);
13613 TCGv t0
= tcg_temp_new();
13615 save_cpu_state(ctx
, 1);
13616 gen_helper_di(t0
, cpu_env
);
13617 gen_store_gpr(t0
, rs
);
13618 /* Stop translation as we may have switched the execution mode */
13619 ctx
->bstate
= BS_STOP
;
13624 check_cp0_enabled(ctx
);
13626 TCGv t0
= tcg_temp_new();
13628 save_cpu_state(ctx
, 1);
13629 gen_helper_ei(t0
, cpu_env
);
13630 gen_store_gpr(t0
, rs
);
13631 /* Stop translation as we may have switched the execution mode */
13632 ctx
->bstate
= BS_STOP
;
13637 goto pool32axf_invalid
;
13647 generate_exception(ctx
, EXCP_SYSCALL
);
13648 ctx
->bstate
= BS_STOP
;
13651 if (is_uhi(extract32(ctx
->opcode
, 16, 10))) {
13652 gen_helper_do_semihosting(cpu_env
);
13654 check_insn(ctx
, ISA_MIPS32
);
13655 if (ctx
->hflags
& MIPS_HFLAG_SBRI
) {
13656 generate_exception(ctx
, EXCP_RI
);
13658 generate_exception(ctx
, EXCP_DBp
);
13663 goto pool32axf_invalid
;
13667 switch (minor
& 3) {
13669 gen_HILO(ctx
, OPC_MFHI
, minor
>> 2, rs
);
13672 gen_HILO(ctx
, OPC_MFLO
, minor
>> 2, rs
);
13675 gen_HILO(ctx
, OPC_MTHI
, minor
>> 2, rs
);
13678 gen_HILO(ctx
, OPC_MTLO
, minor
>> 2, rs
);
13681 goto pool32axf_invalid
;
13685 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13688 gen_HILO(ctx
, OPC_MFHI
, 0, rs
);
13691 gen_HILO(ctx
, OPC_MFLO
, 0, rs
);
13694 gen_HILO(ctx
, OPC_MTHI
, 0, rs
);
13697 gen_HILO(ctx
, OPC_MTLO
, 0, rs
);
13700 goto pool32axf_invalid
;
13705 MIPS_INVAL("pool32axf");
13706 generate_exception(ctx
, EXCP_RI
);
13711 /* Values for microMIPS fmt field. Variable-width, depending on which
13712 formats the instruction supports. */
13731 static void gen_pool32fxf(DisasContext
*ctx
, int rt
, int rs
)
13733 int extension
= (ctx
->opcode
>> 6) & 0x3ff;
13734 uint32_t mips32_op
;
13736 #define FLOAT_1BIT_FMT(opc, fmt) (fmt << 8) | opc
13737 #define FLOAT_2BIT_FMT(opc, fmt) (fmt << 7) | opc
13738 #define COND_FLOAT_MOV(opc, cond) (cond << 7) | opc
13740 switch (extension
) {
13741 case FLOAT_1BIT_FMT(CFC1
, 0):
13742 mips32_op
= OPC_CFC1
;
13744 case FLOAT_1BIT_FMT(CTC1
, 0):
13745 mips32_op
= OPC_CTC1
;
13747 case FLOAT_1BIT_FMT(MFC1
, 0):
13748 mips32_op
= OPC_MFC1
;
13750 case FLOAT_1BIT_FMT(MTC1
, 0):
13751 mips32_op
= OPC_MTC1
;
13753 case FLOAT_1BIT_FMT(MFHC1
, 0):
13754 mips32_op
= OPC_MFHC1
;
13756 case FLOAT_1BIT_FMT(MTHC1
, 0):
13757 mips32_op
= OPC_MTHC1
;
13759 gen_cp1(ctx
, mips32_op
, rt
, rs
);
13762 /* Reciprocal square root */
13763 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_S
):
13764 mips32_op
= OPC_RSQRT_S
;
13766 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_D
):
13767 mips32_op
= OPC_RSQRT_D
;
13771 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_S
):
13772 mips32_op
= OPC_SQRT_S
;
13774 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_D
):
13775 mips32_op
= OPC_SQRT_D
;
13779 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_S
):
13780 mips32_op
= OPC_RECIP_S
;
13782 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_D
):
13783 mips32_op
= OPC_RECIP_D
;
13787 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_S
):
13788 mips32_op
= OPC_FLOOR_L_S
;
13790 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_D
):
13791 mips32_op
= OPC_FLOOR_L_D
;
13793 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_S
):
13794 mips32_op
= OPC_FLOOR_W_S
;
13796 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_D
):
13797 mips32_op
= OPC_FLOOR_W_D
;
13801 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_S
):
13802 mips32_op
= OPC_CEIL_L_S
;
13804 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_D
):
13805 mips32_op
= OPC_CEIL_L_D
;
13807 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_S
):
13808 mips32_op
= OPC_CEIL_W_S
;
13810 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_D
):
13811 mips32_op
= OPC_CEIL_W_D
;
13815 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_S
):
13816 mips32_op
= OPC_TRUNC_L_S
;
13818 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_D
):
13819 mips32_op
= OPC_TRUNC_L_D
;
13821 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_S
):
13822 mips32_op
= OPC_TRUNC_W_S
;
13824 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_D
):
13825 mips32_op
= OPC_TRUNC_W_D
;
13829 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_S
):
13830 mips32_op
= OPC_ROUND_L_S
;
13832 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_D
):
13833 mips32_op
= OPC_ROUND_L_D
;
13835 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_S
):
13836 mips32_op
= OPC_ROUND_W_S
;
13838 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_D
):
13839 mips32_op
= OPC_ROUND_W_D
;
13842 /* Integer to floating-point conversion */
13843 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_S
):
13844 mips32_op
= OPC_CVT_L_S
;
13846 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_D
):
13847 mips32_op
= OPC_CVT_L_D
;
13849 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_S
):
13850 mips32_op
= OPC_CVT_W_S
;
13852 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_D
):
13853 mips32_op
= OPC_CVT_W_D
;
13856 /* Paired-foo conversions */
13857 case FLOAT_1BIT_FMT(CVT_S_PL
, 0):
13858 mips32_op
= OPC_CVT_S_PL
;
13860 case FLOAT_1BIT_FMT(CVT_S_PU
, 0):
13861 mips32_op
= OPC_CVT_S_PU
;
13863 case FLOAT_1BIT_FMT(CVT_PW_PS
, 0):
13864 mips32_op
= OPC_CVT_PW_PS
;
13866 case FLOAT_1BIT_FMT(CVT_PS_PW
, 0):
13867 mips32_op
= OPC_CVT_PS_PW
;
13870 /* Floating-point moves */
13871 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_S
):
13872 mips32_op
= OPC_MOV_S
;
13874 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_D
):
13875 mips32_op
= OPC_MOV_D
;
13877 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_PS
):
13878 mips32_op
= OPC_MOV_PS
;
13881 /* Absolute value */
13882 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_S
):
13883 mips32_op
= OPC_ABS_S
;
13885 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_D
):
13886 mips32_op
= OPC_ABS_D
;
13888 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_PS
):
13889 mips32_op
= OPC_ABS_PS
;
13893 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_S
):
13894 mips32_op
= OPC_NEG_S
;
13896 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_D
):
13897 mips32_op
= OPC_NEG_D
;
13899 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_PS
):
13900 mips32_op
= OPC_NEG_PS
;
13903 /* Reciprocal square root step */
13904 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_S
):
13905 mips32_op
= OPC_RSQRT1_S
;
13907 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_D
):
13908 mips32_op
= OPC_RSQRT1_D
;
13910 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_PS
):
13911 mips32_op
= OPC_RSQRT1_PS
;
13914 /* Reciprocal step */
13915 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_S
):
13916 mips32_op
= OPC_RECIP1_S
;
13918 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_D
):
13919 mips32_op
= OPC_RECIP1_S
;
13921 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_PS
):
13922 mips32_op
= OPC_RECIP1_PS
;
13925 /* Conversions from double */
13926 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_S
):
13927 mips32_op
= OPC_CVT_D_S
;
13929 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_W
):
13930 mips32_op
= OPC_CVT_D_W
;
13932 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_L
):
13933 mips32_op
= OPC_CVT_D_L
;
13936 /* Conversions from single */
13937 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_D
):
13938 mips32_op
= OPC_CVT_S_D
;
13940 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_W
):
13941 mips32_op
= OPC_CVT_S_W
;
13943 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_L
):
13944 mips32_op
= OPC_CVT_S_L
;
13946 gen_farith(ctx
, mips32_op
, -1, rs
, rt
, 0);
13949 /* Conditional moves on floating-point codes */
13950 case COND_FLOAT_MOV(MOVT
, 0):
13951 case COND_FLOAT_MOV(MOVT
, 1):
13952 case COND_FLOAT_MOV(MOVT
, 2):
13953 case COND_FLOAT_MOV(MOVT
, 3):
13954 case COND_FLOAT_MOV(MOVT
, 4):
13955 case COND_FLOAT_MOV(MOVT
, 5):
13956 case COND_FLOAT_MOV(MOVT
, 6):
13957 case COND_FLOAT_MOV(MOVT
, 7):
13958 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13959 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 1);
13961 case COND_FLOAT_MOV(MOVF
, 0):
13962 case COND_FLOAT_MOV(MOVF
, 1):
13963 case COND_FLOAT_MOV(MOVF
, 2):
13964 case COND_FLOAT_MOV(MOVF
, 3):
13965 case COND_FLOAT_MOV(MOVF
, 4):
13966 case COND_FLOAT_MOV(MOVF
, 5):
13967 case COND_FLOAT_MOV(MOVF
, 6):
13968 case COND_FLOAT_MOV(MOVF
, 7):
13969 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
13970 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 0);
13973 MIPS_INVAL("pool32fxf");
13974 generate_exception(ctx
, EXCP_RI
);
13979 static void decode_micromips32_opc(CPUMIPSState
*env
, DisasContext
*ctx
)
13983 int rt
, rs
, rd
, rr
;
13985 uint32_t op
, minor
, mips32_op
;
13986 uint32_t cond
, fmt
, cc
;
13988 insn
= cpu_lduw_code(env
, ctx
->pc
+ 2);
13989 ctx
->opcode
= (ctx
->opcode
<< 16) | insn
;
13991 rt
= (ctx
->opcode
>> 21) & 0x1f;
13992 rs
= (ctx
->opcode
>> 16) & 0x1f;
13993 rd
= (ctx
->opcode
>> 11) & 0x1f;
13994 rr
= (ctx
->opcode
>> 6) & 0x1f;
13995 imm
= (int16_t) ctx
->opcode
;
13997 op
= (ctx
->opcode
>> 26) & 0x3f;
14000 minor
= ctx
->opcode
& 0x3f;
14003 minor
= (ctx
->opcode
>> 6) & 0xf;
14006 mips32_op
= OPC_SLL
;
14009 mips32_op
= OPC_SRA
;
14012 mips32_op
= OPC_SRL
;
14015 mips32_op
= OPC_ROTR
;
14017 gen_shift_imm(ctx
, mips32_op
, rt
, rs
, rd
);
14020 check_insn(ctx
, ISA_MIPS32R6
);
14021 gen_cond_move(ctx
, OPC_SELEQZ
, rd
, rs
, rt
);
14024 check_insn(ctx
, ISA_MIPS32R6
);
14025 gen_cond_move(ctx
, OPC_SELNEZ
, rd
, rs
, rt
);
14028 goto pool32a_invalid
;
14032 minor
= (ctx
->opcode
>> 6) & 0xf;
14036 mips32_op
= OPC_ADD
;
14039 mips32_op
= OPC_ADDU
;
14042 mips32_op
= OPC_SUB
;
14045 mips32_op
= OPC_SUBU
;
14048 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14049 mips32_op
= OPC_MUL
;
14051 gen_arith(ctx
, mips32_op
, rd
, rs
, rt
);
14055 mips32_op
= OPC_SLLV
;
14058 mips32_op
= OPC_SRLV
;
14061 mips32_op
= OPC_SRAV
;
14064 mips32_op
= OPC_ROTRV
;
14066 gen_shift(ctx
, mips32_op
, rd
, rs
, rt
);
14068 /* Logical operations */
14070 mips32_op
= OPC_AND
;
14073 mips32_op
= OPC_OR
;
14076 mips32_op
= OPC_NOR
;
14079 mips32_op
= OPC_XOR
;
14081 gen_logic(ctx
, mips32_op
, rd
, rs
, rt
);
14083 /* Set less than */
14085 mips32_op
= OPC_SLT
;
14088 mips32_op
= OPC_SLTU
;
14090 gen_slt(ctx
, mips32_op
, rd
, rs
, rt
);
14093 goto pool32a_invalid
;
14097 minor
= (ctx
->opcode
>> 6) & 0xf;
14099 /* Conditional moves */
14100 case MOVN
: /* MUL */
14101 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14103 gen_r6_muldiv(ctx
, R6_OPC_MUL
, rd
, rs
, rt
);
14106 gen_cond_move(ctx
, OPC_MOVN
, rd
, rs
, rt
);
14109 case MOVZ
: /* MUH */
14110 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14112 gen_r6_muldiv(ctx
, R6_OPC_MUH
, rd
, rs
, rt
);
14115 gen_cond_move(ctx
, OPC_MOVZ
, rd
, rs
, rt
);
14119 check_insn(ctx
, ISA_MIPS32R6
);
14120 gen_r6_muldiv(ctx
, R6_OPC_MULU
, rd
, rs
, rt
);
14123 check_insn(ctx
, ISA_MIPS32R6
);
14124 gen_r6_muldiv(ctx
, R6_OPC_MUHU
, rd
, rs
, rt
);
14126 case LWXS
: /* DIV */
14127 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14129 gen_r6_muldiv(ctx
, R6_OPC_DIV
, rd
, rs
, rt
);
14132 gen_ldxs(ctx
, rs
, rt
, rd
);
14136 check_insn(ctx
, ISA_MIPS32R6
);
14137 gen_r6_muldiv(ctx
, R6_OPC_MOD
, rd
, rs
, rt
);
14140 check_insn(ctx
, ISA_MIPS32R6
);
14141 gen_r6_muldiv(ctx
, R6_OPC_DIVU
, rd
, rs
, rt
);
14144 check_insn(ctx
, ISA_MIPS32R6
);
14145 gen_r6_muldiv(ctx
, R6_OPC_MODU
, rd
, rs
, rt
);
14148 goto pool32a_invalid
;
14152 gen_bitops(ctx
, OPC_INS
, rt
, rs
, rr
, rd
);
14155 check_insn(ctx
, ISA_MIPS32R6
);
14156 gen_lsa(ctx
, OPC_LSA
, rd
, rs
, rt
,
14157 extract32(ctx
->opcode
, 9, 2));
14160 check_insn(ctx
, ISA_MIPS32R6
);
14161 gen_align(ctx
, OPC_ALIGN
, rd
, rs
, rt
,
14162 extract32(ctx
->opcode
, 9, 2));
14165 gen_bitops(ctx
, OPC_EXT
, rt
, rs
, rr
, rd
);
14168 gen_pool32axf(env
, ctx
, rt
, rs
);
14171 generate_exception(ctx
, EXCP_BREAK
);
14175 MIPS_INVAL("pool32a");
14176 generate_exception(ctx
, EXCP_RI
);
14181 minor
= (ctx
->opcode
>> 12) & 0xf;
14184 check_cp0_enabled(ctx
);
14185 /* Treat as no-op. */
14189 /* COP2: Not implemented. */
14190 generate_exception_err(ctx
, EXCP_CpU
, 2);
14192 #ifdef TARGET_MIPS64
14195 check_insn(ctx
, ISA_MIPS3
);
14196 check_mips_64(ctx
);
14201 gen_ldst_pair(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
14203 #ifdef TARGET_MIPS64
14206 check_insn(ctx
, ISA_MIPS3
);
14207 check_mips_64(ctx
);
14212 gen_ldst_multiple(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
14215 MIPS_INVAL("pool32b");
14216 generate_exception(ctx
, EXCP_RI
);
14221 if (ctx
->CP0_Config1
& (1 << CP0C1_FP
)) {
14222 minor
= ctx
->opcode
& 0x3f;
14223 check_cp1_enabled(ctx
);
14226 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14227 mips32_op
= OPC_ALNV_PS
;
14230 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14231 mips32_op
= OPC_MADD_S
;
14234 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14235 mips32_op
= OPC_MADD_D
;
14238 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14239 mips32_op
= OPC_MADD_PS
;
14242 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14243 mips32_op
= OPC_MSUB_S
;
14246 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14247 mips32_op
= OPC_MSUB_D
;
14250 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14251 mips32_op
= OPC_MSUB_PS
;
14254 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14255 mips32_op
= OPC_NMADD_S
;
14258 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14259 mips32_op
= OPC_NMADD_D
;
14262 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14263 mips32_op
= OPC_NMADD_PS
;
14266 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14267 mips32_op
= OPC_NMSUB_S
;
14270 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14271 mips32_op
= OPC_NMSUB_D
;
14274 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14275 mips32_op
= OPC_NMSUB_PS
;
14277 gen_flt3_arith(ctx
, mips32_op
, rd
, rr
, rs
, rt
);
14279 case CABS_COND_FMT
:
14280 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14281 cond
= (ctx
->opcode
>> 6) & 0xf;
14282 cc
= (ctx
->opcode
>> 13) & 0x7;
14283 fmt
= (ctx
->opcode
>> 10) & 0x3;
14286 gen_cmpabs_s(ctx
, cond
, rt
, rs
, cc
);
14289 gen_cmpabs_d(ctx
, cond
, rt
, rs
, cc
);
14292 gen_cmpabs_ps(ctx
, cond
, rt
, rs
, cc
);
14295 goto pool32f_invalid
;
14299 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14300 cond
= (ctx
->opcode
>> 6) & 0xf;
14301 cc
= (ctx
->opcode
>> 13) & 0x7;
14302 fmt
= (ctx
->opcode
>> 10) & 0x3;
14305 gen_cmp_s(ctx
, cond
, rt
, rs
, cc
);
14308 gen_cmp_d(ctx
, cond
, rt
, rs
, cc
);
14311 gen_cmp_ps(ctx
, cond
, rt
, rs
, cc
);
14314 goto pool32f_invalid
;
14318 check_insn(ctx
, ISA_MIPS32R6
);
14319 gen_r6_cmp_s(ctx
, (ctx
->opcode
>> 6) & 0x1f, rt
, rs
, rd
);
14322 check_insn(ctx
, ISA_MIPS32R6
);
14323 gen_r6_cmp_d(ctx
, (ctx
->opcode
>> 6) & 0x1f, rt
, rs
, rd
);
14326 gen_pool32fxf(ctx
, rt
, rs
);
14330 switch ((ctx
->opcode
>> 6) & 0x7) {
14332 mips32_op
= OPC_PLL_PS
;
14335 mips32_op
= OPC_PLU_PS
;
14338 mips32_op
= OPC_PUL_PS
;
14341 mips32_op
= OPC_PUU_PS
;
14344 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14345 mips32_op
= OPC_CVT_PS_S
;
14347 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
14350 goto pool32f_invalid
;
14354 check_insn(ctx
, ISA_MIPS32R6
);
14355 switch ((ctx
->opcode
>> 9) & 0x3) {
14357 gen_farith(ctx
, OPC_MIN_S
, rt
, rs
, rd
, 0);
14360 gen_farith(ctx
, OPC_MIN_D
, rt
, rs
, rd
, 0);
14363 goto pool32f_invalid
;
14368 switch ((ctx
->opcode
>> 6) & 0x7) {
14370 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14371 mips32_op
= OPC_LWXC1
;
14374 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14375 mips32_op
= OPC_SWXC1
;
14378 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14379 mips32_op
= OPC_LDXC1
;
14382 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14383 mips32_op
= OPC_SDXC1
;
14386 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14387 mips32_op
= OPC_LUXC1
;
14390 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14391 mips32_op
= OPC_SUXC1
;
14393 gen_flt3_ldst(ctx
, mips32_op
, rd
, rd
, rt
, rs
);
14396 goto pool32f_invalid
;
14400 check_insn(ctx
, ISA_MIPS32R6
);
14401 switch ((ctx
->opcode
>> 9) & 0x3) {
14403 gen_farith(ctx
, OPC_MAX_S
, rt
, rs
, rd
, 0);
14406 gen_farith(ctx
, OPC_MAX_D
, rt
, rs
, rd
, 0);
14409 goto pool32f_invalid
;
14414 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14415 fmt
= (ctx
->opcode
>> 9) & 0x3;
14416 switch ((ctx
->opcode
>> 6) & 0x7) {
14420 mips32_op
= OPC_RSQRT2_S
;
14423 mips32_op
= OPC_RSQRT2_D
;
14426 mips32_op
= OPC_RSQRT2_PS
;
14429 goto pool32f_invalid
;
14435 mips32_op
= OPC_RECIP2_S
;
14438 mips32_op
= OPC_RECIP2_D
;
14441 mips32_op
= OPC_RECIP2_PS
;
14444 goto pool32f_invalid
;
14448 mips32_op
= OPC_ADDR_PS
;
14451 mips32_op
= OPC_MULR_PS
;
14453 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
14456 goto pool32f_invalid
;
14460 /* MOV[FT].fmt, PREFX, RINT.fmt, CLASS.fmt*/
14461 cc
= (ctx
->opcode
>> 13) & 0x7;
14462 fmt
= (ctx
->opcode
>> 9) & 0x3;
14463 switch ((ctx
->opcode
>> 6) & 0x7) {
14464 case MOVF_FMT
: /* RINT_FMT */
14465 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14469 gen_farith(ctx
, OPC_RINT_S
, 0, rt
, rs
, 0);
14472 gen_farith(ctx
, OPC_RINT_D
, 0, rt
, rs
, 0);
14475 goto pool32f_invalid
;
14481 gen_movcf_s(ctx
, rs
, rt
, cc
, 0);
14484 gen_movcf_d(ctx
, rs
, rt
, cc
, 0);
14488 gen_movcf_ps(ctx
, rs
, rt
, cc
, 0);
14491 goto pool32f_invalid
;
14495 case MOVT_FMT
: /* CLASS_FMT */
14496 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14500 gen_farith(ctx
, OPC_CLASS_S
, 0, rt
, rs
, 0);
14503 gen_farith(ctx
, OPC_CLASS_D
, 0, rt
, rs
, 0);
14506 goto pool32f_invalid
;
14512 gen_movcf_s(ctx
, rs
, rt
, cc
, 1);
14515 gen_movcf_d(ctx
, rs
, rt
, cc
, 1);
14519 gen_movcf_ps(ctx
, rs
, rt
, cc
, 1);
14522 goto pool32f_invalid
;
14527 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14530 goto pool32f_invalid
;
14533 #define FINSN_3ARG_SDPS(prfx) \
14534 switch ((ctx->opcode >> 8) & 0x3) { \
14536 mips32_op = OPC_##prfx##_S; \
14539 mips32_op = OPC_##prfx##_D; \
14541 case FMT_SDPS_PS: \
14543 mips32_op = OPC_##prfx##_PS; \
14546 goto pool32f_invalid; \
14549 check_insn(ctx
, ISA_MIPS32R6
);
14550 switch ((ctx
->opcode
>> 9) & 0x3) {
14552 gen_farith(ctx
, OPC_MINA_S
, rt
, rs
, rd
, 0);
14555 gen_farith(ctx
, OPC_MINA_D
, rt
, rs
, rd
, 0);
14558 goto pool32f_invalid
;
14562 check_insn(ctx
, ISA_MIPS32R6
);
14563 switch ((ctx
->opcode
>> 9) & 0x3) {
14565 gen_farith(ctx
, OPC_MAXA_S
, rt
, rs
, rd
, 0);
14568 gen_farith(ctx
, OPC_MAXA_D
, rt
, rs
, rd
, 0);
14571 goto pool32f_invalid
;
14575 /* regular FP ops */
14576 switch ((ctx
->opcode
>> 6) & 0x3) {
14578 FINSN_3ARG_SDPS(ADD
);
14581 FINSN_3ARG_SDPS(SUB
);
14584 FINSN_3ARG_SDPS(MUL
);
14587 fmt
= (ctx
->opcode
>> 8) & 0x3;
14589 mips32_op
= OPC_DIV_D
;
14590 } else if (fmt
== 0) {
14591 mips32_op
= OPC_DIV_S
;
14593 goto pool32f_invalid
;
14597 goto pool32f_invalid
;
14602 switch ((ctx
->opcode
>> 6) & 0x7) {
14603 case MOVN_FMT
: /* SELNEZ_FMT */
14604 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14606 switch ((ctx
->opcode
>> 9) & 0x3) {
14608 gen_sel_s(ctx
, OPC_SELNEZ_S
, rd
, rt
, rs
);
14611 gen_sel_d(ctx
, OPC_SELNEZ_D
, rd
, rt
, rs
);
14614 goto pool32f_invalid
;
14618 FINSN_3ARG_SDPS(MOVN
);
14622 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14623 FINSN_3ARG_SDPS(MOVN
);
14625 case MOVZ_FMT
: /* SELEQZ_FMT */
14626 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14628 switch ((ctx
->opcode
>> 9) & 0x3) {
14630 gen_sel_s(ctx
, OPC_SELEQZ_S
, rd
, rt
, rs
);
14633 gen_sel_d(ctx
, OPC_SELEQZ_D
, rd
, rt
, rs
);
14636 goto pool32f_invalid
;
14640 FINSN_3ARG_SDPS(MOVZ
);
14644 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14645 FINSN_3ARG_SDPS(MOVZ
);
14648 check_insn(ctx
, ISA_MIPS32R6
);
14649 switch ((ctx
->opcode
>> 9) & 0x3) {
14651 gen_sel_s(ctx
, OPC_SEL_S
, rd
, rt
, rs
);
14654 gen_sel_d(ctx
, OPC_SEL_D
, rd
, rt
, rs
);
14657 goto pool32f_invalid
;
14661 check_insn(ctx
, ISA_MIPS32R6
);
14662 switch ((ctx
->opcode
>> 9) & 0x3) {
14664 mips32_op
= OPC_MADDF_S
;
14667 mips32_op
= OPC_MADDF_D
;
14670 goto pool32f_invalid
;
14674 check_insn(ctx
, ISA_MIPS32R6
);
14675 switch ((ctx
->opcode
>> 9) & 0x3) {
14677 mips32_op
= OPC_MSUBF_S
;
14680 mips32_op
= OPC_MSUBF_D
;
14683 goto pool32f_invalid
;
14687 goto pool32f_invalid
;
14691 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
14695 MIPS_INVAL("pool32f");
14696 generate_exception(ctx
, EXCP_RI
);
14700 generate_exception_err(ctx
, EXCP_CpU
, 1);
14704 minor
= (ctx
->opcode
>> 21) & 0x1f;
14707 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14708 gen_compute_branch(ctx
, OPC_BLTZ
, 4, rs
, -1, imm
<< 1, 4);
14711 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14712 gen_compute_branch(ctx
, OPC_BLTZAL
, 4, rs
, -1, imm
<< 1, 4);
14713 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
14716 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14717 gen_compute_branch(ctx
, OPC_BLTZAL
, 4, rs
, -1, imm
<< 1, 2);
14718 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
14721 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14722 gen_compute_branch(ctx
, OPC_BGEZ
, 4, rs
, -1, imm
<< 1, 4);
14725 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14726 gen_compute_branch(ctx
, OPC_BGEZAL
, 4, rs
, -1, imm
<< 1, 4);
14727 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
14730 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14731 gen_compute_branch(ctx
, OPC_BGEZAL
, 4, rs
, -1, imm
<< 1, 2);
14732 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
14735 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14736 gen_compute_branch(ctx
, OPC_BLEZ
, 4, rs
, -1, imm
<< 1, 4);
14739 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14740 gen_compute_branch(ctx
, OPC_BGTZ
, 4, rs
, -1, imm
<< 1, 4);
14744 case TLTI
: /* BC1EQZC */
14745 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14747 check_cp1_enabled(ctx
);
14748 gen_compute_branch1_r6(ctx
, OPC_BC1EQZ
, rs
, imm
<< 1, 0);
14751 mips32_op
= OPC_TLTI
;
14755 case TGEI
: /* BC1NEZC */
14756 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14758 check_cp1_enabled(ctx
);
14759 gen_compute_branch1_r6(ctx
, OPC_BC1NEZ
, rs
, imm
<< 1, 0);
14762 mips32_op
= OPC_TGEI
;
14767 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14768 mips32_op
= OPC_TLTIU
;
14771 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14772 mips32_op
= OPC_TGEIU
;
14774 case TNEI
: /* SYNCI */
14775 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14777 /* Break the TB to be able to sync copied instructions
14779 ctx
->bstate
= BS_STOP
;
14782 mips32_op
= OPC_TNEI
;
14787 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14788 mips32_op
= OPC_TEQI
;
14790 gen_trap(ctx
, mips32_op
, rs
, -1, imm
);
14795 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14796 gen_compute_branch(ctx
, minor
== BNEZC
? OPC_BNE
: OPC_BEQ
,
14797 4, rs
, 0, imm
<< 1, 0);
14798 /* Compact branches don't have a delay slot, so just let
14799 the normal delay slot handling take us to the branch
14803 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14804 gen_logic_imm(ctx
, OPC_LUI
, rs
, 0, imm
);
14807 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14808 /* Break the TB to be able to sync copied instructions
14810 ctx
->bstate
= BS_STOP
;
14814 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14815 /* COP2: Not implemented. */
14816 generate_exception_err(ctx
, EXCP_CpU
, 2);
14819 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14820 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1FANY2
: OPC_BC1F
;
14823 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14824 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1TANY2
: OPC_BC1T
;
14827 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14828 mips32_op
= OPC_BC1FANY4
;
14831 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14832 mips32_op
= OPC_BC1TANY4
;
14835 check_insn(ctx
, ASE_MIPS3D
);
14838 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
14839 check_cp1_enabled(ctx
);
14840 gen_compute_branch1(ctx
, mips32_op
,
14841 (ctx
->opcode
>> 18) & 0x7, imm
<< 1);
14843 generate_exception_err(ctx
, EXCP_CpU
, 1);
14848 /* MIPS DSP: not implemented */
14851 MIPS_INVAL("pool32i");
14852 generate_exception(ctx
, EXCP_RI
);
14857 minor
= (ctx
->opcode
>> 12) & 0xf;
14858 offset
= sextract32(ctx
->opcode
, 0,
14859 (ctx
->insn_flags
& ISA_MIPS32R6
) ? 9 : 12);
14862 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14863 mips32_op
= OPC_LWL
;
14866 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14867 mips32_op
= OPC_SWL
;
14870 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14871 mips32_op
= OPC_LWR
;
14874 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14875 mips32_op
= OPC_SWR
;
14877 #if defined(TARGET_MIPS64)
14879 check_insn(ctx
, ISA_MIPS3
);
14880 check_mips_64(ctx
);
14881 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14882 mips32_op
= OPC_LDL
;
14885 check_insn(ctx
, ISA_MIPS3
);
14886 check_mips_64(ctx
);
14887 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14888 mips32_op
= OPC_SDL
;
14891 check_insn(ctx
, ISA_MIPS3
);
14892 check_mips_64(ctx
);
14893 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14894 mips32_op
= OPC_LDR
;
14897 check_insn(ctx
, ISA_MIPS3
);
14898 check_mips_64(ctx
);
14899 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14900 mips32_op
= OPC_SDR
;
14903 check_insn(ctx
, ISA_MIPS3
);
14904 check_mips_64(ctx
);
14905 mips32_op
= OPC_LWU
;
14908 check_insn(ctx
, ISA_MIPS3
);
14909 check_mips_64(ctx
);
14910 mips32_op
= OPC_LLD
;
14914 mips32_op
= OPC_LL
;
14917 gen_ld(ctx
, mips32_op
, rt
, rs
, offset
);
14920 gen_st(ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
14923 gen_st_cond(ctx
, OPC_SC
, rt
, rs
, offset
);
14925 #if defined(TARGET_MIPS64)
14927 check_insn(ctx
, ISA_MIPS3
);
14928 check_mips_64(ctx
);
14929 gen_st_cond(ctx
, OPC_SCD
, rt
, rs
, offset
);
14933 /* Treat as no-op */
14934 if ((ctx
->insn_flags
& ISA_MIPS32R6
) && (rt
>= 24)) {
14935 /* hint codes 24-31 are reserved and signal RI */
14936 generate_exception(ctx
, EXCP_RI
);
14940 MIPS_INVAL("pool32c");
14941 generate_exception(ctx
, EXCP_RI
);
14945 case ADDI32
: /* AUI, LUI */
14946 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14948 gen_logic_imm(ctx
, OPC_LUI
, rt
, rs
, imm
);
14951 mips32_op
= OPC_ADDI
;
14956 mips32_op
= OPC_ADDIU
;
14958 gen_arith_imm(ctx
, mips32_op
, rt
, rs
, imm
);
14961 /* Logical operations */
14963 mips32_op
= OPC_ORI
;
14966 mips32_op
= OPC_XORI
;
14969 mips32_op
= OPC_ANDI
;
14971 gen_logic_imm(ctx
, mips32_op
, rt
, rs
, imm
);
14974 /* Set less than immediate */
14976 mips32_op
= OPC_SLTI
;
14979 mips32_op
= OPC_SLTIU
;
14981 gen_slt_imm(ctx
, mips32_op
, rt
, rs
, imm
);
14984 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
14985 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
14986 gen_compute_branch(ctx
, OPC_JALX
, 4, rt
, rs
, offset
, 4);
14987 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
14989 case JALS32
: /* BOVC, BEQC, BEQZALC */
14990 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
14993 mips32_op
= OPC_BOVC
;
14994 } else if (rs
< rt
&& rs
== 0) {
14996 mips32_op
= OPC_BEQZALC
;
14999 mips32_op
= OPC_BEQC
;
15001 gen_compute_compact_branch(ctx
, mips32_op
, rs
, rt
, imm
<< 1);
15004 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1;
15005 gen_compute_branch(ctx
, OPC_JAL
, 4, rt
, rs
, offset
, 2);
15006 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
15009 case BEQ32
: /* BC */
15010 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
15012 gen_compute_compact_branch(ctx
, OPC_BC
, 0, 0,
15013 sextract32(ctx
->opcode
<< 1, 0, 27));
15016 gen_compute_branch(ctx
, OPC_BEQ
, 4, rt
, rs
, imm
<< 1, 4);
15019 case BNE32
: /* BALC */
15020 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
15022 gen_compute_compact_branch(ctx
, OPC_BALC
, 0, 0,
15023 sextract32(ctx
->opcode
<< 1, 0, 27));
15026 gen_compute_branch(ctx
, OPC_BNE
, 4, rt
, rs
, imm
<< 1, 4);
15029 case J32
: /* BGTZC, BLTZC, BLTC */
15030 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
15031 if (rs
== 0 && rt
!= 0) {
15033 mips32_op
= OPC_BGTZC
;
15034 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
15036 mips32_op
= OPC_BLTZC
;
15039 mips32_op
= OPC_BLTC
;
15041 gen_compute_compact_branch(ctx
, mips32_op
, rs
, rt
, imm
<< 1);
15044 gen_compute_branch(ctx
, OPC_J
, 4, rt
, rs
,
15045 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1, 4);
15048 case JAL32
: /* BLEZC, BGEZC, BGEC */
15049 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
15050 if (rs
== 0 && rt
!= 0) {
15052 mips32_op
= OPC_BLEZC
;
15053 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
15055 mips32_op
= OPC_BGEZC
;
15058 mips32_op
= OPC_BGEC
;
15060 gen_compute_compact_branch(ctx
, mips32_op
, rs
, rt
, imm
<< 1);
15063 gen_compute_branch(ctx
, OPC_JAL
, 4, rt
, rs
,
15064 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1, 4);
15065 ctx
->hflags
|= MIPS_HFLAG_BDS_STRICT
;
15068 /* Floating point (COP1) */
15070 mips32_op
= OPC_LWC1
;
15073 mips32_op
= OPC_LDC1
;
15076 mips32_op
= OPC_SWC1
;
15079 mips32_op
= OPC_SDC1
;
15081 gen_cop1_ldst(ctx
, mips32_op
, rt
, rs
, imm
);
15083 case ADDIUPC
: /* PCREL: ADDIUPC, AUIPC, ALUIPC, LWPC */
15084 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
15085 /* PCREL: ADDIUPC, AUIPC, ALUIPC, LWPC */
15086 switch ((ctx
->opcode
>> 16) & 0x1f) {
15087 case ADDIUPC_00
... ADDIUPC_07
:
15088 gen_pcrel(ctx
, OPC_ADDIUPC
, ctx
->pc
& ~0x3, rt
);
15091 gen_pcrel(ctx
, OPC_AUIPC
, ctx
->pc
, rt
);
15094 gen_pcrel(ctx
, OPC_ALUIPC
, ctx
->pc
, rt
);
15096 case LWPC_08
... LWPC_0F
:
15097 gen_pcrel(ctx
, R6_OPC_LWPC
, ctx
->pc
& ~0x3, rt
);
15100 generate_exception(ctx
, EXCP_RI
);
15105 int reg
= mmreg(ZIMM(ctx
->opcode
, 23, 3));
15106 int offset
= SIMM(ctx
->opcode
, 0, 23) << 2;
15108 gen_addiupc(ctx
, reg
, offset
, 0, 0);
15111 case BNVC
: /* BNEC, BNEZALC */
15112 check_insn(ctx
, ISA_MIPS32R6
);
15115 mips32_op
= OPC_BNVC
;
15116 } else if (rs
< rt
&& rs
== 0) {
15118 mips32_op
= OPC_BNEZALC
;
15121 mips32_op
= OPC_BNEC
;
15123 gen_compute_compact_branch(ctx
, mips32_op
, rs
, rt
, imm
<< 1);
15125 case R6_BNEZC
: /* JIALC */
15126 check_insn(ctx
, ISA_MIPS32R6
);
15129 gen_compute_compact_branch(ctx
, OPC_BNEZC
, rt
, 0,
15130 sextract32(ctx
->opcode
<< 1, 0, 22));
15133 gen_compute_compact_branch(ctx
, OPC_JIALC
, 0, rs
, imm
);
15136 case R6_BEQZC
: /* JIC */
15137 check_insn(ctx
, ISA_MIPS32R6
);
15140 gen_compute_compact_branch(ctx
, OPC_BEQZC
, rt
, 0,
15141 sextract32(ctx
->opcode
<< 1, 0, 22));
15144 gen_compute_compact_branch(ctx
, OPC_JIC
, 0, rs
, imm
);
15147 case BLEZALC
: /* BGEZALC, BGEUC */
15148 check_insn(ctx
, ISA_MIPS32R6
);
15149 if (rs
== 0 && rt
!= 0) {
15151 mips32_op
= OPC_BLEZALC
;
15152 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
15154 mips32_op
= OPC_BGEZALC
;
15157 mips32_op
= OPC_BGEUC
;
15159 gen_compute_compact_branch(ctx
, mips32_op
, rs
, rt
, imm
<< 1);
15161 case BGTZALC
: /* BLTZALC, BLTUC */
15162 check_insn(ctx
, ISA_MIPS32R6
);
15163 if (rs
== 0 && rt
!= 0) {
15165 mips32_op
= OPC_BGTZALC
;
15166 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
15168 mips32_op
= OPC_BLTZALC
;
15171 mips32_op
= OPC_BLTUC
;
15173 gen_compute_compact_branch(ctx
, mips32_op
, rs
, rt
, imm
<< 1);
15175 /* Loads and stores */
15177 mips32_op
= OPC_LB
;
15180 mips32_op
= OPC_LBU
;
15183 mips32_op
= OPC_LH
;
15186 mips32_op
= OPC_LHU
;
15189 mips32_op
= OPC_LW
;
15191 #ifdef TARGET_MIPS64
15193 check_insn(ctx
, ISA_MIPS3
);
15194 check_mips_64(ctx
);
15195 mips32_op
= OPC_LD
;
15198 check_insn(ctx
, ISA_MIPS3
);
15199 check_mips_64(ctx
);
15200 mips32_op
= OPC_SD
;
15204 mips32_op
= OPC_SB
;
15207 mips32_op
= OPC_SH
;
15210 mips32_op
= OPC_SW
;
15213 gen_ld(ctx
, mips32_op
, rt
, rs
, imm
);
15216 gen_st(ctx
, mips32_op
, rt
, rs
, imm
);
15219 generate_exception(ctx
, EXCP_RI
);
15224 static int decode_micromips_opc (CPUMIPSState
*env
, DisasContext
*ctx
)
15228 /* make sure instructions are on a halfword boundary */
15229 if (ctx
->pc
& 0x1) {
15230 env
->CP0_BadVAddr
= ctx
->pc
;
15231 generate_exception(ctx
, EXCP_AdEL
);
15232 ctx
->bstate
= BS_STOP
;
15236 op
= (ctx
->opcode
>> 10) & 0x3f;
15237 /* Enforce properly-sized instructions in a delay slot */
15238 if (ctx
->hflags
& MIPS_HFLAG_BDS_STRICT
) {
15239 switch (op
& 0x7) { /* MSB-3..MSB-5 */
15241 /* POOL32A, POOL32B, POOL32I, POOL32C */
15243 /* ADDI32, ADDIU32, ORI32, XORI32, SLTI32, SLTIU32, ANDI32, JALX32 */
15245 /* LBU32, LHU32, POOL32F, JALS32, BEQ32, BNE32, J32, JAL32 */
15247 /* SB32, SH32, ADDIUPC, SWC132, SDC132, SW32 */
15249 /* LB32, LH32, LWC132, LDC132, LW32 */
15250 if (ctx
->hflags
& MIPS_HFLAG_BDS16
) {
15251 generate_exception(ctx
, EXCP_RI
);
15252 /* Just stop translation; the user is confused. */
15253 ctx
->bstate
= BS_STOP
;
15258 /* POOL16A, POOL16B, POOL16C, LWGP16, POOL16F */
15260 /* LBU16, LHU16, LWSP16, LW16, SB16, SH16, SWSP16, SW16 */
15262 /* MOVE16, ANDI16, POOL16D, POOL16E, BEQZ16, BNEZ16, B16, LI16 */
15263 if (ctx
->hflags
& MIPS_HFLAG_BDS32
) {
15264 generate_exception(ctx
, EXCP_RI
);
15265 /* Just stop translation; the user is confused. */
15266 ctx
->bstate
= BS_STOP
;
15276 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
15277 int rs1
= mmreg(uMIPS_RS1(ctx
->opcode
));
15278 int rs2
= mmreg(uMIPS_RS2(ctx
->opcode
));
15281 switch (ctx
->opcode
& 0x1) {
15289 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
15290 /* In the Release 6 the register number location in
15291 * the instruction encoding has changed.
15293 gen_arith(ctx
, opc
, rs1
, rd
, rs2
);
15295 gen_arith(ctx
, opc
, rd
, rs1
, rs2
);
15301 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
15302 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
15303 int amount
= (ctx
->opcode
>> 1) & 0x7;
15305 amount
= amount
== 0 ? 8 : amount
;
15307 switch (ctx
->opcode
& 0x1) {
15316 gen_shift_imm(ctx
, opc
, rd
, rs
, amount
);
15320 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
15321 gen_pool16c_r6_insn(ctx
);
15323 gen_pool16c_insn(ctx
);
15328 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
15329 int rb
= 28; /* GP */
15330 int16_t offset
= SIMM(ctx
->opcode
, 0, 7) << 2;
15332 gen_ld(ctx
, OPC_LW
, rd
, rb
, offset
);
15336 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
15337 if (ctx
->opcode
& 1) {
15338 generate_exception(ctx
, EXCP_RI
);
15341 int enc_dest
= uMIPS_RD(ctx
->opcode
);
15342 int enc_rt
= uMIPS_RS2(ctx
->opcode
);
15343 int enc_rs
= uMIPS_RS1(ctx
->opcode
);
15344 gen_movep(ctx
, enc_dest
, enc_rt
, enc_rs
);
15349 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
15350 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
15351 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
15352 offset
= (offset
== 0xf ? -1 : offset
);
15354 gen_ld(ctx
, OPC_LBU
, rd
, rb
, offset
);
15359 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
15360 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
15361 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
15363 gen_ld(ctx
, OPC_LHU
, rd
, rb
, offset
);
15368 int rd
= (ctx
->opcode
>> 5) & 0x1f;
15369 int rb
= 29; /* SP */
15370 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
15372 gen_ld(ctx
, OPC_LW
, rd
, rb
, offset
);
15377 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
15378 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
15379 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
15381 gen_ld(ctx
, OPC_LW
, rd
, rb
, offset
);
15386 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
15387 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
15388 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
15390 gen_st(ctx
, OPC_SB
, rd
, rb
, offset
);
15395 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
15396 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
15397 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
15399 gen_st(ctx
, OPC_SH
, rd
, rb
, offset
);
15404 int rd
= (ctx
->opcode
>> 5) & 0x1f;
15405 int rb
= 29; /* SP */
15406 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
15408 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
15413 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
15414 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
15415 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
15417 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
15422 int rd
= uMIPS_RD5(ctx
->opcode
);
15423 int rs
= uMIPS_RS5(ctx
->opcode
);
15425 gen_arith(ctx
, OPC_ADDU
, rd
, rs
, 0);
15432 switch (ctx
->opcode
& 0x1) {
15442 switch (ctx
->opcode
& 0x1) {
15447 gen_addiur1sp(ctx
);
15451 case B16
: /* BC16 */
15452 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0,
15453 sextract32(ctx
->opcode
, 0, 10) << 1,
15454 (ctx
->insn_flags
& ISA_MIPS32R6
) ? 0 : 4);
15456 case BNEZ16
: /* BNEZC16 */
15457 case BEQZ16
: /* BEQZC16 */
15458 gen_compute_branch(ctx
, op
== BNEZ16
? OPC_BNE
: OPC_BEQ
, 2,
15459 mmreg(uMIPS_RD(ctx
->opcode
)),
15460 0, sextract32(ctx
->opcode
, 0, 7) << 1,
15461 (ctx
->insn_flags
& ISA_MIPS32R6
) ? 0 : 4);
15466 int reg
= mmreg(uMIPS_RD(ctx
->opcode
));
15467 int imm
= ZIMM(ctx
->opcode
, 0, 7);
15469 imm
= (imm
== 0x7f ? -1 : imm
);
15470 tcg_gen_movi_tl(cpu_gpr
[reg
], imm
);
15476 generate_exception(ctx
, EXCP_RI
);
15479 decode_micromips32_opc(env
, ctx
);
15486 /* SmartMIPS extension to MIPS32 */
15488 #if defined(TARGET_MIPS64)
15490 /* MDMX extension to MIPS64 */
15494 /* MIPSDSP functions. */
15495 static void gen_mipsdsp_ld(DisasContext
*ctx
, uint32_t opc
,
15496 int rd
, int base
, int offset
)
15498 const char *opn
= "ldx";
15502 t0
= tcg_temp_new();
15505 gen_load_gpr(t0
, offset
);
15506 } else if (offset
== 0) {
15507 gen_load_gpr(t0
, base
);
15509 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], cpu_gpr
[offset
]);
15514 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_UB
);
15515 gen_store_gpr(t0
, rd
);
15519 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TESW
);
15520 gen_store_gpr(t0
, rd
);
15524 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TESL
);
15525 gen_store_gpr(t0
, rd
);
15528 #if defined(TARGET_MIPS64)
15530 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_TEQ
);
15531 gen_store_gpr(t0
, rd
);
15536 (void)opn
; /* avoid a compiler warning */
15537 MIPS_DEBUG("%s %s, %s(%s)", opn
,
15538 regnames
[rd
], regnames
[offset
], regnames
[base
]);
15542 static void gen_mipsdsp_arith(DisasContext
*ctx
, uint32_t op1
, uint32_t op2
,
15543 int ret
, int v1
, int v2
)
15545 const char *opn
= "mipsdsp arith";
15550 /* Treat as NOP. */
15555 v1_t
= tcg_temp_new();
15556 v2_t
= tcg_temp_new();
15558 gen_load_gpr(v1_t
, v1
);
15559 gen_load_gpr(v2_t
, v2
);
15562 /* OPC_MULT_G_2E is equal OPC_ADDUH_QB_DSP */
15563 case OPC_MULT_G_2E
:
15567 gen_helper_adduh_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
15569 case OPC_ADDUH_R_QB
:
15570 gen_helper_adduh_r_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
15573 gen_helper_addqh_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
15575 case OPC_ADDQH_R_PH
:
15576 gen_helper_addqh_r_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
15579 gen_helper_addqh_w(cpu_gpr
[ret
], v1_t
, v2_t
);
15581 case OPC_ADDQH_R_W
:
15582 gen_helper_addqh_r_w(cpu_gpr
[ret
], v1_t
, v2_t
);
15585 gen_helper_subuh_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
15587 case OPC_SUBUH_R_QB
:
15588 gen_helper_subuh_r_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
15591 gen_helper_subqh_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
15593 case OPC_SUBQH_R_PH
:
15594 gen_helper_subqh_r_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
15597 gen_helper_subqh_w(cpu_gpr
[ret
], v1_t
, v2_t
);
15599 case OPC_SUBQH_R_W
:
15600 gen_helper_subqh_r_w(cpu_gpr
[ret
], v1_t
, v2_t
);
15604 case OPC_ABSQ_S_PH_DSP
:
15606 case OPC_ABSQ_S_QB
:
15608 gen_helper_absq_s_qb(cpu_gpr
[ret
], v2_t
, cpu_env
);
15610 case OPC_ABSQ_S_PH
:
15612 gen_helper_absq_s_ph(cpu_gpr
[ret
], v2_t
, cpu_env
);
15616 gen_helper_absq_s_w(cpu_gpr
[ret
], v2_t
, cpu_env
);
15618 case OPC_PRECEQ_W_PHL
:
15620 tcg_gen_andi_tl(cpu_gpr
[ret
], v2_t
, 0xFFFF0000);
15621 tcg_gen_ext32s_tl(cpu_gpr
[ret
], cpu_gpr
[ret
]);
15623 case OPC_PRECEQ_W_PHR
:
15625 tcg_gen_andi_tl(cpu_gpr
[ret
], v2_t
, 0x0000FFFF);
15626 tcg_gen_shli_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], 16);
15627 tcg_gen_ext32s_tl(cpu_gpr
[ret
], cpu_gpr
[ret
]);
15629 case OPC_PRECEQU_PH_QBL
:
15631 gen_helper_precequ_ph_qbl(cpu_gpr
[ret
], v2_t
);
15633 case OPC_PRECEQU_PH_QBR
:
15635 gen_helper_precequ_ph_qbr(cpu_gpr
[ret
], v2_t
);
15637 case OPC_PRECEQU_PH_QBLA
:
15639 gen_helper_precequ_ph_qbla(cpu_gpr
[ret
], v2_t
);
15641 case OPC_PRECEQU_PH_QBRA
:
15643 gen_helper_precequ_ph_qbra(cpu_gpr
[ret
], v2_t
);
15645 case OPC_PRECEU_PH_QBL
:
15647 gen_helper_preceu_ph_qbl(cpu_gpr
[ret
], v2_t
);
15649 case OPC_PRECEU_PH_QBR
:
15651 gen_helper_preceu_ph_qbr(cpu_gpr
[ret
], v2_t
);
15653 case OPC_PRECEU_PH_QBLA
:
15655 gen_helper_preceu_ph_qbla(cpu_gpr
[ret
], v2_t
);
15657 case OPC_PRECEU_PH_QBRA
:
15659 gen_helper_preceu_ph_qbra(cpu_gpr
[ret
], v2_t
);
15663 case OPC_ADDU_QB_DSP
:
15667 gen_helper_addq_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15669 case OPC_ADDQ_S_PH
:
15671 gen_helper_addq_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15675 gen_helper_addq_s_w(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15679 gen_helper_addu_qb(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15681 case OPC_ADDU_S_QB
:
15683 gen_helper_addu_s_qb(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15687 gen_helper_addu_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15689 case OPC_ADDU_S_PH
:
15691 gen_helper_addu_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15695 gen_helper_subq_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15697 case OPC_SUBQ_S_PH
:
15699 gen_helper_subq_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15703 gen_helper_subq_s_w(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15707 gen_helper_subu_qb(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15709 case OPC_SUBU_S_QB
:
15711 gen_helper_subu_s_qb(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15715 gen_helper_subu_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15717 case OPC_SUBU_S_PH
:
15719 gen_helper_subu_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15723 gen_helper_addsc(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15727 gen_helper_addwc(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15731 gen_helper_modsub(cpu_gpr
[ret
], v1_t
, v2_t
);
15733 case OPC_RADDU_W_QB
:
15735 gen_helper_raddu_w_qb(cpu_gpr
[ret
], v1_t
);
15739 case OPC_CMPU_EQ_QB_DSP
:
15741 case OPC_PRECR_QB_PH
:
15743 gen_helper_precr_qb_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
15745 case OPC_PRECRQ_QB_PH
:
15747 gen_helper_precrq_qb_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
15749 case OPC_PRECR_SRA_PH_W
:
15752 TCGv_i32 sa_t
= tcg_const_i32(v2
);
15753 gen_helper_precr_sra_ph_w(cpu_gpr
[ret
], sa_t
, v1_t
,
15755 tcg_temp_free_i32(sa_t
);
15758 case OPC_PRECR_SRA_R_PH_W
:
15761 TCGv_i32 sa_t
= tcg_const_i32(v2
);
15762 gen_helper_precr_sra_r_ph_w(cpu_gpr
[ret
], sa_t
, v1_t
,
15764 tcg_temp_free_i32(sa_t
);
15767 case OPC_PRECRQ_PH_W
:
15769 gen_helper_precrq_ph_w(cpu_gpr
[ret
], v1_t
, v2_t
);
15771 case OPC_PRECRQ_RS_PH_W
:
15773 gen_helper_precrq_rs_ph_w(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15775 case OPC_PRECRQU_S_QB_PH
:
15777 gen_helper_precrqu_s_qb_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15781 #ifdef TARGET_MIPS64
15782 case OPC_ABSQ_S_QH_DSP
:
15784 case OPC_PRECEQ_L_PWL
:
15786 tcg_gen_andi_tl(cpu_gpr
[ret
], v2_t
, 0xFFFFFFFF00000000ull
);
15788 case OPC_PRECEQ_L_PWR
:
15790 tcg_gen_shli_tl(cpu_gpr
[ret
], v2_t
, 32);
15792 case OPC_PRECEQ_PW_QHL
:
15794 gen_helper_preceq_pw_qhl(cpu_gpr
[ret
], v2_t
);
15796 case OPC_PRECEQ_PW_QHR
:
15798 gen_helper_preceq_pw_qhr(cpu_gpr
[ret
], v2_t
);
15800 case OPC_PRECEQ_PW_QHLA
:
15802 gen_helper_preceq_pw_qhla(cpu_gpr
[ret
], v2_t
);
15804 case OPC_PRECEQ_PW_QHRA
:
15806 gen_helper_preceq_pw_qhra(cpu_gpr
[ret
], v2_t
);
15808 case OPC_PRECEQU_QH_OBL
:
15810 gen_helper_precequ_qh_obl(cpu_gpr
[ret
], v2_t
);
15812 case OPC_PRECEQU_QH_OBR
:
15814 gen_helper_precequ_qh_obr(cpu_gpr
[ret
], v2_t
);
15816 case OPC_PRECEQU_QH_OBLA
:
15818 gen_helper_precequ_qh_obla(cpu_gpr
[ret
], v2_t
);
15820 case OPC_PRECEQU_QH_OBRA
:
15822 gen_helper_precequ_qh_obra(cpu_gpr
[ret
], v2_t
);
15824 case OPC_PRECEU_QH_OBL
:
15826 gen_helper_preceu_qh_obl(cpu_gpr
[ret
], v2_t
);
15828 case OPC_PRECEU_QH_OBR
:
15830 gen_helper_preceu_qh_obr(cpu_gpr
[ret
], v2_t
);
15832 case OPC_PRECEU_QH_OBLA
:
15834 gen_helper_preceu_qh_obla(cpu_gpr
[ret
], v2_t
);
15836 case OPC_PRECEU_QH_OBRA
:
15838 gen_helper_preceu_qh_obra(cpu_gpr
[ret
], v2_t
);
15840 case OPC_ABSQ_S_OB
:
15842 gen_helper_absq_s_ob(cpu_gpr
[ret
], v2_t
, cpu_env
);
15844 case OPC_ABSQ_S_PW
:
15846 gen_helper_absq_s_pw(cpu_gpr
[ret
], v2_t
, cpu_env
);
15848 case OPC_ABSQ_S_QH
:
15850 gen_helper_absq_s_qh(cpu_gpr
[ret
], v2_t
, cpu_env
);
15854 case OPC_ADDU_OB_DSP
:
15856 case OPC_RADDU_L_OB
:
15858 gen_helper_raddu_l_ob(cpu_gpr
[ret
], v1_t
);
15862 gen_helper_subq_pw(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15864 case OPC_SUBQ_S_PW
:
15866 gen_helper_subq_s_pw(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15870 gen_helper_subq_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15872 case OPC_SUBQ_S_QH
:
15874 gen_helper_subq_s_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15878 gen_helper_subu_ob(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15880 case OPC_SUBU_S_OB
:
15882 gen_helper_subu_s_ob(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15886 gen_helper_subu_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15888 case OPC_SUBU_S_QH
:
15890 gen_helper_subu_s_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15894 gen_helper_subuh_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
15896 case OPC_SUBUH_R_OB
:
15898 gen_helper_subuh_r_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
15902 gen_helper_addq_pw(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15904 case OPC_ADDQ_S_PW
:
15906 gen_helper_addq_s_pw(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15910 gen_helper_addq_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15912 case OPC_ADDQ_S_QH
:
15914 gen_helper_addq_s_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15918 gen_helper_addu_ob(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15920 case OPC_ADDU_S_OB
:
15922 gen_helper_addu_s_ob(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15926 gen_helper_addu_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15928 case OPC_ADDU_S_QH
:
15930 gen_helper_addu_s_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15934 gen_helper_adduh_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
15936 case OPC_ADDUH_R_OB
:
15938 gen_helper_adduh_r_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
15942 case OPC_CMPU_EQ_OB_DSP
:
15944 case OPC_PRECR_OB_QH
:
15946 gen_helper_precr_ob_qh(cpu_gpr
[ret
], v1_t
, v2_t
);
15948 case OPC_PRECR_SRA_QH_PW
:
15951 TCGv_i32 ret_t
= tcg_const_i32(ret
);
15952 gen_helper_precr_sra_qh_pw(v2_t
, v1_t
, v2_t
, ret_t
);
15953 tcg_temp_free_i32(ret_t
);
15956 case OPC_PRECR_SRA_R_QH_PW
:
15959 TCGv_i32 sa_v
= tcg_const_i32(ret
);
15960 gen_helper_precr_sra_r_qh_pw(v2_t
, v1_t
, v2_t
, sa_v
);
15961 tcg_temp_free_i32(sa_v
);
15964 case OPC_PRECRQ_OB_QH
:
15966 gen_helper_precrq_ob_qh(cpu_gpr
[ret
], v1_t
, v2_t
);
15968 case OPC_PRECRQ_PW_L
:
15970 gen_helper_precrq_pw_l(cpu_gpr
[ret
], v1_t
, v2_t
);
15972 case OPC_PRECRQ_QH_PW
:
15974 gen_helper_precrq_qh_pw(cpu_gpr
[ret
], v1_t
, v2_t
);
15976 case OPC_PRECRQ_RS_QH_PW
:
15978 gen_helper_precrq_rs_qh_pw(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15980 case OPC_PRECRQU_S_OB_QH
:
15982 gen_helper_precrqu_s_ob_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
15989 tcg_temp_free(v1_t
);
15990 tcg_temp_free(v2_t
);
15992 (void)opn
; /* avoid a compiler warning */
15993 MIPS_DEBUG("%s", opn
);
15996 static void gen_mipsdsp_shift(DisasContext
*ctx
, uint32_t opc
,
15997 int ret
, int v1
, int v2
)
16000 const char *opn
= "mipsdsp shift";
16006 /* Treat as NOP. */
16011 t0
= tcg_temp_new();
16012 v1_t
= tcg_temp_new();
16013 v2_t
= tcg_temp_new();
16015 tcg_gen_movi_tl(t0
, v1
);
16016 gen_load_gpr(v1_t
, v1
);
16017 gen_load_gpr(v2_t
, v2
);
16020 case OPC_SHLL_QB_DSP
:
16022 op2
= MASK_SHLL_QB(ctx
->opcode
);
16026 gen_helper_shll_qb(cpu_gpr
[ret
], t0
, v2_t
, cpu_env
);
16030 gen_helper_shll_qb(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16034 gen_helper_shll_ph(cpu_gpr
[ret
], t0
, v2_t
, cpu_env
);
16038 gen_helper_shll_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16040 case OPC_SHLL_S_PH
:
16042 gen_helper_shll_s_ph(cpu_gpr
[ret
], t0
, v2_t
, cpu_env
);
16044 case OPC_SHLLV_S_PH
:
16046 gen_helper_shll_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16050 gen_helper_shll_s_w(cpu_gpr
[ret
], t0
, v2_t
, cpu_env
);
16052 case OPC_SHLLV_S_W
:
16054 gen_helper_shll_s_w(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16058 gen_helper_shrl_qb(cpu_gpr
[ret
], t0
, v2_t
);
16062 gen_helper_shrl_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
16066 gen_helper_shrl_ph(cpu_gpr
[ret
], t0
, v2_t
);
16070 gen_helper_shrl_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
16074 gen_helper_shra_qb(cpu_gpr
[ret
], t0
, v2_t
);
16076 case OPC_SHRA_R_QB
:
16078 gen_helper_shra_r_qb(cpu_gpr
[ret
], t0
, v2_t
);
16082 gen_helper_shra_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
16084 case OPC_SHRAV_R_QB
:
16086 gen_helper_shra_r_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
16090 gen_helper_shra_ph(cpu_gpr
[ret
], t0
, v2_t
);
16092 case OPC_SHRA_R_PH
:
16094 gen_helper_shra_r_ph(cpu_gpr
[ret
], t0
, v2_t
);
16098 gen_helper_shra_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
16100 case OPC_SHRAV_R_PH
:
16102 gen_helper_shra_r_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
16106 gen_helper_shra_r_w(cpu_gpr
[ret
], t0
, v2_t
);
16108 case OPC_SHRAV_R_W
:
16110 gen_helper_shra_r_w(cpu_gpr
[ret
], v1_t
, v2_t
);
16112 default: /* Invalid */
16113 MIPS_INVAL("MASK SHLL.QB");
16114 generate_exception(ctx
, EXCP_RI
);
16119 #ifdef TARGET_MIPS64
16120 case OPC_SHLL_OB_DSP
:
16121 op2
= MASK_SHLL_OB(ctx
->opcode
);
16125 gen_helper_shll_pw(cpu_gpr
[ret
], v2_t
, t0
, cpu_env
);
16129 gen_helper_shll_pw(cpu_gpr
[ret
], v2_t
, v1_t
, cpu_env
);
16131 case OPC_SHLL_S_PW
:
16133 gen_helper_shll_s_pw(cpu_gpr
[ret
], v2_t
, t0
, cpu_env
);
16135 case OPC_SHLLV_S_PW
:
16137 gen_helper_shll_s_pw(cpu_gpr
[ret
], v2_t
, v1_t
, cpu_env
);
16141 gen_helper_shll_ob(cpu_gpr
[ret
], v2_t
, t0
, cpu_env
);
16145 gen_helper_shll_ob(cpu_gpr
[ret
], v2_t
, v1_t
, cpu_env
);
16149 gen_helper_shll_qh(cpu_gpr
[ret
], v2_t
, t0
, cpu_env
);
16153 gen_helper_shll_qh(cpu_gpr
[ret
], v2_t
, v1_t
, cpu_env
);
16155 case OPC_SHLL_S_QH
:
16157 gen_helper_shll_s_qh(cpu_gpr
[ret
], v2_t
, t0
, cpu_env
);
16159 case OPC_SHLLV_S_QH
:
16161 gen_helper_shll_s_qh(cpu_gpr
[ret
], v2_t
, v1_t
, cpu_env
);
16165 gen_helper_shra_ob(cpu_gpr
[ret
], v2_t
, t0
);
16169 gen_helper_shra_ob(cpu_gpr
[ret
], v2_t
, v1_t
);
16171 case OPC_SHRA_R_OB
:
16173 gen_helper_shra_r_ob(cpu_gpr
[ret
], v2_t
, t0
);
16175 case OPC_SHRAV_R_OB
:
16177 gen_helper_shra_r_ob(cpu_gpr
[ret
], v2_t
, v1_t
);
16181 gen_helper_shra_pw(cpu_gpr
[ret
], v2_t
, t0
);
16185 gen_helper_shra_pw(cpu_gpr
[ret
], v2_t
, v1_t
);
16187 case OPC_SHRA_R_PW
:
16189 gen_helper_shra_r_pw(cpu_gpr
[ret
], v2_t
, t0
);
16191 case OPC_SHRAV_R_PW
:
16193 gen_helper_shra_r_pw(cpu_gpr
[ret
], v2_t
, v1_t
);
16197 gen_helper_shra_qh(cpu_gpr
[ret
], v2_t
, t0
);
16201 gen_helper_shra_qh(cpu_gpr
[ret
], v2_t
, v1_t
);
16203 case OPC_SHRA_R_QH
:
16205 gen_helper_shra_r_qh(cpu_gpr
[ret
], v2_t
, t0
);
16207 case OPC_SHRAV_R_QH
:
16209 gen_helper_shra_r_qh(cpu_gpr
[ret
], v2_t
, v1_t
);
16213 gen_helper_shrl_ob(cpu_gpr
[ret
], v2_t
, t0
);
16217 gen_helper_shrl_ob(cpu_gpr
[ret
], v2_t
, v1_t
);
16221 gen_helper_shrl_qh(cpu_gpr
[ret
], v2_t
, t0
);
16225 gen_helper_shrl_qh(cpu_gpr
[ret
], v2_t
, v1_t
);
16227 default: /* Invalid */
16228 MIPS_INVAL("MASK SHLL.OB");
16229 generate_exception(ctx
, EXCP_RI
);
16237 tcg_temp_free(v1_t
);
16238 tcg_temp_free(v2_t
);
16239 (void)opn
; /* avoid a compiler warning */
16240 MIPS_DEBUG("%s", opn
);
16243 static void gen_mipsdsp_multiply(DisasContext
*ctx
, uint32_t op1
, uint32_t op2
,
16244 int ret
, int v1
, int v2
, int check_ret
)
16246 const char *opn
= "mipsdsp multiply";
16251 if ((ret
== 0) && (check_ret
== 1)) {
16252 /* Treat as NOP. */
16257 t0
= tcg_temp_new_i32();
16258 v1_t
= tcg_temp_new();
16259 v2_t
= tcg_temp_new();
16261 tcg_gen_movi_i32(t0
, ret
);
16262 gen_load_gpr(v1_t
, v1
);
16263 gen_load_gpr(v2_t
, v2
);
16266 /* OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have
16267 * the same mask and op1. */
16268 case OPC_MULT_G_2E
:
16272 gen_helper_mul_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16275 gen_helper_mul_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16278 gen_helper_mulq_s_w(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16280 case OPC_MULQ_RS_W
:
16281 gen_helper_mulq_rs_w(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16285 case OPC_DPA_W_PH_DSP
:
16287 case OPC_DPAU_H_QBL
:
16289 gen_helper_dpau_h_qbl(t0
, v1_t
, v2_t
, cpu_env
);
16291 case OPC_DPAU_H_QBR
:
16293 gen_helper_dpau_h_qbr(t0
, v1_t
, v2_t
, cpu_env
);
16295 case OPC_DPSU_H_QBL
:
16297 gen_helper_dpsu_h_qbl(t0
, v1_t
, v2_t
, cpu_env
);
16299 case OPC_DPSU_H_QBR
:
16301 gen_helper_dpsu_h_qbr(t0
, v1_t
, v2_t
, cpu_env
);
16305 gen_helper_dpa_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16307 case OPC_DPAX_W_PH
:
16309 gen_helper_dpax_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16311 case OPC_DPAQ_S_W_PH
:
16313 gen_helper_dpaq_s_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16315 case OPC_DPAQX_S_W_PH
:
16317 gen_helper_dpaqx_s_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16319 case OPC_DPAQX_SA_W_PH
:
16321 gen_helper_dpaqx_sa_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16325 gen_helper_dps_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16327 case OPC_DPSX_W_PH
:
16329 gen_helper_dpsx_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16331 case OPC_DPSQ_S_W_PH
:
16333 gen_helper_dpsq_s_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16335 case OPC_DPSQX_S_W_PH
:
16337 gen_helper_dpsqx_s_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16339 case OPC_DPSQX_SA_W_PH
:
16341 gen_helper_dpsqx_sa_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16343 case OPC_MULSAQ_S_W_PH
:
16345 gen_helper_mulsaq_s_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16347 case OPC_DPAQ_SA_L_W
:
16349 gen_helper_dpaq_sa_l_w(t0
, v1_t
, v2_t
, cpu_env
);
16351 case OPC_DPSQ_SA_L_W
:
16353 gen_helper_dpsq_sa_l_w(t0
, v1_t
, v2_t
, cpu_env
);
16355 case OPC_MAQ_S_W_PHL
:
16357 gen_helper_maq_s_w_phl(t0
, v1_t
, v2_t
, cpu_env
);
16359 case OPC_MAQ_S_W_PHR
:
16361 gen_helper_maq_s_w_phr(t0
, v1_t
, v2_t
, cpu_env
);
16363 case OPC_MAQ_SA_W_PHL
:
16365 gen_helper_maq_sa_w_phl(t0
, v1_t
, v2_t
, cpu_env
);
16367 case OPC_MAQ_SA_W_PHR
:
16369 gen_helper_maq_sa_w_phr(t0
, v1_t
, v2_t
, cpu_env
);
16371 case OPC_MULSA_W_PH
:
16373 gen_helper_mulsa_w_ph(t0
, v1_t
, v2_t
, cpu_env
);
16377 #ifdef TARGET_MIPS64
16378 case OPC_DPAQ_W_QH_DSP
:
16380 int ac
= ret
& 0x03;
16381 tcg_gen_movi_i32(t0
, ac
);
16386 gen_helper_dmadd(v1_t
, v2_t
, t0
, cpu_env
);
16390 gen_helper_dmaddu(v1_t
, v2_t
, t0
, cpu_env
);
16394 gen_helper_dmsub(v1_t
, v2_t
, t0
, cpu_env
);
16398 gen_helper_dmsubu(v1_t
, v2_t
, t0
, cpu_env
);
16402 gen_helper_dpa_w_qh(v1_t
, v2_t
, t0
, cpu_env
);
16404 case OPC_DPAQ_S_W_QH
:
16406 gen_helper_dpaq_s_w_qh(v1_t
, v2_t
, t0
, cpu_env
);
16408 case OPC_DPAQ_SA_L_PW
:
16410 gen_helper_dpaq_sa_l_pw(v1_t
, v2_t
, t0
, cpu_env
);
16412 case OPC_DPAU_H_OBL
:
16414 gen_helper_dpau_h_obl(v1_t
, v2_t
, t0
, cpu_env
);
16416 case OPC_DPAU_H_OBR
:
16418 gen_helper_dpau_h_obr(v1_t
, v2_t
, t0
, cpu_env
);
16422 gen_helper_dps_w_qh(v1_t
, v2_t
, t0
, cpu_env
);
16424 case OPC_DPSQ_S_W_QH
:
16426 gen_helper_dpsq_s_w_qh(v1_t
, v2_t
, t0
, cpu_env
);
16428 case OPC_DPSQ_SA_L_PW
:
16430 gen_helper_dpsq_sa_l_pw(v1_t
, v2_t
, t0
, cpu_env
);
16432 case OPC_DPSU_H_OBL
:
16434 gen_helper_dpsu_h_obl(v1_t
, v2_t
, t0
, cpu_env
);
16436 case OPC_DPSU_H_OBR
:
16438 gen_helper_dpsu_h_obr(v1_t
, v2_t
, t0
, cpu_env
);
16440 case OPC_MAQ_S_L_PWL
:
16442 gen_helper_maq_s_l_pwl(v1_t
, v2_t
, t0
, cpu_env
);
16444 case OPC_MAQ_S_L_PWR
:
16446 gen_helper_maq_s_l_pwr(v1_t
, v2_t
, t0
, cpu_env
);
16448 case OPC_MAQ_S_W_QHLL
:
16450 gen_helper_maq_s_w_qhll(v1_t
, v2_t
, t0
, cpu_env
);
16452 case OPC_MAQ_SA_W_QHLL
:
16454 gen_helper_maq_sa_w_qhll(v1_t
, v2_t
, t0
, cpu_env
);
16456 case OPC_MAQ_S_W_QHLR
:
16458 gen_helper_maq_s_w_qhlr(v1_t
, v2_t
, t0
, cpu_env
);
16460 case OPC_MAQ_SA_W_QHLR
:
16462 gen_helper_maq_sa_w_qhlr(v1_t
, v2_t
, t0
, cpu_env
);
16464 case OPC_MAQ_S_W_QHRL
:
16466 gen_helper_maq_s_w_qhrl(v1_t
, v2_t
, t0
, cpu_env
);
16468 case OPC_MAQ_SA_W_QHRL
:
16470 gen_helper_maq_sa_w_qhrl(v1_t
, v2_t
, t0
, cpu_env
);
16472 case OPC_MAQ_S_W_QHRR
:
16474 gen_helper_maq_s_w_qhrr(v1_t
, v2_t
, t0
, cpu_env
);
16476 case OPC_MAQ_SA_W_QHRR
:
16478 gen_helper_maq_sa_w_qhrr(v1_t
, v2_t
, t0
, cpu_env
);
16480 case OPC_MULSAQ_S_L_PW
:
16482 gen_helper_mulsaq_s_l_pw(v1_t
, v2_t
, t0
, cpu_env
);
16484 case OPC_MULSAQ_S_W_QH
:
16486 gen_helper_mulsaq_s_w_qh(v1_t
, v2_t
, t0
, cpu_env
);
16492 case OPC_ADDU_QB_DSP
:
16494 case OPC_MULEU_S_PH_QBL
:
16496 gen_helper_muleu_s_ph_qbl(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16498 case OPC_MULEU_S_PH_QBR
:
16500 gen_helper_muleu_s_ph_qbr(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16502 case OPC_MULQ_RS_PH
:
16504 gen_helper_mulq_rs_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16506 case OPC_MULEQ_S_W_PHL
:
16508 gen_helper_muleq_s_w_phl(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16510 case OPC_MULEQ_S_W_PHR
:
16512 gen_helper_muleq_s_w_phr(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16514 case OPC_MULQ_S_PH
:
16516 gen_helper_mulq_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16520 #ifdef TARGET_MIPS64
16521 case OPC_ADDU_OB_DSP
:
16523 case OPC_MULEQ_S_PW_QHL
:
16525 gen_helper_muleq_s_pw_qhl(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16527 case OPC_MULEQ_S_PW_QHR
:
16529 gen_helper_muleq_s_pw_qhr(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16531 case OPC_MULEU_S_QH_OBL
:
16533 gen_helper_muleu_s_qh_obl(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16535 case OPC_MULEU_S_QH_OBR
:
16537 gen_helper_muleu_s_qh_obr(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16539 case OPC_MULQ_RS_QH
:
16541 gen_helper_mulq_rs_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16548 tcg_temp_free_i32(t0
);
16549 tcg_temp_free(v1_t
);
16550 tcg_temp_free(v2_t
);
16552 (void)opn
; /* avoid a compiler warning */
16553 MIPS_DEBUG("%s", opn
);
16557 static void gen_mipsdsp_bitinsn(DisasContext
*ctx
, uint32_t op1
, uint32_t op2
,
16560 const char *opn
= "mipsdsp Bit/ Manipulation";
16566 /* Treat as NOP. */
16571 t0
= tcg_temp_new();
16572 val_t
= tcg_temp_new();
16573 gen_load_gpr(val_t
, val
);
16576 case OPC_ABSQ_S_PH_DSP
:
16580 gen_helper_bitrev(cpu_gpr
[ret
], val_t
);
16585 target_long result
;
16586 imm
= (ctx
->opcode
>> 16) & 0xFF;
16587 result
= (uint32_t)imm
<< 24 |
16588 (uint32_t)imm
<< 16 |
16589 (uint32_t)imm
<< 8 |
16591 result
= (int32_t)result
;
16592 tcg_gen_movi_tl(cpu_gpr
[ret
], result
);
16597 tcg_gen_ext8u_tl(cpu_gpr
[ret
], val_t
);
16598 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 8);
16599 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16600 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 16);
16601 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16602 tcg_gen_ext32s_tl(cpu_gpr
[ret
], cpu_gpr
[ret
]);
16607 imm
= (ctx
->opcode
>> 16) & 0x03FF;
16608 imm
= (int16_t)(imm
<< 6) >> 6;
16609 tcg_gen_movi_tl(cpu_gpr
[ret
], \
16610 (target_long
)((int32_t)imm
<< 16 | \
16616 tcg_gen_ext16u_tl(cpu_gpr
[ret
], val_t
);
16617 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 16);
16618 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16619 tcg_gen_ext32s_tl(cpu_gpr
[ret
], cpu_gpr
[ret
]);
16623 #ifdef TARGET_MIPS64
16624 case OPC_ABSQ_S_QH_DSP
:
16631 imm
= (ctx
->opcode
>> 16) & 0xFF;
16632 temp
= ((uint64_t)imm
<< 8) | (uint64_t)imm
;
16633 temp
= (temp
<< 16) | temp
;
16634 temp
= (temp
<< 32) | temp
;
16635 tcg_gen_movi_tl(cpu_gpr
[ret
], temp
);
16643 imm
= (ctx
->opcode
>> 16) & 0x03FF;
16644 imm
= (int16_t)(imm
<< 6) >> 6;
16645 temp
= ((target_long
)imm
<< 32) \
16646 | ((target_long
)imm
& 0xFFFFFFFF);
16647 tcg_gen_movi_tl(cpu_gpr
[ret
], temp
);
16655 imm
= (ctx
->opcode
>> 16) & 0x03FF;
16656 imm
= (int16_t)(imm
<< 6) >> 6;
16658 temp
= ((uint64_t)(uint16_t)imm
<< 48) |
16659 ((uint64_t)(uint16_t)imm
<< 32) |
16660 ((uint64_t)(uint16_t)imm
<< 16) |
16661 (uint64_t)(uint16_t)imm
;
16662 tcg_gen_movi_tl(cpu_gpr
[ret
], temp
);
16667 tcg_gen_ext8u_tl(cpu_gpr
[ret
], val_t
);
16668 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 8);
16669 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16670 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 16);
16671 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16672 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 32);
16673 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16677 tcg_gen_ext32u_i64(cpu_gpr
[ret
], val_t
);
16678 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 32);
16679 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16683 tcg_gen_ext16u_tl(cpu_gpr
[ret
], val_t
);
16684 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 16);
16685 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16686 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 32);
16687 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
16694 tcg_temp_free(val_t
);
16696 (void)opn
; /* avoid a compiler warning */
16697 MIPS_DEBUG("%s", opn
);
16700 static void gen_mipsdsp_add_cmp_pick(DisasContext
*ctx
,
16701 uint32_t op1
, uint32_t op2
,
16702 int ret
, int v1
, int v2
, int check_ret
)
16704 const char *opn
= "mipsdsp add compare pick";
16709 if ((ret
== 0) && (check_ret
== 1)) {
16710 /* Treat as NOP. */
16715 t1
= tcg_temp_new();
16716 v1_t
= tcg_temp_new();
16717 v2_t
= tcg_temp_new();
16719 gen_load_gpr(v1_t
, v1
);
16720 gen_load_gpr(v2_t
, v2
);
16723 case OPC_CMPU_EQ_QB_DSP
:
16725 case OPC_CMPU_EQ_QB
:
16727 gen_helper_cmpu_eq_qb(v1_t
, v2_t
, cpu_env
);
16729 case OPC_CMPU_LT_QB
:
16731 gen_helper_cmpu_lt_qb(v1_t
, v2_t
, cpu_env
);
16733 case OPC_CMPU_LE_QB
:
16735 gen_helper_cmpu_le_qb(v1_t
, v2_t
, cpu_env
);
16737 case OPC_CMPGU_EQ_QB
:
16739 gen_helper_cmpgu_eq_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
16741 case OPC_CMPGU_LT_QB
:
16743 gen_helper_cmpgu_lt_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
16745 case OPC_CMPGU_LE_QB
:
16747 gen_helper_cmpgu_le_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
16749 case OPC_CMPGDU_EQ_QB
:
16751 gen_helper_cmpgu_eq_qb(t1
, v1_t
, v2_t
);
16752 tcg_gen_mov_tl(cpu_gpr
[ret
], t1
);
16753 tcg_gen_andi_tl(cpu_dspctrl
, cpu_dspctrl
, 0xF0FFFFFF);
16754 tcg_gen_shli_tl(t1
, t1
, 24);
16755 tcg_gen_or_tl(cpu_dspctrl
, cpu_dspctrl
, t1
);
16757 case OPC_CMPGDU_LT_QB
:
16759 gen_helper_cmpgu_lt_qb(t1
, v1_t
, v2_t
);
16760 tcg_gen_mov_tl(cpu_gpr
[ret
], t1
);
16761 tcg_gen_andi_tl(cpu_dspctrl
, cpu_dspctrl
, 0xF0FFFFFF);
16762 tcg_gen_shli_tl(t1
, t1
, 24);
16763 tcg_gen_or_tl(cpu_dspctrl
, cpu_dspctrl
, t1
);
16765 case OPC_CMPGDU_LE_QB
:
16767 gen_helper_cmpgu_le_qb(t1
, v1_t
, v2_t
);
16768 tcg_gen_mov_tl(cpu_gpr
[ret
], t1
);
16769 tcg_gen_andi_tl(cpu_dspctrl
, cpu_dspctrl
, 0xF0FFFFFF);
16770 tcg_gen_shli_tl(t1
, t1
, 24);
16771 tcg_gen_or_tl(cpu_dspctrl
, cpu_dspctrl
, t1
);
16773 case OPC_CMP_EQ_PH
:
16775 gen_helper_cmp_eq_ph(v1_t
, v2_t
, cpu_env
);
16777 case OPC_CMP_LT_PH
:
16779 gen_helper_cmp_lt_ph(v1_t
, v2_t
, cpu_env
);
16781 case OPC_CMP_LE_PH
:
16783 gen_helper_cmp_le_ph(v1_t
, v2_t
, cpu_env
);
16787 gen_helper_pick_qb(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16791 gen_helper_pick_ph(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16793 case OPC_PACKRL_PH
:
16795 gen_helper_packrl_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
16799 #ifdef TARGET_MIPS64
16800 case OPC_CMPU_EQ_OB_DSP
:
16802 case OPC_CMP_EQ_PW
:
16804 gen_helper_cmp_eq_pw(v1_t
, v2_t
, cpu_env
);
16806 case OPC_CMP_LT_PW
:
16808 gen_helper_cmp_lt_pw(v1_t
, v2_t
, cpu_env
);
16810 case OPC_CMP_LE_PW
:
16812 gen_helper_cmp_le_pw(v1_t
, v2_t
, cpu_env
);
16814 case OPC_CMP_EQ_QH
:
16816 gen_helper_cmp_eq_qh(v1_t
, v2_t
, cpu_env
);
16818 case OPC_CMP_LT_QH
:
16820 gen_helper_cmp_lt_qh(v1_t
, v2_t
, cpu_env
);
16822 case OPC_CMP_LE_QH
:
16824 gen_helper_cmp_le_qh(v1_t
, v2_t
, cpu_env
);
16826 case OPC_CMPGDU_EQ_OB
:
16828 gen_helper_cmpgdu_eq_ob(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16830 case OPC_CMPGDU_LT_OB
:
16832 gen_helper_cmpgdu_lt_ob(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16834 case OPC_CMPGDU_LE_OB
:
16836 gen_helper_cmpgdu_le_ob(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16838 case OPC_CMPGU_EQ_OB
:
16840 gen_helper_cmpgu_eq_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
16842 case OPC_CMPGU_LT_OB
:
16844 gen_helper_cmpgu_lt_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
16846 case OPC_CMPGU_LE_OB
:
16848 gen_helper_cmpgu_le_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
16850 case OPC_CMPU_EQ_OB
:
16852 gen_helper_cmpu_eq_ob(v1_t
, v2_t
, cpu_env
);
16854 case OPC_CMPU_LT_OB
:
16856 gen_helper_cmpu_lt_ob(v1_t
, v2_t
, cpu_env
);
16858 case OPC_CMPU_LE_OB
:
16860 gen_helper_cmpu_le_ob(v1_t
, v2_t
, cpu_env
);
16862 case OPC_PACKRL_PW
:
16864 gen_helper_packrl_pw(cpu_gpr
[ret
], v1_t
, v2_t
);
16868 gen_helper_pick_ob(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16872 gen_helper_pick_pw(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16876 gen_helper_pick_qh(cpu_gpr
[ret
], v1_t
, v2_t
, cpu_env
);
16884 tcg_temp_free(v1_t
);
16885 tcg_temp_free(v2_t
);
16887 (void)opn
; /* avoid a compiler warning */
16888 MIPS_DEBUG("%s", opn
);
16891 static void gen_mipsdsp_append(CPUMIPSState
*env
, DisasContext
*ctx
,
16892 uint32_t op1
, int rt
, int rs
, int sa
)
16894 const char *opn
= "mipsdsp append/dappend";
16900 /* Treat as NOP. */
16905 t0
= tcg_temp_new();
16906 gen_load_gpr(t0
, rs
);
16909 case OPC_APPEND_DSP
:
16910 switch (MASK_APPEND(ctx
->opcode
)) {
16913 tcg_gen_deposit_tl(cpu_gpr
[rt
], t0
, cpu_gpr
[rt
], sa
, 32 - sa
);
16915 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
16919 tcg_gen_ext32u_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
16920 tcg_gen_shri_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], sa
);
16921 tcg_gen_shli_tl(t0
, t0
, 32 - sa
);
16922 tcg_gen_or_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], t0
);
16924 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
16928 if (sa
!= 0 && sa
!= 2) {
16929 tcg_gen_shli_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], 8 * sa
);
16930 tcg_gen_ext32u_tl(t0
, t0
);
16931 tcg_gen_shri_tl(t0
, t0
, 8 * (4 - sa
));
16932 tcg_gen_or_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], t0
);
16934 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
16936 default: /* Invalid */
16937 MIPS_INVAL("MASK APPEND");
16938 generate_exception(ctx
, EXCP_RI
);
16942 #ifdef TARGET_MIPS64
16943 case OPC_DAPPEND_DSP
:
16944 switch (MASK_DAPPEND(ctx
->opcode
)) {
16947 tcg_gen_deposit_tl(cpu_gpr
[rt
], t0
, cpu_gpr
[rt
], sa
, 64 - sa
);
16951 tcg_gen_shri_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], 0x20 | sa
);
16952 tcg_gen_shli_tl(t0
, t0
, 64 - (0x20 | sa
));
16953 tcg_gen_or_tl(cpu_gpr
[rt
], t0
, t0
);
16957 tcg_gen_shri_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], sa
);
16958 tcg_gen_shli_tl(t0
, t0
, 64 - sa
);
16959 tcg_gen_or_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], t0
);
16964 if (sa
!= 0 && sa
!= 2 && sa
!= 4) {
16965 tcg_gen_shli_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], 8 * sa
);
16966 tcg_gen_shri_tl(t0
, t0
, 8 * (8 - sa
));
16967 tcg_gen_or_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], t0
);
16970 default: /* Invalid */
16971 MIPS_INVAL("MASK DAPPEND");
16972 generate_exception(ctx
, EXCP_RI
);
16979 (void)opn
; /* avoid a compiler warning */
16980 MIPS_DEBUG("%s", opn
);
16983 static void gen_mipsdsp_accinsn(DisasContext
*ctx
, uint32_t op1
, uint32_t op2
,
16984 int ret
, int v1
, int v2
, int check_ret
)
16987 const char *opn
= "mipsdsp accumulator";
16994 if ((ret
== 0) && (check_ret
== 1)) {
16995 /* Treat as NOP. */
17000 t0
= tcg_temp_new();
17001 t1
= tcg_temp_new();
17002 v1_t
= tcg_temp_new();
17003 v2_t
= tcg_temp_new();
17005 gen_load_gpr(v1_t
, v1
);
17006 gen_load_gpr(v2_t
, v2
);
17009 case OPC_EXTR_W_DSP
:
17013 tcg_gen_movi_tl(t0
, v2
);
17014 tcg_gen_movi_tl(t1
, v1
);
17015 gen_helper_extr_w(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17018 tcg_gen_movi_tl(t0
, v2
);
17019 tcg_gen_movi_tl(t1
, v1
);
17020 gen_helper_extr_r_w(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17022 case OPC_EXTR_RS_W
:
17023 tcg_gen_movi_tl(t0
, v2
);
17024 tcg_gen_movi_tl(t1
, v1
);
17025 gen_helper_extr_rs_w(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17028 tcg_gen_movi_tl(t0
, v2
);
17029 tcg_gen_movi_tl(t1
, v1
);
17030 gen_helper_extr_s_h(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17032 case OPC_EXTRV_S_H
:
17033 tcg_gen_movi_tl(t0
, v2
);
17034 gen_helper_extr_s_h(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17037 tcg_gen_movi_tl(t0
, v2
);
17038 gen_helper_extr_w(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17040 case OPC_EXTRV_R_W
:
17041 tcg_gen_movi_tl(t0
, v2
);
17042 gen_helper_extr_r_w(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17044 case OPC_EXTRV_RS_W
:
17045 tcg_gen_movi_tl(t0
, v2
);
17046 gen_helper_extr_rs_w(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17049 tcg_gen_movi_tl(t0
, v2
);
17050 tcg_gen_movi_tl(t1
, v1
);
17051 gen_helper_extp(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17054 tcg_gen_movi_tl(t0
, v2
);
17055 gen_helper_extp(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17058 tcg_gen_movi_tl(t0
, v2
);
17059 tcg_gen_movi_tl(t1
, v1
);
17060 gen_helper_extpdp(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17063 tcg_gen_movi_tl(t0
, v2
);
17064 gen_helper_extpdp(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17067 imm
= (ctx
->opcode
>> 20) & 0x3F;
17068 tcg_gen_movi_tl(t0
, ret
);
17069 tcg_gen_movi_tl(t1
, imm
);
17070 gen_helper_shilo(t0
, t1
, cpu_env
);
17073 tcg_gen_movi_tl(t0
, ret
);
17074 gen_helper_shilo(t0
, v1_t
, cpu_env
);
17077 tcg_gen_movi_tl(t0
, ret
);
17078 gen_helper_mthlip(t0
, v1_t
, cpu_env
);
17081 imm
= (ctx
->opcode
>> 11) & 0x3FF;
17082 tcg_gen_movi_tl(t0
, imm
);
17083 gen_helper_wrdsp(v1_t
, t0
, cpu_env
);
17086 imm
= (ctx
->opcode
>> 16) & 0x03FF;
17087 tcg_gen_movi_tl(t0
, imm
);
17088 gen_helper_rddsp(cpu_gpr
[ret
], t0
, cpu_env
);
17092 #ifdef TARGET_MIPS64
17093 case OPC_DEXTR_W_DSP
:
17097 tcg_gen_movi_tl(t0
, ret
);
17098 gen_helper_dmthlip(v1_t
, t0
, cpu_env
);
17102 int shift
= (ctx
->opcode
>> 19) & 0x7F;
17103 int ac
= (ctx
->opcode
>> 11) & 0x03;
17104 tcg_gen_movi_tl(t0
, shift
);
17105 tcg_gen_movi_tl(t1
, ac
);
17106 gen_helper_dshilo(t0
, t1
, cpu_env
);
17111 int ac
= (ctx
->opcode
>> 11) & 0x03;
17112 tcg_gen_movi_tl(t0
, ac
);
17113 gen_helper_dshilo(v1_t
, t0
, cpu_env
);
17117 tcg_gen_movi_tl(t0
, v2
);
17118 tcg_gen_movi_tl(t1
, v1
);
17120 gen_helper_dextp(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17123 tcg_gen_movi_tl(t0
, v2
);
17124 gen_helper_dextp(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17127 tcg_gen_movi_tl(t0
, v2
);
17128 tcg_gen_movi_tl(t1
, v1
);
17129 gen_helper_dextpdp(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17132 tcg_gen_movi_tl(t0
, v2
);
17133 gen_helper_dextpdp(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17136 tcg_gen_movi_tl(t0
, v2
);
17137 tcg_gen_movi_tl(t1
, v1
);
17138 gen_helper_dextr_l(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17140 case OPC_DEXTR_R_L
:
17141 tcg_gen_movi_tl(t0
, v2
);
17142 tcg_gen_movi_tl(t1
, v1
);
17143 gen_helper_dextr_r_l(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17145 case OPC_DEXTR_RS_L
:
17146 tcg_gen_movi_tl(t0
, v2
);
17147 tcg_gen_movi_tl(t1
, v1
);
17148 gen_helper_dextr_rs_l(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17151 tcg_gen_movi_tl(t0
, v2
);
17152 tcg_gen_movi_tl(t1
, v1
);
17153 gen_helper_dextr_w(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17155 case OPC_DEXTR_R_W
:
17156 tcg_gen_movi_tl(t0
, v2
);
17157 tcg_gen_movi_tl(t1
, v1
);
17158 gen_helper_dextr_r_w(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17160 case OPC_DEXTR_RS_W
:
17161 tcg_gen_movi_tl(t0
, v2
);
17162 tcg_gen_movi_tl(t1
, v1
);
17163 gen_helper_dextr_rs_w(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17165 case OPC_DEXTR_S_H
:
17166 tcg_gen_movi_tl(t0
, v2
);
17167 tcg_gen_movi_tl(t1
, v1
);
17168 gen_helper_dextr_s_h(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17170 case OPC_DEXTRV_S_H
:
17171 tcg_gen_movi_tl(t0
, v2
);
17172 tcg_gen_movi_tl(t1
, v1
);
17173 gen_helper_dextr_s_h(cpu_gpr
[ret
], t0
, t1
, cpu_env
);
17176 tcg_gen_movi_tl(t0
, v2
);
17177 gen_helper_dextr_l(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17179 case OPC_DEXTRV_R_L
:
17180 tcg_gen_movi_tl(t0
, v2
);
17181 gen_helper_dextr_r_l(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17183 case OPC_DEXTRV_RS_L
:
17184 tcg_gen_movi_tl(t0
, v2
);
17185 gen_helper_dextr_rs_l(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17188 tcg_gen_movi_tl(t0
, v2
);
17189 gen_helper_dextr_w(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17191 case OPC_DEXTRV_R_W
:
17192 tcg_gen_movi_tl(t0
, v2
);
17193 gen_helper_dextr_r_w(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17195 case OPC_DEXTRV_RS_W
:
17196 tcg_gen_movi_tl(t0
, v2
);
17197 gen_helper_dextr_rs_w(cpu_gpr
[ret
], t0
, v1_t
, cpu_env
);
17206 tcg_temp_free(v1_t
);
17207 tcg_temp_free(v2_t
);
17209 (void)opn
; /* avoid a compiler warning */
17210 MIPS_DEBUG("%s", opn
);
17213 /* End MIPSDSP functions. */
17215 static void decode_opc_special_r6(CPUMIPSState
*env
, DisasContext
*ctx
)
17217 int rs
, rt
, rd
, sa
;
17220 rs
= (ctx
->opcode
>> 21) & 0x1f;
17221 rt
= (ctx
->opcode
>> 16) & 0x1f;
17222 rd
= (ctx
->opcode
>> 11) & 0x1f;
17223 sa
= (ctx
->opcode
>> 6) & 0x1f;
17225 op1
= MASK_SPECIAL(ctx
->opcode
);
17228 gen_lsa(ctx
, op1
, rd
, rs
, rt
, extract32(ctx
->opcode
, 6, 2));
17230 case OPC_MULT
... OPC_DIVU
:
17231 op2
= MASK_R6_MULDIV(ctx
->opcode
);
17241 gen_r6_muldiv(ctx
, op2
, rd
, rs
, rt
);
17244 MIPS_INVAL("special_r6 muldiv");
17245 generate_exception(ctx
, EXCP_RI
);
17251 gen_cond_move(ctx
, op1
, rd
, rs
, rt
);
17255 if (rt
== 0 && sa
== 1) {
17256 /* Major opcode and function field is shared with preR6 MFHI/MTHI.
17257 We need additionally to check other fields */
17258 gen_cl(ctx
, op1
, rd
, rs
);
17260 generate_exception(ctx
, EXCP_RI
);
17264 if (is_uhi(extract32(ctx
->opcode
, 6, 20))) {
17265 gen_helper_do_semihosting(cpu_env
);
17267 if (ctx
->hflags
& MIPS_HFLAG_SBRI
) {
17268 generate_exception(ctx
, EXCP_RI
);
17270 generate_exception(ctx
, EXCP_DBp
);
17274 #if defined(TARGET_MIPS64)
17276 check_mips_64(ctx
);
17277 gen_lsa(ctx
, op1
, rd
, rs
, rt
, extract32(ctx
->opcode
, 6, 2));
17281 if (rt
== 0 && sa
== 1) {
17282 /* Major opcode and function field is shared with preR6 MFHI/MTHI.
17283 We need additionally to check other fields */
17284 check_mips_64(ctx
);
17285 gen_cl(ctx
, op1
, rd
, rs
);
17287 generate_exception(ctx
, EXCP_RI
);
17290 case OPC_DMULT
... OPC_DDIVU
:
17291 op2
= MASK_R6_MULDIV(ctx
->opcode
);
17301 check_mips_64(ctx
);
17302 gen_r6_muldiv(ctx
, op2
, rd
, rs
, rt
);
17305 MIPS_INVAL("special_r6 muldiv");
17306 generate_exception(ctx
, EXCP_RI
);
17311 default: /* Invalid */
17312 MIPS_INVAL("special_r6");
17313 generate_exception(ctx
, EXCP_RI
);
17318 static void decode_opc_special_legacy(CPUMIPSState
*env
, DisasContext
*ctx
)
17320 int rs
, rt
, rd
, sa
;
17323 rs
= (ctx
->opcode
>> 21) & 0x1f;
17324 rt
= (ctx
->opcode
>> 16) & 0x1f;
17325 rd
= (ctx
->opcode
>> 11) & 0x1f;
17326 sa
= (ctx
->opcode
>> 6) & 0x1f;
17328 op1
= MASK_SPECIAL(ctx
->opcode
);
17330 case OPC_MOVN
: /* Conditional move */
17332 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS32
|
17333 INSN_LOONGSON2E
| INSN_LOONGSON2F
);
17334 gen_cond_move(ctx
, op1
, rd
, rs
, rt
);
17336 case OPC_MFHI
: /* Move from HI/LO */
17338 gen_HILO(ctx
, op1
, rs
& 3, rd
);
17341 case OPC_MTLO
: /* Move to HI/LO */
17342 gen_HILO(ctx
, op1
, rd
& 3, rs
);
17345 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS32
);
17346 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
17347 check_cp1_enabled(ctx
);
17348 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
17349 (ctx
->opcode
>> 16) & 1);
17351 generate_exception_err(ctx
, EXCP_CpU
, 1);
17357 check_insn(ctx
, INSN_VR54XX
);
17358 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
17359 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
17361 gen_muldiv(ctx
, op1
, rd
& 3, rs
, rt
);
17366 gen_muldiv(ctx
, op1
, 0, rs
, rt
);
17368 #if defined(TARGET_MIPS64)
17369 case OPC_DMULT
... OPC_DDIVU
:
17370 check_insn(ctx
, ISA_MIPS3
);
17371 check_mips_64(ctx
);
17372 gen_muldiv(ctx
, op1
, 0, rs
, rt
);
17376 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
, 4);
17379 #ifdef MIPS_STRICT_STANDARD
17380 MIPS_INVAL("SPIM");
17381 generate_exception(ctx
, EXCP_RI
);
17383 /* Implemented as RI exception for now. */
17384 MIPS_INVAL("spim (unofficial)");
17385 generate_exception(ctx
, EXCP_RI
);
17388 default: /* Invalid */
17389 MIPS_INVAL("special_legacy");
17390 generate_exception(ctx
, EXCP_RI
);
17395 static void decode_opc_special(CPUMIPSState
*env
, DisasContext
*ctx
)
17397 int rs
, rt
, rd
, sa
;
17400 rs
= (ctx
->opcode
>> 21) & 0x1f;
17401 rt
= (ctx
->opcode
>> 16) & 0x1f;
17402 rd
= (ctx
->opcode
>> 11) & 0x1f;
17403 sa
= (ctx
->opcode
>> 6) & 0x1f;
17405 op1
= MASK_SPECIAL(ctx
->opcode
);
17407 case OPC_SLL
: /* Shift with immediate */
17408 if (sa
== 5 && rd
== 0 &&
17409 rs
== 0 && rt
== 0) { /* PAUSE */
17410 if ((ctx
->insn_flags
& ISA_MIPS32R6
) &&
17411 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
17412 MIPS_DEBUG("CTI in delay / forbidden slot");
17413 generate_exception(ctx
, EXCP_RI
);
17419 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
17422 switch ((ctx
->opcode
>> 21) & 0x1f) {
17424 /* rotr is decoded as srl on non-R2 CPUs */
17425 if (ctx
->insn_flags
& ISA_MIPS32R2
) {
17430 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
17433 generate_exception(ctx
, EXCP_RI
);
17437 case OPC_ADD
... OPC_SUBU
:
17438 gen_arith(ctx
, op1
, rd
, rs
, rt
);
17440 case OPC_SLLV
: /* Shifts */
17442 gen_shift(ctx
, op1
, rd
, rs
, rt
);
17445 switch ((ctx
->opcode
>> 6) & 0x1f) {
17447 /* rotrv is decoded as srlv on non-R2 CPUs */
17448 if (ctx
->insn_flags
& ISA_MIPS32R2
) {
17453 gen_shift(ctx
, op1
, rd
, rs
, rt
);
17456 generate_exception(ctx
, EXCP_RI
);
17460 case OPC_SLT
: /* Set on less than */
17462 gen_slt(ctx
, op1
, rd
, rs
, rt
);
17464 case OPC_AND
: /* Logic*/
17468 gen_logic(ctx
, op1
, rd
, rs
, rt
);
17471 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
, 4);
17473 case OPC_TGE
... OPC_TEQ
: /* Traps */
17475 check_insn(ctx
, ISA_MIPS2
);
17476 gen_trap(ctx
, op1
, rs
, rt
, -1);
17478 case OPC_LSA
: /* OPC_PMON */
17479 if ((ctx
->insn_flags
& ISA_MIPS32R6
) ||
17480 (env
->CP0_Config3
& (1 << CP0C3_MSAP
))) {
17481 decode_opc_special_r6(env
, ctx
);
17483 /* Pmon entry point, also R4010 selsl */
17484 #ifdef MIPS_STRICT_STANDARD
17485 MIPS_INVAL("PMON / selsl");
17486 generate_exception(ctx
, EXCP_RI
);
17488 gen_helper_0e0i(pmon
, sa
);
17493 generate_exception(ctx
, EXCP_SYSCALL
);
17494 ctx
->bstate
= BS_STOP
;
17497 generate_exception(ctx
, EXCP_BREAK
);
17500 check_insn(ctx
, ISA_MIPS2
);
17501 /* Treat as NOP. */
17504 #if defined(TARGET_MIPS64)
17505 /* MIPS64 specific opcodes */
17510 check_insn(ctx
, ISA_MIPS3
);
17511 check_mips_64(ctx
);
17512 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
17515 switch ((ctx
->opcode
>> 21) & 0x1f) {
17517 /* drotr is decoded as dsrl on non-R2 CPUs */
17518 if (ctx
->insn_flags
& ISA_MIPS32R2
) {
17523 check_insn(ctx
, ISA_MIPS3
);
17524 check_mips_64(ctx
);
17525 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
17528 generate_exception(ctx
, EXCP_RI
);
17533 switch ((ctx
->opcode
>> 21) & 0x1f) {
17535 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
17536 if (ctx
->insn_flags
& ISA_MIPS32R2
) {
17541 check_insn(ctx
, ISA_MIPS3
);
17542 check_mips_64(ctx
);
17543 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
17546 generate_exception(ctx
, EXCP_RI
);
17550 case OPC_DADD
... OPC_DSUBU
:
17551 check_insn(ctx
, ISA_MIPS3
);
17552 check_mips_64(ctx
);
17553 gen_arith(ctx
, op1
, rd
, rs
, rt
);
17557 check_insn(ctx
, ISA_MIPS3
);
17558 check_mips_64(ctx
);
17559 gen_shift(ctx
, op1
, rd
, rs
, rt
);
17562 switch ((ctx
->opcode
>> 6) & 0x1f) {
17564 /* drotrv is decoded as dsrlv on non-R2 CPUs */
17565 if (ctx
->insn_flags
& ISA_MIPS32R2
) {
17570 check_insn(ctx
, ISA_MIPS3
);
17571 check_mips_64(ctx
);
17572 gen_shift(ctx
, op1
, rd
, rs
, rt
);
17575 generate_exception(ctx
, EXCP_RI
);
17580 if ((ctx
->insn_flags
& ISA_MIPS32R6
) ||
17581 (env
->CP0_Config3
& (1 << CP0C3_MSAP
))) {
17582 decode_opc_special_r6(env
, ctx
);
17587 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
17588 decode_opc_special_r6(env
, ctx
);
17590 decode_opc_special_legacy(env
, ctx
);
17595 static void decode_opc_special2_legacy(CPUMIPSState
*env
, DisasContext
*ctx
)
17600 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
17602 rs
= (ctx
->opcode
>> 21) & 0x1f;
17603 rt
= (ctx
->opcode
>> 16) & 0x1f;
17604 rd
= (ctx
->opcode
>> 11) & 0x1f;
17606 op1
= MASK_SPECIAL2(ctx
->opcode
);
17608 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
17609 case OPC_MSUB
... OPC_MSUBU
:
17610 check_insn(ctx
, ISA_MIPS32
);
17611 gen_muldiv(ctx
, op1
, rd
& 3, rs
, rt
);
17614 gen_arith(ctx
, op1
, rd
, rs
, rt
);
17617 case OPC_DIVU_G_2F
:
17618 case OPC_MULT_G_2F
:
17619 case OPC_MULTU_G_2F
:
17621 case OPC_MODU_G_2F
:
17622 check_insn(ctx
, INSN_LOONGSON2F
);
17623 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
17627 check_insn(ctx
, ISA_MIPS32
);
17628 gen_cl(ctx
, op1
, rd
, rs
);
17631 if (is_uhi(extract32(ctx
->opcode
, 6, 20))) {
17632 gen_helper_do_semihosting(cpu_env
);
17634 /* XXX: not clear which exception should be raised
17635 * when in debug mode...
17637 check_insn(ctx
, ISA_MIPS32
);
17638 generate_exception(ctx
, EXCP_DBp
);
17641 #if defined(TARGET_MIPS64)
17644 check_insn(ctx
, ISA_MIPS64
);
17645 check_mips_64(ctx
);
17646 gen_cl(ctx
, op1
, rd
, rs
);
17648 case OPC_DMULT_G_2F
:
17649 case OPC_DMULTU_G_2F
:
17650 case OPC_DDIV_G_2F
:
17651 case OPC_DDIVU_G_2F
:
17652 case OPC_DMOD_G_2F
:
17653 case OPC_DMODU_G_2F
:
17654 check_insn(ctx
, INSN_LOONGSON2F
);
17655 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
17658 default: /* Invalid */
17659 MIPS_INVAL("special2_legacy");
17660 generate_exception(ctx
, EXCP_RI
);
17665 static void decode_opc_special3_r6(CPUMIPSState
*env
, DisasContext
*ctx
)
17667 int rs
, rt
, rd
, sa
;
17671 rs
= (ctx
->opcode
>> 21) & 0x1f;
17672 rt
= (ctx
->opcode
>> 16) & 0x1f;
17673 rd
= (ctx
->opcode
>> 11) & 0x1f;
17674 sa
= (ctx
->opcode
>> 6) & 0x1f;
17675 imm
= (int16_t)ctx
->opcode
>> 7;
17677 op1
= MASK_SPECIAL3(ctx
->opcode
);
17681 /* hint codes 24-31 are reserved and signal RI */
17682 generate_exception(ctx
, EXCP_RI
);
17684 /* Treat as NOP. */
17687 /* Treat as NOP. */
17690 gen_st_cond(ctx
, op1
, rt
, rs
, imm
);
17693 gen_ld(ctx
, op1
, rt
, rs
, imm
);
17698 /* Treat as NOP. */
17701 op2
= MASK_BSHFL(ctx
->opcode
);
17703 case OPC_ALIGN
... OPC_ALIGN_END
:
17704 gen_align(ctx
, OPC_ALIGN
, rd
, rs
, rt
, sa
& 3);
17707 gen_bitswap(ctx
, op2
, rd
, rt
);
17712 #if defined(TARGET_MIPS64)
17714 gen_st_cond(ctx
, op1
, rt
, rs
, imm
);
17717 gen_ld(ctx
, op1
, rt
, rs
, imm
);
17720 check_mips_64(ctx
);
17723 /* Treat as NOP. */
17726 op2
= MASK_DBSHFL(ctx
->opcode
);
17728 case OPC_DALIGN
... OPC_DALIGN_END
:
17729 gen_align(ctx
, OPC_DALIGN
, rd
, rs
, rt
, sa
& 7);
17732 gen_bitswap(ctx
, op2
, rd
, rt
);
17739 default: /* Invalid */
17740 MIPS_INVAL("special3_r6");
17741 generate_exception(ctx
, EXCP_RI
);
17746 static void decode_opc_special3_legacy(CPUMIPSState
*env
, DisasContext
*ctx
)
17751 rs
= (ctx
->opcode
>> 21) & 0x1f;
17752 rt
= (ctx
->opcode
>> 16) & 0x1f;
17753 rd
= (ctx
->opcode
>> 11) & 0x1f;
17755 op1
= MASK_SPECIAL3(ctx
->opcode
);
17757 case OPC_DIV_G_2E
... OPC_DIVU_G_2E
:
17758 case OPC_MOD_G_2E
... OPC_MODU_G_2E
:
17759 case OPC_MULT_G_2E
... OPC_MULTU_G_2E
:
17760 /* OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have
17761 * the same mask and op1. */
17762 if ((ctx
->insn_flags
& ASE_DSPR2
) && (op1
== OPC_MULT_G_2E
)) {
17763 op2
= MASK_ADDUH_QB(ctx
->opcode
);
17766 case OPC_ADDUH_R_QB
:
17768 case OPC_ADDQH_R_PH
:
17770 case OPC_ADDQH_R_W
:
17772 case OPC_SUBUH_R_QB
:
17774 case OPC_SUBQH_R_PH
:
17776 case OPC_SUBQH_R_W
:
17777 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
17782 case OPC_MULQ_RS_W
:
17783 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
17786 MIPS_INVAL("MASK ADDUH.QB");
17787 generate_exception(ctx
, EXCP_RI
);
17790 } else if (ctx
->insn_flags
& INSN_LOONGSON2E
) {
17791 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
17793 generate_exception(ctx
, EXCP_RI
);
17797 op2
= MASK_LX(ctx
->opcode
);
17799 #if defined(TARGET_MIPS64)
17805 gen_mipsdsp_ld(ctx
, op2
, rd
, rs
, rt
);
17807 default: /* Invalid */
17808 MIPS_INVAL("MASK LX");
17809 generate_exception(ctx
, EXCP_RI
);
17813 case OPC_ABSQ_S_PH_DSP
:
17814 op2
= MASK_ABSQ_S_PH(ctx
->opcode
);
17816 case OPC_ABSQ_S_QB
:
17817 case OPC_ABSQ_S_PH
:
17819 case OPC_PRECEQ_W_PHL
:
17820 case OPC_PRECEQ_W_PHR
:
17821 case OPC_PRECEQU_PH_QBL
:
17822 case OPC_PRECEQU_PH_QBR
:
17823 case OPC_PRECEQU_PH_QBLA
:
17824 case OPC_PRECEQU_PH_QBRA
:
17825 case OPC_PRECEU_PH_QBL
:
17826 case OPC_PRECEU_PH_QBR
:
17827 case OPC_PRECEU_PH_QBLA
:
17828 case OPC_PRECEU_PH_QBRA
:
17829 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
17836 gen_mipsdsp_bitinsn(ctx
, op1
, op2
, rd
, rt
);
17839 MIPS_INVAL("MASK ABSQ_S.PH");
17840 generate_exception(ctx
, EXCP_RI
);
17844 case OPC_ADDU_QB_DSP
:
17845 op2
= MASK_ADDU_QB(ctx
->opcode
);
17848 case OPC_ADDQ_S_PH
:
17851 case OPC_ADDU_S_QB
:
17853 case OPC_ADDU_S_PH
:
17855 case OPC_SUBQ_S_PH
:
17858 case OPC_SUBU_S_QB
:
17860 case OPC_SUBU_S_PH
:
17864 case OPC_RADDU_W_QB
:
17865 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
17867 case OPC_MULEU_S_PH_QBL
:
17868 case OPC_MULEU_S_PH_QBR
:
17869 case OPC_MULQ_RS_PH
:
17870 case OPC_MULEQ_S_W_PHL
:
17871 case OPC_MULEQ_S_W_PHR
:
17872 case OPC_MULQ_S_PH
:
17873 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
17875 default: /* Invalid */
17876 MIPS_INVAL("MASK ADDU.QB");
17877 generate_exception(ctx
, EXCP_RI
);
17882 case OPC_CMPU_EQ_QB_DSP
:
17883 op2
= MASK_CMPU_EQ_QB(ctx
->opcode
);
17885 case OPC_PRECR_SRA_PH_W
:
17886 case OPC_PRECR_SRA_R_PH_W
:
17887 gen_mipsdsp_arith(ctx
, op1
, op2
, rt
, rs
, rd
);
17889 case OPC_PRECR_QB_PH
:
17890 case OPC_PRECRQ_QB_PH
:
17891 case OPC_PRECRQ_PH_W
:
17892 case OPC_PRECRQ_RS_PH_W
:
17893 case OPC_PRECRQU_S_QB_PH
:
17894 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
17896 case OPC_CMPU_EQ_QB
:
17897 case OPC_CMPU_LT_QB
:
17898 case OPC_CMPU_LE_QB
:
17899 case OPC_CMP_EQ_PH
:
17900 case OPC_CMP_LT_PH
:
17901 case OPC_CMP_LE_PH
:
17902 gen_mipsdsp_add_cmp_pick(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
17904 case OPC_CMPGU_EQ_QB
:
17905 case OPC_CMPGU_LT_QB
:
17906 case OPC_CMPGU_LE_QB
:
17907 case OPC_CMPGDU_EQ_QB
:
17908 case OPC_CMPGDU_LT_QB
:
17909 case OPC_CMPGDU_LE_QB
:
17912 case OPC_PACKRL_PH
:
17913 gen_mipsdsp_add_cmp_pick(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
17915 default: /* Invalid */
17916 MIPS_INVAL("MASK CMPU.EQ.QB");
17917 generate_exception(ctx
, EXCP_RI
);
17921 case OPC_SHLL_QB_DSP
:
17922 gen_mipsdsp_shift(ctx
, op1
, rd
, rs
, rt
);
17924 case OPC_DPA_W_PH_DSP
:
17925 op2
= MASK_DPA_W_PH(ctx
->opcode
);
17927 case OPC_DPAU_H_QBL
:
17928 case OPC_DPAU_H_QBR
:
17929 case OPC_DPSU_H_QBL
:
17930 case OPC_DPSU_H_QBR
:
17932 case OPC_DPAX_W_PH
:
17933 case OPC_DPAQ_S_W_PH
:
17934 case OPC_DPAQX_S_W_PH
:
17935 case OPC_DPAQX_SA_W_PH
:
17937 case OPC_DPSX_W_PH
:
17938 case OPC_DPSQ_S_W_PH
:
17939 case OPC_DPSQX_S_W_PH
:
17940 case OPC_DPSQX_SA_W_PH
:
17941 case OPC_MULSAQ_S_W_PH
:
17942 case OPC_DPAQ_SA_L_W
:
17943 case OPC_DPSQ_SA_L_W
:
17944 case OPC_MAQ_S_W_PHL
:
17945 case OPC_MAQ_S_W_PHR
:
17946 case OPC_MAQ_SA_W_PHL
:
17947 case OPC_MAQ_SA_W_PHR
:
17948 case OPC_MULSA_W_PH
:
17949 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
17951 default: /* Invalid */
17952 MIPS_INVAL("MASK DPAW.PH");
17953 generate_exception(ctx
, EXCP_RI
);
17958 op2
= MASK_INSV(ctx
->opcode
);
17970 t0
= tcg_temp_new();
17971 t1
= tcg_temp_new();
17973 gen_load_gpr(t0
, rt
);
17974 gen_load_gpr(t1
, rs
);
17976 gen_helper_insv(cpu_gpr
[rt
], cpu_env
, t1
, t0
);
17982 default: /* Invalid */
17983 MIPS_INVAL("MASK INSV");
17984 generate_exception(ctx
, EXCP_RI
);
17988 case OPC_APPEND_DSP
:
17989 gen_mipsdsp_append(env
, ctx
, op1
, rt
, rs
, rd
);
17991 case OPC_EXTR_W_DSP
:
17992 op2
= MASK_EXTR_W(ctx
->opcode
);
17996 case OPC_EXTR_RS_W
:
17998 case OPC_EXTRV_S_H
:
18000 case OPC_EXTRV_R_W
:
18001 case OPC_EXTRV_RS_W
:
18006 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rt
, rs
, rd
, 1);
18009 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
18015 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
18017 default: /* Invalid */
18018 MIPS_INVAL("MASK EXTR.W");
18019 generate_exception(ctx
, EXCP_RI
);
18023 #if defined(TARGET_MIPS64)
18024 case OPC_DDIV_G_2E
... OPC_DDIVU_G_2E
:
18025 case OPC_DMULT_G_2E
... OPC_DMULTU_G_2E
:
18026 case OPC_DMOD_G_2E
... OPC_DMODU_G_2E
:
18027 check_insn(ctx
, INSN_LOONGSON2E
);
18028 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
18030 case OPC_ABSQ_S_QH_DSP
:
18031 op2
= MASK_ABSQ_S_QH(ctx
->opcode
);
18033 case OPC_PRECEQ_L_PWL
:
18034 case OPC_PRECEQ_L_PWR
:
18035 case OPC_PRECEQ_PW_QHL
:
18036 case OPC_PRECEQ_PW_QHR
:
18037 case OPC_PRECEQ_PW_QHLA
:
18038 case OPC_PRECEQ_PW_QHRA
:
18039 case OPC_PRECEQU_QH_OBL
:
18040 case OPC_PRECEQU_QH_OBR
:
18041 case OPC_PRECEQU_QH_OBLA
:
18042 case OPC_PRECEQU_QH_OBRA
:
18043 case OPC_PRECEU_QH_OBL
:
18044 case OPC_PRECEU_QH_OBR
:
18045 case OPC_PRECEU_QH_OBLA
:
18046 case OPC_PRECEU_QH_OBRA
:
18047 case OPC_ABSQ_S_OB
:
18048 case OPC_ABSQ_S_PW
:
18049 case OPC_ABSQ_S_QH
:
18050 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
18058 gen_mipsdsp_bitinsn(ctx
, op1
, op2
, rd
, rt
);
18060 default: /* Invalid */
18061 MIPS_INVAL("MASK ABSQ_S.QH");
18062 generate_exception(ctx
, EXCP_RI
);
18066 case OPC_ADDU_OB_DSP
:
18067 op2
= MASK_ADDU_OB(ctx
->opcode
);
18069 case OPC_RADDU_L_OB
:
18071 case OPC_SUBQ_S_PW
:
18073 case OPC_SUBQ_S_QH
:
18075 case OPC_SUBU_S_OB
:
18077 case OPC_SUBU_S_QH
:
18079 case OPC_SUBUH_R_OB
:
18081 case OPC_ADDQ_S_PW
:
18083 case OPC_ADDQ_S_QH
:
18085 case OPC_ADDU_S_OB
:
18087 case OPC_ADDU_S_QH
:
18089 case OPC_ADDUH_R_OB
:
18090 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
18092 case OPC_MULEQ_S_PW_QHL
:
18093 case OPC_MULEQ_S_PW_QHR
:
18094 case OPC_MULEU_S_QH_OBL
:
18095 case OPC_MULEU_S_QH_OBR
:
18096 case OPC_MULQ_RS_QH
:
18097 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
18099 default: /* Invalid */
18100 MIPS_INVAL("MASK ADDU.OB");
18101 generate_exception(ctx
, EXCP_RI
);
18105 case OPC_CMPU_EQ_OB_DSP
:
18106 op2
= MASK_CMPU_EQ_OB(ctx
->opcode
);
18108 case OPC_PRECR_SRA_QH_PW
:
18109 case OPC_PRECR_SRA_R_QH_PW
:
18110 /* Return value is rt. */
18111 gen_mipsdsp_arith(ctx
, op1
, op2
, rt
, rs
, rd
);
18113 case OPC_PRECR_OB_QH
:
18114 case OPC_PRECRQ_OB_QH
:
18115 case OPC_PRECRQ_PW_L
:
18116 case OPC_PRECRQ_QH_PW
:
18117 case OPC_PRECRQ_RS_QH_PW
:
18118 case OPC_PRECRQU_S_OB_QH
:
18119 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
18121 case OPC_CMPU_EQ_OB
:
18122 case OPC_CMPU_LT_OB
:
18123 case OPC_CMPU_LE_OB
:
18124 case OPC_CMP_EQ_QH
:
18125 case OPC_CMP_LT_QH
:
18126 case OPC_CMP_LE_QH
:
18127 case OPC_CMP_EQ_PW
:
18128 case OPC_CMP_LT_PW
:
18129 case OPC_CMP_LE_PW
:
18130 gen_mipsdsp_add_cmp_pick(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
18132 case OPC_CMPGDU_EQ_OB
:
18133 case OPC_CMPGDU_LT_OB
:
18134 case OPC_CMPGDU_LE_OB
:
18135 case OPC_CMPGU_EQ_OB
:
18136 case OPC_CMPGU_LT_OB
:
18137 case OPC_CMPGU_LE_OB
:
18138 case OPC_PACKRL_PW
:
18142 gen_mipsdsp_add_cmp_pick(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
18144 default: /* Invalid */
18145 MIPS_INVAL("MASK CMPU_EQ.OB");
18146 generate_exception(ctx
, EXCP_RI
);
18150 case OPC_DAPPEND_DSP
:
18151 gen_mipsdsp_append(env
, ctx
, op1
, rt
, rs
, rd
);
18153 case OPC_DEXTR_W_DSP
:
18154 op2
= MASK_DEXTR_W(ctx
->opcode
);
18161 case OPC_DEXTR_R_L
:
18162 case OPC_DEXTR_RS_L
:
18164 case OPC_DEXTR_R_W
:
18165 case OPC_DEXTR_RS_W
:
18166 case OPC_DEXTR_S_H
:
18168 case OPC_DEXTRV_R_L
:
18169 case OPC_DEXTRV_RS_L
:
18170 case OPC_DEXTRV_S_H
:
18172 case OPC_DEXTRV_R_W
:
18173 case OPC_DEXTRV_RS_W
:
18174 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rt
, rs
, rd
, 1);
18179 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
18181 default: /* Invalid */
18182 MIPS_INVAL("MASK EXTR.W");
18183 generate_exception(ctx
, EXCP_RI
);
18187 case OPC_DPAQ_W_QH_DSP
:
18188 op2
= MASK_DPAQ_W_QH(ctx
->opcode
);
18190 case OPC_DPAU_H_OBL
:
18191 case OPC_DPAU_H_OBR
:
18192 case OPC_DPSU_H_OBL
:
18193 case OPC_DPSU_H_OBR
:
18195 case OPC_DPAQ_S_W_QH
:
18197 case OPC_DPSQ_S_W_QH
:
18198 case OPC_MULSAQ_S_W_QH
:
18199 case OPC_DPAQ_SA_L_PW
:
18200 case OPC_DPSQ_SA_L_PW
:
18201 case OPC_MULSAQ_S_L_PW
:
18202 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
18204 case OPC_MAQ_S_W_QHLL
:
18205 case OPC_MAQ_S_W_QHLR
:
18206 case OPC_MAQ_S_W_QHRL
:
18207 case OPC_MAQ_S_W_QHRR
:
18208 case OPC_MAQ_SA_W_QHLL
:
18209 case OPC_MAQ_SA_W_QHLR
:
18210 case OPC_MAQ_SA_W_QHRL
:
18211 case OPC_MAQ_SA_W_QHRR
:
18212 case OPC_MAQ_S_L_PWL
:
18213 case OPC_MAQ_S_L_PWR
:
18218 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
18220 default: /* Invalid */
18221 MIPS_INVAL("MASK DPAQ.W.QH");
18222 generate_exception(ctx
, EXCP_RI
);
18226 case OPC_DINSV_DSP
:
18227 op2
= MASK_INSV(ctx
->opcode
);
18239 t0
= tcg_temp_new();
18240 t1
= tcg_temp_new();
18242 gen_load_gpr(t0
, rt
);
18243 gen_load_gpr(t1
, rs
);
18245 gen_helper_dinsv(cpu_gpr
[rt
], cpu_env
, t1
, t0
);
18251 default: /* Invalid */
18252 MIPS_INVAL("MASK DINSV");
18253 generate_exception(ctx
, EXCP_RI
);
18257 case OPC_SHLL_OB_DSP
:
18258 gen_mipsdsp_shift(ctx
, op1
, rd
, rs
, rt
);
18261 default: /* Invalid */
18262 MIPS_INVAL("special3_legacy");
18263 generate_exception(ctx
, EXCP_RI
);
18268 static void decode_opc_special3(CPUMIPSState
*env
, DisasContext
*ctx
)
18270 int rs
, rt
, rd
, sa
;
18273 rs
= (ctx
->opcode
>> 21) & 0x1f;
18274 rt
= (ctx
->opcode
>> 16) & 0x1f;
18275 rd
= (ctx
->opcode
>> 11) & 0x1f;
18276 sa
= (ctx
->opcode
>> 6) & 0x1f;
18278 op1
= MASK_SPECIAL3(ctx
->opcode
);
18282 check_insn(ctx
, ISA_MIPS32R2
);
18283 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
18286 op2
= MASK_BSHFL(ctx
->opcode
);
18288 case OPC_ALIGN
... OPC_ALIGN_END
:
18290 check_insn(ctx
, ISA_MIPS32R6
);
18291 decode_opc_special3_r6(env
, ctx
);
18294 check_insn(ctx
, ISA_MIPS32R2
);
18295 gen_bshfl(ctx
, op2
, rt
, rd
);
18299 #if defined(TARGET_MIPS64)
18300 case OPC_DEXTM
... OPC_DEXT
:
18301 case OPC_DINSM
... OPC_DINS
:
18302 check_insn(ctx
, ISA_MIPS64R2
);
18303 check_mips_64(ctx
);
18304 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
18307 op2
= MASK_DBSHFL(ctx
->opcode
);
18309 case OPC_DALIGN
... OPC_DALIGN_END
:
18311 check_insn(ctx
, ISA_MIPS32R6
);
18312 decode_opc_special3_r6(env
, ctx
);
18315 check_insn(ctx
, ISA_MIPS64R2
);
18316 check_mips_64(ctx
);
18317 op2
= MASK_DBSHFL(ctx
->opcode
);
18318 gen_bshfl(ctx
, op2
, rt
, rd
);
18324 gen_rdhwr(ctx
, rt
, rd
);
18327 check_insn(ctx
, ASE_MT
);
18329 TCGv t0
= tcg_temp_new();
18330 TCGv t1
= tcg_temp_new();
18332 gen_load_gpr(t0
, rt
);
18333 gen_load_gpr(t1
, rs
);
18334 gen_helper_fork(t0
, t1
);
18340 check_insn(ctx
, ASE_MT
);
18342 TCGv t0
= tcg_temp_new();
18344 save_cpu_state(ctx
, 1);
18345 gen_load_gpr(t0
, rs
);
18346 gen_helper_yield(t0
, cpu_env
, t0
);
18347 gen_store_gpr(t0
, rd
);
18352 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
18353 decode_opc_special3_r6(env
, ctx
);
18355 decode_opc_special3_legacy(env
, ctx
);
18360 /* MIPS SIMD Architecture (MSA) */
18361 static inline int check_msa_access(DisasContext
*ctx
)
18363 if (unlikely((ctx
->hflags
& MIPS_HFLAG_FPU
) &&
18364 !(ctx
->hflags
& MIPS_HFLAG_F64
))) {
18365 generate_exception(ctx
, EXCP_RI
);
18369 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_MSA
))) {
18370 if (ctx
->insn_flags
& ASE_MSA
) {
18371 generate_exception(ctx
, EXCP_MSADIS
);
18374 generate_exception(ctx
, EXCP_RI
);
18381 static void gen_check_zero_element(TCGv tresult
, uint8_t df
, uint8_t wt
)
18383 /* generates tcg ops to check if any element is 0 */
18384 /* Note this function only works with MSA_WRLEN = 128 */
18385 uint64_t eval_zero_or_big
= 0;
18386 uint64_t eval_big
= 0;
18387 TCGv_i64 t0
= tcg_temp_new_i64();
18388 TCGv_i64 t1
= tcg_temp_new_i64();
18391 eval_zero_or_big
= 0x0101010101010101ULL
;
18392 eval_big
= 0x8080808080808080ULL
;
18395 eval_zero_or_big
= 0x0001000100010001ULL
;
18396 eval_big
= 0x8000800080008000ULL
;
18399 eval_zero_or_big
= 0x0000000100000001ULL
;
18400 eval_big
= 0x8000000080000000ULL
;
18403 eval_zero_or_big
= 0x0000000000000001ULL
;
18404 eval_big
= 0x8000000000000000ULL
;
18407 tcg_gen_subi_i64(t0
, msa_wr_d
[wt
<<1], eval_zero_or_big
);
18408 tcg_gen_andc_i64(t0
, t0
, msa_wr_d
[wt
<<1]);
18409 tcg_gen_andi_i64(t0
, t0
, eval_big
);
18410 tcg_gen_subi_i64(t1
, msa_wr_d
[(wt
<<1)+1], eval_zero_or_big
);
18411 tcg_gen_andc_i64(t1
, t1
, msa_wr_d
[(wt
<<1)+1]);
18412 tcg_gen_andi_i64(t1
, t1
, eval_big
);
18413 tcg_gen_or_i64(t0
, t0
, t1
);
18414 /* if all bits are zero then all elements are not zero */
18415 /* if some bit is non-zero then some element is zero */
18416 tcg_gen_setcondi_i64(TCG_COND_NE
, t0
, t0
, 0);
18417 tcg_gen_trunc_i64_tl(tresult
, t0
);
18418 tcg_temp_free_i64(t0
);
18419 tcg_temp_free_i64(t1
);
18422 static void gen_msa_branch(CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t op1
)
18424 uint8_t df
= (ctx
->opcode
>> 21) & 0x3;
18425 uint8_t wt
= (ctx
->opcode
>> 16) & 0x1f;
18426 int64_t s16
= (int16_t)ctx
->opcode
;
18428 check_msa_access(ctx
);
18430 if (ctx
->insn_flags
& ISA_MIPS32R6
&& ctx
->hflags
& MIPS_HFLAG_BMASK
) {
18431 MIPS_DEBUG("CTI in delay / forbidden slot");
18432 generate_exception(ctx
, EXCP_RI
);
18439 TCGv_i64 t0
= tcg_temp_new_i64();
18440 tcg_gen_or_i64(t0
, msa_wr_d
[wt
<<1], msa_wr_d
[(wt
<<1)+1]);
18441 tcg_gen_setcondi_i64((op1
== OPC_BZ_V
) ?
18442 TCG_COND_EQ
: TCG_COND_NE
, t0
, t0
, 0);
18443 tcg_gen_trunc_i64_tl(bcond
, t0
);
18444 tcg_temp_free_i64(t0
);
18451 gen_check_zero_element(bcond
, df
, wt
);
18457 gen_check_zero_element(bcond
, df
, wt
);
18458 tcg_gen_setcondi_tl(TCG_COND_EQ
, bcond
, bcond
, 0);
18462 ctx
->btarget
= ctx
->pc
+ (s16
<< 2) + 4;
18464 ctx
->hflags
|= MIPS_HFLAG_BC
;
18465 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
18468 static void gen_msa_i8(CPUMIPSState
*env
, DisasContext
*ctx
)
18470 #define MASK_MSA_I8(op) (MASK_MSA_MINOR(op) | (op & (0x03 << 24)))
18471 uint8_t i8
= (ctx
->opcode
>> 16) & 0xff;
18472 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
18473 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
18475 TCGv_i32 twd
= tcg_const_i32(wd
);
18476 TCGv_i32 tws
= tcg_const_i32(ws
);
18477 TCGv_i32 ti8
= tcg_const_i32(i8
);
18479 switch (MASK_MSA_I8(ctx
->opcode
)) {
18481 gen_helper_msa_andi_b(cpu_env
, twd
, tws
, ti8
);
18484 gen_helper_msa_ori_b(cpu_env
, twd
, tws
, ti8
);
18487 gen_helper_msa_nori_b(cpu_env
, twd
, tws
, ti8
);
18490 gen_helper_msa_xori_b(cpu_env
, twd
, tws
, ti8
);
18493 gen_helper_msa_bmnzi_b(cpu_env
, twd
, tws
, ti8
);
18496 gen_helper_msa_bmzi_b(cpu_env
, twd
, tws
, ti8
);
18499 gen_helper_msa_bseli_b(cpu_env
, twd
, tws
, ti8
);
18505 uint8_t df
= (ctx
->opcode
>> 24) & 0x3;
18506 if (df
== DF_DOUBLE
) {
18507 generate_exception(ctx
, EXCP_RI
);
18509 TCGv_i32 tdf
= tcg_const_i32(df
);
18510 gen_helper_msa_shf_df(cpu_env
, tdf
, twd
, tws
, ti8
);
18511 tcg_temp_free_i32(tdf
);
18516 MIPS_INVAL("MSA instruction");
18517 generate_exception(ctx
, EXCP_RI
);
18521 tcg_temp_free_i32(twd
);
18522 tcg_temp_free_i32(tws
);
18523 tcg_temp_free_i32(ti8
);
18526 static void gen_msa_i5(CPUMIPSState
*env
, DisasContext
*ctx
)
18528 #define MASK_MSA_I5(op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))
18529 uint8_t df
= (ctx
->opcode
>> 21) & 0x3;
18530 int8_t s5
= (int8_t) sextract32(ctx
->opcode
, 16, 5);
18531 uint8_t u5
= (ctx
->opcode
>> 16) & 0x1f;
18532 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
18533 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
18535 TCGv_i32 tdf
= tcg_const_i32(df
);
18536 TCGv_i32 twd
= tcg_const_i32(wd
);
18537 TCGv_i32 tws
= tcg_const_i32(ws
);
18538 TCGv_i32 timm
= tcg_temp_new_i32();
18539 tcg_gen_movi_i32(timm
, u5
);
18541 switch (MASK_MSA_I5(ctx
->opcode
)) {
18543 gen_helper_msa_addvi_df(cpu_env
, tdf
, twd
, tws
, timm
);
18546 gen_helper_msa_subvi_df(cpu_env
, tdf
, twd
, tws
, timm
);
18548 case OPC_MAXI_S_df
:
18549 tcg_gen_movi_i32(timm
, s5
);
18550 gen_helper_msa_maxi_s_df(cpu_env
, tdf
, twd
, tws
, timm
);
18552 case OPC_MAXI_U_df
:
18553 gen_helper_msa_maxi_u_df(cpu_env
, tdf
, twd
, tws
, timm
);
18555 case OPC_MINI_S_df
:
18556 tcg_gen_movi_i32(timm
, s5
);
18557 gen_helper_msa_mini_s_df(cpu_env
, tdf
, twd
, tws
, timm
);
18559 case OPC_MINI_U_df
:
18560 gen_helper_msa_mini_u_df(cpu_env
, tdf
, twd
, tws
, timm
);
18563 tcg_gen_movi_i32(timm
, s5
);
18564 gen_helper_msa_ceqi_df(cpu_env
, tdf
, twd
, tws
, timm
);
18566 case OPC_CLTI_S_df
:
18567 tcg_gen_movi_i32(timm
, s5
);
18568 gen_helper_msa_clti_s_df(cpu_env
, tdf
, twd
, tws
, timm
);
18570 case OPC_CLTI_U_df
:
18571 gen_helper_msa_clti_u_df(cpu_env
, tdf
, twd
, tws
, timm
);
18573 case OPC_CLEI_S_df
:
18574 tcg_gen_movi_i32(timm
, s5
);
18575 gen_helper_msa_clei_s_df(cpu_env
, tdf
, twd
, tws
, timm
);
18577 case OPC_CLEI_U_df
:
18578 gen_helper_msa_clei_u_df(cpu_env
, tdf
, twd
, tws
, timm
);
18582 int32_t s10
= sextract32(ctx
->opcode
, 11, 10);
18583 tcg_gen_movi_i32(timm
, s10
);
18584 gen_helper_msa_ldi_df(cpu_env
, tdf
, twd
, timm
);
18588 MIPS_INVAL("MSA instruction");
18589 generate_exception(ctx
, EXCP_RI
);
18593 tcg_temp_free_i32(tdf
);
18594 tcg_temp_free_i32(twd
);
18595 tcg_temp_free_i32(tws
);
18596 tcg_temp_free_i32(timm
);
18599 static void gen_msa_bit(CPUMIPSState
*env
, DisasContext
*ctx
)
18601 #define MASK_MSA_BIT(op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))
18602 uint8_t dfm
= (ctx
->opcode
>> 16) & 0x7f;
18603 uint32_t df
= 0, m
= 0;
18604 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
18605 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
18612 if ((dfm
& 0x40) == 0x00) {
18615 } else if ((dfm
& 0x60) == 0x40) {
18618 } else if ((dfm
& 0x70) == 0x60) {
18621 } else if ((dfm
& 0x78) == 0x70) {
18625 generate_exception(ctx
, EXCP_RI
);
18629 tdf
= tcg_const_i32(df
);
18630 tm
= tcg_const_i32(m
);
18631 twd
= tcg_const_i32(wd
);
18632 tws
= tcg_const_i32(ws
);
18634 switch (MASK_MSA_BIT(ctx
->opcode
)) {
18636 gen_helper_msa_slli_df(cpu_env
, tdf
, twd
, tws
, tm
);
18639 gen_helper_msa_srai_df(cpu_env
, tdf
, twd
, tws
, tm
);
18642 gen_helper_msa_srli_df(cpu_env
, tdf
, twd
, tws
, tm
);
18645 gen_helper_msa_bclri_df(cpu_env
, tdf
, twd
, tws
, tm
);
18648 gen_helper_msa_bseti_df(cpu_env
, tdf
, twd
, tws
, tm
);
18651 gen_helper_msa_bnegi_df(cpu_env
, tdf
, twd
, tws
, tm
);
18653 case OPC_BINSLI_df
:
18654 gen_helper_msa_binsli_df(cpu_env
, tdf
, twd
, tws
, tm
);
18656 case OPC_BINSRI_df
:
18657 gen_helper_msa_binsri_df(cpu_env
, tdf
, twd
, tws
, tm
);
18660 gen_helper_msa_sat_s_df(cpu_env
, tdf
, twd
, tws
, tm
);
18663 gen_helper_msa_sat_u_df(cpu_env
, tdf
, twd
, tws
, tm
);
18666 gen_helper_msa_srari_df(cpu_env
, tdf
, twd
, tws
, tm
);
18669 gen_helper_msa_srlri_df(cpu_env
, tdf
, twd
, tws
, tm
);
18672 MIPS_INVAL("MSA instruction");
18673 generate_exception(ctx
, EXCP_RI
);
18677 tcg_temp_free_i32(tdf
);
18678 tcg_temp_free_i32(tm
);
18679 tcg_temp_free_i32(twd
);
18680 tcg_temp_free_i32(tws
);
18683 static void gen_msa_3r(CPUMIPSState
*env
, DisasContext
*ctx
)
18685 #define MASK_MSA_3R(op) (MASK_MSA_MINOR(op) | (op & (0x7 << 23)))
18686 uint8_t df
= (ctx
->opcode
>> 21) & 0x3;
18687 uint8_t wt
= (ctx
->opcode
>> 16) & 0x1f;
18688 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
18689 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
18691 TCGv_i32 tdf
= tcg_const_i32(df
);
18692 TCGv_i32 twd
= tcg_const_i32(wd
);
18693 TCGv_i32 tws
= tcg_const_i32(ws
);
18694 TCGv_i32 twt
= tcg_const_i32(wt
);
18696 switch (MASK_MSA_3R(ctx
->opcode
)) {
18698 gen_helper_msa_sll_df(cpu_env
, tdf
, twd
, tws
, twt
);
18701 gen_helper_msa_addv_df(cpu_env
, tdf
, twd
, tws
, twt
);
18704 gen_helper_msa_ceq_df(cpu_env
, tdf
, twd
, tws
, twt
);
18707 gen_helper_msa_add_a_df(cpu_env
, tdf
, twd
, tws
, twt
);
18709 case OPC_SUBS_S_df
:
18710 gen_helper_msa_subs_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18713 gen_helper_msa_mulv_df(cpu_env
, tdf
, twd
, tws
, twt
);
18716 gen_helper_msa_sld_df(cpu_env
, tdf
, twd
, tws
, twt
);
18719 gen_helper_msa_vshf_df(cpu_env
, tdf
, twd
, tws
, twt
);
18722 gen_helper_msa_sra_df(cpu_env
, tdf
, twd
, tws
, twt
);
18725 gen_helper_msa_subv_df(cpu_env
, tdf
, twd
, tws
, twt
);
18727 case OPC_ADDS_A_df
:
18728 gen_helper_msa_adds_a_df(cpu_env
, tdf
, twd
, tws
, twt
);
18730 case OPC_SUBS_U_df
:
18731 gen_helper_msa_subs_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18734 gen_helper_msa_maddv_df(cpu_env
, tdf
, twd
, tws
, twt
);
18737 gen_helper_msa_splat_df(cpu_env
, tdf
, twd
, tws
, twt
);
18740 gen_helper_msa_srar_df(cpu_env
, tdf
, twd
, tws
, twt
);
18743 gen_helper_msa_srl_df(cpu_env
, tdf
, twd
, tws
, twt
);
18746 gen_helper_msa_max_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18749 gen_helper_msa_clt_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18751 case OPC_ADDS_S_df
:
18752 gen_helper_msa_adds_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18754 case OPC_SUBSUS_U_df
:
18755 gen_helper_msa_subsus_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18758 gen_helper_msa_msubv_df(cpu_env
, tdf
, twd
, tws
, twt
);
18761 gen_helper_msa_pckev_df(cpu_env
, tdf
, twd
, tws
, twt
);
18764 gen_helper_msa_srlr_df(cpu_env
, tdf
, twd
, tws
, twt
);
18767 gen_helper_msa_bclr_df(cpu_env
, tdf
, twd
, tws
, twt
);
18770 gen_helper_msa_max_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18773 gen_helper_msa_clt_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18775 case OPC_ADDS_U_df
:
18776 gen_helper_msa_adds_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18778 case OPC_SUBSUU_S_df
:
18779 gen_helper_msa_subsuu_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18782 gen_helper_msa_pckod_df(cpu_env
, tdf
, twd
, tws
, twt
);
18785 gen_helper_msa_bset_df(cpu_env
, tdf
, twd
, tws
, twt
);
18788 gen_helper_msa_min_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18791 gen_helper_msa_cle_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18794 gen_helper_msa_ave_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18796 case OPC_ASUB_S_df
:
18797 gen_helper_msa_asub_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18800 gen_helper_msa_div_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18803 gen_helper_msa_ilvl_df(cpu_env
, tdf
, twd
, tws
, twt
);
18806 gen_helper_msa_bneg_df(cpu_env
, tdf
, twd
, tws
, twt
);
18809 gen_helper_msa_min_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18812 gen_helper_msa_cle_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18815 gen_helper_msa_ave_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18817 case OPC_ASUB_U_df
:
18818 gen_helper_msa_asub_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18821 gen_helper_msa_div_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18824 gen_helper_msa_ilvr_df(cpu_env
, tdf
, twd
, tws
, twt
);
18827 gen_helper_msa_binsl_df(cpu_env
, tdf
, twd
, tws
, twt
);
18830 gen_helper_msa_max_a_df(cpu_env
, tdf
, twd
, tws
, twt
);
18832 case OPC_AVER_S_df
:
18833 gen_helper_msa_aver_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18836 gen_helper_msa_mod_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18839 gen_helper_msa_ilvev_df(cpu_env
, tdf
, twd
, tws
, twt
);
18842 gen_helper_msa_binsr_df(cpu_env
, tdf
, twd
, tws
, twt
);
18845 gen_helper_msa_min_a_df(cpu_env
, tdf
, twd
, tws
, twt
);
18847 case OPC_AVER_U_df
:
18848 gen_helper_msa_aver_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18851 gen_helper_msa_mod_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18854 gen_helper_msa_ilvod_df(cpu_env
, tdf
, twd
, tws
, twt
);
18857 case OPC_DOTP_S_df
:
18858 case OPC_DOTP_U_df
:
18859 case OPC_DPADD_S_df
:
18860 case OPC_DPADD_U_df
:
18861 case OPC_DPSUB_S_df
:
18862 case OPC_HADD_S_df
:
18863 case OPC_DPSUB_U_df
:
18864 case OPC_HADD_U_df
:
18865 case OPC_HSUB_S_df
:
18866 case OPC_HSUB_U_df
:
18867 if (df
== DF_BYTE
) {
18868 generate_exception(ctx
, EXCP_RI
);
18870 switch (MASK_MSA_3R(ctx
->opcode
)) {
18871 case OPC_DOTP_S_df
:
18872 gen_helper_msa_dotp_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18874 case OPC_DOTP_U_df
:
18875 gen_helper_msa_dotp_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18877 case OPC_DPADD_S_df
:
18878 gen_helper_msa_dpadd_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18880 case OPC_DPADD_U_df
:
18881 gen_helper_msa_dpadd_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18883 case OPC_DPSUB_S_df
:
18884 gen_helper_msa_dpsub_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18886 case OPC_HADD_S_df
:
18887 gen_helper_msa_hadd_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18889 case OPC_DPSUB_U_df
:
18890 gen_helper_msa_dpsub_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18892 case OPC_HADD_U_df
:
18893 gen_helper_msa_hadd_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18895 case OPC_HSUB_S_df
:
18896 gen_helper_msa_hsub_s_df(cpu_env
, tdf
, twd
, tws
, twt
);
18898 case OPC_HSUB_U_df
:
18899 gen_helper_msa_hsub_u_df(cpu_env
, tdf
, twd
, tws
, twt
);
18904 MIPS_INVAL("MSA instruction");
18905 generate_exception(ctx
, EXCP_RI
);
18908 tcg_temp_free_i32(twd
);
18909 tcg_temp_free_i32(tws
);
18910 tcg_temp_free_i32(twt
);
18911 tcg_temp_free_i32(tdf
);
18914 static void gen_msa_elm_3e(CPUMIPSState
*env
, DisasContext
*ctx
)
18916 #define MASK_MSA_ELM_DF3E(op) (MASK_MSA_MINOR(op) | (op & (0x3FF << 16)))
18917 uint8_t source
= (ctx
->opcode
>> 11) & 0x1f;
18918 uint8_t dest
= (ctx
->opcode
>> 6) & 0x1f;
18919 TCGv telm
= tcg_temp_new();
18920 TCGv_i32 tsr
= tcg_const_i32(source
);
18921 TCGv_i32 tdt
= tcg_const_i32(dest
);
18923 switch (MASK_MSA_ELM_DF3E(ctx
->opcode
)) {
18925 gen_load_gpr(telm
, source
);
18926 gen_helper_msa_ctcmsa(cpu_env
, telm
, tdt
);
18929 gen_helper_msa_cfcmsa(telm
, cpu_env
, tsr
);
18930 gen_store_gpr(telm
, dest
);
18933 gen_helper_msa_move_v(cpu_env
, tdt
, tsr
);
18936 MIPS_INVAL("MSA instruction");
18937 generate_exception(ctx
, EXCP_RI
);
18941 tcg_temp_free(telm
);
18942 tcg_temp_free_i32(tdt
);
18943 tcg_temp_free_i32(tsr
);
18946 static void gen_msa_elm_df(CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t df
,
18949 #define MASK_MSA_ELM(op) (MASK_MSA_MINOR(op) | (op & (0xf << 22)))
18950 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
18951 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
18953 TCGv_i32 tws
= tcg_const_i32(ws
);
18954 TCGv_i32 twd
= tcg_const_i32(wd
);
18955 TCGv_i32 tn
= tcg_const_i32(n
);
18956 TCGv_i32 tdf
= tcg_const_i32(df
);
18958 switch (MASK_MSA_ELM(ctx
->opcode
)) {
18960 gen_helper_msa_sldi_df(cpu_env
, tdf
, twd
, tws
, tn
);
18962 case OPC_SPLATI_df
:
18963 gen_helper_msa_splati_df(cpu_env
, tdf
, twd
, tws
, tn
);
18966 gen_helper_msa_insve_df(cpu_env
, tdf
, twd
, tws
, tn
);
18968 case OPC_COPY_S_df
:
18969 case OPC_COPY_U_df
:
18970 case OPC_INSERT_df
:
18971 #if !defined(TARGET_MIPS64)
18972 /* Double format valid only for MIPS64 */
18973 if (df
== DF_DOUBLE
) {
18974 generate_exception(ctx
, EXCP_RI
);
18978 switch (MASK_MSA_ELM(ctx
->opcode
)) {
18979 case OPC_COPY_S_df
:
18980 gen_helper_msa_copy_s_df(cpu_env
, tdf
, twd
, tws
, tn
);
18982 case OPC_COPY_U_df
:
18983 gen_helper_msa_copy_u_df(cpu_env
, tdf
, twd
, tws
, tn
);
18985 case OPC_INSERT_df
:
18986 gen_helper_msa_insert_df(cpu_env
, tdf
, twd
, tws
, tn
);
18991 MIPS_INVAL("MSA instruction");
18992 generate_exception(ctx
, EXCP_RI
);
18994 tcg_temp_free_i32(twd
);
18995 tcg_temp_free_i32(tws
);
18996 tcg_temp_free_i32(tn
);
18997 tcg_temp_free_i32(tdf
);
19000 static void gen_msa_elm(CPUMIPSState
*env
, DisasContext
*ctx
)
19002 uint8_t dfn
= (ctx
->opcode
>> 16) & 0x3f;
19003 uint32_t df
= 0, n
= 0;
19005 if ((dfn
& 0x30) == 0x00) {
19008 } else if ((dfn
& 0x38) == 0x20) {
19011 } else if ((dfn
& 0x3c) == 0x30) {
19014 } else if ((dfn
& 0x3e) == 0x38) {
19017 } else if (dfn
== 0x3E) {
19018 /* CTCMSA, CFCMSA, MOVE.V */
19019 gen_msa_elm_3e(env
, ctx
);
19022 generate_exception(ctx
, EXCP_RI
);
19026 gen_msa_elm_df(env
, ctx
, df
, n
);
19029 static void gen_msa_3rf(CPUMIPSState
*env
, DisasContext
*ctx
)
19031 #define MASK_MSA_3RF(op) (MASK_MSA_MINOR(op) | (op & (0xf << 22)))
19032 uint8_t df
= (ctx
->opcode
>> 21) & 0x1;
19033 uint8_t wt
= (ctx
->opcode
>> 16) & 0x1f;
19034 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
19035 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
19037 TCGv_i32 twd
= tcg_const_i32(wd
);
19038 TCGv_i32 tws
= tcg_const_i32(ws
);
19039 TCGv_i32 twt
= tcg_const_i32(wt
);
19040 TCGv_i32 tdf
= tcg_temp_new_i32();
19042 /* adjust df value for floating-point instruction */
19043 tcg_gen_movi_i32(tdf
, df
+ 2);
19045 switch (MASK_MSA_3RF(ctx
->opcode
)) {
19047 gen_helper_msa_fcaf_df(cpu_env
, tdf
, twd
, tws
, twt
);
19050 gen_helper_msa_fadd_df(cpu_env
, tdf
, twd
, tws
, twt
);
19053 gen_helper_msa_fcun_df(cpu_env
, tdf
, twd
, tws
, twt
);
19056 gen_helper_msa_fsub_df(cpu_env
, tdf
, twd
, tws
, twt
);
19059 gen_helper_msa_fcor_df(cpu_env
, tdf
, twd
, tws
, twt
);
19062 gen_helper_msa_fceq_df(cpu_env
, tdf
, twd
, tws
, twt
);
19065 gen_helper_msa_fmul_df(cpu_env
, tdf
, twd
, tws
, twt
);
19068 gen_helper_msa_fcune_df(cpu_env
, tdf
, twd
, tws
, twt
);
19071 gen_helper_msa_fcueq_df(cpu_env
, tdf
, twd
, tws
, twt
);
19074 gen_helper_msa_fdiv_df(cpu_env
, tdf
, twd
, tws
, twt
);
19077 gen_helper_msa_fcne_df(cpu_env
, tdf
, twd
, tws
, twt
);
19080 gen_helper_msa_fclt_df(cpu_env
, tdf
, twd
, tws
, twt
);
19083 gen_helper_msa_fmadd_df(cpu_env
, tdf
, twd
, tws
, twt
);
19086 tcg_gen_movi_i32(tdf
, df
+ 1);
19087 gen_helper_msa_mul_q_df(cpu_env
, tdf
, twd
, tws
, twt
);
19090 gen_helper_msa_fcult_df(cpu_env
, tdf
, twd
, tws
, twt
);
19093 gen_helper_msa_fmsub_df(cpu_env
, tdf
, twd
, tws
, twt
);
19095 case OPC_MADD_Q_df
:
19096 tcg_gen_movi_i32(tdf
, df
+ 1);
19097 gen_helper_msa_madd_q_df(cpu_env
, tdf
, twd
, tws
, twt
);
19100 gen_helper_msa_fcle_df(cpu_env
, tdf
, twd
, tws
, twt
);
19102 case OPC_MSUB_Q_df
:
19103 tcg_gen_movi_i32(tdf
, df
+ 1);
19104 gen_helper_msa_msub_q_df(cpu_env
, tdf
, twd
, tws
, twt
);
19107 gen_helper_msa_fcule_df(cpu_env
, tdf
, twd
, tws
, twt
);
19110 gen_helper_msa_fexp2_df(cpu_env
, tdf
, twd
, tws
, twt
);
19113 gen_helper_msa_fsaf_df(cpu_env
, tdf
, twd
, tws
, twt
);
19116 gen_helper_msa_fexdo_df(cpu_env
, tdf
, twd
, tws
, twt
);
19119 gen_helper_msa_fsun_df(cpu_env
, tdf
, twd
, tws
, twt
);
19122 gen_helper_msa_fsor_df(cpu_env
, tdf
, twd
, tws
, twt
);
19125 gen_helper_msa_fseq_df(cpu_env
, tdf
, twd
, tws
, twt
);
19128 gen_helper_msa_ftq_df(cpu_env
, tdf
, twd
, tws
, twt
);
19131 gen_helper_msa_fsune_df(cpu_env
, tdf
, twd
, tws
, twt
);
19134 gen_helper_msa_fsueq_df(cpu_env
, tdf
, twd
, tws
, twt
);
19137 gen_helper_msa_fsne_df(cpu_env
, tdf
, twd
, tws
, twt
);
19140 gen_helper_msa_fslt_df(cpu_env
, tdf
, twd
, tws
, twt
);
19143 gen_helper_msa_fmin_df(cpu_env
, tdf
, twd
, tws
, twt
);
19145 case OPC_MULR_Q_df
:
19146 tcg_gen_movi_i32(tdf
, df
+ 1);
19147 gen_helper_msa_mulr_q_df(cpu_env
, tdf
, twd
, tws
, twt
);
19150 gen_helper_msa_fsult_df(cpu_env
, tdf
, twd
, tws
, twt
);
19152 case OPC_FMIN_A_df
:
19153 gen_helper_msa_fmin_a_df(cpu_env
, tdf
, twd
, tws
, twt
);
19155 case OPC_MADDR_Q_df
:
19156 tcg_gen_movi_i32(tdf
, df
+ 1);
19157 gen_helper_msa_maddr_q_df(cpu_env
, tdf
, twd
, tws
, twt
);
19160 gen_helper_msa_fsle_df(cpu_env
, tdf
, twd
, tws
, twt
);
19163 gen_helper_msa_fmax_df(cpu_env
, tdf
, twd
, tws
, twt
);
19165 case OPC_MSUBR_Q_df
:
19166 tcg_gen_movi_i32(tdf
, df
+ 1);
19167 gen_helper_msa_msubr_q_df(cpu_env
, tdf
, twd
, tws
, twt
);
19170 gen_helper_msa_fsule_df(cpu_env
, tdf
, twd
, tws
, twt
);
19172 case OPC_FMAX_A_df
:
19173 gen_helper_msa_fmax_a_df(cpu_env
, tdf
, twd
, tws
, twt
);
19176 MIPS_INVAL("MSA instruction");
19177 generate_exception(ctx
, EXCP_RI
);
19181 tcg_temp_free_i32(twd
);
19182 tcg_temp_free_i32(tws
);
19183 tcg_temp_free_i32(twt
);
19184 tcg_temp_free_i32(tdf
);
19187 static void gen_msa_2r(CPUMIPSState
*env
, DisasContext
*ctx
)
19189 #define MASK_MSA_2R(op) (MASK_MSA_MINOR(op) | (op & (0x1f << 21)) | \
19190 (op & (0x7 << 18)))
19191 uint8_t wt
= (ctx
->opcode
>> 16) & 0x1f;
19192 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
19193 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
19194 uint8_t df
= (ctx
->opcode
>> 16) & 0x3;
19195 TCGv_i32 twd
= tcg_const_i32(wd
);
19196 TCGv_i32 tws
= tcg_const_i32(ws
);
19197 TCGv_i32 twt
= tcg_const_i32(wt
);
19198 TCGv_i32 tdf
= tcg_const_i32(df
);
19200 switch (MASK_MSA_2R(ctx
->opcode
)) {
19202 #if !defined(TARGET_MIPS64)
19203 /* Double format valid only for MIPS64 */
19204 if (df
== DF_DOUBLE
) {
19205 generate_exception(ctx
, EXCP_RI
);
19209 gen_helper_msa_fill_df(cpu_env
, tdf
, twd
, tws
); /* trs */
19212 gen_helper_msa_pcnt_df(cpu_env
, tdf
, twd
, tws
);
19215 gen_helper_msa_nloc_df(cpu_env
, tdf
, twd
, tws
);
19218 gen_helper_msa_nlzc_df(cpu_env
, tdf
, twd
, tws
);
19221 MIPS_INVAL("MSA instruction");
19222 generate_exception(ctx
, EXCP_RI
);
19226 tcg_temp_free_i32(twd
);
19227 tcg_temp_free_i32(tws
);
19228 tcg_temp_free_i32(twt
);
19229 tcg_temp_free_i32(tdf
);
19232 static void gen_msa_2rf(CPUMIPSState
*env
, DisasContext
*ctx
)
19234 #define MASK_MSA_2RF(op) (MASK_MSA_MINOR(op) | (op & (0x1f << 21)) | \
19235 (op & (0xf << 17)))
19236 uint8_t wt
= (ctx
->opcode
>> 16) & 0x1f;
19237 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
19238 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
19239 uint8_t df
= (ctx
->opcode
>> 16) & 0x1;
19240 TCGv_i32 twd
= tcg_const_i32(wd
);
19241 TCGv_i32 tws
= tcg_const_i32(ws
);
19242 TCGv_i32 twt
= tcg_const_i32(wt
);
19243 /* adjust df value for floating-point instruction */
19244 TCGv_i32 tdf
= tcg_const_i32(df
+ 2);
19246 switch (MASK_MSA_2RF(ctx
->opcode
)) {
19247 case OPC_FCLASS_df
:
19248 gen_helper_msa_fclass_df(cpu_env
, tdf
, twd
, tws
);
19250 case OPC_FTRUNC_S_df
:
19251 gen_helper_msa_ftrunc_s_df(cpu_env
, tdf
, twd
, tws
);
19253 case OPC_FTRUNC_U_df
:
19254 gen_helper_msa_ftrunc_u_df(cpu_env
, tdf
, twd
, tws
);
19257 gen_helper_msa_fsqrt_df(cpu_env
, tdf
, twd
, tws
);
19259 case OPC_FRSQRT_df
:
19260 gen_helper_msa_frsqrt_df(cpu_env
, tdf
, twd
, tws
);
19263 gen_helper_msa_frcp_df(cpu_env
, tdf
, twd
, tws
);
19266 gen_helper_msa_frint_df(cpu_env
, tdf
, twd
, tws
);
19269 gen_helper_msa_flog2_df(cpu_env
, tdf
, twd
, tws
);
19271 case OPC_FEXUPL_df
:
19272 gen_helper_msa_fexupl_df(cpu_env
, tdf
, twd
, tws
);
19274 case OPC_FEXUPR_df
:
19275 gen_helper_msa_fexupr_df(cpu_env
, tdf
, twd
, tws
);
19278 gen_helper_msa_ffql_df(cpu_env
, tdf
, twd
, tws
);
19281 gen_helper_msa_ffqr_df(cpu_env
, tdf
, twd
, tws
);
19283 case OPC_FTINT_S_df
:
19284 gen_helper_msa_ftint_s_df(cpu_env
, tdf
, twd
, tws
);
19286 case OPC_FTINT_U_df
:
19287 gen_helper_msa_ftint_u_df(cpu_env
, tdf
, twd
, tws
);
19289 case OPC_FFINT_S_df
:
19290 gen_helper_msa_ffint_s_df(cpu_env
, tdf
, twd
, tws
);
19292 case OPC_FFINT_U_df
:
19293 gen_helper_msa_ffint_u_df(cpu_env
, tdf
, twd
, tws
);
19297 tcg_temp_free_i32(twd
);
19298 tcg_temp_free_i32(tws
);
19299 tcg_temp_free_i32(twt
);
19300 tcg_temp_free_i32(tdf
);
19303 static void gen_msa_vec_v(CPUMIPSState
*env
, DisasContext
*ctx
)
19305 #define MASK_MSA_VEC(op) (MASK_MSA_MINOR(op) | (op & (0x1f << 21)))
19306 uint8_t wt
= (ctx
->opcode
>> 16) & 0x1f;
19307 uint8_t ws
= (ctx
->opcode
>> 11) & 0x1f;
19308 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
19309 TCGv_i32 twd
= tcg_const_i32(wd
);
19310 TCGv_i32 tws
= tcg_const_i32(ws
);
19311 TCGv_i32 twt
= tcg_const_i32(wt
);
19313 switch (MASK_MSA_VEC(ctx
->opcode
)) {
19315 gen_helper_msa_and_v(cpu_env
, twd
, tws
, twt
);
19318 gen_helper_msa_or_v(cpu_env
, twd
, tws
, twt
);
19321 gen_helper_msa_nor_v(cpu_env
, twd
, tws
, twt
);
19324 gen_helper_msa_xor_v(cpu_env
, twd
, tws
, twt
);
19327 gen_helper_msa_bmnz_v(cpu_env
, twd
, tws
, twt
);
19330 gen_helper_msa_bmz_v(cpu_env
, twd
, tws
, twt
);
19333 gen_helper_msa_bsel_v(cpu_env
, twd
, tws
, twt
);
19336 MIPS_INVAL("MSA instruction");
19337 generate_exception(ctx
, EXCP_RI
);
19341 tcg_temp_free_i32(twd
);
19342 tcg_temp_free_i32(tws
);
19343 tcg_temp_free_i32(twt
);
19346 static void gen_msa_vec(CPUMIPSState
*env
, DisasContext
*ctx
)
19348 switch (MASK_MSA_VEC(ctx
->opcode
)) {
19356 gen_msa_vec_v(env
, ctx
);
19359 gen_msa_2r(env
, ctx
);
19362 gen_msa_2rf(env
, ctx
);
19365 MIPS_INVAL("MSA instruction");
19366 generate_exception(ctx
, EXCP_RI
);
19371 static void gen_msa(CPUMIPSState
*env
, DisasContext
*ctx
)
19373 uint32_t opcode
= ctx
->opcode
;
19374 check_insn(ctx
, ASE_MSA
);
19375 check_msa_access(ctx
);
19377 switch (MASK_MSA_MINOR(opcode
)) {
19378 case OPC_MSA_I8_00
:
19379 case OPC_MSA_I8_01
:
19380 case OPC_MSA_I8_02
:
19381 gen_msa_i8(env
, ctx
);
19383 case OPC_MSA_I5_06
:
19384 case OPC_MSA_I5_07
:
19385 gen_msa_i5(env
, ctx
);
19387 case OPC_MSA_BIT_09
:
19388 case OPC_MSA_BIT_0A
:
19389 gen_msa_bit(env
, ctx
);
19391 case OPC_MSA_3R_0D
:
19392 case OPC_MSA_3R_0E
:
19393 case OPC_MSA_3R_0F
:
19394 case OPC_MSA_3R_10
:
19395 case OPC_MSA_3R_11
:
19396 case OPC_MSA_3R_12
:
19397 case OPC_MSA_3R_13
:
19398 case OPC_MSA_3R_14
:
19399 case OPC_MSA_3R_15
:
19400 gen_msa_3r(env
, ctx
);
19403 gen_msa_elm(env
, ctx
);
19405 case OPC_MSA_3RF_1A
:
19406 case OPC_MSA_3RF_1B
:
19407 case OPC_MSA_3RF_1C
:
19408 gen_msa_3rf(env
, ctx
);
19411 gen_msa_vec(env
, ctx
);
19422 int32_t s10
= sextract32(ctx
->opcode
, 16, 10);
19423 uint8_t rs
= (ctx
->opcode
>> 11) & 0x1f;
19424 uint8_t wd
= (ctx
->opcode
>> 6) & 0x1f;
19425 uint8_t df
= (ctx
->opcode
>> 0) & 0x3;
19427 TCGv_i32 twd
= tcg_const_i32(wd
);
19428 TCGv taddr
= tcg_temp_new();
19429 gen_base_offset_addr(ctx
, taddr
, rs
, s10
<< df
);
19431 switch (MASK_MSA_MINOR(opcode
)) {
19433 gen_helper_msa_ld_b(cpu_env
, twd
, taddr
);
19436 gen_helper_msa_ld_h(cpu_env
, twd
, taddr
);
19439 gen_helper_msa_ld_w(cpu_env
, twd
, taddr
);
19442 gen_helper_msa_ld_d(cpu_env
, twd
, taddr
);
19445 gen_helper_msa_st_b(cpu_env
, twd
, taddr
);
19448 gen_helper_msa_st_h(cpu_env
, twd
, taddr
);
19451 gen_helper_msa_st_w(cpu_env
, twd
, taddr
);
19454 gen_helper_msa_st_d(cpu_env
, twd
, taddr
);
19458 tcg_temp_free_i32(twd
);
19459 tcg_temp_free(taddr
);
19463 MIPS_INVAL("MSA instruction");
19464 generate_exception(ctx
, EXCP_RI
);
19470 static void decode_opc(CPUMIPSState
*env
, DisasContext
*ctx
)
19473 int rs
, rt
, rd
, sa
;
19477 /* make sure instructions are on a word boundary */
19478 if (ctx
->pc
& 0x3) {
19479 env
->CP0_BadVAddr
= ctx
->pc
;
19480 generate_exception_err(ctx
, EXCP_AdEL
, EXCP_INST_NOTAVAIL
);
19481 ctx
->bstate
= BS_STOP
;
19485 /* Handle blikely not taken case */
19486 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
19487 TCGLabel
*l1
= gen_new_label();
19489 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
19490 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
19491 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
19492 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
19496 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
19497 tcg_gen_debug_insn_start(ctx
->pc
);
19500 op
= MASK_OP_MAJOR(ctx
->opcode
);
19501 rs
= (ctx
->opcode
>> 21) & 0x1f;
19502 rt
= (ctx
->opcode
>> 16) & 0x1f;
19503 rd
= (ctx
->opcode
>> 11) & 0x1f;
19504 sa
= (ctx
->opcode
>> 6) & 0x1f;
19505 imm
= (int16_t)ctx
->opcode
;
19508 decode_opc_special(env
, ctx
);
19511 decode_opc_special2_legacy(env
, ctx
);
19514 decode_opc_special3(env
, ctx
);
19517 op1
= MASK_REGIMM(ctx
->opcode
);
19519 case OPC_BLTZL
: /* REGIMM branches */
19523 check_insn(ctx
, ISA_MIPS2
);
19524 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19528 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2, 4);
19532 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
19534 /* OPC_NAL, OPC_BAL */
19535 gen_compute_branch(ctx
, op1
, 4, 0, -1, imm
<< 2, 4);
19537 generate_exception(ctx
, EXCP_RI
);
19540 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2, 4);
19543 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
19545 check_insn(ctx
, ISA_MIPS2
);
19546 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19547 gen_trap(ctx
, op1
, rs
, -1, imm
);
19550 check_insn(ctx
, ISA_MIPS32R2
);
19551 /* Break the TB to be able to sync copied instructions
19553 ctx
->bstate
= BS_STOP
;
19555 case OPC_BPOSGE32
: /* MIPS DSP branch */
19556 #if defined(TARGET_MIPS64)
19560 gen_compute_branch(ctx
, op1
, 4, -1, -2, (int32_t)imm
<< 2, 4);
19562 #if defined(TARGET_MIPS64)
19564 check_insn(ctx
, ISA_MIPS32R6
);
19565 check_mips_64(ctx
);
19567 tcg_gen_addi_tl(cpu_gpr
[rs
], cpu_gpr
[rs
], (int64_t)imm
<< 32);
19569 MIPS_DEBUG("dahi %s, %04x", regnames
[rs
], imm
);
19572 check_insn(ctx
, ISA_MIPS32R6
);
19573 check_mips_64(ctx
);
19575 tcg_gen_addi_tl(cpu_gpr
[rs
], cpu_gpr
[rs
], (int64_t)imm
<< 48);
19577 MIPS_DEBUG("dati %s, %04x", regnames
[rs
], imm
);
19580 default: /* Invalid */
19581 MIPS_INVAL("regimm");
19582 generate_exception(ctx
, EXCP_RI
);
19587 check_cp0_enabled(ctx
);
19588 op1
= MASK_CP0(ctx
->opcode
);
19596 #if defined(TARGET_MIPS64)
19600 #ifndef CONFIG_USER_ONLY
19601 gen_cp0(env
, ctx
, op1
, rt
, rd
);
19602 #endif /* !CONFIG_USER_ONLY */
19604 case OPC_C0_FIRST
... OPC_C0_LAST
:
19605 #ifndef CONFIG_USER_ONLY
19606 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
19607 #endif /* !CONFIG_USER_ONLY */
19610 #ifndef CONFIG_USER_ONLY
19613 TCGv t0
= tcg_temp_new();
19615 op2
= MASK_MFMC0(ctx
->opcode
);
19618 check_insn(ctx
, ASE_MT
);
19619 gen_helper_dmt(t0
);
19620 gen_store_gpr(t0
, rt
);
19623 check_insn(ctx
, ASE_MT
);
19624 gen_helper_emt(t0
);
19625 gen_store_gpr(t0
, rt
);
19628 check_insn(ctx
, ASE_MT
);
19629 gen_helper_dvpe(t0
, cpu_env
);
19630 gen_store_gpr(t0
, rt
);
19633 check_insn(ctx
, ASE_MT
);
19634 gen_helper_evpe(t0
, cpu_env
);
19635 gen_store_gpr(t0
, rt
);
19638 check_insn(ctx
, ISA_MIPS32R2
);
19639 save_cpu_state(ctx
, 1);
19640 gen_helper_di(t0
, cpu_env
);
19641 gen_store_gpr(t0
, rt
);
19642 /* Stop translation as we may have switched
19643 the execution mode. */
19644 ctx
->bstate
= BS_STOP
;
19647 check_insn(ctx
, ISA_MIPS32R2
);
19648 save_cpu_state(ctx
, 1);
19649 gen_helper_ei(t0
, cpu_env
);
19650 gen_store_gpr(t0
, rt
);
19651 /* Stop translation as we may have switched
19652 the execution mode. */
19653 ctx
->bstate
= BS_STOP
;
19655 default: /* Invalid */
19656 MIPS_INVAL("mfmc0");
19657 generate_exception(ctx
, EXCP_RI
);
19662 #endif /* !CONFIG_USER_ONLY */
19665 check_insn(ctx
, ISA_MIPS32R2
);
19666 gen_load_srsgpr(rt
, rd
);
19669 check_insn(ctx
, ISA_MIPS32R2
);
19670 gen_store_srsgpr(rt
, rd
);
19674 generate_exception(ctx
, EXCP_RI
);
19678 case OPC_BOVC
: /* OPC_BEQZALC, OPC_BEQC, OPC_ADDI */
19679 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
19680 /* OPC_BOVC, OPC_BEQZALC, OPC_BEQC */
19681 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
19684 /* Arithmetic with immediate opcode */
19685 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
19689 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
19691 case OPC_SLTI
: /* Set on less than with immediate opcode */
19693 gen_slt_imm(ctx
, op
, rt
, rs
, imm
);
19695 case OPC_ANDI
: /* Arithmetic with immediate opcode */
19696 case OPC_LUI
: /* OPC_AUI */
19699 gen_logic_imm(ctx
, op
, rt
, rs
, imm
);
19701 case OPC_J
... OPC_JAL
: /* Jump */
19702 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
19703 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
, 4);
19706 case OPC_BLEZC
: /* OPC_BGEZC, OPC_BGEC, OPC_BLEZL */
19707 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
19709 generate_exception(ctx
, EXCP_RI
);
19712 /* OPC_BLEZC, OPC_BGEZC, OPC_BGEC */
19713 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
19716 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
19719 case OPC_BGTZC
: /* OPC_BLTZC, OPC_BLTC, OPC_BGTZL */
19720 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
19722 generate_exception(ctx
, EXCP_RI
);
19725 /* OPC_BGTZC, OPC_BLTZC, OPC_BLTC */
19726 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
19729 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
19732 case OPC_BLEZALC
: /* OPC_BGEZALC, OPC_BGEUC, OPC_BLEZ */
19735 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
19737 check_insn(ctx
, ISA_MIPS32R6
);
19738 /* OPC_BLEZALC, OPC_BGEZALC, OPC_BGEUC */
19739 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
19742 case OPC_BGTZALC
: /* OPC_BLTZALC, OPC_BLTUC, OPC_BGTZ */
19745 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
19747 check_insn(ctx
, ISA_MIPS32R6
);
19748 /* OPC_BGTZALC, OPC_BLTZALC, OPC_BLTUC */
19749 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
19754 check_insn(ctx
, ISA_MIPS2
);
19755 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19759 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
19761 case OPC_LL
: /* Load and stores */
19762 check_insn(ctx
, ISA_MIPS2
);
19766 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19768 case OPC_LB
... OPC_LH
:
19769 case OPC_LW
... OPC_LHU
:
19770 gen_ld(ctx
, op
, rt
, rs
, imm
);
19774 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19776 case OPC_SB
... OPC_SH
:
19778 gen_st(ctx
, op
, rt
, rs
, imm
);
19781 check_insn(ctx
, ISA_MIPS2
);
19782 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19783 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
19786 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19787 check_cp0_enabled(ctx
);
19788 check_insn(ctx
, ISA_MIPS3
| ISA_MIPS32
);
19789 /* Treat as NOP. */
19792 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19793 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS32
);
19794 /* Treat as NOP. */
19797 /* Floating point (COP1). */
19802 gen_cop1_ldst(ctx
, op
, rt
, rs
, imm
);
19806 op1
= MASK_CP1(ctx
->opcode
);
19811 check_cp1_enabled(ctx
);
19812 check_insn(ctx
, ISA_MIPS32R2
);
19817 check_cp1_enabled(ctx
);
19818 gen_cp1(ctx
, op1
, rt
, rd
);
19820 #if defined(TARGET_MIPS64)
19823 check_cp1_enabled(ctx
);
19824 check_insn(ctx
, ISA_MIPS3
);
19825 check_mips_64(ctx
);
19826 gen_cp1(ctx
, op1
, rt
, rd
);
19829 case OPC_BC1EQZ
: /* OPC_BC1ANY2 */
19830 check_cp1_enabled(ctx
);
19831 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
19833 gen_compute_branch1_r6(ctx
, MASK_CP1(ctx
->opcode
),
19838 check_insn(ctx
, ASE_MIPS3D
);
19839 gen_compute_branch1(ctx
, MASK_BC1(ctx
->opcode
),
19840 (rt
>> 2) & 0x7, imm
<< 2);
19844 check_cp1_enabled(ctx
);
19845 check_insn(ctx
, ISA_MIPS32R6
);
19846 gen_compute_branch1_r6(ctx
, MASK_CP1(ctx
->opcode
),
19850 check_cp1_enabled(ctx
);
19851 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19853 check_insn(ctx
, ASE_MIPS3D
);
19856 check_cp1_enabled(ctx
);
19857 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19858 gen_compute_branch1(ctx
, MASK_BC1(ctx
->opcode
),
19859 (rt
>> 2) & 0x7, imm
<< 2);
19866 check_cp1_enabled(ctx
);
19867 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
19873 int r6_op
= ctx
->opcode
& FOP(0x3f, 0x1f);
19874 check_cp1_enabled(ctx
);
19875 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
19877 case R6_OPC_CMP_AF_S
:
19878 case R6_OPC_CMP_UN_S
:
19879 case R6_OPC_CMP_EQ_S
:
19880 case R6_OPC_CMP_UEQ_S
:
19881 case R6_OPC_CMP_LT_S
:
19882 case R6_OPC_CMP_ULT_S
:
19883 case R6_OPC_CMP_LE_S
:
19884 case R6_OPC_CMP_ULE_S
:
19885 case R6_OPC_CMP_SAF_S
:
19886 case R6_OPC_CMP_SUN_S
:
19887 case R6_OPC_CMP_SEQ_S
:
19888 case R6_OPC_CMP_SEUQ_S
:
19889 case R6_OPC_CMP_SLT_S
:
19890 case R6_OPC_CMP_SULT_S
:
19891 case R6_OPC_CMP_SLE_S
:
19892 case R6_OPC_CMP_SULE_S
:
19893 case R6_OPC_CMP_OR_S
:
19894 case R6_OPC_CMP_UNE_S
:
19895 case R6_OPC_CMP_NE_S
:
19896 case R6_OPC_CMP_SOR_S
:
19897 case R6_OPC_CMP_SUNE_S
:
19898 case R6_OPC_CMP_SNE_S
:
19899 gen_r6_cmp_s(ctx
, ctx
->opcode
& 0x1f, rt
, rd
, sa
);
19901 case R6_OPC_CMP_AF_D
:
19902 case R6_OPC_CMP_UN_D
:
19903 case R6_OPC_CMP_EQ_D
:
19904 case R6_OPC_CMP_UEQ_D
:
19905 case R6_OPC_CMP_LT_D
:
19906 case R6_OPC_CMP_ULT_D
:
19907 case R6_OPC_CMP_LE_D
:
19908 case R6_OPC_CMP_ULE_D
:
19909 case R6_OPC_CMP_SAF_D
:
19910 case R6_OPC_CMP_SUN_D
:
19911 case R6_OPC_CMP_SEQ_D
:
19912 case R6_OPC_CMP_SEUQ_D
:
19913 case R6_OPC_CMP_SLT_D
:
19914 case R6_OPC_CMP_SULT_D
:
19915 case R6_OPC_CMP_SLE_D
:
19916 case R6_OPC_CMP_SULE_D
:
19917 case R6_OPC_CMP_OR_D
:
19918 case R6_OPC_CMP_UNE_D
:
19919 case R6_OPC_CMP_NE_D
:
19920 case R6_OPC_CMP_SOR_D
:
19921 case R6_OPC_CMP_SUNE_D
:
19922 case R6_OPC_CMP_SNE_D
:
19923 gen_r6_cmp_d(ctx
, ctx
->opcode
& 0x1f, rt
, rd
, sa
);
19926 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f),
19927 rt
, rd
, sa
, (imm
>> 8) & 0x7);
19932 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
19947 check_insn(ctx
, ASE_MSA
);
19948 gen_msa_branch(env
, ctx
, op1
);
19952 generate_exception(ctx
, EXCP_RI
);
19957 /* Compact branches [R6] and COP2 [non-R6] */
19958 case OPC_BC
: /* OPC_LWC2 */
19959 case OPC_BALC
: /* OPC_SWC2 */
19960 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
19961 /* OPC_BC, OPC_BALC */
19962 gen_compute_compact_branch(ctx
, op
, 0, 0,
19963 sextract32(ctx
->opcode
<< 2, 0, 28));
19965 /* OPC_LWC2, OPC_SWC2 */
19966 /* COP2: Not implemented. */
19967 generate_exception_err(ctx
, EXCP_CpU
, 2);
19970 case OPC_BEQZC
: /* OPC_JIC, OPC_LDC2 */
19971 case OPC_BNEZC
: /* OPC_JIALC, OPC_SDC2 */
19972 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
19974 /* OPC_BEQZC, OPC_BNEZC */
19975 gen_compute_compact_branch(ctx
, op
, rs
, 0,
19976 sextract32(ctx
->opcode
<< 2, 0, 23));
19978 /* OPC_JIC, OPC_JIALC */
19979 gen_compute_compact_branch(ctx
, op
, 0, rt
, imm
);
19982 /* OPC_LWC2, OPC_SWC2 */
19983 /* COP2: Not implemented. */
19984 generate_exception_err(ctx
, EXCP_CpU
, 2);
19988 check_insn(ctx
, INSN_LOONGSON2F
);
19989 /* Note that these instructions use different fields. */
19990 gen_loongson_multimedia(ctx
, sa
, rd
, rt
);
19994 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
19995 if (ctx
->CP0_Config1
& (1 << CP0C1_FP
)) {
19996 check_cp1_enabled(ctx
);
19997 op1
= MASK_CP3(ctx
->opcode
);
20001 check_insn(ctx
, ISA_MIPS5
| ISA_MIPS32R2
);
20007 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS32R2
);
20008 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
20011 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS32R2
);
20012 /* Treat as NOP. */
20015 check_insn(ctx
, ISA_MIPS5
| ISA_MIPS32R2
);
20029 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS32R2
);
20030 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
20034 generate_exception (ctx
, EXCP_RI
);
20038 generate_exception_err(ctx
, EXCP_CpU
, 1);
20042 #if defined(TARGET_MIPS64)
20043 /* MIPS64 opcodes */
20044 case OPC_LDL
... OPC_LDR
:
20046 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
20050 check_insn(ctx
, ISA_MIPS3
);
20051 check_mips_64(ctx
);
20052 gen_ld(ctx
, op
, rt
, rs
, imm
);
20054 case OPC_SDL
... OPC_SDR
:
20055 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
20058 check_insn(ctx
, ISA_MIPS3
);
20059 check_mips_64(ctx
);
20060 gen_st(ctx
, op
, rt
, rs
, imm
);
20063 check_insn_opc_removed(ctx
, ISA_MIPS32R6
);
20064 check_insn(ctx
, ISA_MIPS3
);
20065 check_mips_64(ctx
);
20066 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
20068 case OPC_BNVC
: /* OPC_BNEZALC, OPC_BNEC, OPC_DADDI */
20069 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
20070 /* OPC_BNVC, OPC_BNEZALC, OPC_BNEC */
20071 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
20074 check_insn(ctx
, ISA_MIPS3
);
20075 check_mips_64(ctx
);
20076 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
20080 check_insn(ctx
, ISA_MIPS3
);
20081 check_mips_64(ctx
);
20082 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
20085 case OPC_BNVC
: /* OPC_BNEZALC, OPC_BNEC */
20086 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
20087 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
20089 MIPS_INVAL("major opcode");
20090 generate_exception(ctx
, EXCP_RI
);
20094 case OPC_DAUI
: /* OPC_JALX */
20095 if (ctx
->insn_flags
& ISA_MIPS32R6
) {
20096 #if defined(TARGET_MIPS64)
20098 check_mips_64(ctx
);
20100 TCGv t0
= tcg_temp_new();
20101 gen_load_gpr(t0
, rs
);
20102 tcg_gen_addi_tl(cpu_gpr
[rt
], t0
, imm
<< 16);
20105 MIPS_DEBUG("daui %s, %s, %04x", regnames
[rt
], regnames
[rs
], imm
);
20107 generate_exception(ctx
, EXCP_RI
);
20108 MIPS_INVAL("major opcode");
20112 check_insn(ctx
, ASE_MIPS16
| ASE_MICROMIPS
);
20113 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
20114 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
, 4);
20117 case OPC_MSA
: /* OPC_MDMX */
20118 /* MDMX: Not implemented. */
20122 check_insn(ctx
, ISA_MIPS32R6
);
20123 gen_pcrel(ctx
, ctx
->opcode
, ctx
->pc
, rs
);
20125 default: /* Invalid */
20126 MIPS_INVAL("major opcode");
20127 generate_exception(ctx
, EXCP_RI
);
20133 gen_intermediate_code_internal(MIPSCPU
*cpu
, TranslationBlock
*tb
,
20136 CPUState
*cs
= CPU(cpu
);
20137 CPUMIPSState
*env
= &cpu
->env
;
20139 target_ulong pc_start
;
20140 target_ulong next_page_start
;
20149 qemu_log("search pc %d\n", search_pc
);
20152 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
20155 ctx
.singlestep_enabled
= cs
->singlestep_enabled
;
20156 ctx
.insn_flags
= env
->insn_flags
;
20157 ctx
.CP0_Config1
= env
->CP0_Config1
;
20159 ctx
.bstate
= BS_NONE
;
20160 ctx
.kscrexist
= (env
->CP0_Config4
>> CP0C4_KScrExist
) & 0xff;
20161 ctx
.rxi
= (env
->CP0_Config3
>> CP0C3_RXI
) & 1;
20162 ctx
.ie
= (env
->CP0_Config4
>> CP0C4_IE
) & 3;
20163 ctx
.bi
= (env
->CP0_Config3
>> CP0C3_BI
) & 1;
20164 ctx
.bp
= (env
->CP0_Config3
>> CP0C3_BP
) & 1;
20165 ctx
.PAMask
= env
->PAMask
;
20166 ctx
.mvh
= (env
->CP0_Config5
>> CP0C5_MVH
) & 1;
20167 ctx
.CP0_LLAddr_shift
= env
->CP0_LLAddr_shift
;
20168 /* Restore delay slot state from the tb context. */
20169 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
20170 ctx
.ulri
= (env
->CP0_Config3
>> CP0C3_ULRI
) & 1;
20171 ctx
.ps
= ((env
->active_fpu
.fcr0
>> FCR0_PS
) & 1) ||
20172 (env
->insn_flags
& (INSN_LOONGSON2E
| INSN_LOONGSON2F
));
20173 restore_cpu_state(env
, &ctx
);
20174 #ifdef CONFIG_USER_ONLY
20175 ctx
.mem_idx
= MIPS_HFLAG_UM
;
20177 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
20179 ctx
.default_tcg_memop_mask
= (ctx
.insn_flags
& ISA_MIPS32R6
) ?
20180 MO_UNALN
: MO_ALIGN
;
20182 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
20183 if (max_insns
== 0)
20184 max_insns
= CF_COUNT_MASK
;
20185 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
20187 while (ctx
.bstate
== BS_NONE
) {
20188 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
20189 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
20190 if (bp
->pc
== ctx
.pc
) {
20191 save_cpu_state(&ctx
, 1);
20192 ctx
.bstate
= BS_BRANCH
;
20193 gen_helper_0e0i(raise_exception
, EXCP_DEBUG
);
20194 /* Include the breakpoint location or the tb won't
20195 * be flushed when it must be. */
20197 goto done_generating
;
20203 j
= tcg_op_buf_count();
20207 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
20209 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.pc
;
20210 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
20211 gen_opc_btarget
[lj
] = ctx
.btarget
;
20212 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
20213 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
20215 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
20218 is_slot
= ctx
.hflags
& MIPS_HFLAG_BMASK
;
20219 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
20220 ctx
.opcode
= cpu_ldl_code(env
, ctx
.pc
);
20222 decode_opc(env
, &ctx
);
20223 } else if (ctx
.insn_flags
& ASE_MICROMIPS
) {
20224 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
20225 insn_bytes
= decode_micromips_opc(env
, &ctx
);
20226 } else if (ctx
.insn_flags
& ASE_MIPS16
) {
20227 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
20228 insn_bytes
= decode_mips16_opc(env
, &ctx
);
20230 generate_exception(&ctx
, EXCP_RI
);
20231 ctx
.bstate
= BS_STOP
;
20235 if (ctx
.hflags
& MIPS_HFLAG_BMASK
) {
20236 if (!(ctx
.hflags
& (MIPS_HFLAG_BDS16
| MIPS_HFLAG_BDS32
|
20237 MIPS_HFLAG_FBNSLOT
))) {
20238 /* force to generate branch as there is neither delay nor
20242 if ((ctx
.hflags
& MIPS_HFLAG_M16
) &&
20243 (ctx
.hflags
& MIPS_HFLAG_FBNSLOT
)) {
20244 /* Force to generate branch as microMIPS R6 doesn't restrict
20245 branches in the forbidden slot. */
20250 gen_branch(&ctx
, insn_bytes
);
20252 ctx
.pc
+= insn_bytes
;
20256 /* Execute a branch and its delay slot as a single instruction.
20257 This is what GDB expects and is consistent with what the
20258 hardware does (e.g. if a delay slot instruction faults, the
20259 reported PC is the PC of the branch). */
20260 if (cs
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0) {
20264 if (ctx
.pc
>= next_page_start
) {
20268 if (tcg_op_buf_full()) {
20272 if (num_insns
>= max_insns
)
20278 if (tb
->cflags
& CF_LAST_IO
) {
20281 if (cs
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
20282 save_cpu_state(&ctx
, ctx
.bstate
!= BS_EXCP
);
20283 gen_helper_0e0i(raise_exception
, EXCP_DEBUG
);
20285 switch (ctx
.bstate
) {
20287 gen_goto_tb(&ctx
, 0, ctx
.pc
);
20290 save_cpu_state(&ctx
, 0);
20291 gen_goto_tb(&ctx
, 0, ctx
.pc
);
20294 tcg_gen_exit_tb(0);
20302 gen_tb_end(tb
, num_insns
);
20305 j
= tcg_op_buf_count();
20308 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
20310 tb
->size
= ctx
.pc
- pc_start
;
20311 tb
->icount
= num_insns
;
20315 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
20316 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
20317 log_target_disas(cs
, pc_start
, ctx
.pc
- pc_start
, 0);
20323 void gen_intermediate_code (CPUMIPSState
*env
, struct TranslationBlock
*tb
)
20325 gen_intermediate_code_internal(mips_env_get_cpu(env
), tb
, false);
20328 void gen_intermediate_code_pc (CPUMIPSState
*env
, struct TranslationBlock
*tb
)
20330 gen_intermediate_code_internal(mips_env_get_cpu(env
), tb
, true);
20333 static void fpu_dump_state(CPUMIPSState
*env
, FILE *f
, fprintf_function fpu_fprintf
,
20337 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
20339 #define printfpr(fp) \
20342 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
20343 " fd:%13g fs:%13g psu: %13g\n", \
20344 (fp)->w[FP_ENDIAN_IDX], (fp)->d, \
20345 (double)(fp)->fd, \
20346 (double)(fp)->fs[FP_ENDIAN_IDX], \
20347 (double)(fp)->fs[!FP_ENDIAN_IDX]); \
20350 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
20351 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
20352 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
20353 " fd:%13g fs:%13g psu:%13g\n", \
20354 tmp.w[FP_ENDIAN_IDX], tmp.d, \
20356 (double)tmp.fs[FP_ENDIAN_IDX], \
20357 (double)tmp.fs[!FP_ENDIAN_IDX]); \
20362 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%02x\n",
20363 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
,
20364 get_float_exception_flags(&env
->active_fpu
.fp_status
));
20365 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
20366 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
20367 printfpr(&env
->active_fpu
.fpr
[i
]);
20373 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
20374 /* Debug help: The architecture requires 32bit code to maintain proper
20375 sign-extended values on 64bit machines. */
20377 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
20380 cpu_mips_check_sign_extensions (CPUMIPSState
*env
, FILE *f
,
20381 fprintf_function cpu_fprintf
,
20386 if (!SIGN_EXT_P(env
->active_tc
.PC
))
20387 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
20388 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
20389 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
20390 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
20391 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
20392 if (!SIGN_EXT_P(env
->btarget
))
20393 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
20395 for (i
= 0; i
< 32; i
++) {
20396 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
20397 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
20400 if (!SIGN_EXT_P(env
->CP0_EPC
))
20401 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
20402 if (!SIGN_EXT_P(env
->lladdr
))
20403 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
20407 void mips_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
20410 MIPSCPU
*cpu
= MIPS_CPU(cs
);
20411 CPUMIPSState
*env
= &cpu
->env
;
20414 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
20415 " LO=0x" TARGET_FMT_lx
" ds %04x "
20416 TARGET_FMT_lx
" " TARGET_FMT_ld
"\n",
20417 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
20418 env
->hflags
, env
->btarget
, env
->bcond
);
20419 for (i
= 0; i
< 32; i
++) {
20421 cpu_fprintf(f
, "GPR%02d:", i
);
20422 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
20424 cpu_fprintf(f
, "\n");
20427 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
20428 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
20429 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x%016"
20431 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
20432 cpu_fprintf(f
, " Config2 0x%08x Config3 0x%08x\n",
20433 env
->CP0_Config2
, env
->CP0_Config3
);
20434 cpu_fprintf(f
, " Config4 0x%08x Config5 0x%08x\n",
20435 env
->CP0_Config4
, env
->CP0_Config5
);
20436 if (env
->hflags
& MIPS_HFLAG_FPU
)
20437 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
20438 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
20439 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
20443 void mips_tcg_init(void)
20448 /* Initialize various static tables. */
20452 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
20453 TCGV_UNUSED(cpu_gpr
[0]);
20454 for (i
= 1; i
< 32; i
++)
20455 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
20456 offsetof(CPUMIPSState
, active_tc
.gpr
[i
]),
20459 for (i
= 0; i
< 32; i
++) {
20460 int off
= offsetof(CPUMIPSState
, active_fpu
.fpr
[i
].wr
.d
[0]);
20462 tcg_global_mem_new_i64(TCG_AREG0
, off
, msaregnames
[i
* 2]);
20463 /* The scalar floating-point unit (FPU) registers are mapped on
20464 * the MSA vector registers. */
20465 fpu_f64
[i
] = msa_wr_d
[i
* 2];
20466 off
= offsetof(CPUMIPSState
, active_fpu
.fpr
[i
].wr
.d
[1]);
20467 msa_wr_d
[i
* 2 + 1] =
20468 tcg_global_mem_new_i64(TCG_AREG0
, off
, msaregnames
[i
* 2 + 1]);
20471 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
20472 offsetof(CPUMIPSState
, active_tc
.PC
), "PC");
20473 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
20474 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
20475 offsetof(CPUMIPSState
, active_tc
.HI
[i
]),
20477 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
20478 offsetof(CPUMIPSState
, active_tc
.LO
[i
]),
20481 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
20482 offsetof(CPUMIPSState
, active_tc
.DSPControl
),
20484 bcond
= tcg_global_mem_new(TCG_AREG0
,
20485 offsetof(CPUMIPSState
, bcond
), "bcond");
20486 btarget
= tcg_global_mem_new(TCG_AREG0
,
20487 offsetof(CPUMIPSState
, btarget
), "btarget");
20488 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
20489 offsetof(CPUMIPSState
, hflags
), "hflags");
20491 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
20492 offsetof(CPUMIPSState
, active_fpu
.fcr0
),
20494 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
20495 offsetof(CPUMIPSState
, active_fpu
.fcr31
),
20501 #include "translate_init.c"
20503 MIPSCPU
*cpu_mips_init(const char *cpu_model
)
20507 const mips_def_t
*def
;
20509 def
= cpu_mips_find_by_name(cpu_model
);
20512 cpu
= MIPS_CPU(object_new(TYPE_MIPS_CPU
));
20514 env
->cpu_model
= def
;
20516 #ifndef CONFIG_USER_ONLY
20517 mmu_init(env
, def
);
20519 fpu_init(env
, def
);
20520 mvp_init(env
, def
);
20522 object_property_set_bool(OBJECT(cpu
), true, "realized", NULL
);
20527 void cpu_state_reset(CPUMIPSState
*env
)
20529 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
20530 CPUState
*cs
= CPU(cpu
);
20532 /* Reset registers to their default values */
20533 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
20534 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
20535 #ifdef TARGET_WORDS_BIGENDIAN
20536 env
->CP0_Config0
|= (1 << CP0C0_BE
);
20538 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
20539 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
20540 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
20541 env
->CP0_Config4
= env
->cpu_model
->CP0_Config4
;
20542 env
->CP0_Config4_rw_bitmask
= env
->cpu_model
->CP0_Config4_rw_bitmask
;
20543 env
->CP0_Config5
= env
->cpu_model
->CP0_Config5
;
20544 env
->CP0_Config5_rw_bitmask
= env
->cpu_model
->CP0_Config5_rw_bitmask
;
20545 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
20546 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
20547 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
20548 << env
->cpu_model
->CP0_LLAddr_shift
;
20549 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
20550 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
20551 env
->CCRes
= env
->cpu_model
->CCRes
;
20552 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
20553 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
20554 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
20555 env
->current_tc
= 0;
20556 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
20557 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
20558 #if defined(TARGET_MIPS64)
20559 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
20560 env
->SEGMask
|= 3ULL << 62;
20563 env
->PABITS
= env
->cpu_model
->PABITS
;
20564 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
20565 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
20566 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
20567 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
20568 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
20569 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
20570 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
20571 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
20572 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
20573 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
20574 env
->CP0_PageGrain_rw_bitmask
= env
->cpu_model
->CP0_PageGrain_rw_bitmask
;
20575 env
->CP0_PageGrain
= env
->cpu_model
->CP0_PageGrain
;
20576 env
->active_fpu
.fcr0
= env
->cpu_model
->CP1_fcr0
;
20577 env
->msair
= env
->cpu_model
->MSAIR
;
20578 env
->insn_flags
= env
->cpu_model
->insn_flags
;
20580 #if defined(CONFIG_USER_ONLY)
20581 env
->CP0_Status
= (MIPS_HFLAG_UM
<< CP0St_KSU
);
20582 # ifdef TARGET_MIPS64
20583 /* Enable 64-bit register mode. */
20584 env
->CP0_Status
|= (1 << CP0St_PX
);
20586 # ifdef TARGET_ABI_MIPSN64
20587 /* Enable 64-bit address mode. */
20588 env
->CP0_Status
|= (1 << CP0St_UX
);
20590 /* Enable access to the CPUNum, SYNCI_Step, CC, and CCRes RDHWR
20591 hardware registers. */
20592 env
->CP0_HWREna
|= 0x0000000F;
20593 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
20594 env
->CP0_Status
|= (1 << CP0St_CU1
);
20596 if (env
->CP0_Config3
& (1 << CP0C3_DSPP
)) {
20597 env
->CP0_Status
|= (1 << CP0St_MX
);
20599 # if defined(TARGET_MIPS64)
20600 /* For MIPS64, init FR bit to 1 if FPU unit is there and bit is writable. */
20601 if ((env
->CP0_Config1
& (1 << CP0C1_FP
)) &&
20602 (env
->CP0_Status_rw_bitmask
& (1 << CP0St_FR
))) {
20603 env
->CP0_Status
|= (1 << CP0St_FR
);
20607 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
20608 /* If the exception was raised from a delay slot,
20609 come back to the jump. */
20610 env
->CP0_ErrorEPC
= (env
->active_tc
.PC
20611 - (env
->hflags
& MIPS_HFLAG_B16
? 2 : 4));
20613 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
20615 env
->active_tc
.PC
= (int32_t)0xBFC00000;
20616 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
20617 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
20618 env
->CP0_Wired
= 0;
20619 env
->CP0_EBase
= (cs
->cpu_index
& 0x3FF);
20620 if (kvm_enabled()) {
20621 env
->CP0_EBase
|= 0x40000000;
20623 env
->CP0_EBase
|= 0x80000000;
20625 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
20626 /* vectored interrupts not implemented, timer on int 7,
20627 no performance counters. */
20628 env
->CP0_IntCtl
= 0xe0000000;
20632 for (i
= 0; i
< 7; i
++) {
20633 env
->CP0_WatchLo
[i
] = 0;
20634 env
->CP0_WatchHi
[i
] = 0x80000000;
20636 env
->CP0_WatchLo
[7] = 0;
20637 env
->CP0_WatchHi
[7] = 0;
20639 /* Count register increments in debug mode, EJTAG version 1 */
20640 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
20642 cpu_mips_store_count(env
, 1);
20644 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
20647 /* Only TC0 on VPE 0 starts as active. */
20648 for (i
= 0; i
< ARRAY_SIZE(env
->tcs
); i
++) {
20649 env
->tcs
[i
].CP0_TCBind
= cs
->cpu_index
<< CP0TCBd_CurVPE
;
20650 env
->tcs
[i
].CP0_TCHalt
= 1;
20652 env
->active_tc
.CP0_TCHalt
= 1;
20655 if (cs
->cpu_index
== 0) {
20656 /* VPE0 starts up enabled. */
20657 env
->mvp
->CP0_MVPControl
|= (1 << CP0MVPCo_EVP
);
20658 env
->CP0_VPEConf0
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
20660 /* TC0 starts up unhalted. */
20662 env
->active_tc
.CP0_TCHalt
= 0;
20663 env
->tcs
[0].CP0_TCHalt
= 0;
20664 /* With thread 0 active. */
20665 env
->active_tc
.CP0_TCStatus
= (1 << CP0TCSt_A
);
20666 env
->tcs
[0].CP0_TCStatus
= (1 << CP0TCSt_A
);
20670 if ((env
->insn_flags
& ISA_MIPS32R6
) &&
20671 (env
->active_fpu
.fcr0
& (1 << FCR0_F64
))) {
20672 /* Status.FR = 0 mode in 64-bit FPU not allowed in R6 */
20673 env
->CP0_Status
|= (1 << CP0St_FR
);
20677 if (env
->CP0_Config3
& (1 << CP0C3_MSAP
)) {
20681 compute_hflags(env
);
20682 restore_rounding_mode(env
);
20683 restore_flush_mode(env
);
20684 restore_pamask(env
);
20685 cs
->exception_index
= EXCP_NONE
;
20687 if (semihosting_get_argc()) {
20688 /* UHI interface can be used to obtain argc and argv */
20689 env
->active_tc
.gpr
[4] = -1;
20693 void restore_state_to_opc(CPUMIPSState
*env
, TranslationBlock
*tb
, int pc_pos
)
20695 env
->active_tc
.PC
= tcg_ctx
.gen_opc_pc
[pc_pos
];
20696 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
20697 env
->hflags
|= gen_opc_hflags
[pc_pos
];
20698 switch (env
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
20699 case MIPS_HFLAG_BR
:
20701 case MIPS_HFLAG_BC
:
20702 case MIPS_HFLAG_BL
:
20704 env
->btarget
= gen_opc_btarget
[pc_pos
];