2 * MIPS 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)
9 * Copyright (c) 2020 Philippe Mathieu-Daudé
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 #include "qemu/osdep.h"
26 #include "translate.h"
28 #include "exec/helper-proto.h"
29 #include "exec/translation-block.h"
30 #include "semihosting/semihost.h"
32 #include "fpu_helper.h"
34 #define HELPER_H "helper.h"
35 #include "exec/helper-info.c.inc"
40 * Many sysemu-only helpers are not reachable for user-only.
41 * Define stub generators here, so that we need not either sprinkle
42 * ifdefs through the translator, nor provide the helper function.
44 #define STUB_HELPER(NAME, ...) \
45 static inline void gen_helper_##NAME(__VA_ARGS__) \
46 { g_assert_not_reached(); }
48 #ifdef CONFIG_USER_ONLY
49 STUB_HELPER(cache
, TCGv_env env
, TCGv val
, TCGv_i32 reg
)
53 /* indirect opcode tables */
54 OPC_SPECIAL
= (0x00 << 26),
55 OPC_REGIMM
= (0x01 << 26),
56 OPC_CP0
= (0x10 << 26),
57 OPC_CP2
= (0x12 << 26),
58 OPC_CP3
= (0x13 << 26),
59 OPC_SPECIAL2
= (0x1C << 26),
60 OPC_SPECIAL3
= (0x1F << 26),
61 /* arithmetic with immediate */
62 OPC_ADDI
= (0x08 << 26),
63 OPC_ADDIU
= (0x09 << 26),
64 OPC_SLTI
= (0x0A << 26),
65 OPC_SLTIU
= (0x0B << 26),
66 /* logic with immediate */
67 OPC_ANDI
= (0x0C << 26),
68 OPC_ORI
= (0x0D << 26),
69 OPC_XORI
= (0x0E << 26),
70 OPC_LUI
= (0x0F << 26),
71 /* arithmetic with immediate */
72 OPC_DADDI
= (0x18 << 26),
73 OPC_DADDIU
= (0x19 << 26),
74 /* Jump and branches */
76 OPC_JAL
= (0x03 << 26),
77 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
78 OPC_BEQL
= (0x14 << 26),
79 OPC_BNE
= (0x05 << 26),
80 OPC_BNEL
= (0x15 << 26),
81 OPC_BLEZ
= (0x06 << 26),
82 OPC_BLEZL
= (0x16 << 26),
83 OPC_BGTZ
= (0x07 << 26),
84 OPC_BGTZL
= (0x17 << 26),
85 OPC_JALX
= (0x1D << 26),
86 OPC_DAUI
= (0x1D << 26),
88 OPC_LDL
= (0x1A << 26),
89 OPC_LDR
= (0x1B << 26),
90 OPC_LB
= (0x20 << 26),
91 OPC_LH
= (0x21 << 26),
92 OPC_LWL
= (0x22 << 26),
93 OPC_LW
= (0x23 << 26),
94 OPC_LWPC
= OPC_LW
| 0x5,
95 OPC_LBU
= (0x24 << 26),
96 OPC_LHU
= (0x25 << 26),
97 OPC_LWR
= (0x26 << 26),
98 OPC_LWU
= (0x27 << 26),
99 OPC_SB
= (0x28 << 26),
100 OPC_SH
= (0x29 << 26),
101 OPC_SWL
= (0x2A << 26),
102 OPC_SW
= (0x2B << 26),
103 OPC_SDL
= (0x2C << 26),
104 OPC_SDR
= (0x2D << 26),
105 OPC_SWR
= (0x2E << 26),
106 OPC_LL
= (0x30 << 26),
107 OPC_LLD
= (0x34 << 26),
108 OPC_LD
= (0x37 << 26),
109 OPC_LDPC
= OPC_LD
| 0x5,
110 OPC_SC
= (0x38 << 26),
111 OPC_SCD
= (0x3C << 26),
112 OPC_SD
= (0x3F << 26),
113 /* Floating point load/store */
114 OPC_LWC1
= (0x31 << 26),
115 OPC_LWC2
= (0x32 << 26),
116 OPC_LDC1
= (0x35 << 26),
117 OPC_LDC2
= (0x36 << 26),
118 OPC_SWC1
= (0x39 << 26),
119 OPC_SWC2
= (0x3A << 26),
120 OPC_SDC1
= (0x3D << 26),
121 OPC_SDC2
= (0x3E << 26),
122 /* Compact Branches */
123 OPC_BLEZALC
= (0x06 << 26),
124 OPC_BGEZALC
= (0x06 << 26),
125 OPC_BGEUC
= (0x06 << 26),
126 OPC_BGTZALC
= (0x07 << 26),
127 OPC_BLTZALC
= (0x07 << 26),
128 OPC_BLTUC
= (0x07 << 26),
129 OPC_BOVC
= (0x08 << 26),
130 OPC_BEQZALC
= (0x08 << 26),
131 OPC_BEQC
= (0x08 << 26),
132 OPC_BLEZC
= (0x16 << 26),
133 OPC_BGEZC
= (0x16 << 26),
134 OPC_BGEC
= (0x16 << 26),
135 OPC_BGTZC
= (0x17 << 26),
136 OPC_BLTZC
= (0x17 << 26),
137 OPC_BLTC
= (0x17 << 26),
138 OPC_BNVC
= (0x18 << 26),
139 OPC_BNEZALC
= (0x18 << 26),
140 OPC_BNEC
= (0x18 << 26),
141 OPC_BC
= (0x32 << 26),
142 OPC_BEQZC
= (0x36 << 26),
143 OPC_JIC
= (0x36 << 26),
144 OPC_BALC
= (0x3A << 26),
145 OPC_BNEZC
= (0x3E << 26),
146 OPC_JIALC
= (0x3E << 26),
147 /* MDMX ASE specific */
148 OPC_MDMX
= (0x1E << 26),
149 /* Cache and prefetch */
150 OPC_CACHE
= (0x2F << 26),
151 OPC_PREF
= (0x33 << 26),
152 /* PC-relative address computation / loads */
153 OPC_PCREL
= (0x3B << 26),
156 /* PC-relative address computation / loads */
157 #define MASK_OPC_PCREL_TOP2BITS(op) (MASK_OP_MAJOR(op) | (op & (3 << 19)))
158 #define MASK_OPC_PCREL_TOP5BITS(op) (MASK_OP_MAJOR(op) | (op & (0x1f << 16)))
160 /* Instructions determined by bits 19 and 20 */
161 OPC_ADDIUPC
= OPC_PCREL
| (0 << 19),
162 R6_OPC_LWPC
= OPC_PCREL
| (1 << 19),
163 OPC_LWUPC
= OPC_PCREL
| (2 << 19),
165 /* Instructions determined by bits 16 ... 20 */
166 OPC_AUIPC
= OPC_PCREL
| (0x1e << 16),
167 OPC_ALUIPC
= OPC_PCREL
| (0x1f << 16),
170 R6_OPC_LDPC
= OPC_PCREL
| (6 << 18),
173 /* MIPS special opcodes */
174 #define MASK_SPECIAL(op) (MASK_OP_MAJOR(op) | (op & 0x3F))
178 OPC_SLL
= 0x00 | OPC_SPECIAL
,
179 /* NOP is SLL r0, r0, 0 */
180 /* SSNOP is SLL r0, r0, 1 */
181 /* EHB is SLL r0, r0, 3 */
182 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
183 OPC_ROTR
= OPC_SRL
| (1 << 21),
184 OPC_SRA
= 0x03 | OPC_SPECIAL
,
185 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
186 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
187 OPC_ROTRV
= OPC_SRLV
| (1 << 6),
188 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
189 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
190 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
191 OPC_DROTRV
= OPC_DSRLV
| (1 << 6),
192 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
193 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
194 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
195 OPC_DROTR
= OPC_DSRL
| (1 << 21),
196 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
197 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
198 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
199 OPC_DROTR32
= OPC_DSRL32
| (1 << 21),
200 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
201 /* Multiplication / division */
202 OPC_MULT
= 0x18 | OPC_SPECIAL
,
203 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
204 OPC_DIV
= 0x1A | OPC_SPECIAL
,
205 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
206 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
207 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
208 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
209 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
211 /* 2 registers arithmetic / logic */
212 OPC_ADD
= 0x20 | OPC_SPECIAL
,
213 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
214 OPC_SUB
= 0x22 | OPC_SPECIAL
,
215 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
216 OPC_AND
= 0x24 | OPC_SPECIAL
,
217 OPC_OR
= 0x25 | OPC_SPECIAL
,
218 OPC_XOR
= 0x26 | OPC_SPECIAL
,
219 OPC_NOR
= 0x27 | OPC_SPECIAL
,
220 OPC_SLT
= 0x2A | OPC_SPECIAL
,
221 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
222 OPC_DADD
= 0x2C | OPC_SPECIAL
,
223 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
224 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
225 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
227 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
228 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
230 OPC_TGE
= 0x30 | OPC_SPECIAL
,
231 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
232 OPC_TLT
= 0x32 | OPC_SPECIAL
,
233 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
234 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
235 OPC_TNE
= 0x36 | OPC_SPECIAL
,
236 /* HI / LO registers load & stores */
237 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
238 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
239 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
240 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
241 /* Conditional moves */
242 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
243 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
245 OPC_SELEQZ
= 0x35 | OPC_SPECIAL
,
246 OPC_SELNEZ
= 0x37 | OPC_SPECIAL
,
248 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
251 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* unofficial */
252 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
253 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
254 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
255 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
257 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
258 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
259 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
260 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
264 * R6 Multiply and Divide instructions have the same opcode
265 * and function field as legacy OPC_MULT[U]/OPC_DIV[U]
267 #define MASK_R6_MULDIV(op) (MASK_SPECIAL(op) | (op & (0x7ff)))
270 R6_OPC_MUL
= OPC_MULT
| (2 << 6),
271 R6_OPC_MUH
= OPC_MULT
| (3 << 6),
272 R6_OPC_MULU
= OPC_MULTU
| (2 << 6),
273 R6_OPC_MUHU
= OPC_MULTU
| (3 << 6),
274 R6_OPC_DIV
= OPC_DIV
| (2 << 6),
275 R6_OPC_MOD
= OPC_DIV
| (3 << 6),
276 R6_OPC_DIVU
= OPC_DIVU
| (2 << 6),
277 R6_OPC_MODU
= OPC_DIVU
| (3 << 6),
279 R6_OPC_DMUL
= OPC_DMULT
| (2 << 6),
280 R6_OPC_DMUH
= OPC_DMULT
| (3 << 6),
281 R6_OPC_DMULU
= OPC_DMULTU
| (2 << 6),
282 R6_OPC_DMUHU
= OPC_DMULTU
| (3 << 6),
283 R6_OPC_DDIV
= OPC_DDIV
| (2 << 6),
284 R6_OPC_DMOD
= OPC_DDIV
| (3 << 6),
285 R6_OPC_DDIVU
= OPC_DDIVU
| (2 << 6),
286 R6_OPC_DMODU
= OPC_DDIVU
| (3 << 6),
288 R6_OPC_CLZ
= 0x10 | OPC_SPECIAL
,
289 R6_OPC_CLO
= 0x11 | OPC_SPECIAL
,
290 R6_OPC_DCLZ
= 0x12 | OPC_SPECIAL
,
291 R6_OPC_DCLO
= 0x13 | OPC_SPECIAL
,
292 R6_OPC_SDBBP
= 0x0e | OPC_SPECIAL
,
295 /* REGIMM (rt field) opcodes */
296 #define MASK_REGIMM(op) (MASK_OP_MAJOR(op) | (op & (0x1F << 16)))
299 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
300 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
301 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
302 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
303 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
304 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
305 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
306 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
307 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
308 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
309 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
310 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
311 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
312 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
313 OPC_SIGRIE
= (0x17 << 16) | OPC_REGIMM
,
314 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
316 OPC_DAHI
= (0x06 << 16) | OPC_REGIMM
,
317 OPC_DATI
= (0x1e << 16) | OPC_REGIMM
,
320 /* Special2 opcodes */
321 #define MASK_SPECIAL2(op) (MASK_OP_MAJOR(op) | (op & 0x3F))
324 /* Multiply & xxx operations */
325 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
326 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
327 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
328 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
329 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
331 OPC_MULT_G_2F
= 0x10 | OPC_SPECIAL2
,
332 OPC_DMULT_G_2F
= 0x11 | OPC_SPECIAL2
,
333 OPC_MULTU_G_2F
= 0x12 | OPC_SPECIAL2
,
334 OPC_DMULTU_G_2F
= 0x13 | OPC_SPECIAL2
,
335 OPC_DIV_G_2F
= 0x14 | OPC_SPECIAL2
,
336 OPC_DDIV_G_2F
= 0x15 | OPC_SPECIAL2
,
337 OPC_DIVU_G_2F
= 0x16 | OPC_SPECIAL2
,
338 OPC_DDIVU_G_2F
= 0x17 | OPC_SPECIAL2
,
339 OPC_MOD_G_2F
= 0x1c | OPC_SPECIAL2
,
340 OPC_DMOD_G_2F
= 0x1d | OPC_SPECIAL2
,
341 OPC_MODU_G_2F
= 0x1e | OPC_SPECIAL2
,
342 OPC_DMODU_G_2F
= 0x1f | OPC_SPECIAL2
,
344 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
345 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
346 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
347 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
349 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
352 /* Special3 opcodes */
353 #define MASK_SPECIAL3(op) (MASK_OP_MAJOR(op) | (op & 0x3F))
356 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
357 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
358 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
359 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
360 OPC_INS
= 0x04 | OPC_SPECIAL3
,
361 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
362 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
363 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
364 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
365 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
366 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
367 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
368 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
369 OPC_GINV
= 0x3D | OPC_SPECIAL3
,
372 OPC_MULT_G_2E
= 0x18 | OPC_SPECIAL3
,
373 OPC_MULTU_G_2E
= 0x19 | OPC_SPECIAL3
,
374 OPC_DIV_G_2E
= 0x1A | OPC_SPECIAL3
,
375 OPC_DIVU_G_2E
= 0x1B | OPC_SPECIAL3
,
376 OPC_DMULT_G_2E
= 0x1C | OPC_SPECIAL3
,
377 OPC_DMULTU_G_2E
= 0x1D | OPC_SPECIAL3
,
378 OPC_DDIV_G_2E
= 0x1E | OPC_SPECIAL3
,
379 OPC_DDIVU_G_2E
= 0x1F | OPC_SPECIAL3
,
380 OPC_MOD_G_2E
= 0x22 | OPC_SPECIAL3
,
381 OPC_MODU_G_2E
= 0x23 | OPC_SPECIAL3
,
382 OPC_DMOD_G_2E
= 0x26 | OPC_SPECIAL3
,
383 OPC_DMODU_G_2E
= 0x27 | OPC_SPECIAL3
,
386 OPC_LX_DSP
= 0x0A | OPC_SPECIAL3
,
387 /* MIPS DSP Arithmetic */
388 OPC_ADDU_QB_DSP
= 0x10 | OPC_SPECIAL3
,
389 OPC_ADDU_OB_DSP
= 0x14 | OPC_SPECIAL3
,
390 OPC_ABSQ_S_PH_DSP
= 0x12 | OPC_SPECIAL3
,
391 OPC_ABSQ_S_QH_DSP
= 0x16 | OPC_SPECIAL3
,
392 /* OPC_ADDUH_QB_DSP is same as OPC_MULT_G_2E. */
393 /* OPC_ADDUH_QB_DSP = 0x18 | OPC_SPECIAL3, */
394 OPC_CMPU_EQ_QB_DSP
= 0x11 | OPC_SPECIAL3
,
395 OPC_CMPU_EQ_OB_DSP
= 0x15 | OPC_SPECIAL3
,
396 /* MIPS DSP GPR-Based Shift Sub-class */
397 OPC_SHLL_QB_DSP
= 0x13 | OPC_SPECIAL3
,
398 OPC_SHLL_OB_DSP
= 0x17 | OPC_SPECIAL3
,
399 /* MIPS DSP Multiply Sub-class insns */
400 /* OPC_MUL_PH_DSP is same as OPC_ADDUH_QB_DSP. */
401 /* OPC_MUL_PH_DSP = 0x18 | OPC_SPECIAL3, */
402 OPC_DPA_W_PH_DSP
= 0x30 | OPC_SPECIAL3
,
403 OPC_DPAQ_W_QH_DSP
= 0x34 | OPC_SPECIAL3
,
404 /* DSP Bit/Manipulation Sub-class */
405 OPC_INSV_DSP
= 0x0C | OPC_SPECIAL3
,
406 OPC_DINSV_DSP
= 0x0D | OPC_SPECIAL3
,
407 /* MIPS DSP Append Sub-class */
408 OPC_APPEND_DSP
= 0x31 | OPC_SPECIAL3
,
409 OPC_DAPPEND_DSP
= 0x35 | OPC_SPECIAL3
,
410 /* MIPS DSP Accumulator and DSPControl Access Sub-class */
411 OPC_EXTR_W_DSP
= 0x38 | OPC_SPECIAL3
,
412 OPC_DEXTR_W_DSP
= 0x3C | OPC_SPECIAL3
,
415 OPC_LWLE
= 0x19 | OPC_SPECIAL3
,
416 OPC_LWRE
= 0x1A | OPC_SPECIAL3
,
417 OPC_CACHEE
= 0x1B | OPC_SPECIAL3
,
418 OPC_SBE
= 0x1C | OPC_SPECIAL3
,
419 OPC_SHE
= 0x1D | OPC_SPECIAL3
,
420 OPC_SCE
= 0x1E | OPC_SPECIAL3
,
421 OPC_SWE
= 0x1F | OPC_SPECIAL3
,
422 OPC_SWLE
= 0x21 | OPC_SPECIAL3
,
423 OPC_SWRE
= 0x22 | OPC_SPECIAL3
,
424 OPC_PREFE
= 0x23 | OPC_SPECIAL3
,
425 OPC_LBUE
= 0x28 | OPC_SPECIAL3
,
426 OPC_LHUE
= 0x29 | OPC_SPECIAL3
,
427 OPC_LBE
= 0x2C | OPC_SPECIAL3
,
428 OPC_LHE
= 0x2D | OPC_SPECIAL3
,
429 OPC_LLE
= 0x2E | OPC_SPECIAL3
,
430 OPC_LWE
= 0x2F | OPC_SPECIAL3
,
433 R6_OPC_PREF
= 0x35 | OPC_SPECIAL3
,
434 R6_OPC_CACHE
= 0x25 | OPC_SPECIAL3
,
435 R6_OPC_LL
= 0x36 | OPC_SPECIAL3
,
436 R6_OPC_SC
= 0x26 | OPC_SPECIAL3
,
437 R6_OPC_LLD
= 0x37 | OPC_SPECIAL3
,
438 R6_OPC_SCD
= 0x27 | OPC_SPECIAL3
,
441 /* Loongson EXT load/store quad word opcodes */
442 #define MASK_LOONGSON_GSLSQ(op) (MASK_OP_MAJOR(op) | (op & 0x8020))
444 OPC_GSLQ
= 0x0020 | OPC_LWC2
,
445 OPC_GSLQC1
= 0x8020 | OPC_LWC2
,
446 OPC_GSSHFL
= OPC_LWC2
,
447 OPC_GSSQ
= 0x0020 | OPC_SWC2
,
448 OPC_GSSQC1
= 0x8020 | OPC_SWC2
,
449 OPC_GSSHFS
= OPC_SWC2
,
452 /* Loongson EXT shifted load/store opcodes */
453 #define MASK_LOONGSON_GSSHFLS(op) (MASK_OP_MAJOR(op) | (op & 0xc03f))
455 OPC_GSLWLC1
= 0x4 | OPC_GSSHFL
,
456 OPC_GSLWRC1
= 0x5 | OPC_GSSHFL
,
457 OPC_GSLDLC1
= 0x6 | OPC_GSSHFL
,
458 OPC_GSLDRC1
= 0x7 | OPC_GSSHFL
,
459 OPC_GSSWLC1
= 0x4 | OPC_GSSHFS
,
460 OPC_GSSWRC1
= 0x5 | OPC_GSSHFS
,
461 OPC_GSSDLC1
= 0x6 | OPC_GSSHFS
,
462 OPC_GSSDRC1
= 0x7 | OPC_GSSHFS
,
465 /* Loongson EXT LDC2/SDC2 opcodes */
466 #define MASK_LOONGSON_LSDC2(op) (MASK_OP_MAJOR(op) | (op & 0x7))
469 OPC_GSLBX
= 0x0 | OPC_LDC2
,
470 OPC_GSLHX
= 0x1 | OPC_LDC2
,
471 OPC_GSLWX
= 0x2 | OPC_LDC2
,
472 OPC_GSLDX
= 0x3 | OPC_LDC2
,
473 OPC_GSLWXC1
= 0x6 | OPC_LDC2
,
474 OPC_GSLDXC1
= 0x7 | OPC_LDC2
,
475 OPC_GSSBX
= 0x0 | OPC_SDC2
,
476 OPC_GSSHX
= 0x1 | OPC_SDC2
,
477 OPC_GSSWX
= 0x2 | OPC_SDC2
,
478 OPC_GSSDX
= 0x3 | OPC_SDC2
,
479 OPC_GSSWXC1
= 0x6 | OPC_SDC2
,
480 OPC_GSSDXC1
= 0x7 | OPC_SDC2
,
484 #define MASK_BSHFL(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
487 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
488 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
489 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
490 OPC_ALIGN
= (0x08 << 6) | OPC_BSHFL
, /* 010.bp (010.00 to 010.11) */
491 OPC_ALIGN_1
= (0x09 << 6) | OPC_BSHFL
,
492 OPC_ALIGN_2
= (0x0A << 6) | OPC_BSHFL
,
493 OPC_ALIGN_3
= (0x0B << 6) | OPC_BSHFL
,
494 OPC_BITSWAP
= (0x00 << 6) | OPC_BSHFL
/* 00000 */
498 #define MASK_DBSHFL(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
501 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
502 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
503 OPC_DALIGN
= (0x08 << 6) | OPC_DBSHFL
, /* 01.bp (01.000 to 01.111) */
504 OPC_DALIGN_1
= (0x09 << 6) | OPC_DBSHFL
,
505 OPC_DALIGN_2
= (0x0A << 6) | OPC_DBSHFL
,
506 OPC_DALIGN_3
= (0x0B << 6) | OPC_DBSHFL
,
507 OPC_DALIGN_4
= (0x0C << 6) | OPC_DBSHFL
,
508 OPC_DALIGN_5
= (0x0D << 6) | OPC_DBSHFL
,
509 OPC_DALIGN_6
= (0x0E << 6) | OPC_DBSHFL
,
510 OPC_DALIGN_7
= (0x0F << 6) | OPC_DBSHFL
,
511 OPC_DBITSWAP
= (0x00 << 6) | OPC_DBSHFL
, /* 00000 */
514 /* MIPS DSP REGIMM opcodes */
516 OPC_BPOSGE32
= (0x1C << 16) | OPC_REGIMM
,
517 OPC_BPOSGE64
= (0x1D << 16) | OPC_REGIMM
,
520 #define MASK_LX(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
523 OPC_LBUX
= (0x06 << 6) | OPC_LX_DSP
,
524 OPC_LHX
= (0x04 << 6) | OPC_LX_DSP
,
525 OPC_LWX
= (0x00 << 6) | OPC_LX_DSP
,
526 OPC_LDX
= (0x08 << 6) | OPC_LX_DSP
,
529 #define MASK_ADDU_QB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
531 /* MIPS DSP Arithmetic Sub-class */
532 OPC_ADDQ_PH
= (0x0A << 6) | OPC_ADDU_QB_DSP
,
533 OPC_ADDQ_S_PH
= (0x0E << 6) | OPC_ADDU_QB_DSP
,
534 OPC_ADDQ_S_W
= (0x16 << 6) | OPC_ADDU_QB_DSP
,
535 OPC_ADDU_QB
= (0x00 << 6) | OPC_ADDU_QB_DSP
,
536 OPC_ADDU_S_QB
= (0x04 << 6) | OPC_ADDU_QB_DSP
,
537 OPC_ADDU_PH
= (0x08 << 6) | OPC_ADDU_QB_DSP
,
538 OPC_ADDU_S_PH
= (0x0C << 6) | OPC_ADDU_QB_DSP
,
539 OPC_SUBQ_PH
= (0x0B << 6) | OPC_ADDU_QB_DSP
,
540 OPC_SUBQ_S_PH
= (0x0F << 6) | OPC_ADDU_QB_DSP
,
541 OPC_SUBQ_S_W
= (0x17 << 6) | OPC_ADDU_QB_DSP
,
542 OPC_SUBU_QB
= (0x01 << 6) | OPC_ADDU_QB_DSP
,
543 OPC_SUBU_S_QB
= (0x05 << 6) | OPC_ADDU_QB_DSP
,
544 OPC_SUBU_PH
= (0x09 << 6) | OPC_ADDU_QB_DSP
,
545 OPC_SUBU_S_PH
= (0x0D << 6) | OPC_ADDU_QB_DSP
,
546 OPC_ADDSC
= (0x10 << 6) | OPC_ADDU_QB_DSP
,
547 OPC_ADDWC
= (0x11 << 6) | OPC_ADDU_QB_DSP
,
548 OPC_MODSUB
= (0x12 << 6) | OPC_ADDU_QB_DSP
,
549 OPC_RADDU_W_QB
= (0x14 << 6) | OPC_ADDU_QB_DSP
,
550 /* MIPS DSP Multiply Sub-class insns */
551 OPC_MULEU_S_PH_QBL
= (0x06 << 6) | OPC_ADDU_QB_DSP
,
552 OPC_MULEU_S_PH_QBR
= (0x07 << 6) | OPC_ADDU_QB_DSP
,
553 OPC_MULQ_RS_PH
= (0x1F << 6) | OPC_ADDU_QB_DSP
,
554 OPC_MULEQ_S_W_PHL
= (0x1C << 6) | OPC_ADDU_QB_DSP
,
555 OPC_MULEQ_S_W_PHR
= (0x1D << 6) | OPC_ADDU_QB_DSP
,
556 OPC_MULQ_S_PH
= (0x1E << 6) | OPC_ADDU_QB_DSP
,
559 #define OPC_ADDUH_QB_DSP OPC_MULT_G_2E
560 #define MASK_ADDUH_QB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
562 /* MIPS DSP Arithmetic Sub-class */
563 OPC_ADDUH_QB
= (0x00 << 6) | OPC_ADDUH_QB_DSP
,
564 OPC_ADDUH_R_QB
= (0x02 << 6) | OPC_ADDUH_QB_DSP
,
565 OPC_ADDQH_PH
= (0x08 << 6) | OPC_ADDUH_QB_DSP
,
566 OPC_ADDQH_R_PH
= (0x0A << 6) | OPC_ADDUH_QB_DSP
,
567 OPC_ADDQH_W
= (0x10 << 6) | OPC_ADDUH_QB_DSP
,
568 OPC_ADDQH_R_W
= (0x12 << 6) | OPC_ADDUH_QB_DSP
,
569 OPC_SUBUH_QB
= (0x01 << 6) | OPC_ADDUH_QB_DSP
,
570 OPC_SUBUH_R_QB
= (0x03 << 6) | OPC_ADDUH_QB_DSP
,
571 OPC_SUBQH_PH
= (0x09 << 6) | OPC_ADDUH_QB_DSP
,
572 OPC_SUBQH_R_PH
= (0x0B << 6) | OPC_ADDUH_QB_DSP
,
573 OPC_SUBQH_W
= (0x11 << 6) | OPC_ADDUH_QB_DSP
,
574 OPC_SUBQH_R_W
= (0x13 << 6) | OPC_ADDUH_QB_DSP
,
575 /* MIPS DSP Multiply Sub-class insns */
576 OPC_MUL_PH
= (0x0C << 6) | OPC_ADDUH_QB_DSP
,
577 OPC_MUL_S_PH
= (0x0E << 6) | OPC_ADDUH_QB_DSP
,
578 OPC_MULQ_S_W
= (0x16 << 6) | OPC_ADDUH_QB_DSP
,
579 OPC_MULQ_RS_W
= (0x17 << 6) | OPC_ADDUH_QB_DSP
,
582 #define MASK_ABSQ_S_PH(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
584 /* MIPS DSP Arithmetic Sub-class */
585 OPC_ABSQ_S_QB
= (0x01 << 6) | OPC_ABSQ_S_PH_DSP
,
586 OPC_ABSQ_S_PH
= (0x09 << 6) | OPC_ABSQ_S_PH_DSP
,
587 OPC_ABSQ_S_W
= (0x11 << 6) | OPC_ABSQ_S_PH_DSP
,
588 OPC_PRECEQ_W_PHL
= (0x0C << 6) | OPC_ABSQ_S_PH_DSP
,
589 OPC_PRECEQ_W_PHR
= (0x0D << 6) | OPC_ABSQ_S_PH_DSP
,
590 OPC_PRECEQU_PH_QBL
= (0x04 << 6) | OPC_ABSQ_S_PH_DSP
,
591 OPC_PRECEQU_PH_QBR
= (0x05 << 6) | OPC_ABSQ_S_PH_DSP
,
592 OPC_PRECEQU_PH_QBLA
= (0x06 << 6) | OPC_ABSQ_S_PH_DSP
,
593 OPC_PRECEQU_PH_QBRA
= (0x07 << 6) | OPC_ABSQ_S_PH_DSP
,
594 OPC_PRECEU_PH_QBL
= (0x1C << 6) | OPC_ABSQ_S_PH_DSP
,
595 OPC_PRECEU_PH_QBR
= (0x1D << 6) | OPC_ABSQ_S_PH_DSP
,
596 OPC_PRECEU_PH_QBLA
= (0x1E << 6) | OPC_ABSQ_S_PH_DSP
,
597 OPC_PRECEU_PH_QBRA
= (0x1F << 6) | OPC_ABSQ_S_PH_DSP
,
598 /* DSP Bit/Manipulation Sub-class */
599 OPC_BITREV
= (0x1B << 6) | OPC_ABSQ_S_PH_DSP
,
600 OPC_REPL_QB
= (0x02 << 6) | OPC_ABSQ_S_PH_DSP
,
601 OPC_REPLV_QB
= (0x03 << 6) | OPC_ABSQ_S_PH_DSP
,
602 OPC_REPL_PH
= (0x0A << 6) | OPC_ABSQ_S_PH_DSP
,
603 OPC_REPLV_PH
= (0x0B << 6) | OPC_ABSQ_S_PH_DSP
,
606 #define MASK_CMPU_EQ_QB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
608 /* MIPS DSP Arithmetic Sub-class */
609 OPC_PRECR_QB_PH
= (0x0D << 6) | OPC_CMPU_EQ_QB_DSP
,
610 OPC_PRECRQ_QB_PH
= (0x0C << 6) | OPC_CMPU_EQ_QB_DSP
,
611 OPC_PRECR_SRA_PH_W
= (0x1E << 6) | OPC_CMPU_EQ_QB_DSP
,
612 OPC_PRECR_SRA_R_PH_W
= (0x1F << 6) | OPC_CMPU_EQ_QB_DSP
,
613 OPC_PRECRQ_PH_W
= (0x14 << 6) | OPC_CMPU_EQ_QB_DSP
,
614 OPC_PRECRQ_RS_PH_W
= (0x15 << 6) | OPC_CMPU_EQ_QB_DSP
,
615 OPC_PRECRQU_S_QB_PH
= (0x0F << 6) | OPC_CMPU_EQ_QB_DSP
,
616 /* DSP Compare-Pick Sub-class */
617 OPC_CMPU_EQ_QB
= (0x00 << 6) | OPC_CMPU_EQ_QB_DSP
,
618 OPC_CMPU_LT_QB
= (0x01 << 6) | OPC_CMPU_EQ_QB_DSP
,
619 OPC_CMPU_LE_QB
= (0x02 << 6) | OPC_CMPU_EQ_QB_DSP
,
620 OPC_CMPGU_EQ_QB
= (0x04 << 6) | OPC_CMPU_EQ_QB_DSP
,
621 OPC_CMPGU_LT_QB
= (0x05 << 6) | OPC_CMPU_EQ_QB_DSP
,
622 OPC_CMPGU_LE_QB
= (0x06 << 6) | OPC_CMPU_EQ_QB_DSP
,
623 OPC_CMPGDU_EQ_QB
= (0x18 << 6) | OPC_CMPU_EQ_QB_DSP
,
624 OPC_CMPGDU_LT_QB
= (0x19 << 6) | OPC_CMPU_EQ_QB_DSP
,
625 OPC_CMPGDU_LE_QB
= (0x1A << 6) | OPC_CMPU_EQ_QB_DSP
,
626 OPC_CMP_EQ_PH
= (0x08 << 6) | OPC_CMPU_EQ_QB_DSP
,
627 OPC_CMP_LT_PH
= (0x09 << 6) | OPC_CMPU_EQ_QB_DSP
,
628 OPC_CMP_LE_PH
= (0x0A << 6) | OPC_CMPU_EQ_QB_DSP
,
629 OPC_PICK_QB
= (0x03 << 6) | OPC_CMPU_EQ_QB_DSP
,
630 OPC_PICK_PH
= (0x0B << 6) | OPC_CMPU_EQ_QB_DSP
,
631 OPC_PACKRL_PH
= (0x0E << 6) | OPC_CMPU_EQ_QB_DSP
,
634 #define MASK_SHLL_QB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
636 /* MIPS DSP GPR-Based Shift Sub-class */
637 OPC_SHLL_QB
= (0x00 << 6) | OPC_SHLL_QB_DSP
,
638 OPC_SHLLV_QB
= (0x02 << 6) | OPC_SHLL_QB_DSP
,
639 OPC_SHLL_PH
= (0x08 << 6) | OPC_SHLL_QB_DSP
,
640 OPC_SHLLV_PH
= (0x0A << 6) | OPC_SHLL_QB_DSP
,
641 OPC_SHLL_S_PH
= (0x0C << 6) | OPC_SHLL_QB_DSP
,
642 OPC_SHLLV_S_PH
= (0x0E << 6) | OPC_SHLL_QB_DSP
,
643 OPC_SHLL_S_W
= (0x14 << 6) | OPC_SHLL_QB_DSP
,
644 OPC_SHLLV_S_W
= (0x16 << 6) | OPC_SHLL_QB_DSP
,
645 OPC_SHRL_QB
= (0x01 << 6) | OPC_SHLL_QB_DSP
,
646 OPC_SHRLV_QB
= (0x03 << 6) | OPC_SHLL_QB_DSP
,
647 OPC_SHRL_PH
= (0x19 << 6) | OPC_SHLL_QB_DSP
,
648 OPC_SHRLV_PH
= (0x1B << 6) | OPC_SHLL_QB_DSP
,
649 OPC_SHRA_QB
= (0x04 << 6) | OPC_SHLL_QB_DSP
,
650 OPC_SHRA_R_QB
= (0x05 << 6) | OPC_SHLL_QB_DSP
,
651 OPC_SHRAV_QB
= (0x06 << 6) | OPC_SHLL_QB_DSP
,
652 OPC_SHRAV_R_QB
= (0x07 << 6) | OPC_SHLL_QB_DSP
,
653 OPC_SHRA_PH
= (0x09 << 6) | OPC_SHLL_QB_DSP
,
654 OPC_SHRAV_PH
= (0x0B << 6) | OPC_SHLL_QB_DSP
,
655 OPC_SHRA_R_PH
= (0x0D << 6) | OPC_SHLL_QB_DSP
,
656 OPC_SHRAV_R_PH
= (0x0F << 6) | OPC_SHLL_QB_DSP
,
657 OPC_SHRA_R_W
= (0x15 << 6) | OPC_SHLL_QB_DSP
,
658 OPC_SHRAV_R_W
= (0x17 << 6) | OPC_SHLL_QB_DSP
,
661 #define MASK_DPA_W_PH(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
663 /* MIPS DSP Multiply Sub-class insns */
664 OPC_DPAU_H_QBL
= (0x03 << 6) | OPC_DPA_W_PH_DSP
,
665 OPC_DPAU_H_QBR
= (0x07 << 6) | OPC_DPA_W_PH_DSP
,
666 OPC_DPSU_H_QBL
= (0x0B << 6) | OPC_DPA_W_PH_DSP
,
667 OPC_DPSU_H_QBR
= (0x0F << 6) | OPC_DPA_W_PH_DSP
,
668 OPC_DPA_W_PH
= (0x00 << 6) | OPC_DPA_W_PH_DSP
,
669 OPC_DPAX_W_PH
= (0x08 << 6) | OPC_DPA_W_PH_DSP
,
670 OPC_DPAQ_S_W_PH
= (0x04 << 6) | OPC_DPA_W_PH_DSP
,
671 OPC_DPAQX_S_W_PH
= (0x18 << 6) | OPC_DPA_W_PH_DSP
,
672 OPC_DPAQX_SA_W_PH
= (0x1A << 6) | OPC_DPA_W_PH_DSP
,
673 OPC_DPS_W_PH
= (0x01 << 6) | OPC_DPA_W_PH_DSP
,
674 OPC_DPSX_W_PH
= (0x09 << 6) | OPC_DPA_W_PH_DSP
,
675 OPC_DPSQ_S_W_PH
= (0x05 << 6) | OPC_DPA_W_PH_DSP
,
676 OPC_DPSQX_S_W_PH
= (0x19 << 6) | OPC_DPA_W_PH_DSP
,
677 OPC_DPSQX_SA_W_PH
= (0x1B << 6) | OPC_DPA_W_PH_DSP
,
678 OPC_MULSAQ_S_W_PH
= (0x06 << 6) | OPC_DPA_W_PH_DSP
,
679 OPC_DPAQ_SA_L_W
= (0x0C << 6) | OPC_DPA_W_PH_DSP
,
680 OPC_DPSQ_SA_L_W
= (0x0D << 6) | OPC_DPA_W_PH_DSP
,
681 OPC_MAQ_S_W_PHL
= (0x14 << 6) | OPC_DPA_W_PH_DSP
,
682 OPC_MAQ_S_W_PHR
= (0x16 << 6) | OPC_DPA_W_PH_DSP
,
683 OPC_MAQ_SA_W_PHL
= (0x10 << 6) | OPC_DPA_W_PH_DSP
,
684 OPC_MAQ_SA_W_PHR
= (0x12 << 6) | OPC_DPA_W_PH_DSP
,
685 OPC_MULSA_W_PH
= (0x02 << 6) | OPC_DPA_W_PH_DSP
,
688 #define MASK_INSV(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
690 /* DSP Bit/Manipulation Sub-class */
691 OPC_INSV
= (0x00 << 6) | OPC_INSV_DSP
,
694 #define MASK_APPEND(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
696 /* MIPS DSP Append Sub-class */
697 OPC_APPEND
= (0x00 << 6) | OPC_APPEND_DSP
,
698 OPC_PREPEND
= (0x01 << 6) | OPC_APPEND_DSP
,
699 OPC_BALIGN
= (0x10 << 6) | OPC_APPEND_DSP
,
702 #define MASK_EXTR_W(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
704 /* MIPS DSP Accumulator and DSPControl Access Sub-class */
705 OPC_EXTR_W
= (0x00 << 6) | OPC_EXTR_W_DSP
,
706 OPC_EXTR_R_W
= (0x04 << 6) | OPC_EXTR_W_DSP
,
707 OPC_EXTR_RS_W
= (0x06 << 6) | OPC_EXTR_W_DSP
,
708 OPC_EXTR_S_H
= (0x0E << 6) | OPC_EXTR_W_DSP
,
709 OPC_EXTRV_S_H
= (0x0F << 6) | OPC_EXTR_W_DSP
,
710 OPC_EXTRV_W
= (0x01 << 6) | OPC_EXTR_W_DSP
,
711 OPC_EXTRV_R_W
= (0x05 << 6) | OPC_EXTR_W_DSP
,
712 OPC_EXTRV_RS_W
= (0x07 << 6) | OPC_EXTR_W_DSP
,
713 OPC_EXTP
= (0x02 << 6) | OPC_EXTR_W_DSP
,
714 OPC_EXTPV
= (0x03 << 6) | OPC_EXTR_W_DSP
,
715 OPC_EXTPDP
= (0x0A << 6) | OPC_EXTR_W_DSP
,
716 OPC_EXTPDPV
= (0x0B << 6) | OPC_EXTR_W_DSP
,
717 OPC_SHILO
= (0x1A << 6) | OPC_EXTR_W_DSP
,
718 OPC_SHILOV
= (0x1B << 6) | OPC_EXTR_W_DSP
,
719 OPC_MTHLIP
= (0x1F << 6) | OPC_EXTR_W_DSP
,
720 OPC_WRDSP
= (0x13 << 6) | OPC_EXTR_W_DSP
,
721 OPC_RDDSP
= (0x12 << 6) | OPC_EXTR_W_DSP
,
724 #define MASK_ABSQ_S_QH(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
726 /* MIPS DSP Arithmetic Sub-class */
727 OPC_PRECEQ_L_PWL
= (0x14 << 6) | OPC_ABSQ_S_QH_DSP
,
728 OPC_PRECEQ_L_PWR
= (0x15 << 6) | OPC_ABSQ_S_QH_DSP
,
729 OPC_PRECEQ_PW_QHL
= (0x0C << 6) | OPC_ABSQ_S_QH_DSP
,
730 OPC_PRECEQ_PW_QHR
= (0x0D << 6) | OPC_ABSQ_S_QH_DSP
,
731 OPC_PRECEQ_PW_QHLA
= (0x0E << 6) | OPC_ABSQ_S_QH_DSP
,
732 OPC_PRECEQ_PW_QHRA
= (0x0F << 6) | OPC_ABSQ_S_QH_DSP
,
733 OPC_PRECEQU_QH_OBL
= (0x04 << 6) | OPC_ABSQ_S_QH_DSP
,
734 OPC_PRECEQU_QH_OBR
= (0x05 << 6) | OPC_ABSQ_S_QH_DSP
,
735 OPC_PRECEQU_QH_OBLA
= (0x06 << 6) | OPC_ABSQ_S_QH_DSP
,
736 OPC_PRECEQU_QH_OBRA
= (0x07 << 6) | OPC_ABSQ_S_QH_DSP
,
737 OPC_PRECEU_QH_OBL
= (0x1C << 6) | OPC_ABSQ_S_QH_DSP
,
738 OPC_PRECEU_QH_OBR
= (0x1D << 6) | OPC_ABSQ_S_QH_DSP
,
739 OPC_PRECEU_QH_OBLA
= (0x1E << 6) | OPC_ABSQ_S_QH_DSP
,
740 OPC_PRECEU_QH_OBRA
= (0x1F << 6) | OPC_ABSQ_S_QH_DSP
,
741 OPC_ABSQ_S_OB
= (0x01 << 6) | OPC_ABSQ_S_QH_DSP
,
742 OPC_ABSQ_S_PW
= (0x11 << 6) | OPC_ABSQ_S_QH_DSP
,
743 OPC_ABSQ_S_QH
= (0x09 << 6) | OPC_ABSQ_S_QH_DSP
,
744 /* DSP Bit/Manipulation Sub-class */
745 OPC_REPL_OB
= (0x02 << 6) | OPC_ABSQ_S_QH_DSP
,
746 OPC_REPL_PW
= (0x12 << 6) | OPC_ABSQ_S_QH_DSP
,
747 OPC_REPL_QH
= (0x0A << 6) | OPC_ABSQ_S_QH_DSP
,
748 OPC_REPLV_OB
= (0x03 << 6) | OPC_ABSQ_S_QH_DSP
,
749 OPC_REPLV_PW
= (0x13 << 6) | OPC_ABSQ_S_QH_DSP
,
750 OPC_REPLV_QH
= (0x0B << 6) | OPC_ABSQ_S_QH_DSP
,
753 #define MASK_ADDU_OB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
755 /* MIPS DSP Multiply Sub-class insns */
756 OPC_MULEQ_S_PW_QHL
= (0x1C << 6) | OPC_ADDU_OB_DSP
,
757 OPC_MULEQ_S_PW_QHR
= (0x1D << 6) | OPC_ADDU_OB_DSP
,
758 OPC_MULEU_S_QH_OBL
= (0x06 << 6) | OPC_ADDU_OB_DSP
,
759 OPC_MULEU_S_QH_OBR
= (0x07 << 6) | OPC_ADDU_OB_DSP
,
760 OPC_MULQ_RS_QH
= (0x1F << 6) | OPC_ADDU_OB_DSP
,
761 /* MIPS DSP Arithmetic Sub-class */
762 OPC_RADDU_L_OB
= (0x14 << 6) | OPC_ADDU_OB_DSP
,
763 OPC_SUBQ_PW
= (0x13 << 6) | OPC_ADDU_OB_DSP
,
764 OPC_SUBQ_S_PW
= (0x17 << 6) | OPC_ADDU_OB_DSP
,
765 OPC_SUBQ_QH
= (0x0B << 6) | OPC_ADDU_OB_DSP
,
766 OPC_SUBQ_S_QH
= (0x0F << 6) | OPC_ADDU_OB_DSP
,
767 OPC_SUBU_OB
= (0x01 << 6) | OPC_ADDU_OB_DSP
,
768 OPC_SUBU_S_OB
= (0x05 << 6) | OPC_ADDU_OB_DSP
,
769 OPC_SUBU_QH
= (0x09 << 6) | OPC_ADDU_OB_DSP
,
770 OPC_SUBU_S_QH
= (0x0D << 6) | OPC_ADDU_OB_DSP
,
771 OPC_SUBUH_OB
= (0x19 << 6) | OPC_ADDU_OB_DSP
,
772 OPC_SUBUH_R_OB
= (0x1B << 6) | OPC_ADDU_OB_DSP
,
773 OPC_ADDQ_PW
= (0x12 << 6) | OPC_ADDU_OB_DSP
,
774 OPC_ADDQ_S_PW
= (0x16 << 6) | OPC_ADDU_OB_DSP
,
775 OPC_ADDQ_QH
= (0x0A << 6) | OPC_ADDU_OB_DSP
,
776 OPC_ADDQ_S_QH
= (0x0E << 6) | OPC_ADDU_OB_DSP
,
777 OPC_ADDU_OB
= (0x00 << 6) | OPC_ADDU_OB_DSP
,
778 OPC_ADDU_S_OB
= (0x04 << 6) | OPC_ADDU_OB_DSP
,
779 OPC_ADDU_QH
= (0x08 << 6) | OPC_ADDU_OB_DSP
,
780 OPC_ADDU_S_QH
= (0x0C << 6) | OPC_ADDU_OB_DSP
,
781 OPC_ADDUH_OB
= (0x18 << 6) | OPC_ADDU_OB_DSP
,
782 OPC_ADDUH_R_OB
= (0x1A << 6) | OPC_ADDU_OB_DSP
,
785 #define MASK_CMPU_EQ_OB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
787 /* DSP Compare-Pick Sub-class */
788 OPC_CMP_EQ_PW
= (0x10 << 6) | OPC_CMPU_EQ_OB_DSP
,
789 OPC_CMP_LT_PW
= (0x11 << 6) | OPC_CMPU_EQ_OB_DSP
,
790 OPC_CMP_LE_PW
= (0x12 << 6) | OPC_CMPU_EQ_OB_DSP
,
791 OPC_CMP_EQ_QH
= (0x08 << 6) | OPC_CMPU_EQ_OB_DSP
,
792 OPC_CMP_LT_QH
= (0x09 << 6) | OPC_CMPU_EQ_OB_DSP
,
793 OPC_CMP_LE_QH
= (0x0A << 6) | OPC_CMPU_EQ_OB_DSP
,
794 OPC_CMPGDU_EQ_OB
= (0x18 << 6) | OPC_CMPU_EQ_OB_DSP
,
795 OPC_CMPGDU_LT_OB
= (0x19 << 6) | OPC_CMPU_EQ_OB_DSP
,
796 OPC_CMPGDU_LE_OB
= (0x1A << 6) | OPC_CMPU_EQ_OB_DSP
,
797 OPC_CMPGU_EQ_OB
= (0x04 << 6) | OPC_CMPU_EQ_OB_DSP
,
798 OPC_CMPGU_LT_OB
= (0x05 << 6) | OPC_CMPU_EQ_OB_DSP
,
799 OPC_CMPGU_LE_OB
= (0x06 << 6) | OPC_CMPU_EQ_OB_DSP
,
800 OPC_CMPU_EQ_OB
= (0x00 << 6) | OPC_CMPU_EQ_OB_DSP
,
801 OPC_CMPU_LT_OB
= (0x01 << 6) | OPC_CMPU_EQ_OB_DSP
,
802 OPC_CMPU_LE_OB
= (0x02 << 6) | OPC_CMPU_EQ_OB_DSP
,
803 OPC_PACKRL_PW
= (0x0E << 6) | OPC_CMPU_EQ_OB_DSP
,
804 OPC_PICK_OB
= (0x03 << 6) | OPC_CMPU_EQ_OB_DSP
,
805 OPC_PICK_PW
= (0x13 << 6) | OPC_CMPU_EQ_OB_DSP
,
806 OPC_PICK_QH
= (0x0B << 6) | OPC_CMPU_EQ_OB_DSP
,
807 /* MIPS DSP Arithmetic Sub-class */
808 OPC_PRECR_OB_QH
= (0x0D << 6) | OPC_CMPU_EQ_OB_DSP
,
809 OPC_PRECR_SRA_QH_PW
= (0x1E << 6) | OPC_CMPU_EQ_OB_DSP
,
810 OPC_PRECR_SRA_R_QH_PW
= (0x1F << 6) | OPC_CMPU_EQ_OB_DSP
,
811 OPC_PRECRQ_OB_QH
= (0x0C << 6) | OPC_CMPU_EQ_OB_DSP
,
812 OPC_PRECRQ_PW_L
= (0x1C << 6) | OPC_CMPU_EQ_OB_DSP
,
813 OPC_PRECRQ_QH_PW
= (0x14 << 6) | OPC_CMPU_EQ_OB_DSP
,
814 OPC_PRECRQ_RS_QH_PW
= (0x15 << 6) | OPC_CMPU_EQ_OB_DSP
,
815 OPC_PRECRQU_S_OB_QH
= (0x0F << 6) | OPC_CMPU_EQ_OB_DSP
,
818 #define MASK_DAPPEND(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
820 /* DSP Append Sub-class */
821 OPC_DAPPEND
= (0x00 << 6) | OPC_DAPPEND_DSP
,
822 OPC_PREPENDD
= (0x03 << 6) | OPC_DAPPEND_DSP
,
823 OPC_PREPENDW
= (0x01 << 6) | OPC_DAPPEND_DSP
,
824 OPC_DBALIGN
= (0x10 << 6) | OPC_DAPPEND_DSP
,
827 #define MASK_DEXTR_W(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
829 /* MIPS DSP Accumulator and DSPControl Access Sub-class */
830 OPC_DMTHLIP
= (0x1F << 6) | OPC_DEXTR_W_DSP
,
831 OPC_DSHILO
= (0x1A << 6) | OPC_DEXTR_W_DSP
,
832 OPC_DEXTP
= (0x02 << 6) | OPC_DEXTR_W_DSP
,
833 OPC_DEXTPDP
= (0x0A << 6) | OPC_DEXTR_W_DSP
,
834 OPC_DEXTPDPV
= (0x0B << 6) | OPC_DEXTR_W_DSP
,
835 OPC_DEXTPV
= (0x03 << 6) | OPC_DEXTR_W_DSP
,
836 OPC_DEXTR_L
= (0x10 << 6) | OPC_DEXTR_W_DSP
,
837 OPC_DEXTR_R_L
= (0x14 << 6) | OPC_DEXTR_W_DSP
,
838 OPC_DEXTR_RS_L
= (0x16 << 6) | OPC_DEXTR_W_DSP
,
839 OPC_DEXTR_W
= (0x00 << 6) | OPC_DEXTR_W_DSP
,
840 OPC_DEXTR_R_W
= (0x04 << 6) | OPC_DEXTR_W_DSP
,
841 OPC_DEXTR_RS_W
= (0x06 << 6) | OPC_DEXTR_W_DSP
,
842 OPC_DEXTR_S_H
= (0x0E << 6) | OPC_DEXTR_W_DSP
,
843 OPC_DEXTRV_L
= (0x11 << 6) | OPC_DEXTR_W_DSP
,
844 OPC_DEXTRV_R_L
= (0x15 << 6) | OPC_DEXTR_W_DSP
,
845 OPC_DEXTRV_RS_L
= (0x17 << 6) | OPC_DEXTR_W_DSP
,
846 OPC_DEXTRV_S_H
= (0x0F << 6) | OPC_DEXTR_W_DSP
,
847 OPC_DEXTRV_W
= (0x01 << 6) | OPC_DEXTR_W_DSP
,
848 OPC_DEXTRV_R_W
= (0x05 << 6) | OPC_DEXTR_W_DSP
,
849 OPC_DEXTRV_RS_W
= (0x07 << 6) | OPC_DEXTR_W_DSP
,
850 OPC_DSHILOV
= (0x1B << 6) | OPC_DEXTR_W_DSP
,
853 #define MASK_DINSV(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
855 /* DSP Bit/Manipulation Sub-class */
856 OPC_DINSV
= (0x00 << 6) | OPC_DINSV_DSP
,
859 #define MASK_DPAQ_W_QH(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
861 /* MIPS DSP Multiply Sub-class insns */
862 OPC_DMADD
= (0x19 << 6) | OPC_DPAQ_W_QH_DSP
,
863 OPC_DMADDU
= (0x1D << 6) | OPC_DPAQ_W_QH_DSP
,
864 OPC_DMSUB
= (0x1B << 6) | OPC_DPAQ_W_QH_DSP
,
865 OPC_DMSUBU
= (0x1F << 6) | OPC_DPAQ_W_QH_DSP
,
866 OPC_DPA_W_QH
= (0x00 << 6) | OPC_DPAQ_W_QH_DSP
,
867 OPC_DPAQ_S_W_QH
= (0x04 << 6) | OPC_DPAQ_W_QH_DSP
,
868 OPC_DPAQ_SA_L_PW
= (0x0C << 6) | OPC_DPAQ_W_QH_DSP
,
869 OPC_DPAU_H_OBL
= (0x03 << 6) | OPC_DPAQ_W_QH_DSP
,
870 OPC_DPAU_H_OBR
= (0x07 << 6) | OPC_DPAQ_W_QH_DSP
,
871 OPC_DPS_W_QH
= (0x01 << 6) | OPC_DPAQ_W_QH_DSP
,
872 OPC_DPSQ_S_W_QH
= (0x05 << 6) | OPC_DPAQ_W_QH_DSP
,
873 OPC_DPSQ_SA_L_PW
= (0x0D << 6) | OPC_DPAQ_W_QH_DSP
,
874 OPC_DPSU_H_OBL
= (0x0B << 6) | OPC_DPAQ_W_QH_DSP
,
875 OPC_DPSU_H_OBR
= (0x0F << 6) | OPC_DPAQ_W_QH_DSP
,
876 OPC_MAQ_S_L_PWL
= (0x1C << 6) | OPC_DPAQ_W_QH_DSP
,
877 OPC_MAQ_S_L_PWR
= (0x1E << 6) | OPC_DPAQ_W_QH_DSP
,
878 OPC_MAQ_S_W_QHLL
= (0x14 << 6) | OPC_DPAQ_W_QH_DSP
,
879 OPC_MAQ_SA_W_QHLL
= (0x10 << 6) | OPC_DPAQ_W_QH_DSP
,
880 OPC_MAQ_S_W_QHLR
= (0x15 << 6) | OPC_DPAQ_W_QH_DSP
,
881 OPC_MAQ_SA_W_QHLR
= (0x11 << 6) | OPC_DPAQ_W_QH_DSP
,
882 OPC_MAQ_S_W_QHRL
= (0x16 << 6) | OPC_DPAQ_W_QH_DSP
,
883 OPC_MAQ_SA_W_QHRL
= (0x12 << 6) | OPC_DPAQ_W_QH_DSP
,
884 OPC_MAQ_S_W_QHRR
= (0x17 << 6) | OPC_DPAQ_W_QH_DSP
,
885 OPC_MAQ_SA_W_QHRR
= (0x13 << 6) | OPC_DPAQ_W_QH_DSP
,
886 OPC_MULSAQ_S_L_PW
= (0x0E << 6) | OPC_DPAQ_W_QH_DSP
,
887 OPC_MULSAQ_S_W_QH
= (0x06 << 6) | OPC_DPAQ_W_QH_DSP
,
890 #define MASK_SHLL_OB(op) (MASK_SPECIAL3(op) | (op & (0x1F << 6)))
892 /* MIPS DSP GPR-Based Shift Sub-class */
893 OPC_SHLL_PW
= (0x10 << 6) | OPC_SHLL_OB_DSP
,
894 OPC_SHLL_S_PW
= (0x14 << 6) | OPC_SHLL_OB_DSP
,
895 OPC_SHLLV_OB
= (0x02 << 6) | OPC_SHLL_OB_DSP
,
896 OPC_SHLLV_PW
= (0x12 << 6) | OPC_SHLL_OB_DSP
,
897 OPC_SHLLV_S_PW
= (0x16 << 6) | OPC_SHLL_OB_DSP
,
898 OPC_SHLLV_QH
= (0x0A << 6) | OPC_SHLL_OB_DSP
,
899 OPC_SHLLV_S_QH
= (0x0E << 6) | OPC_SHLL_OB_DSP
,
900 OPC_SHRA_PW
= (0x11 << 6) | OPC_SHLL_OB_DSP
,
901 OPC_SHRA_R_PW
= (0x15 << 6) | OPC_SHLL_OB_DSP
,
902 OPC_SHRAV_OB
= (0x06 << 6) | OPC_SHLL_OB_DSP
,
903 OPC_SHRAV_R_OB
= (0x07 << 6) | OPC_SHLL_OB_DSP
,
904 OPC_SHRAV_PW
= (0x13 << 6) | OPC_SHLL_OB_DSP
,
905 OPC_SHRAV_R_PW
= (0x17 << 6) | OPC_SHLL_OB_DSP
,
906 OPC_SHRAV_QH
= (0x0B << 6) | OPC_SHLL_OB_DSP
,
907 OPC_SHRAV_R_QH
= (0x0F << 6) | OPC_SHLL_OB_DSP
,
908 OPC_SHRLV_OB
= (0x03 << 6) | OPC_SHLL_OB_DSP
,
909 OPC_SHRLV_QH
= (0x1B << 6) | OPC_SHLL_OB_DSP
,
910 OPC_SHLL_OB
= (0x00 << 6) | OPC_SHLL_OB_DSP
,
911 OPC_SHLL_QH
= (0x08 << 6) | OPC_SHLL_OB_DSP
,
912 OPC_SHLL_S_QH
= (0x0C << 6) | OPC_SHLL_OB_DSP
,
913 OPC_SHRA_OB
= (0x04 << 6) | OPC_SHLL_OB_DSP
,
914 OPC_SHRA_R_OB
= (0x05 << 6) | OPC_SHLL_OB_DSP
,
915 OPC_SHRA_QH
= (0x09 << 6) | OPC_SHLL_OB_DSP
,
916 OPC_SHRA_R_QH
= (0x0D << 6) | OPC_SHLL_OB_DSP
,
917 OPC_SHRL_OB
= (0x01 << 6) | OPC_SHLL_OB_DSP
,
918 OPC_SHRL_QH
= (0x19 << 6) | OPC_SHLL_OB_DSP
,
921 /* Coprocessor 0 (rs field) */
922 #define MASK_CP0(op) (MASK_OP_MAJOR(op) | (op & (0x1F << 21)))
925 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
926 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
927 OPC_MFHC0
= (0x02 << 21) | OPC_CP0
,
928 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
929 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
930 OPC_MTHC0
= (0x06 << 21) | OPC_CP0
,
931 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
932 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
933 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
934 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
935 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
936 OPC_C0
= (0x10 << 21) | OPC_CP0
,
937 OPC_C0_1
= (0x11 << 21) | OPC_CP0
,
938 OPC_C0_2
= (0x12 << 21) | OPC_CP0
,
939 OPC_C0_3
= (0x13 << 21) | OPC_CP0
,
940 OPC_C0_4
= (0x14 << 21) | OPC_CP0
,
941 OPC_C0_5
= (0x15 << 21) | OPC_CP0
,
942 OPC_C0_6
= (0x16 << 21) | OPC_CP0
,
943 OPC_C0_7
= (0x17 << 21) | OPC_CP0
,
944 OPC_C0_8
= (0x18 << 21) | OPC_CP0
,
945 OPC_C0_9
= (0x19 << 21) | OPC_CP0
,
946 OPC_C0_A
= (0x1A << 21) | OPC_CP0
,
947 OPC_C0_B
= (0x1B << 21) | OPC_CP0
,
948 OPC_C0_C
= (0x1C << 21) | OPC_CP0
,
949 OPC_C0_D
= (0x1D << 21) | OPC_CP0
,
950 OPC_C0_E
= (0x1E << 21) | OPC_CP0
,
951 OPC_C0_F
= (0x1F << 21) | OPC_CP0
,
955 #define MASK_MFMC0(op) (MASK_CP0(op) | (op & 0xFFFF))
958 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
959 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
960 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
961 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
962 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
963 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
964 OPC_DVP
= 0x04 | (0 << 3) | (1 << 5) | (0 << 11) | OPC_MFMC0
,
965 OPC_EVP
= 0x04 | (0 << 3) | (0 << 5) | (0 << 11) | OPC_MFMC0
,
968 /* Coprocessor 0 (with rs == C0) */
969 #define MASK_C0(op) (MASK_CP0(op) | (op & 0x3F))
972 OPC_TLBR
= 0x01 | OPC_C0
,
973 OPC_TLBWI
= 0x02 | OPC_C0
,
974 OPC_TLBINV
= 0x03 | OPC_C0
,
975 OPC_TLBINVF
= 0x04 | OPC_C0
,
976 OPC_TLBWR
= 0x06 | OPC_C0
,
977 OPC_TLBP
= 0x08 | OPC_C0
,
978 OPC_RFE
= 0x10 | OPC_C0
,
979 OPC_ERET
= 0x18 | OPC_C0
,
980 OPC_DERET
= 0x1F | OPC_C0
,
981 OPC_WAIT
= 0x20 | OPC_C0
,
984 #define MASK_CP2(op) (MASK_OP_MAJOR(op) | (op & (0x1F << 21)))
987 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
988 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
989 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
990 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
991 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
992 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
993 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
994 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
995 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
996 OPC_BC2EQZ
= (0x09 << 21) | OPC_CP2
,
997 OPC_BC2NEZ
= (0x0D << 21) | OPC_CP2
,
1000 #define MASK_LMMI(op) (MASK_OP_MAJOR(op) | (op & (0x1F << 21)) | (op & 0x1F))
1003 OPC_PADDSH
= (24 << 21) | (0x00) | OPC_CP2
,
1004 OPC_PADDUSH
= (25 << 21) | (0x00) | OPC_CP2
,
1005 OPC_PADDH
= (26 << 21) | (0x00) | OPC_CP2
,
1006 OPC_PADDW
= (27 << 21) | (0x00) | OPC_CP2
,
1007 OPC_PADDSB
= (28 << 21) | (0x00) | OPC_CP2
,
1008 OPC_PADDUSB
= (29 << 21) | (0x00) | OPC_CP2
,
1009 OPC_PADDB
= (30 << 21) | (0x00) | OPC_CP2
,
1010 OPC_PADDD
= (31 << 21) | (0x00) | OPC_CP2
,
1012 OPC_PSUBSH
= (24 << 21) | (0x01) | OPC_CP2
,
1013 OPC_PSUBUSH
= (25 << 21) | (0x01) | OPC_CP2
,
1014 OPC_PSUBH
= (26 << 21) | (0x01) | OPC_CP2
,
1015 OPC_PSUBW
= (27 << 21) | (0x01) | OPC_CP2
,
1016 OPC_PSUBSB
= (28 << 21) | (0x01) | OPC_CP2
,
1017 OPC_PSUBUSB
= (29 << 21) | (0x01) | OPC_CP2
,
1018 OPC_PSUBB
= (30 << 21) | (0x01) | OPC_CP2
,
1019 OPC_PSUBD
= (31 << 21) | (0x01) | OPC_CP2
,
1021 OPC_PSHUFH
= (24 << 21) | (0x02) | OPC_CP2
,
1022 OPC_PACKSSWH
= (25 << 21) | (0x02) | OPC_CP2
,
1023 OPC_PACKSSHB
= (26 << 21) | (0x02) | OPC_CP2
,
1024 OPC_PACKUSHB
= (27 << 21) | (0x02) | OPC_CP2
,
1025 OPC_XOR_CP2
= (28 << 21) | (0x02) | OPC_CP2
,
1026 OPC_NOR_CP2
= (29 << 21) | (0x02) | OPC_CP2
,
1027 OPC_AND_CP2
= (30 << 21) | (0x02) | OPC_CP2
,
1028 OPC_PANDN
= (31 << 21) | (0x02) | OPC_CP2
,
1030 OPC_PUNPCKLHW
= (24 << 21) | (0x03) | OPC_CP2
,
1031 OPC_PUNPCKHHW
= (25 << 21) | (0x03) | OPC_CP2
,
1032 OPC_PUNPCKLBH
= (26 << 21) | (0x03) | OPC_CP2
,
1033 OPC_PUNPCKHBH
= (27 << 21) | (0x03) | OPC_CP2
,
1034 OPC_PINSRH_0
= (28 << 21) | (0x03) | OPC_CP2
,
1035 OPC_PINSRH_1
= (29 << 21) | (0x03) | OPC_CP2
,
1036 OPC_PINSRH_2
= (30 << 21) | (0x03) | OPC_CP2
,
1037 OPC_PINSRH_3
= (31 << 21) | (0x03) | OPC_CP2
,
1039 OPC_PAVGH
= (24 << 21) | (0x08) | OPC_CP2
,
1040 OPC_PAVGB
= (25 << 21) | (0x08) | OPC_CP2
,
1041 OPC_PMAXSH
= (26 << 21) | (0x08) | OPC_CP2
,
1042 OPC_PMINSH
= (27 << 21) | (0x08) | OPC_CP2
,
1043 OPC_PMAXUB
= (28 << 21) | (0x08) | OPC_CP2
,
1044 OPC_PMINUB
= (29 << 21) | (0x08) | OPC_CP2
,
1046 OPC_PCMPEQW
= (24 << 21) | (0x09) | OPC_CP2
,
1047 OPC_PCMPGTW
= (25 << 21) | (0x09) | OPC_CP2
,
1048 OPC_PCMPEQH
= (26 << 21) | (0x09) | OPC_CP2
,
1049 OPC_PCMPGTH
= (27 << 21) | (0x09) | OPC_CP2
,
1050 OPC_PCMPEQB
= (28 << 21) | (0x09) | OPC_CP2
,
1051 OPC_PCMPGTB
= (29 << 21) | (0x09) | OPC_CP2
,
1053 OPC_PSLLW
= (24 << 21) | (0x0A) | OPC_CP2
,
1054 OPC_PSLLH
= (25 << 21) | (0x0A) | OPC_CP2
,
1055 OPC_PMULLH
= (26 << 21) | (0x0A) | OPC_CP2
,
1056 OPC_PMULHH
= (27 << 21) | (0x0A) | OPC_CP2
,
1057 OPC_PMULUW
= (28 << 21) | (0x0A) | OPC_CP2
,
1058 OPC_PMULHUH
= (29 << 21) | (0x0A) | OPC_CP2
,
1060 OPC_PSRLW
= (24 << 21) | (0x0B) | OPC_CP2
,
1061 OPC_PSRLH
= (25 << 21) | (0x0B) | OPC_CP2
,
1062 OPC_PSRAW
= (26 << 21) | (0x0B) | OPC_CP2
,
1063 OPC_PSRAH
= (27 << 21) | (0x0B) | OPC_CP2
,
1064 OPC_PUNPCKLWD
= (28 << 21) | (0x0B) | OPC_CP2
,
1065 OPC_PUNPCKHWD
= (29 << 21) | (0x0B) | OPC_CP2
,
1067 OPC_ADDU_CP2
= (24 << 21) | (0x0C) | OPC_CP2
,
1068 OPC_OR_CP2
= (25 << 21) | (0x0C) | OPC_CP2
,
1069 OPC_ADD_CP2
= (26 << 21) | (0x0C) | OPC_CP2
,
1070 OPC_DADD_CP2
= (27 << 21) | (0x0C) | OPC_CP2
,
1071 OPC_SEQU_CP2
= (28 << 21) | (0x0C) | OPC_CP2
,
1072 OPC_SEQ_CP2
= (29 << 21) | (0x0C) | OPC_CP2
,
1074 OPC_SUBU_CP2
= (24 << 21) | (0x0D) | OPC_CP2
,
1075 OPC_PASUBUB
= (25 << 21) | (0x0D) | OPC_CP2
,
1076 OPC_SUB_CP2
= (26 << 21) | (0x0D) | OPC_CP2
,
1077 OPC_DSUB_CP2
= (27 << 21) | (0x0D) | OPC_CP2
,
1078 OPC_SLTU_CP2
= (28 << 21) | (0x0D) | OPC_CP2
,
1079 OPC_SLT_CP2
= (29 << 21) | (0x0D) | OPC_CP2
,
1081 OPC_SLL_CP2
= (24 << 21) | (0x0E) | OPC_CP2
,
1082 OPC_DSLL_CP2
= (25 << 21) | (0x0E) | OPC_CP2
,
1083 OPC_PEXTRH
= (26 << 21) | (0x0E) | OPC_CP2
,
1084 OPC_PMADDHW
= (27 << 21) | (0x0E) | OPC_CP2
,
1085 OPC_SLEU_CP2
= (28 << 21) | (0x0E) | OPC_CP2
,
1086 OPC_SLE_CP2
= (29 << 21) | (0x0E) | OPC_CP2
,
1088 OPC_SRL_CP2
= (24 << 21) | (0x0F) | OPC_CP2
,
1089 OPC_DSRL_CP2
= (25 << 21) | (0x0F) | OPC_CP2
,
1090 OPC_SRA_CP2
= (26 << 21) | (0x0F) | OPC_CP2
,
1091 OPC_DSRA_CP2
= (27 << 21) | (0x0F) | OPC_CP2
,
1092 OPC_BIADD
= (28 << 21) | (0x0F) | OPC_CP2
,
1093 OPC_PMOVMSKB
= (29 << 21) | (0x0F) | OPC_CP2
,
1097 #define MASK_CP3(op) (MASK_OP_MAJOR(op) | (op & 0x3F))
1100 OPC_LWXC1
= 0x00 | OPC_CP3
,
1101 OPC_LDXC1
= 0x01 | OPC_CP3
,
1102 OPC_LUXC1
= 0x05 | OPC_CP3
,
1103 OPC_SWXC1
= 0x08 | OPC_CP3
,
1104 OPC_SDXC1
= 0x09 | OPC_CP3
,
1105 OPC_SUXC1
= 0x0D | OPC_CP3
,
1106 OPC_PREFX
= 0x0F | OPC_CP3
,
1107 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
1108 OPC_MADD_S
= 0x20 | OPC_CP3
,
1109 OPC_MADD_D
= 0x21 | OPC_CP3
,
1110 OPC_MADD_PS
= 0x26 | OPC_CP3
,
1111 OPC_MSUB_S
= 0x28 | OPC_CP3
,
1112 OPC_MSUB_D
= 0x29 | OPC_CP3
,
1113 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
1114 OPC_NMADD_S
= 0x30 | OPC_CP3
,
1115 OPC_NMADD_D
= 0x31 | OPC_CP3
,
1116 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
1117 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
1118 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
1119 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
1123 * MMI (MultiMedia Instruction) encodings
1124 * ======================================
1126 * MMI instructions encoding table keys:
1128 * * This code is reserved for future use. An attempt to execute it
1129 * causes a Reserved Instruction exception.
1130 * % This code indicates an instruction class. The instruction word
1131 * must be further decoded by examining additional tables that show
1132 * the values for other instruction fields.
1133 * # This code is reserved for the unsupported instructions DMULT,
1134 * DMULTU, DDIV, DDIVU, LL, LLD, SC, SCD, LWC2 and SWC2. An attempt
1135 * to execute it causes a Reserved Instruction exception.
1137 * MMI instructions encoded by opcode field (MMI, LQ, SQ):
1140 * +--------+----------------------------------------+
1142 * +--------+----------------------------------------+
1144 * opcode bits 28..26
1145 * bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
1146 * 31..29 | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111
1147 * -------+-------+-------+-------+-------+-------+-------+-------+-------
1148 * 0 000 |SPECIAL| REGIMM| J | JAL | BEQ | BNE | BLEZ | BGTZ
1149 * 1 001 | ADDI | ADDIU | SLTI | SLTIU | ANDI | ORI | XORI | LUI
1150 * 2 010 | COP0 | COP1 | * | * | BEQL | BNEL | BLEZL | BGTZL
1151 * 3 011 | DADDI | DADDIU| LDL | LDR | MMI% | * | LQ | SQ
1152 * 4 100 | LB | LH | LWL | LW | LBU | LHU | LWR | LWU
1153 * 5 101 | SB | SH | SWL | SW | SDL | SDR | SWR | CACHE
1154 * 6 110 | # | LWC1 | # | PREF | # | LDC1 | # | LD
1155 * 7 111 | # | SWC1 | # | * | # | SDC1 | # | SD
1159 MMI_OPC_CLASS_MMI
= 0x1C << 26, /* Same as OPC_SPECIAL2 */
1160 MMI_OPC_SQ
= 0x1F << 26, /* Same as OPC_SPECIAL3 */
1164 * MMI instructions with opcode field = MMI:
1167 * +--------+-------------------------------+--------+
1168 * | MMI | |function|
1169 * +--------+-------------------------------+--------+
1171 * function bits 2..0
1172 * bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
1173 * 5..3 | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111
1174 * -------+-------+-------+-------+-------+-------+-------+-------+-------
1175 * 0 000 | MADD | MADDU | * | * | PLZCW | * | * | *
1176 * 1 001 | MMI0% | MMI2% | * | * | * | * | * | *
1177 * 2 010 | MFHI1 | MTHI1 | MFLO1 | MTLO1 | * | * | * | *
1178 * 3 011 | MULT1 | MULTU1| DIV1 | DIVU1 | * | * | * | *
1179 * 4 100 | MADD1 | MADDU1| * | * | * | * | * | *
1180 * 5 101 | MMI1% | MMI3% | * | * | * | * | * | *
1181 * 6 110 | PMFHL | PMTHL | * | * | PSLLH | * | PSRLH | PSRAH
1182 * 7 111 | * | * | * | * | PSLLW | * | PSRLW | PSRAW
1185 #define MASK_MMI(op) (MASK_OP_MAJOR(op) | ((op) & 0x3F))
1187 MMI_OPC_MADD
= 0x00 | MMI_OPC_CLASS_MMI
, /* Same as OPC_MADD */
1188 MMI_OPC_MADDU
= 0x01 | MMI_OPC_CLASS_MMI
, /* Same as OPC_MADDU */
1189 MMI_OPC_MULT1
= 0x18 | MMI_OPC_CLASS_MMI
, /* Same minor as OPC_MULT */
1190 MMI_OPC_MULTU1
= 0x19 | MMI_OPC_CLASS_MMI
, /* Same min. as OPC_MULTU */
1191 MMI_OPC_DIV1
= 0x1A | MMI_OPC_CLASS_MMI
, /* Same minor as OPC_DIV */
1192 MMI_OPC_DIVU1
= 0x1B | MMI_OPC_CLASS_MMI
, /* Same minor as OPC_DIVU */
1193 MMI_OPC_MADD1
= 0x20 | MMI_OPC_CLASS_MMI
,
1194 MMI_OPC_MADDU1
= 0x21 | MMI_OPC_CLASS_MMI
,
1197 /* global register indices */
1198 TCGv cpu_gpr
[32], cpu_PC
;
1200 * For CPUs using 128-bit GPR registers, we put the lower halves in cpu_gpr[])
1201 * and the upper halves in cpu_gpr_hi[].
1203 TCGv_i64 cpu_gpr_hi
[32];
1204 TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
];
1205 static TCGv cpu_dspctrl
, btarget
;
1207 static TCGv cpu_lladdr
, cpu_llval
;
1208 static TCGv_i32 hflags
;
1209 TCGv_i32 fpu_fcr0
, fpu_fcr31
;
1210 TCGv_i64 fpu_f64
[32];
1212 static const char regnames_HI
[][4] = {
1213 "HI0", "HI1", "HI2", "HI3",
1216 static const char regnames_LO
[][4] = {
1217 "LO0", "LO1", "LO2", "LO3",
1220 /* General purpose registers moves. */
1221 void gen_load_gpr(TCGv t
, int reg
)
1223 assert(reg
>= 0 && reg
<= ARRAY_SIZE(cpu_gpr
));
1225 tcg_gen_movi_tl(t
, 0);
1227 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
1231 void gen_store_gpr(TCGv t
, int reg
)
1233 assert(reg
>= 0 && reg
<= ARRAY_SIZE(cpu_gpr
));
1235 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
1239 #if defined(TARGET_MIPS64)
1240 void gen_load_gpr_hi(TCGv_i64 t
, int reg
)
1242 assert(reg
>= 0 && reg
<= ARRAY_SIZE(cpu_gpr_hi
));
1244 tcg_gen_movi_i64(t
, 0);
1246 tcg_gen_mov_i64(t
, cpu_gpr_hi
[reg
]);
1250 void gen_store_gpr_hi(TCGv_i64 t
, int reg
)
1252 assert(reg
>= 0 && reg
<= ARRAY_SIZE(cpu_gpr_hi
));
1254 tcg_gen_mov_i64(cpu_gpr_hi
[reg
], t
);
1257 #endif /* TARGET_MIPS64 */
1259 /* Moves to/from shadow registers. */
1260 static inline void gen_load_srsgpr(int from
, int to
)
1262 TCGv t0
= tcg_temp_new();
1265 tcg_gen_movi_tl(t0
, 0);
1267 TCGv_i32 t2
= tcg_temp_new_i32();
1268 TCGv_ptr addr
= tcg_temp_new_ptr();
1270 tcg_gen_ld_i32(t2
, tcg_env
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
1271 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
1272 tcg_gen_andi_i32(t2
, t2
, 0xf);
1273 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
1274 tcg_gen_ext_i32_ptr(addr
, t2
);
1275 tcg_gen_add_ptr(addr
, tcg_env
, addr
);
1277 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
1279 gen_store_gpr(t0
, to
);
1282 static inline void gen_store_srsgpr(int from
, int to
)
1285 TCGv t0
= tcg_temp_new();
1286 TCGv_i32 t2
= tcg_temp_new_i32();
1287 TCGv_ptr addr
= tcg_temp_new_ptr();
1289 gen_load_gpr(t0
, from
);
1290 tcg_gen_ld_i32(t2
, tcg_env
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
1291 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
1292 tcg_gen_andi_i32(t2
, t2
, 0xf);
1293 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
1294 tcg_gen_ext_i32_ptr(addr
, t2
);
1295 tcg_gen_add_ptr(addr
, tcg_env
, addr
);
1297 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
1302 static inline void gen_save_pc(target_ulong pc
)
1304 tcg_gen_movi_tl(cpu_PC
, pc
);
1307 static inline void save_cpu_state(DisasContext
*ctx
, int do_save_pc
)
1309 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
1310 if (do_save_pc
&& ctx
->base
.pc_next
!= ctx
->saved_pc
) {
1311 gen_save_pc(ctx
->base
.pc_next
);
1312 ctx
->saved_pc
= ctx
->base
.pc_next
;
1314 if (ctx
->hflags
!= ctx
->saved_hflags
) {
1315 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
1316 ctx
->saved_hflags
= ctx
->hflags
;
1317 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
1323 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
1329 static inline void restore_cpu_state(CPUMIPSState
*env
, DisasContext
*ctx
)
1331 ctx
->saved_hflags
= ctx
->hflags
;
1332 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
1338 ctx
->btarget
= env
->btarget
;
1343 void generate_exception_err(DisasContext
*ctx
, int excp
, int err
)
1345 save_cpu_state(ctx
, 1);
1346 gen_helper_raise_exception_err(tcg_env
, tcg_constant_i32(excp
),
1347 tcg_constant_i32(err
));
1348 ctx
->base
.is_jmp
= DISAS_NORETURN
;
1351 void generate_exception(DisasContext
*ctx
, int excp
)
1353 gen_helper_raise_exception(tcg_env
, tcg_constant_i32(excp
));
1356 void generate_exception_end(DisasContext
*ctx
, int excp
)
1358 generate_exception_err(ctx
, excp
, 0);
1361 void generate_exception_break(DisasContext
*ctx
, int code
)
1363 #ifdef CONFIG_USER_ONLY
1364 /* Pass the break code along to cpu_loop. */
1365 tcg_gen_st_i32(tcg_constant_i32(code
), tcg_env
,
1366 offsetof(CPUMIPSState
, error_code
));
1368 generate_exception_end(ctx
, EXCP_BREAK
);
1371 void gen_reserved_instruction(DisasContext
*ctx
)
1373 generate_exception_end(ctx
, EXCP_RI
);
1376 /* Floating point register moves. */
1377 void gen_load_fpr32(DisasContext
*ctx
, TCGv_i32 t
, int reg
)
1379 if (ctx
->hflags
& MIPS_HFLAG_FRE
) {
1380 generate_exception(ctx
, EXCP_RI
);
1382 tcg_gen_extrl_i64_i32(t
, fpu_f64
[reg
]);
1385 void gen_store_fpr32(DisasContext
*ctx
, TCGv_i32 t
, int reg
)
1388 if (ctx
->hflags
& MIPS_HFLAG_FRE
) {
1389 generate_exception(ctx
, EXCP_RI
);
1391 t64
= tcg_temp_new_i64();
1392 tcg_gen_extu_i32_i64(t64
, t
);
1393 tcg_gen_deposit_i64(fpu_f64
[reg
], fpu_f64
[reg
], t64
, 0, 32);
1396 static void gen_load_fpr32h(DisasContext
*ctx
, TCGv_i32 t
, int reg
)
1398 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
1399 tcg_gen_extrh_i64_i32(t
, fpu_f64
[reg
]);
1401 gen_load_fpr32(ctx
, t
, reg
| 1);
1405 static void gen_store_fpr32h(DisasContext
*ctx
, TCGv_i32 t
, int reg
)
1407 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
1408 TCGv_i64 t64
= tcg_temp_new_i64();
1409 tcg_gen_extu_i32_i64(t64
, t
);
1410 tcg_gen_deposit_i64(fpu_f64
[reg
], fpu_f64
[reg
], t64
, 32, 32);
1412 gen_store_fpr32(ctx
, t
, reg
| 1);
1416 void gen_load_fpr64(DisasContext
*ctx
, TCGv_i64 t
, int reg
)
1418 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
1419 tcg_gen_mov_i64(t
, fpu_f64
[reg
]);
1421 tcg_gen_concat32_i64(t
, fpu_f64
[reg
& ~1], fpu_f64
[reg
| 1]);
1425 void gen_store_fpr64(DisasContext
*ctx
, TCGv_i64 t
, int reg
)
1427 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
1428 tcg_gen_mov_i64(fpu_f64
[reg
], t
);
1431 tcg_gen_deposit_i64(fpu_f64
[reg
& ~1], fpu_f64
[reg
& ~1], t
, 0, 32);
1432 t0
= tcg_temp_new_i64();
1433 tcg_gen_shri_i64(t0
, t
, 32);
1434 tcg_gen_deposit_i64(fpu_f64
[reg
| 1], fpu_f64
[reg
| 1], t0
, 0, 32);
1438 int get_fp_bit(int cc
)
1447 /* Addresses computation */
1448 void gen_op_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
1450 tcg_gen_add_tl(ret
, arg0
, arg1
);
1452 #if defined(TARGET_MIPS64)
1453 if (ctx
->hflags
& MIPS_HFLAG_AWRAP
) {
1454 tcg_gen_ext32s_i64(ret
, ret
);
1459 void gen_op_addr_addi(DisasContext
*ctx
, TCGv ret
, TCGv base
, target_long ofs
)
1461 tcg_gen_addi_tl(ret
, base
, ofs
);
1463 #if defined(TARGET_MIPS64)
1464 if (ctx
->hflags
& MIPS_HFLAG_AWRAP
) {
1465 tcg_gen_ext32s_i64(ret
, ret
);
1470 /* Addresses computation (translation time) */
1471 static target_long
addr_add(DisasContext
*ctx
, target_long base
,
1474 target_long sum
= base
+ offset
;
1476 #if defined(TARGET_MIPS64)
1477 if (ctx
->hflags
& MIPS_HFLAG_AWRAP
) {
1484 /* Sign-extract the low 32-bits to a target_long. */
1485 void gen_move_low32(TCGv ret
, TCGv_i64 arg
)
1487 #if defined(TARGET_MIPS64)
1488 tcg_gen_ext32s_i64(ret
, arg
);
1490 tcg_gen_extrl_i64_i32(ret
, arg
);
1494 /* Sign-extract the high 32-bits to a target_long. */
1495 void gen_move_high32(TCGv ret
, TCGv_i64 arg
)
1497 #if defined(TARGET_MIPS64)
1498 tcg_gen_sari_i64(ret
, arg
, 32);
1500 tcg_gen_extrh_i64_i32(ret
, arg
);
1504 bool check_cp0_enabled(DisasContext
*ctx
)
1506 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
))) {
1507 generate_exception_end(ctx
, EXCP_CpU
);
1513 void check_cp1_enabled(DisasContext
*ctx
)
1515 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
))) {
1516 generate_exception_err(ctx
, EXCP_CpU
, 1);
1521 * Verify that the processor is running with COP1X instructions enabled.
1522 * This is associated with the nabla symbol in the MIPS32 and MIPS64
1525 void check_cop1x(DisasContext
*ctx
)
1527 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
))) {
1528 gen_reserved_instruction(ctx
);
1533 * Verify that the processor is running with 64-bit floating-point
1534 * operations enabled.
1536 void check_cp1_64bitmode(DisasContext
*ctx
)
1538 if (unlikely(~ctx
->hflags
& MIPS_HFLAG_F64
)) {
1539 gen_reserved_instruction(ctx
);
1544 * Verify if floating point register is valid; an operation is not defined
1545 * if bit 0 of any register specification is set and the FR bit in the
1546 * Status register equals zero, since the register numbers specify an
1547 * even-odd pair of adjacent coprocessor general registers. When the FR bit
1548 * in the Status register equals one, both even and odd register numbers
1549 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
1551 * Multiple 64 bit wide registers can be checked by calling
1552 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
1554 void check_cp1_registers(DisasContext
*ctx
, int regs
)
1556 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1))) {
1557 gen_reserved_instruction(ctx
);
1562 * Verify that the processor is running with DSP instructions enabled.
1563 * This is enabled by CP0 Status register MX(24) bit.
1565 static inline void check_dsp(DisasContext
*ctx
)
1567 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_DSP
))) {
1568 if (ctx
->insn_flags
& ASE_DSP
) {
1569 generate_exception_end(ctx
, EXCP_DSPDIS
);
1571 gen_reserved_instruction(ctx
);
1576 static inline void check_dsp_r2(DisasContext
*ctx
)
1578 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_DSP_R2
))) {
1579 if (ctx
->insn_flags
& ASE_DSP
) {
1580 generate_exception_end(ctx
, EXCP_DSPDIS
);
1582 gen_reserved_instruction(ctx
);
1587 static inline void check_dsp_r3(DisasContext
*ctx
)
1589 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_DSP_R3
))) {
1590 if (ctx
->insn_flags
& ASE_DSP
) {
1591 generate_exception_end(ctx
, EXCP_DSPDIS
);
1593 gen_reserved_instruction(ctx
);
1599 * This code generates a "reserved instruction" exception if the
1600 * CPU does not support the instruction set corresponding to flags.
1602 void check_insn(DisasContext
*ctx
, uint64_t flags
)
1604 if (unlikely(!(ctx
->insn_flags
& flags
))) {
1605 gen_reserved_instruction(ctx
);
1610 * This code generates a "reserved instruction" exception if the
1611 * CPU has corresponding flag set which indicates that the instruction
1614 static inline void check_insn_opc_removed(DisasContext
*ctx
, uint64_t flags
)
1616 if (unlikely(ctx
->insn_flags
& flags
)) {
1617 gen_reserved_instruction(ctx
);
1622 * The Linux kernel traps certain reserved instruction exceptions to
1623 * emulate the corresponding instructions. QEMU is the kernel in user
1624 * mode, so those traps are emulated by accepting the instructions.
1626 * A reserved instruction exception is generated for flagged CPUs if
1627 * QEMU runs in system mode.
1629 static inline void check_insn_opc_user_only(DisasContext
*ctx
, uint64_t flags
)
1631 #ifndef CONFIG_USER_ONLY
1632 check_insn_opc_removed(ctx
, flags
);
1637 * This code generates a "reserved instruction" exception if the
1638 * CPU does not support 64-bit paired-single (PS) floating point data type.
1640 static inline void check_ps(DisasContext
*ctx
)
1642 if (unlikely(!ctx
->ps
)) {
1643 generate_exception(ctx
, EXCP_RI
);
1645 check_cp1_64bitmode(ctx
);
1649 * This code generates a "reserved instruction" exception if cpu is not
1650 * 64-bit or 64-bit instructions are not enabled.
1652 void check_mips_64(DisasContext
*ctx
)
1654 if (unlikely((TARGET_LONG_BITS
!= 64) || !(ctx
->hflags
& MIPS_HFLAG_64
))) {
1655 gen_reserved_instruction(ctx
);
1659 #ifndef CONFIG_USER_ONLY
1660 static inline void check_mvh(DisasContext
*ctx
)
1662 if (unlikely(!ctx
->mvh
)) {
1663 generate_exception(ctx
, EXCP_RI
);
1669 * This code generates a "reserved instruction" exception if the
1670 * Config5 XNP bit is set.
1672 static inline void check_xnp(DisasContext
*ctx
)
1674 if (unlikely(ctx
->CP0_Config5
& (1 << CP0C5_XNP
))) {
1675 gen_reserved_instruction(ctx
);
1679 #ifndef CONFIG_USER_ONLY
1681 * This code generates a "reserved instruction" exception if the
1682 * Config3 PW bit is NOT set.
1684 static inline void check_pw(DisasContext
*ctx
)
1686 if (unlikely(!(ctx
->CP0_Config3
& (1 << CP0C3_PW
)))) {
1687 gen_reserved_instruction(ctx
);
1693 * This code generates a "reserved instruction" exception if the
1694 * Config3 MT bit is NOT set.
1696 static inline void check_mt(DisasContext
*ctx
)
1698 if (unlikely(!(ctx
->CP0_Config3
& (1 << CP0C3_MT
)))) {
1699 gen_reserved_instruction(ctx
);
1703 #ifndef CONFIG_USER_ONLY
1705 * This code generates a "coprocessor unusable" exception if CP0 is not
1706 * available, and, if that is not the case, generates a "reserved instruction"
1707 * exception if the Config5 MT bit is NOT set. This is needed for availability
1708 * control of some of MT ASE instructions.
1710 static inline void check_cp0_mt(DisasContext
*ctx
)
1712 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
))) {
1713 generate_exception_end(ctx
, EXCP_CpU
);
1715 if (unlikely(!(ctx
->CP0_Config3
& (1 << CP0C3_MT
)))) {
1716 gen_reserved_instruction(ctx
);
1723 * This code generates a "reserved instruction" exception if the
1724 * Config5 NMS bit is set.
1726 static inline void check_nms(DisasContext
*ctx
)
1728 if (unlikely(ctx
->CP0_Config5
& (1 << CP0C5_NMS
))) {
1729 gen_reserved_instruction(ctx
);
1734 * This code generates a "reserved instruction" exception if the
1735 * Config5 NMS bit is set, and Config1 DL, Config1 IL, Config2 SL,
1736 * Config2 TL, and Config5 L2C are unset.
1738 static inline void check_nms_dl_il_sl_tl_l2c(DisasContext
*ctx
)
1740 if (unlikely((ctx
->CP0_Config5
& (1 << CP0C5_NMS
)) &&
1741 !(ctx
->CP0_Config1
& (1 << CP0C1_DL
)) &&
1742 !(ctx
->CP0_Config1
& (1 << CP0C1_IL
)) &&
1743 !(ctx
->CP0_Config2
& (1 << CP0C2_SL
)) &&
1744 !(ctx
->CP0_Config2
& (1 << CP0C2_TL
)) &&
1745 !(ctx
->CP0_Config5
& (1 << CP0C5_L2C
)))) {
1746 gen_reserved_instruction(ctx
);
1751 * This code generates a "reserved instruction" exception if the
1752 * Config5 EVA bit is NOT set.
1754 static inline void check_eva(DisasContext
*ctx
)
1756 if (unlikely(!(ctx
->CP0_Config5
& (1 << CP0C5_EVA
)))) {
1757 gen_reserved_instruction(ctx
);
1763 * Define small wrappers for gen_load_fpr* so that we have a uniform
1764 * calling interface for 32 and 64-bit FPRs. No sense in changing
1765 * all callers for gen_load_fpr32 when we need the CTX parameter for
1768 #define gen_ldcmp_fpr32(ctx, x, y) gen_load_fpr32(ctx, x, y)
1769 #define gen_ldcmp_fpr64(ctx, x, y) gen_load_fpr64(ctx, x, y)
1770 #define FOP_CONDS(type, abs, fmt, ifmt, bits) \
1771 static inline void gen_cmp ## type ## _ ## fmt(DisasContext *ctx, int n, \
1772 int ft, int fs, int cc) \
1774 TCGv_i##bits fp0 = tcg_temp_new_i##bits(); \
1775 TCGv_i##bits fp1 = tcg_temp_new_i##bits(); \
1784 check_cp1_registers(ctx, fs | ft); \
1792 gen_ldcmp_fpr##bits(ctx, fp0, fs); \
1793 gen_ldcmp_fpr##bits(ctx, fp1, ft); \
1796 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _f, fp0, fp1, cc); \
1799 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _un, fp0, fp1, cc); \
1802 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _eq, fp0, fp1, cc); \
1805 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ueq, fp0, fp1, cc); \
1808 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _olt, fp0, fp1, cc); \
1811 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ult, fp0, fp1, cc); \
1814 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ole, fp0, fp1, cc); \
1817 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ule, fp0, fp1, cc); \
1820 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _sf, fp0, fp1, cc); \
1823 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngle, fp0, fp1, cc); \
1826 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _seq, fp0, fp1, cc); \
1829 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngl, fp0, fp1, cc); \
1832 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _lt, fp0, fp1, cc); \
1835 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _nge, fp0, fp1, cc); \
1838 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _le, fp0, fp1, cc); \
1841 gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngt, fp0, fp1, cc); \
1848 FOP_CONDS(, 0, d
, FMT_D
, 64)
1849 FOP_CONDS(abs
, 1, d
, FMT_D
, 64)
1850 FOP_CONDS(, 0, s
, FMT_S
, 32)
1851 FOP_CONDS(abs
, 1, s
, FMT_S
, 32)
1852 FOP_CONDS(, 0, ps
, FMT_PS
, 64)
1853 FOP_CONDS(abs
, 1, ps
, FMT_PS
, 64)
1856 #define FOP_CONDNS(fmt, ifmt, bits, STORE) \
1857 static inline void gen_r6_cmp_ ## fmt(DisasContext *ctx, int n, \
1858 int ft, int fs, int fd) \
1860 TCGv_i ## bits fp0 = tcg_temp_new_i ## bits(); \
1861 TCGv_i ## bits fp1 = tcg_temp_new_i ## bits(); \
1862 if (ifmt == FMT_D) { \
1863 check_cp1_registers(ctx, fs | ft | fd); \
1865 gen_ldcmp_fpr ## bits(ctx, fp0, fs); \
1866 gen_ldcmp_fpr ## bits(ctx, fp1, ft); \
1869 gen_helper_r6_cmp_ ## fmt ## _af(fp0, tcg_env, fp0, fp1); \
1872 gen_helper_r6_cmp_ ## fmt ## _un(fp0, tcg_env, fp0, fp1); \
1875 gen_helper_r6_cmp_ ## fmt ## _eq(fp0, tcg_env, fp0, fp1); \
1878 gen_helper_r6_cmp_ ## fmt ## _ueq(fp0, tcg_env, fp0, fp1); \
1881 gen_helper_r6_cmp_ ## fmt ## _lt(fp0, tcg_env, fp0, fp1); \
1884 gen_helper_r6_cmp_ ## fmt ## _ult(fp0, tcg_env, fp0, fp1); \
1887 gen_helper_r6_cmp_ ## fmt ## _le(fp0, tcg_env, fp0, fp1); \
1890 gen_helper_r6_cmp_ ## fmt ## _ule(fp0, tcg_env, fp0, fp1); \
1893 gen_helper_r6_cmp_ ## fmt ## _saf(fp0, tcg_env, fp0, fp1); \
1896 gen_helper_r6_cmp_ ## fmt ## _sun(fp0, tcg_env, fp0, fp1); \
1899 gen_helper_r6_cmp_ ## fmt ## _seq(fp0, tcg_env, fp0, fp1); \
1902 gen_helper_r6_cmp_ ## fmt ## _sueq(fp0, tcg_env, fp0, fp1); \
1905 gen_helper_r6_cmp_ ## fmt ## _slt(fp0, tcg_env, fp0, fp1); \
1908 gen_helper_r6_cmp_ ## fmt ## _sult(fp0, tcg_env, fp0, fp1); \
1911 gen_helper_r6_cmp_ ## fmt ## _sle(fp0, tcg_env, fp0, fp1); \
1914 gen_helper_r6_cmp_ ## fmt ## _sule(fp0, tcg_env, fp0, fp1); \
1917 gen_helper_r6_cmp_ ## fmt ## _or(fp0, tcg_env, fp0, fp1); \
1920 gen_helper_r6_cmp_ ## fmt ## _une(fp0, tcg_env, fp0, fp1); \
1923 gen_helper_r6_cmp_ ## fmt ## _ne(fp0, tcg_env, fp0, fp1); \
1926 gen_helper_r6_cmp_ ## fmt ## _sor(fp0, tcg_env, fp0, fp1); \
1929 gen_helper_r6_cmp_ ## fmt ## _sune(fp0, tcg_env, fp0, fp1); \
1932 gen_helper_r6_cmp_ ## fmt ## _sne(fp0, tcg_env, fp0, fp1); \
1940 FOP_CONDNS(d
, FMT_D
, 64, gen_store_fpr64(ctx
, fp0
, fd
))
1941 FOP_CONDNS(s
, FMT_S
, 32, gen_store_fpr32(ctx
, fp0
, fd
))
1943 #undef gen_ldcmp_fpr32
1944 #undef gen_ldcmp_fpr64
1946 /* load/store instructions. */
1947 #ifdef CONFIG_USER_ONLY
1948 #define OP_LD_ATOMIC(insn, memop) \
1949 static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx, \
1950 DisasContext *ctx) \
1952 TCGv t0 = tcg_temp_new(); \
1953 tcg_gen_mov_tl(t0, arg1); \
1954 tcg_gen_qemu_ld_tl(ret, arg1, ctx->mem_idx, memop); \
1955 tcg_gen_st_tl(t0, tcg_env, offsetof(CPUMIPSState, lladdr)); \
1956 tcg_gen_st_tl(ret, tcg_env, offsetof(CPUMIPSState, llval)); \
1959 #define OP_LD_ATOMIC(insn, ignored_memop) \
1960 static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx, \
1961 DisasContext *ctx) \
1963 gen_helper_##insn(ret, tcg_env, arg1, tcg_constant_i32(mem_idx)); \
1966 OP_LD_ATOMIC(ll
, mo_endian(ctx
) | MO_SL
);
1967 #if defined(TARGET_MIPS64)
1968 OP_LD_ATOMIC(lld
, mo_endian(ctx
) | MO_UQ
);
1972 void gen_base_offset_addr(DisasContext
*ctx
, TCGv addr
, int base
, int offset
)
1975 tcg_gen_movi_tl(addr
, offset
);
1976 } else if (offset
== 0) {
1977 gen_load_gpr(addr
, base
);
1979 tcg_gen_movi_tl(addr
, offset
);
1980 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
1984 static target_ulong
pc_relative_pc(DisasContext
*ctx
)
1986 target_ulong pc
= ctx
->base
.pc_next
;
1988 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1989 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
1994 pc
&= ~(target_ulong
)3;
1998 /* LWL or LDL, depending on MemOp. */
1999 static void gen_lxl(DisasContext
*ctx
, TCGv reg
, TCGv addr
,
2000 int mem_idx
, MemOp mop
)
2002 int sizem1
= memop_size(mop
) - 1;
2003 TCGv t0
= tcg_temp_new();
2004 TCGv t1
= tcg_temp_new();
2007 * Do a byte access to possibly trigger a page
2008 * fault with the unaligned address.
2010 tcg_gen_qemu_ld_tl(t1
, addr
, mem_idx
, MO_UB
);
2011 tcg_gen_andi_tl(t1
, addr
, sizem1
);
2012 if (!disas_is_bigendian(ctx
)) {
2013 tcg_gen_xori_tl(t1
, t1
, sizem1
);
2015 tcg_gen_shli_tl(t1
, t1
, 3);
2016 tcg_gen_andi_tl(t0
, addr
, ~sizem1
);
2017 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mop
);
2018 tcg_gen_shl_tl(t0
, t0
, t1
);
2019 tcg_gen_shl_tl(t1
, tcg_constant_tl(-1), t1
);
2020 tcg_gen_andc_tl(t1
, reg
, t1
);
2021 tcg_gen_or_tl(reg
, t0
, t1
);
2024 /* LWR or LDR, depending on MemOp. */
2025 static void gen_lxr(DisasContext
*ctx
, TCGv reg
, TCGv addr
,
2026 int mem_idx
, MemOp mop
)
2028 int size
= memop_size(mop
);
2029 int sizem1
= size
- 1;
2030 TCGv t0
= tcg_temp_new();
2031 TCGv t1
= tcg_temp_new();
2034 * Do a byte access to possibly trigger a page
2035 * fault with the unaligned address.
2037 tcg_gen_qemu_ld_tl(t1
, addr
, mem_idx
, MO_UB
);
2038 tcg_gen_andi_tl(t1
, addr
, sizem1
);
2039 if (disas_is_bigendian(ctx
)) {
2040 tcg_gen_xori_tl(t1
, t1
, sizem1
);
2042 tcg_gen_shli_tl(t1
, t1
, 3);
2043 tcg_gen_andi_tl(t0
, addr
, ~sizem1
);
2044 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mop
);
2045 tcg_gen_shr_tl(t0
, t0
, t1
);
2046 tcg_gen_xori_tl(t1
, t1
, size
* 8 - 1);
2047 tcg_gen_shl_tl(t1
, tcg_constant_tl(~1), t1
);
2048 tcg_gen_and_tl(t1
, reg
, t1
);
2049 tcg_gen_or_tl(reg
, t0
, t1
);
2053 static void gen_ld(DisasContext
*ctx
, uint32_t opc
,
2054 int rt
, int base
, int offset
)
2057 int mem_idx
= ctx
->mem_idx
;
2059 if (rt
== 0 && ctx
->insn_flags
& (INSN_LOONGSON2E
| INSN_LOONGSON2F
|
2062 * Loongson CPU uses a load to zero register for prefetch.
2063 * We emulate it as a NOP. On other CPU we must perform the
2064 * actual memory access.
2069 t0
= tcg_temp_new();
2070 gen_base_offset_addr(ctx
, t0
, base
, offset
);
2073 #if defined(TARGET_MIPS64)
2075 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mo_endian(ctx
) | MO_UL
|
2076 ctx
->default_tcg_memop_mask
);
2077 gen_store_gpr(t0
, rt
);
2080 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mo_endian(ctx
) | MO_UQ
|
2081 ctx
->default_tcg_memop_mask
);
2082 gen_store_gpr(t0
, rt
);
2086 op_ld_lld(t0
, t0
, mem_idx
, ctx
);
2087 gen_store_gpr(t0
, rt
);
2090 t1
= tcg_temp_new();
2091 gen_load_gpr(t1
, rt
);
2092 gen_lxl(ctx
, t1
, t0
, mem_idx
, mo_endian(ctx
) | MO_UQ
);
2093 gen_store_gpr(t1
, rt
);
2096 t1
= tcg_temp_new();
2097 gen_load_gpr(t1
, rt
);
2098 gen_lxr(ctx
, t1
, t0
, mem_idx
, mo_endian(ctx
) | MO_UQ
);
2099 gen_store_gpr(t1
, rt
);
2102 t1
= tcg_constant_tl(pc_relative_pc(ctx
));
2103 gen_op_addr_add(ctx
, t0
, t0
, t1
);
2104 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mo_endian(ctx
) | MO_UQ
);
2105 gen_store_gpr(t0
, rt
);
2109 t1
= tcg_constant_tl(pc_relative_pc(ctx
));
2110 gen_op_addr_add(ctx
, t0
, t0
, t1
);
2111 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mo_endian(ctx
) | MO_SL
);
2112 gen_store_gpr(t0
, rt
);
2115 mem_idx
= MIPS_HFLAG_UM
;
2118 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mo_endian(ctx
) | MO_SL
|
2119 ctx
->default_tcg_memop_mask
);
2120 gen_store_gpr(t0
, rt
);
2123 mem_idx
= MIPS_HFLAG_UM
;
2126 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mo_endian(ctx
) | MO_SW
|
2127 ctx
->default_tcg_memop_mask
);
2128 gen_store_gpr(t0
, rt
);
2131 mem_idx
= MIPS_HFLAG_UM
;
2134 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, mo_endian(ctx
) | MO_UW
|
2135 ctx
->default_tcg_memop_mask
);
2136 gen_store_gpr(t0
, rt
);
2139 mem_idx
= MIPS_HFLAG_UM
;
2142 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, MO_SB
);
2143 gen_store_gpr(t0
, rt
);
2146 mem_idx
= MIPS_HFLAG_UM
;
2149 tcg_gen_qemu_ld_tl(t0
, t0
, mem_idx
, MO_UB
);
2150 gen_store_gpr(t0
, rt
);
2153 mem_idx
= MIPS_HFLAG_UM
;
2156 t1
= tcg_temp_new();
2157 gen_load_gpr(t1
, rt
);
2158 gen_lxl(ctx
, t1
, t0
, mem_idx
, mo_endian(ctx
) | MO_UL
);
2159 tcg_gen_ext32s_tl(t1
, t1
);
2160 gen_store_gpr(t1
, rt
);
2163 mem_idx
= MIPS_HFLAG_UM
;
2166 t1
= tcg_temp_new();
2167 gen_load_gpr(t1
, rt
);
2168 gen_lxr(ctx
, t1
, t0
, mem_idx
, mo_endian(ctx
) | MO_UL
);
2169 tcg_gen_ext32s_tl(t1
, t1
);
2170 gen_store_gpr(t1
, rt
);
2173 mem_idx
= MIPS_HFLAG_UM
;
2177 op_ld_ll(t0
, t0
, mem_idx
, ctx
);
2178 gen_store_gpr(t0
, rt
);
2184 static void gen_st(DisasContext
*ctx
, uint32_t opc
, int rt
,
2185 int base
, int offset
)
2187 TCGv t0
= tcg_temp_new();
2188 TCGv t1
= tcg_temp_new();
2189 int mem_idx
= ctx
->mem_idx
;
2191 gen_base_offset_addr(ctx
, t0
, base
, offset
);
2192 gen_load_gpr(t1
, rt
);
2194 #if defined(TARGET_MIPS64)
2196 tcg_gen_qemu_st_tl(t1
, t0
, mem_idx
, mo_endian(ctx
) | MO_UQ
|
2197 ctx
->default_tcg_memop_mask
);
2200 gen_helper_0e2i(sdl
, t1
, t0
, mem_idx
);
2203 gen_helper_0e2i(sdr
, t1
, t0
, mem_idx
);
2207 mem_idx
= MIPS_HFLAG_UM
;
2210 tcg_gen_qemu_st_tl(t1
, t0
, mem_idx
, mo_endian(ctx
) | MO_UL
|
2211 ctx
->default_tcg_memop_mask
);
2214 mem_idx
= MIPS_HFLAG_UM
;
2217 tcg_gen_qemu_st_tl(t1
, t0
, mem_idx
, mo_endian(ctx
) | MO_UW
|
2218 ctx
->default_tcg_memop_mask
);
2221 mem_idx
= MIPS_HFLAG_UM
;
2224 tcg_gen_qemu_st_tl(t1
, t0
, mem_idx
, MO_8
);
2227 mem_idx
= MIPS_HFLAG_UM
;
2230 gen_helper_0e2i(swl
, t1
, t0
, mem_idx
);
2233 mem_idx
= MIPS_HFLAG_UM
;
2236 gen_helper_0e2i(swr
, t1
, t0
, mem_idx
);
2242 /* Store conditional */
2243 static void gen_st_cond(DisasContext
*ctx
, int rt
, int base
, int offset
,
2244 MemOp tcg_mo
, bool eva
)
2247 TCGLabel
*l1
= gen_new_label();
2248 TCGLabel
*done
= gen_new_label();
2250 t0
= tcg_temp_new();
2251 addr
= tcg_temp_new();
2252 /* compare the address against that of the preceding LL */
2253 gen_base_offset_addr(ctx
, addr
, base
, offset
);
2254 tcg_gen_brcond_tl(TCG_COND_EQ
, addr
, cpu_lladdr
, l1
);
2255 gen_store_gpr(tcg_constant_tl(0), rt
);
2259 /* generate cmpxchg */
2260 val
= tcg_temp_new();
2261 gen_load_gpr(val
, rt
);
2262 tcg_gen_atomic_cmpxchg_tl(t0
, cpu_lladdr
, cpu_llval
, val
,
2263 eva
? MIPS_HFLAG_UM
: ctx
->mem_idx
, tcg_mo
);
2264 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, t0
, cpu_llval
);
2265 gen_store_gpr(t0
, rt
);
2267 gen_set_label(done
);
2270 /* Load and store */
2271 static void gen_flt_ldst(DisasContext
*ctx
, uint32_t opc
, int ft
,
2275 * Don't do NOP if destination is zero: we must perform the actual
2281 TCGv_i32 fp0
= tcg_temp_new_i32();
2282 tcg_gen_qemu_ld_i32(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SL
|
2283 ctx
->default_tcg_memop_mask
);
2284 gen_store_fpr32(ctx
, fp0
, ft
);
2289 TCGv_i32 fp0
= tcg_temp_new_i32();
2290 gen_load_fpr32(ctx
, fp0
, ft
);
2291 tcg_gen_qemu_st_i32(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UL
|
2292 ctx
->default_tcg_memop_mask
);
2297 TCGv_i64 fp0
= tcg_temp_new_i64();
2298 tcg_gen_qemu_ld_i64(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
2299 ctx
->default_tcg_memop_mask
);
2300 gen_store_fpr64(ctx
, fp0
, ft
);
2305 TCGv_i64 fp0
= tcg_temp_new_i64();
2306 gen_load_fpr64(ctx
, fp0
, ft
);
2307 tcg_gen_qemu_st_i64(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
2308 ctx
->default_tcg_memop_mask
);
2312 MIPS_INVAL("flt_ldst");
2313 gen_reserved_instruction(ctx
);
2318 static void gen_cop1_ldst(DisasContext
*ctx
, uint32_t op
, int rt
,
2319 int rs
, int16_t imm
)
2321 TCGv t0
= tcg_temp_new();
2323 if (ctx
->CP0_Config1
& (1 << CP0C1_FP
)) {
2324 check_cp1_enabled(ctx
);
2328 check_insn(ctx
, ISA_MIPS2
);
2331 gen_base_offset_addr(ctx
, t0
, rs
, imm
);
2332 gen_flt_ldst(ctx
, op
, rt
, t0
);
2335 generate_exception_err(ctx
, EXCP_CpU
, 1);
2339 /* Arithmetic with immediate operand */
2340 static void gen_arith_imm(DisasContext
*ctx
, uint32_t opc
,
2341 int rt
, int rs
, int imm
)
2343 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
2345 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
2347 * If no destination, treat it as a NOP.
2348 * For addi, we must generate the overflow exception when needed.
2355 TCGv t0
= tcg_temp_new();
2356 TCGv t1
= tcg_temp_new();
2357 TCGv t2
= tcg_temp_new();
2358 TCGLabel
*l1
= gen_new_label();
2360 gen_load_gpr(t1
, rs
);
2361 tcg_gen_addi_tl(t0
, t1
, uimm
);
2362 tcg_gen_ext32s_tl(t0
, t0
);
2364 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
2365 tcg_gen_xori_tl(t2
, t0
, uimm
);
2366 tcg_gen_and_tl(t1
, t1
, t2
);
2367 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2368 /* operands of same sign, result different sign */
2369 generate_exception(ctx
, EXCP_OVERFLOW
);
2371 tcg_gen_ext32s_tl(t0
, t0
);
2372 gen_store_gpr(t0
, rt
);
2377 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2378 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
2380 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
2383 #if defined(TARGET_MIPS64)
2386 TCGv t0
= tcg_temp_new();
2387 TCGv t1
= tcg_temp_new();
2388 TCGv t2
= tcg_temp_new();
2389 TCGLabel
*l1
= gen_new_label();
2391 gen_load_gpr(t1
, rs
);
2392 tcg_gen_addi_tl(t0
, t1
, uimm
);
2394 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
2395 tcg_gen_xori_tl(t2
, t0
, uimm
);
2396 tcg_gen_and_tl(t1
, t1
, t2
);
2397 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2398 /* operands of same sign, result different sign */
2399 generate_exception(ctx
, EXCP_OVERFLOW
);
2401 gen_store_gpr(t0
, rt
);
2406 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2408 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
2415 /* Logic with immediate operand */
2416 static void gen_logic_imm(DisasContext
*ctx
, uint32_t opc
,
2417 int rt
, int rs
, int16_t imm
)
2422 /* If no destination, treat it as a NOP. */
2425 uimm
= (uint16_t)imm
;
2428 if (likely(rs
!= 0)) {
2429 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2431 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
2436 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2438 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
2442 if (likely(rs
!= 0)) {
2443 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
2445 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
2449 if (rs
!= 0 && (ctx
->insn_flags
& ISA_MIPS_R6
)) {
2451 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], imm
<< 16);
2452 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
2454 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
2463 /* Set on less than with immediate operand */
2464 static void gen_slt_imm(DisasContext
*ctx
, uint32_t opc
,
2465 int rt
, int rs
, int16_t imm
)
2467 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
2471 /* If no destination, treat it as a NOP. */
2474 t0
= tcg_temp_new();
2475 gen_load_gpr(t0
, rs
);
2478 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
2481 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
2486 /* Shifts with immediate operand */
2487 static void gen_shift_imm(DisasContext
*ctx
, uint32_t opc
,
2488 int rt
, int rs
, int16_t imm
)
2490 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
2494 /* If no destination, treat it as a NOP. */
2498 t0
= tcg_temp_new();
2499 gen_load_gpr(t0
, rs
);
2502 tcg_gen_shli_tl(t0
, t0
, uimm
);
2503 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
2506 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
2510 tcg_gen_ext32u_tl(t0
, t0
);
2511 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
2513 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
2518 TCGv_i32 t1
= tcg_temp_new_i32();
2520 tcg_gen_trunc_tl_i32(t1
, t0
);
2521 tcg_gen_rotri_i32(t1
, t1
, uimm
);
2522 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
2524 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
2527 #if defined(TARGET_MIPS64)
2529 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
2532 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
2535 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
2539 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
2541 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
2545 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
2548 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
2551 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
2554 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
2561 static void gen_arith(DisasContext
*ctx
, uint32_t opc
,
2562 int rd
, int rs
, int rt
)
2564 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
2565 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
2567 * If no destination, treat it as a NOP.
2568 * For add & sub, we must generate the overflow exception when needed.
2576 TCGv t0
= tcg_temp_new();
2577 TCGv t1
= tcg_temp_new();
2578 TCGv t2
= tcg_temp_new();
2579 TCGLabel
*l1
= gen_new_label();
2581 gen_load_gpr(t1
, rs
);
2582 gen_load_gpr(t2
, rt
);
2583 tcg_gen_add_tl(t0
, t1
, t2
);
2584 tcg_gen_ext32s_tl(t0
, t0
);
2585 tcg_gen_xor_tl(t1
, t1
, t2
);
2586 tcg_gen_xor_tl(t2
, t0
, t2
);
2587 tcg_gen_andc_tl(t1
, t2
, t1
);
2588 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2589 /* operands of same sign, result different sign */
2590 generate_exception(ctx
, EXCP_OVERFLOW
);
2592 gen_store_gpr(t0
, rd
);
2596 if (rs
!= 0 && rt
!= 0) {
2597 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2598 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2599 } else if (rs
== 0 && rt
!= 0) {
2600 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2601 } else if (rs
!= 0 && rt
== 0) {
2602 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2604 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2609 TCGv t0
= tcg_temp_new();
2610 TCGv t1
= tcg_temp_new();
2611 TCGv t2
= tcg_temp_new();
2612 TCGLabel
*l1
= gen_new_label();
2614 gen_load_gpr(t1
, rs
);
2615 gen_load_gpr(t2
, rt
);
2616 tcg_gen_sub_tl(t0
, t1
, t2
);
2617 tcg_gen_ext32s_tl(t0
, t0
);
2618 tcg_gen_xor_tl(t2
, t1
, t2
);
2619 tcg_gen_xor_tl(t1
, t0
, t1
);
2620 tcg_gen_and_tl(t1
, t1
, t2
);
2621 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2623 * operands of different sign, first operand and the result
2626 generate_exception(ctx
, EXCP_OVERFLOW
);
2628 gen_store_gpr(t0
, rd
);
2632 if (rs
!= 0 && rt
!= 0) {
2633 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2634 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2635 } else if (rs
== 0 && rt
!= 0) {
2636 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2637 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2638 } else if (rs
!= 0 && rt
== 0) {
2639 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2641 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2644 #if defined(TARGET_MIPS64)
2647 TCGv t0
= tcg_temp_new();
2648 TCGv t1
= tcg_temp_new();
2649 TCGv t2
= tcg_temp_new();
2650 TCGLabel
*l1
= gen_new_label();
2652 gen_load_gpr(t1
, rs
);
2653 gen_load_gpr(t2
, rt
);
2654 tcg_gen_add_tl(t0
, t1
, t2
);
2655 tcg_gen_xor_tl(t1
, t1
, t2
);
2656 tcg_gen_xor_tl(t2
, t0
, t2
);
2657 tcg_gen_andc_tl(t1
, t2
, t1
);
2658 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2659 /* operands of same sign, result different sign */
2660 generate_exception(ctx
, EXCP_OVERFLOW
);
2662 gen_store_gpr(t0
, rd
);
2666 if (rs
!= 0 && rt
!= 0) {
2667 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2668 } else if (rs
== 0 && rt
!= 0) {
2669 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2670 } else if (rs
!= 0 && rt
== 0) {
2671 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2673 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2678 TCGv t0
= tcg_temp_new();
2679 TCGv t1
= tcg_temp_new();
2680 TCGv t2
= tcg_temp_new();
2681 TCGLabel
*l1
= gen_new_label();
2683 gen_load_gpr(t1
, rs
);
2684 gen_load_gpr(t2
, rt
);
2685 tcg_gen_sub_tl(t0
, t1
, t2
);
2686 tcg_gen_xor_tl(t2
, t1
, t2
);
2687 tcg_gen_xor_tl(t1
, t0
, t1
);
2688 tcg_gen_and_tl(t1
, t1
, t2
);
2689 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
2691 * Operands of different sign, first operand and result different
2694 generate_exception(ctx
, EXCP_OVERFLOW
);
2696 gen_store_gpr(t0
, rd
);
2700 if (rs
!= 0 && rt
!= 0) {
2701 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2702 } else if (rs
== 0 && rt
!= 0) {
2703 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2704 } else if (rs
!= 0 && rt
== 0) {
2705 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2707 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2712 if (likely(rs
!= 0 && rt
!= 0)) {
2713 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2714 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2716 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2722 /* Conditional move */
2723 static void gen_cond_move(DisasContext
*ctx
, uint32_t opc
,
2724 int rd
, int rs
, int rt
)
2729 /* If no destination, treat it as a NOP. */
2733 t0
= tcg_temp_new();
2734 gen_load_gpr(t0
, rt
);
2735 t1
= tcg_constant_tl(0);
2736 t2
= tcg_temp_new();
2737 gen_load_gpr(t2
, rs
);
2740 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rd
], t0
, t1
, t2
, cpu_gpr
[rd
]);
2743 tcg_gen_movcond_tl(TCG_COND_EQ
, cpu_gpr
[rd
], t0
, t1
, t2
, cpu_gpr
[rd
]);
2746 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rd
], t0
, t1
, t2
, t1
);
2749 tcg_gen_movcond_tl(TCG_COND_EQ
, cpu_gpr
[rd
], t0
, t1
, t2
, t1
);
2755 static void gen_logic(DisasContext
*ctx
, uint32_t opc
,
2756 int rd
, int rs
, int rt
)
2759 /* If no destination, treat it as a NOP. */
2765 if (likely(rs
!= 0 && rt
!= 0)) {
2766 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2768 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2772 if (rs
!= 0 && rt
!= 0) {
2773 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2774 } else if (rs
== 0 && rt
!= 0) {
2775 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2776 } else if (rs
!= 0 && rt
== 0) {
2777 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2779 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
2783 if (likely(rs
!= 0 && rt
!= 0)) {
2784 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2785 } else if (rs
== 0 && rt
!= 0) {
2786 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2787 } else if (rs
!= 0 && rt
== 0) {
2788 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2790 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2794 if (likely(rs
!= 0 && rt
!= 0)) {
2795 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
2796 } else if (rs
== 0 && rt
!= 0) {
2797 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
2798 } else if (rs
!= 0 && rt
== 0) {
2799 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
2801 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2807 /* Set on lower than */
2808 static void gen_slt(DisasContext
*ctx
, uint32_t opc
,
2809 int rd
, int rs
, int rt
)
2814 /* If no destination, treat it as a NOP. */
2818 t0
= tcg_temp_new();
2819 t1
= tcg_temp_new();
2820 gen_load_gpr(t0
, rs
);
2821 gen_load_gpr(t1
, rt
);
2824 tcg_gen_setcond_tl(TCG_COND_LT
, cpu_gpr
[rd
], t0
, t1
);
2827 tcg_gen_setcond_tl(TCG_COND_LTU
, cpu_gpr
[rd
], t0
, t1
);
2833 static void gen_shift(DisasContext
*ctx
, uint32_t opc
,
2834 int rd
, int rs
, int rt
)
2840 * If no destination, treat it as a NOP.
2841 * For add & sub, we must generate the overflow exception when needed.
2846 t0
= tcg_temp_new();
2847 t1
= tcg_temp_new();
2848 gen_load_gpr(t0
, rs
);
2849 gen_load_gpr(t1
, rt
);
2852 tcg_gen_andi_tl(t0
, t0
, 0x1f);
2853 tcg_gen_shl_tl(t0
, t1
, t0
);
2854 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2857 tcg_gen_andi_tl(t0
, t0
, 0x1f);
2858 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
2861 tcg_gen_ext32u_tl(t1
, t1
);
2862 tcg_gen_andi_tl(t0
, t0
, 0x1f);
2863 tcg_gen_shr_tl(t0
, t1
, t0
);
2864 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2868 TCGv_i32 t2
= tcg_temp_new_i32();
2869 TCGv_i32 t3
= tcg_temp_new_i32();
2871 tcg_gen_trunc_tl_i32(t2
, t0
);
2872 tcg_gen_trunc_tl_i32(t3
, t1
);
2873 tcg_gen_andi_i32(t2
, t2
, 0x1f);
2874 tcg_gen_rotr_i32(t2
, t3
, t2
);
2875 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
2878 #if defined(TARGET_MIPS64)
2880 tcg_gen_andi_tl(t0
, t0
, 0x3f);
2881 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
2884 tcg_gen_andi_tl(t0
, t0
, 0x3f);
2885 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
2888 tcg_gen_andi_tl(t0
, t0
, 0x3f);
2889 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
2892 tcg_gen_andi_tl(t0
, t0
, 0x3f);
2893 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
2899 /* Arithmetic on HI/LO registers */
2900 static void gen_HILO(DisasContext
*ctx
, uint32_t opc
, int acc
, int reg
)
2902 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
2913 #if defined(TARGET_MIPS64)
2915 tcg_gen_ext32s_tl(cpu_gpr
[reg
], cpu_HI
[acc
]);
2919 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[acc
]);
2923 #if defined(TARGET_MIPS64)
2925 tcg_gen_ext32s_tl(cpu_gpr
[reg
], cpu_LO
[acc
]);
2929 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[acc
]);
2934 #if defined(TARGET_MIPS64)
2936 tcg_gen_ext32s_tl(cpu_HI
[acc
], cpu_gpr
[reg
]);
2940 tcg_gen_mov_tl(cpu_HI
[acc
], cpu_gpr
[reg
]);
2943 tcg_gen_movi_tl(cpu_HI
[acc
], 0);
2948 #if defined(TARGET_MIPS64)
2950 tcg_gen_ext32s_tl(cpu_LO
[acc
], cpu_gpr
[reg
]);
2954 tcg_gen_mov_tl(cpu_LO
[acc
], cpu_gpr
[reg
]);
2957 tcg_gen_movi_tl(cpu_LO
[acc
], 0);
2963 static inline void gen_r6_ld(target_long addr
, int reg
, int memidx
,
2966 TCGv t0
= tcg_temp_new();
2967 tcg_gen_qemu_ld_tl(t0
, tcg_constant_tl(addr
), memidx
, memop
);
2968 gen_store_gpr(t0
, reg
);
2971 static inline void gen_pcrel(DisasContext
*ctx
, int opc
, target_ulong pc
,
2977 switch (MASK_OPC_PCREL_TOP2BITS(opc
)) {
2980 offset
= sextract32(ctx
->opcode
<< 2, 0, 21);
2981 addr
= addr_add(ctx
, pc
, offset
);
2982 tcg_gen_movi_tl(cpu_gpr
[rs
], addr
);
2986 offset
= sextract32(ctx
->opcode
<< 2, 0, 21);
2987 addr
= addr_add(ctx
, pc
, offset
);
2988 gen_r6_ld(addr
, rs
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SL
);
2990 #if defined(TARGET_MIPS64)
2993 offset
= sextract32(ctx
->opcode
<< 2, 0, 21);
2994 addr
= addr_add(ctx
, pc
, offset
);
2995 gen_r6_ld(addr
, rs
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UL
);
2999 switch (MASK_OPC_PCREL_TOP5BITS(opc
)) {
3002 offset
= sextract32(ctx
->opcode
, 0, 16) << 16;
3003 addr
= addr_add(ctx
, pc
, offset
);
3004 tcg_gen_movi_tl(cpu_gpr
[rs
], addr
);
3009 offset
= sextract32(ctx
->opcode
, 0, 16) << 16;
3010 addr
= ~0xFFFF & addr_add(ctx
, pc
, offset
);
3011 tcg_gen_movi_tl(cpu_gpr
[rs
], addr
);
3014 #if defined(TARGET_MIPS64)
3015 case R6_OPC_LDPC
: /* bits 16 and 17 are part of immediate */
3016 case R6_OPC_LDPC
+ (1 << 16):
3017 case R6_OPC_LDPC
+ (2 << 16):
3018 case R6_OPC_LDPC
+ (3 << 16):
3020 offset
= sextract32(ctx
->opcode
<< 3, 0, 21);
3021 addr
= addr_add(ctx
, (pc
& ~0x7), offset
);
3022 gen_r6_ld(addr
, rs
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
);
3026 MIPS_INVAL("OPC_PCREL");
3027 gen_reserved_instruction(ctx
);
3034 static void gen_r6_muldiv(DisasContext
*ctx
, int opc
, int rd
, int rs
, int rt
)
3043 t0
= tcg_temp_new();
3044 t1
= tcg_temp_new();
3046 gen_load_gpr(t0
, rs
);
3047 gen_load_gpr(t1
, rt
);
3052 TCGv t2
= tcg_temp_new();
3053 TCGv t3
= tcg_temp_new();
3054 tcg_gen_ext32s_tl(t0
, t0
);
3055 tcg_gen_ext32s_tl(t1
, t1
);
3056 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
3057 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1);
3058 tcg_gen_and_tl(t2
, t2
, t3
);
3059 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3060 tcg_gen_or_tl(t2
, t2
, t3
);
3061 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, tcg_constant_tl(0), t2
, t1
);
3062 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
3063 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3068 TCGv t2
= tcg_temp_new();
3069 TCGv t3
= tcg_temp_new();
3070 tcg_gen_ext32s_tl(t0
, t0
);
3071 tcg_gen_ext32s_tl(t1
, t1
);
3072 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
3073 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1);
3074 tcg_gen_and_tl(t2
, t2
, t3
);
3075 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3076 tcg_gen_or_tl(t2
, t2
, t3
);
3077 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, tcg_constant_tl(0), t2
, t1
);
3078 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
3079 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3084 tcg_gen_ext32u_tl(t0
, t0
);
3085 tcg_gen_ext32u_tl(t1
, t1
);
3086 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
,
3087 tcg_constant_tl(0), tcg_constant_tl(1), t1
);
3088 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
3089 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3094 tcg_gen_ext32u_tl(t0
, t0
);
3095 tcg_gen_ext32u_tl(t1
, t1
);
3096 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
,
3097 tcg_constant_tl(0), tcg_constant_tl(1), t1
);
3098 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
3099 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3104 TCGv_i32 t2
= tcg_temp_new_i32();
3105 TCGv_i32 t3
= tcg_temp_new_i32();
3106 tcg_gen_trunc_tl_i32(t2
, t0
);
3107 tcg_gen_trunc_tl_i32(t3
, t1
);
3108 tcg_gen_mul_i32(t2
, t2
, t3
);
3109 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
3114 TCGv_i32 t2
= tcg_temp_new_i32();
3115 TCGv_i32 t3
= tcg_temp_new_i32();
3116 tcg_gen_trunc_tl_i32(t2
, t0
);
3117 tcg_gen_trunc_tl_i32(t3
, t1
);
3118 tcg_gen_muls2_i32(t2
, t3
, t2
, t3
);
3119 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t3
);
3124 TCGv_i32 t2
= tcg_temp_new_i32();
3125 TCGv_i32 t3
= tcg_temp_new_i32();
3126 tcg_gen_trunc_tl_i32(t2
, t0
);
3127 tcg_gen_trunc_tl_i32(t3
, t1
);
3128 tcg_gen_mul_i32(t2
, t2
, t3
);
3129 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
3134 TCGv_i32 t2
= tcg_temp_new_i32();
3135 TCGv_i32 t3
= tcg_temp_new_i32();
3136 tcg_gen_trunc_tl_i32(t2
, t0
);
3137 tcg_gen_trunc_tl_i32(t3
, t1
);
3138 tcg_gen_mulu2_i32(t2
, t3
, t2
, t3
);
3139 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t3
);
3142 #if defined(TARGET_MIPS64)
3145 TCGv t2
= tcg_temp_new();
3146 TCGv t3
= tcg_temp_new();
3147 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, -1LL << 63);
3148 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1LL);
3149 tcg_gen_and_tl(t2
, t2
, t3
);
3150 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3151 tcg_gen_or_tl(t2
, t2
, t3
);
3152 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, tcg_constant_tl(0), t2
, t1
);
3153 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
3158 TCGv t2
= tcg_temp_new();
3159 TCGv t3
= tcg_temp_new();
3160 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, -1LL << 63);
3161 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1LL);
3162 tcg_gen_and_tl(t2
, t2
, t3
);
3163 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3164 tcg_gen_or_tl(t2
, t2
, t3
);
3165 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, tcg_constant_tl(0), t2
, t1
);
3166 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
3171 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
,
3172 tcg_constant_tl(0), tcg_constant_tl(1), t1
);
3173 tcg_gen_divu_i64(cpu_gpr
[rd
], t0
, t1
);
3178 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
,
3179 tcg_constant_tl(0), tcg_constant_tl(1), t1
);
3180 tcg_gen_remu_i64(cpu_gpr
[rd
], t0
, t1
);
3184 tcg_gen_mul_i64(cpu_gpr
[rd
], t0
, t1
);
3188 TCGv t2
= tcg_temp_new();
3189 tcg_gen_muls2_i64(t2
, cpu_gpr
[rd
], t0
, t1
);
3193 tcg_gen_mul_i64(cpu_gpr
[rd
], t0
, t1
);
3197 TCGv t2
= tcg_temp_new();
3198 tcg_gen_mulu2_i64(t2
, cpu_gpr
[rd
], t0
, t1
);
3203 MIPS_INVAL("r6 mul/div");
3204 gen_reserved_instruction(ctx
);
3209 #if defined(TARGET_MIPS64)
3210 static void gen_div1_tx79(DisasContext
*ctx
, uint32_t opc
, int rs
, int rt
)
3214 t0
= tcg_temp_new();
3215 t1
= tcg_temp_new();
3217 gen_load_gpr(t0
, rs
);
3218 gen_load_gpr(t1
, rt
);
3223 TCGv t2
= tcg_temp_new();
3224 TCGv t3
= tcg_temp_new();
3225 tcg_gen_ext32s_tl(t0
, t0
);
3226 tcg_gen_ext32s_tl(t1
, t1
);
3227 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
3228 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1);
3229 tcg_gen_and_tl(t2
, t2
, t3
);
3230 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3231 tcg_gen_or_tl(t2
, t2
, t3
);
3232 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, tcg_constant_tl(0), t2
, t1
);
3233 tcg_gen_div_tl(cpu_LO
[1], t0
, t1
);
3234 tcg_gen_rem_tl(cpu_HI
[1], t0
, t1
);
3235 tcg_gen_ext32s_tl(cpu_LO
[1], cpu_LO
[1]);
3236 tcg_gen_ext32s_tl(cpu_HI
[1], cpu_HI
[1]);
3241 TCGv t2
= tcg_constant_tl(0);
3242 TCGv t3
= tcg_constant_tl(1);
3243 tcg_gen_ext32u_tl(t0
, t0
);
3244 tcg_gen_ext32u_tl(t1
, t1
);
3245 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
, t2
, t3
, t1
);
3246 tcg_gen_divu_tl(cpu_LO
[1], t0
, t1
);
3247 tcg_gen_remu_tl(cpu_HI
[1], t0
, t1
);
3248 tcg_gen_ext32s_tl(cpu_LO
[1], cpu_LO
[1]);
3249 tcg_gen_ext32s_tl(cpu_HI
[1], cpu_HI
[1]);
3253 MIPS_INVAL("div1 TX79");
3254 gen_reserved_instruction(ctx
);
3260 static void gen_muldiv(DisasContext
*ctx
, uint32_t opc
,
3261 int acc
, int rs
, int rt
)
3265 t0
= tcg_temp_new();
3266 t1
= tcg_temp_new();
3268 gen_load_gpr(t0
, rs
);
3269 gen_load_gpr(t1
, rt
);
3278 TCGv t2
= tcg_temp_new();
3279 TCGv t3
= tcg_temp_new();
3280 tcg_gen_ext32s_tl(t0
, t0
);
3281 tcg_gen_ext32s_tl(t1
, t1
);
3282 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
3283 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1);
3284 tcg_gen_and_tl(t2
, t2
, t3
);
3285 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3286 tcg_gen_or_tl(t2
, t2
, t3
);
3287 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, tcg_constant_tl(0), t2
, t1
);
3288 tcg_gen_div_tl(cpu_LO
[acc
], t0
, t1
);
3289 tcg_gen_rem_tl(cpu_HI
[acc
], t0
, t1
);
3290 tcg_gen_ext32s_tl(cpu_LO
[acc
], cpu_LO
[acc
]);
3291 tcg_gen_ext32s_tl(cpu_HI
[acc
], cpu_HI
[acc
]);
3296 TCGv t2
= tcg_constant_tl(0);
3297 TCGv t3
= tcg_constant_tl(1);
3298 tcg_gen_ext32u_tl(t0
, t0
);
3299 tcg_gen_ext32u_tl(t1
, t1
);
3300 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
, t2
, t3
, t1
);
3301 tcg_gen_divu_tl(cpu_LO
[acc
], t0
, t1
);
3302 tcg_gen_remu_tl(cpu_HI
[acc
], t0
, t1
);
3303 tcg_gen_ext32s_tl(cpu_LO
[acc
], cpu_LO
[acc
]);
3304 tcg_gen_ext32s_tl(cpu_HI
[acc
], cpu_HI
[acc
]);
3309 TCGv_i32 t2
= tcg_temp_new_i32();
3310 TCGv_i32 t3
= tcg_temp_new_i32();
3311 tcg_gen_trunc_tl_i32(t2
, t0
);
3312 tcg_gen_trunc_tl_i32(t3
, t1
);
3313 tcg_gen_muls2_i32(t2
, t3
, t2
, t3
);
3314 tcg_gen_ext_i32_tl(cpu_LO
[acc
], t2
);
3315 tcg_gen_ext_i32_tl(cpu_HI
[acc
], t3
);
3320 TCGv_i32 t2
= tcg_temp_new_i32();
3321 TCGv_i32 t3
= tcg_temp_new_i32();
3322 tcg_gen_trunc_tl_i32(t2
, t0
);
3323 tcg_gen_trunc_tl_i32(t3
, t1
);
3324 tcg_gen_mulu2_i32(t2
, t3
, t2
, t3
);
3325 tcg_gen_ext_i32_tl(cpu_LO
[acc
], t2
);
3326 tcg_gen_ext_i32_tl(cpu_HI
[acc
], t3
);
3329 #if defined(TARGET_MIPS64)
3332 TCGv t2
= tcg_temp_new();
3333 TCGv t3
= tcg_temp_new();
3334 tcg_gen_setcondi_tl(TCG_COND_EQ
, t2
, t0
, -1LL << 63);
3335 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, -1LL);
3336 tcg_gen_and_tl(t2
, t2
, t3
);
3337 tcg_gen_setcondi_tl(TCG_COND_EQ
, t3
, t1
, 0);
3338 tcg_gen_or_tl(t2
, t2
, t3
);
3339 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t2
, tcg_constant_tl(0), t2
, t1
);
3340 tcg_gen_div_tl(cpu_LO
[acc
], t0
, t1
);
3341 tcg_gen_rem_tl(cpu_HI
[acc
], t0
, t1
);
3346 tcg_gen_movcond_tl(TCG_COND_EQ
, t1
, t1
,
3347 tcg_constant_tl(0), tcg_constant_tl(1), t1
);
3348 tcg_gen_divu_i64(cpu_LO
[acc
], t0
, t1
);
3349 tcg_gen_remu_i64(cpu_HI
[acc
], t0
, t1
);
3353 tcg_gen_muls2_i64(cpu_LO
[acc
], cpu_HI
[acc
], t0
, t1
);
3356 tcg_gen_mulu2_i64(cpu_LO
[acc
], cpu_HI
[acc
], t0
, t1
);
3361 TCGv_i64 t2
= tcg_temp_new_i64();
3362 TCGv_i64 t3
= tcg_temp_new_i64();
3364 tcg_gen_ext_tl_i64(t2
, t0
);
3365 tcg_gen_ext_tl_i64(t3
, t1
);
3366 tcg_gen_mul_i64(t2
, t2
, t3
);
3367 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3368 tcg_gen_add_i64(t2
, t2
, t3
);
3369 gen_move_low32(cpu_LO
[acc
], t2
);
3370 gen_move_high32(cpu_HI
[acc
], t2
);
3375 TCGv_i64 t2
= tcg_temp_new_i64();
3376 TCGv_i64 t3
= tcg_temp_new_i64();
3378 tcg_gen_ext32u_tl(t0
, t0
);
3379 tcg_gen_ext32u_tl(t1
, t1
);
3380 tcg_gen_extu_tl_i64(t2
, t0
);
3381 tcg_gen_extu_tl_i64(t3
, t1
);
3382 tcg_gen_mul_i64(t2
, t2
, t3
);
3383 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3384 tcg_gen_add_i64(t2
, t2
, t3
);
3385 gen_move_low32(cpu_LO
[acc
], t2
);
3386 gen_move_high32(cpu_HI
[acc
], t2
);
3391 TCGv_i64 t2
= tcg_temp_new_i64();
3392 TCGv_i64 t3
= tcg_temp_new_i64();
3394 tcg_gen_ext_tl_i64(t2
, t0
);
3395 tcg_gen_ext_tl_i64(t3
, t1
);
3396 tcg_gen_mul_i64(t2
, t2
, t3
);
3397 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3398 tcg_gen_sub_i64(t2
, t3
, t2
);
3399 gen_move_low32(cpu_LO
[acc
], t2
);
3400 gen_move_high32(cpu_HI
[acc
], t2
);
3405 TCGv_i64 t2
= tcg_temp_new_i64();
3406 TCGv_i64 t3
= tcg_temp_new_i64();
3408 tcg_gen_ext32u_tl(t0
, t0
);
3409 tcg_gen_ext32u_tl(t1
, t1
);
3410 tcg_gen_extu_tl_i64(t2
, t0
);
3411 tcg_gen_extu_tl_i64(t3
, t1
);
3412 tcg_gen_mul_i64(t2
, t2
, t3
);
3413 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3414 tcg_gen_sub_i64(t2
, t3
, t2
);
3415 gen_move_low32(cpu_LO
[acc
], t2
);
3416 gen_move_high32(cpu_HI
[acc
], t2
);
3420 MIPS_INVAL("mul/div");
3421 gen_reserved_instruction(ctx
);
3427 * These MULT[U] and MADD[U] instructions implemented in for example
3428 * the Toshiba/Sony R5900 and the Toshiba TX19, TX39 and TX79 core
3429 * architectures are special three-operand variants with the syntax
3431 * MULT[U][1] rd, rs, rt
3435 * (rd, LO, HI) <- rs * rt
3439 * MADD[U][1] rd, rs, rt
3443 * (rd, LO, HI) <- (LO, HI) + rs * rt
3445 * where the low-order 32-bits of the result is placed into both the
3446 * GPR rd and the special register LO. The high-order 32-bits of the
3447 * result is placed into the special register HI.
3449 * If the GPR rd is omitted in assembly language, it is taken to be 0,
3450 * which is the zero register that always reads as 0.
3452 static void gen_mul_txx9(DisasContext
*ctx
, uint32_t opc
,
3453 int rd
, int rs
, int rt
)
3455 TCGv t0
= tcg_temp_new();
3456 TCGv t1
= tcg_temp_new();
3459 gen_load_gpr(t0
, rs
);
3460 gen_load_gpr(t1
, rt
);
3468 TCGv_i32 t2
= tcg_temp_new_i32();
3469 TCGv_i32 t3
= tcg_temp_new_i32();
3470 tcg_gen_trunc_tl_i32(t2
, t0
);
3471 tcg_gen_trunc_tl_i32(t3
, t1
);
3472 tcg_gen_muls2_i32(t2
, t3
, t2
, t3
);
3474 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
3476 tcg_gen_ext_i32_tl(cpu_LO
[acc
], t2
);
3477 tcg_gen_ext_i32_tl(cpu_HI
[acc
], t3
);
3480 case MMI_OPC_MULTU1
:
3485 TCGv_i32 t2
= tcg_temp_new_i32();
3486 TCGv_i32 t3
= tcg_temp_new_i32();
3487 tcg_gen_trunc_tl_i32(t2
, t0
);
3488 tcg_gen_trunc_tl_i32(t3
, t1
);
3489 tcg_gen_mulu2_i32(t2
, t3
, t2
, t3
);
3491 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
3493 tcg_gen_ext_i32_tl(cpu_LO
[acc
], t2
);
3494 tcg_gen_ext_i32_tl(cpu_HI
[acc
], t3
);
3502 TCGv_i64 t2
= tcg_temp_new_i64();
3503 TCGv_i64 t3
= tcg_temp_new_i64();
3505 tcg_gen_ext_tl_i64(t2
, t0
);
3506 tcg_gen_ext_tl_i64(t3
, t1
);
3507 tcg_gen_mul_i64(t2
, t2
, t3
);
3508 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3509 tcg_gen_add_i64(t2
, t2
, t3
);
3510 gen_move_low32(cpu_LO
[acc
], t2
);
3511 gen_move_high32(cpu_HI
[acc
], t2
);
3513 gen_move_low32(cpu_gpr
[rd
], t2
);
3517 case MMI_OPC_MADDU1
:
3522 TCGv_i64 t2
= tcg_temp_new_i64();
3523 TCGv_i64 t3
= tcg_temp_new_i64();
3525 tcg_gen_ext32u_tl(t0
, t0
);
3526 tcg_gen_ext32u_tl(t1
, t1
);
3527 tcg_gen_extu_tl_i64(t2
, t0
);
3528 tcg_gen_extu_tl_i64(t3
, t1
);
3529 tcg_gen_mul_i64(t2
, t2
, t3
);
3530 tcg_gen_concat_tl_i64(t3
, cpu_LO
[acc
], cpu_HI
[acc
]);
3531 tcg_gen_add_i64(t2
, t2
, t3
);
3532 gen_move_low32(cpu_LO
[acc
], t2
);
3533 gen_move_high32(cpu_HI
[acc
], t2
);
3535 gen_move_low32(cpu_gpr
[rd
], t2
);
3540 MIPS_INVAL("mul/madd TXx9");
3541 gen_reserved_instruction(ctx
);
3546 static void gen_cl(DisasContext
*ctx
, uint32_t opc
,
3556 gen_load_gpr(t0
, rs
);
3561 #if defined(TARGET_MIPS64)
3565 tcg_gen_not_tl(t0
, t0
);
3574 tcg_gen_ext32u_tl(t0
, t0
);
3575 tcg_gen_clzi_tl(t0
, t0
, TARGET_LONG_BITS
);
3576 tcg_gen_subi_tl(t0
, t0
, TARGET_LONG_BITS
- 32);
3578 #if defined(TARGET_MIPS64)
3583 tcg_gen_clzi_i64(t0
, t0
, 64);
3589 /* Godson integer instructions */
3590 static void gen_loongson_integer(DisasContext
*ctx
, uint32_t opc
,
3591 int rd
, int rs
, int rt
)
3600 t0
= tcg_temp_new();
3601 t1
= tcg_temp_new();
3602 gen_load_gpr(t0
, rs
);
3603 gen_load_gpr(t1
, rt
);
3608 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
3609 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3611 case OPC_MULTU_G_2E
:
3612 case OPC_MULTU_G_2F
:
3613 tcg_gen_ext32u_tl(t0
, t0
);
3614 tcg_gen_ext32u_tl(t1
, t1
);
3615 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
3616 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3621 TCGLabel
*l1
= gen_new_label();
3622 TCGLabel
*l2
= gen_new_label();
3623 TCGLabel
*l3
= gen_new_label();
3624 tcg_gen_ext32s_tl(t0
, t0
);
3625 tcg_gen_ext32s_tl(t1
, t1
);
3626 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3627 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3630 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
3631 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
3632 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
3635 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
3636 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3643 TCGLabel
*l1
= gen_new_label();
3644 TCGLabel
*l2
= gen_new_label();
3645 tcg_gen_ext32u_tl(t0
, t0
);
3646 tcg_gen_ext32u_tl(t1
, t1
);
3647 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3648 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3651 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
3652 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3659 TCGLabel
*l1
= gen_new_label();
3660 TCGLabel
*l2
= gen_new_label();
3661 TCGLabel
*l3
= gen_new_label();
3662 tcg_gen_ext32u_tl(t0
, t0
);
3663 tcg_gen_ext32u_tl(t1
, t1
);
3664 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
3665 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
3666 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
3668 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3671 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
3672 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3679 TCGLabel
*l1
= gen_new_label();
3680 TCGLabel
*l2
= gen_new_label();
3681 tcg_gen_ext32u_tl(t0
, t0
);
3682 tcg_gen_ext32u_tl(t1
, t1
);
3683 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3684 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3687 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
3688 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
3692 #if defined(TARGET_MIPS64)
3693 case OPC_DMULT_G_2E
:
3694 case OPC_DMULT_G_2F
:
3695 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
3697 case OPC_DMULTU_G_2E
:
3698 case OPC_DMULTU_G_2F
:
3699 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
3704 TCGLabel
*l1
= gen_new_label();
3705 TCGLabel
*l2
= gen_new_label();
3706 TCGLabel
*l3
= gen_new_label();
3707 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3708 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3711 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
3712 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
3713 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
3716 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
3720 case OPC_DDIVU_G_2E
:
3721 case OPC_DDIVU_G_2F
:
3723 TCGLabel
*l1
= gen_new_label();
3724 TCGLabel
*l2
= gen_new_label();
3725 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3726 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3729 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
3736 TCGLabel
*l1
= gen_new_label();
3737 TCGLabel
*l2
= gen_new_label();
3738 TCGLabel
*l3
= gen_new_label();
3739 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
3740 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
3741 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
3743 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3746 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
3750 case OPC_DMODU_G_2E
:
3751 case OPC_DMODU_G_2F
:
3753 TCGLabel
*l1
= gen_new_label();
3754 TCGLabel
*l2
= gen_new_label();
3755 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
3756 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
3759 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
3767 /* Loongson multimedia instructions */
3768 static void gen_loongson_multimedia(DisasContext
*ctx
, int rd
, int rs
, int rt
)
3770 uint32_t opc
, shift_max
;
3774 opc
= MASK_LMMI(ctx
->opcode
);
3775 check_cp1_enabled(ctx
);
3777 t0
= tcg_temp_new_i64();
3778 t1
= tcg_temp_new_i64();
3779 gen_load_fpr64(ctx
, t0
, rs
);
3780 gen_load_fpr64(ctx
, t1
, rt
);
3784 gen_helper_paddsh(t0
, t0
, t1
);
3787 gen_helper_paddush(t0
, t0
, t1
);
3790 gen_helper_paddh(t0
, t0
, t1
);
3793 gen_helper_paddw(t0
, t0
, t1
);
3796 gen_helper_paddsb(t0
, t0
, t1
);
3799 gen_helper_paddusb(t0
, t0
, t1
);
3802 gen_helper_paddb(t0
, t0
, t1
);
3806 gen_helper_psubsh(t0
, t0
, t1
);
3809 gen_helper_psubush(t0
, t0
, t1
);
3812 gen_helper_psubh(t0
, t0
, t1
);
3815 gen_helper_psubw(t0
, t0
, t1
);
3818 gen_helper_psubsb(t0
, t0
, t1
);
3821 gen_helper_psubusb(t0
, t0
, t1
);
3824 gen_helper_psubb(t0
, t0
, t1
);
3828 gen_helper_pshufh(t0
, t0
, t1
);
3831 gen_helper_packsswh(t0
, t0
, t1
);
3834 gen_helper_packsshb(t0
, t0
, t1
);
3837 gen_helper_packushb(t0
, t0
, t1
);
3841 gen_helper_punpcklhw(t0
, t0
, t1
);
3844 gen_helper_punpckhhw(t0
, t0
, t1
);
3847 gen_helper_punpcklbh(t0
, t0
, t1
);
3850 gen_helper_punpckhbh(t0
, t0
, t1
);
3853 gen_helper_punpcklwd(t0
, t0
, t1
);
3856 gen_helper_punpckhwd(t0
, t0
, t1
);
3860 gen_helper_pavgh(t0
, t0
, t1
);
3863 gen_helper_pavgb(t0
, t0
, t1
);
3866 gen_helper_pmaxsh(t0
, t0
, t1
);
3869 gen_helper_pminsh(t0
, t0
, t1
);
3872 gen_helper_pmaxub(t0
, t0
, t1
);
3875 gen_helper_pminub(t0
, t0
, t1
);
3879 gen_helper_pcmpeqw(t0
, t0
, t1
);
3882 gen_helper_pcmpgtw(t0
, t0
, t1
);
3885 gen_helper_pcmpeqh(t0
, t0
, t1
);
3888 gen_helper_pcmpgth(t0
, t0
, t1
);
3891 gen_helper_pcmpeqb(t0
, t0
, t1
);
3894 gen_helper_pcmpgtb(t0
, t0
, t1
);
3898 gen_helper_psllw(t0
, t0
, t1
);
3901 gen_helper_psllh(t0
, t0
, t1
);
3904 gen_helper_psrlw(t0
, t0
, t1
);
3907 gen_helper_psrlh(t0
, t0
, t1
);
3910 gen_helper_psraw(t0
, t0
, t1
);
3913 gen_helper_psrah(t0
, t0
, t1
);
3917 gen_helper_pmullh(t0
, t0
, t1
);
3920 gen_helper_pmulhh(t0
, t0
, t1
);
3923 gen_helper_pmulhuh(t0
, t0
, t1
);
3926 gen_helper_pmaddhw(t0
, t0
, t1
);
3930 gen_helper_pasubub(t0
, t0
, t1
);
3933 gen_helper_biadd(t0
, t0
);
3936 gen_helper_pmovmskb(t0
, t0
);
3940 tcg_gen_add_i64(t0
, t0
, t1
);
3943 tcg_gen_sub_i64(t0
, t0
, t1
);
3946 tcg_gen_xor_i64(t0
, t0
, t1
);
3949 tcg_gen_nor_i64(t0
, t0
, t1
);
3952 tcg_gen_and_i64(t0
, t0
, t1
);
3955 tcg_gen_or_i64(t0
, t0
, t1
);
3959 tcg_gen_andc_i64(t0
, t1
, t0
);
3963 tcg_gen_deposit_i64(t0
, t0
, t1
, 0, 16);
3966 tcg_gen_deposit_i64(t0
, t0
, t1
, 16, 16);
3969 tcg_gen_deposit_i64(t0
, t0
, t1
, 32, 16);
3972 tcg_gen_deposit_i64(t0
, t0
, t1
, 48, 16);
3976 tcg_gen_andi_i64(t1
, t1
, 3);
3977 tcg_gen_shli_i64(t1
, t1
, 4);
3978 tcg_gen_shr_i64(t0
, t0
, t1
);
3979 tcg_gen_ext16u_i64(t0
, t0
);
3983 tcg_gen_add_i64(t0
, t0
, t1
);
3984 tcg_gen_ext32s_i64(t0
, t0
);
3987 tcg_gen_sub_i64(t0
, t0
, t1
);
3988 tcg_gen_ext32s_i64(t0
, t0
);
4010 /* Make sure shift count isn't TCG undefined behaviour. */
4011 tcg_gen_andi_i64(t1
, t1
, shift_max
- 1);
4016 tcg_gen_shl_i64(t0
, t0
, t1
);
4021 * Since SRA is UndefinedResult without sign-extended inputs,
4022 * we can treat SRA and DSRA the same.
4024 tcg_gen_sar_i64(t0
, t0
, t1
);
4027 /* We want to shift in zeros for SRL; zero-extend first. */
4028 tcg_gen_ext32u_i64(t0
, t0
);
4031 tcg_gen_shr_i64(t0
, t0
, t1
);
4035 if (shift_max
== 32) {
4036 tcg_gen_ext32s_i64(t0
, t0
);
4039 /* Shifts larger than MAX produce zero. */
4040 tcg_gen_setcondi_i64(TCG_COND_LTU
, t1
, t1
, shift_max
);
4041 tcg_gen_neg_i64(t1
, t1
);
4042 tcg_gen_and_i64(t0
, t0
, t1
);
4048 TCGv_i64 t2
= tcg_temp_new_i64();
4049 TCGLabel
*lab
= gen_new_label();
4051 tcg_gen_mov_i64(t2
, t0
);
4052 tcg_gen_add_i64(t0
, t1
, t2
);
4053 if (opc
== OPC_ADD_CP2
) {
4054 tcg_gen_ext32s_i64(t0
, t0
);
4056 tcg_gen_xor_i64(t1
, t1
, t2
);
4057 tcg_gen_xor_i64(t2
, t2
, t0
);
4058 tcg_gen_andc_i64(t1
, t2
, t1
);
4059 tcg_gen_brcondi_i64(TCG_COND_GE
, t1
, 0, lab
);
4060 generate_exception(ctx
, EXCP_OVERFLOW
);
4068 TCGv_i64 t2
= tcg_temp_new_i64();
4069 TCGLabel
*lab
= gen_new_label();
4071 tcg_gen_mov_i64(t2
, t0
);
4072 tcg_gen_sub_i64(t0
, t1
, t2
);
4073 if (opc
== OPC_SUB_CP2
) {
4074 tcg_gen_ext32s_i64(t0
, t0
);
4076 tcg_gen_xor_i64(t1
, t1
, t2
);
4077 tcg_gen_xor_i64(t2
, t2
, t0
);
4078 tcg_gen_and_i64(t1
, t1
, t2
);
4079 tcg_gen_brcondi_i64(TCG_COND_GE
, t1
, 0, lab
);
4080 generate_exception(ctx
, EXCP_OVERFLOW
);
4086 tcg_gen_ext32u_i64(t0
, t0
);
4087 tcg_gen_ext32u_i64(t1
, t1
);
4088 tcg_gen_mul_i64(t0
, t0
, t1
);
4097 cond
= TCG_COND_LTU
;
4105 cond
= TCG_COND_LEU
;
4112 int cc
= (ctx
->opcode
>> 8) & 0x7;
4113 TCGv_i64 t64
= tcg_temp_new_i64();
4114 TCGv_i32 t32
= tcg_temp_new_i32();
4116 tcg_gen_setcond_i64(cond
, t64
, t0
, t1
);
4117 tcg_gen_extrl_i64_i32(t32
, t64
);
4118 tcg_gen_deposit_i32(fpu_fcr31
, fpu_fcr31
, t32
,
4123 MIPS_INVAL("loongson_cp2");
4124 gen_reserved_instruction(ctx
);
4128 gen_store_fpr64(ctx
, t0
, rd
);
4131 static void gen_loongson_lswc2(DisasContext
*ctx
, int rt
,
4136 #if defined(TARGET_MIPS64)
4137 int lsq_rt1
= ctx
->opcode
& 0x1f;
4138 int lsq_offset
= sextract32(ctx
->opcode
, 6, 9) << 4;
4140 int shf_offset
= sextract32(ctx
->opcode
, 6, 8);
4142 t0
= tcg_temp_new();
4144 switch (MASK_LOONGSON_GSLSQ(ctx
->opcode
)) {
4145 #if defined(TARGET_MIPS64)
4147 t1
= tcg_temp_new();
4148 gen_base_offset_addr(ctx
, t0
, rs
, lsq_offset
);
4149 tcg_gen_qemu_ld_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4150 ctx
->default_tcg_memop_mask
);
4151 gen_base_offset_addr(ctx
, t0
, rs
, lsq_offset
+ 8);
4152 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4153 ctx
->default_tcg_memop_mask
);
4154 gen_store_gpr(t1
, rt
);
4155 gen_store_gpr(t0
, lsq_rt1
);
4158 check_cp1_enabled(ctx
);
4159 t1
= tcg_temp_new();
4160 gen_base_offset_addr(ctx
, t0
, rs
, lsq_offset
);
4161 tcg_gen_qemu_ld_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4162 ctx
->default_tcg_memop_mask
);
4163 gen_base_offset_addr(ctx
, t0
, rs
, lsq_offset
+ 8);
4164 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4165 ctx
->default_tcg_memop_mask
);
4166 gen_store_fpr64(ctx
, t1
, rt
);
4167 gen_store_fpr64(ctx
, t0
, lsq_rt1
);
4170 t1
= tcg_temp_new();
4171 gen_base_offset_addr(ctx
, t0
, rs
, lsq_offset
);
4172 gen_load_gpr(t1
, rt
);
4173 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4174 ctx
->default_tcg_memop_mask
);
4175 gen_base_offset_addr(ctx
, t0
, rs
, lsq_offset
+ 8);
4176 gen_load_gpr(t1
, lsq_rt1
);
4177 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4178 ctx
->default_tcg_memop_mask
);
4181 check_cp1_enabled(ctx
);
4182 t1
= tcg_temp_new();
4183 gen_base_offset_addr(ctx
, t0
, rs
, lsq_offset
);
4184 gen_load_fpr64(ctx
, t1
, rt
);
4185 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4186 ctx
->default_tcg_memop_mask
);
4187 gen_base_offset_addr(ctx
, t0
, rs
, lsq_offset
+ 8);
4188 gen_load_fpr64(ctx
, t1
, lsq_rt1
);
4189 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4190 ctx
->default_tcg_memop_mask
);
4194 switch (MASK_LOONGSON_GSSHFLS(ctx
->opcode
)) {
4196 check_cp1_enabled(ctx
);
4197 gen_base_offset_addr(ctx
, t0
, rs
, shf_offset
);
4198 fp0
= tcg_temp_new_i32();
4199 gen_load_fpr32(ctx
, fp0
, rt
);
4200 t1
= tcg_temp_new();
4201 tcg_gen_ext_i32_tl(t1
, fp0
);
4202 gen_lxl(ctx
, t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UL
);
4203 tcg_gen_trunc_tl_i32(fp0
, t1
);
4204 gen_store_fpr32(ctx
, fp0
, rt
);
4207 check_cp1_enabled(ctx
);
4208 gen_base_offset_addr(ctx
, t0
, rs
, shf_offset
);
4209 fp0
= tcg_temp_new_i32();
4210 gen_load_fpr32(ctx
, fp0
, rt
);
4211 t1
= tcg_temp_new();
4212 tcg_gen_ext_i32_tl(t1
, fp0
);
4213 gen_lxr(ctx
, t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UL
);
4214 tcg_gen_trunc_tl_i32(fp0
, t1
);
4215 gen_store_fpr32(ctx
, fp0
, rt
);
4217 #if defined(TARGET_MIPS64)
4219 check_cp1_enabled(ctx
);
4220 gen_base_offset_addr(ctx
, t0
, rs
, shf_offset
);
4221 t1
= tcg_temp_new();
4222 gen_load_fpr64(ctx
, t1
, rt
);
4223 gen_lxl(ctx
, t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
);
4224 gen_store_fpr64(ctx
, t1
, rt
);
4227 check_cp1_enabled(ctx
);
4228 gen_base_offset_addr(ctx
, t0
, rs
, shf_offset
);
4229 t1
= tcg_temp_new();
4230 gen_load_fpr64(ctx
, t1
, rt
);
4231 gen_lxr(ctx
, t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
);
4232 gen_store_fpr64(ctx
, t1
, rt
);
4236 MIPS_INVAL("loongson_gsshfl");
4237 gen_reserved_instruction(ctx
);
4242 switch (MASK_LOONGSON_GSSHFLS(ctx
->opcode
)) {
4244 check_cp1_enabled(ctx
);
4245 t1
= tcg_temp_new();
4246 gen_base_offset_addr(ctx
, t0
, rs
, shf_offset
);
4247 fp0
= tcg_temp_new_i32();
4248 gen_load_fpr32(ctx
, fp0
, rt
);
4249 tcg_gen_ext_i32_tl(t1
, fp0
);
4250 gen_helper_0e2i(swl
, t1
, t0
, ctx
->mem_idx
);
4253 check_cp1_enabled(ctx
);
4254 t1
= tcg_temp_new();
4255 gen_base_offset_addr(ctx
, t0
, rs
, shf_offset
);
4256 fp0
= tcg_temp_new_i32();
4257 gen_load_fpr32(ctx
, fp0
, rt
);
4258 tcg_gen_ext_i32_tl(t1
, fp0
);
4259 gen_helper_0e2i(swr
, t1
, t0
, ctx
->mem_idx
);
4261 #if defined(TARGET_MIPS64)
4263 check_cp1_enabled(ctx
);
4264 t1
= tcg_temp_new();
4265 gen_base_offset_addr(ctx
, t0
, rs
, shf_offset
);
4266 gen_load_fpr64(ctx
, t1
, rt
);
4267 gen_helper_0e2i(sdl
, t1
, t0
, ctx
->mem_idx
);
4270 check_cp1_enabled(ctx
);
4271 t1
= tcg_temp_new();
4272 gen_base_offset_addr(ctx
, t0
, rs
, shf_offset
);
4273 gen_load_fpr64(ctx
, t1
, rt
);
4274 gen_helper_0e2i(sdr
, t1
, t0
, ctx
->mem_idx
);
4278 MIPS_INVAL("loongson_gsshfs");
4279 gen_reserved_instruction(ctx
);
4284 MIPS_INVAL("loongson_gslsq");
4285 gen_reserved_instruction(ctx
);
4290 /* Loongson EXT LDC2/SDC2 */
4291 static void gen_loongson_lsdc2(DisasContext
*ctx
, int rt
,
4294 int offset
= sextract32(ctx
->opcode
, 3, 8);
4295 uint32_t opc
= MASK_LOONGSON_LSDC2(ctx
->opcode
);
4299 /* Pre-conditions */
4305 /* prefetch, implement as NOP */
4316 #if defined(TARGET_MIPS64)
4319 check_cp1_enabled(ctx
);
4320 /* prefetch, implement as NOP */
4326 #if defined(TARGET_MIPS64)
4329 check_cp1_enabled(ctx
);
4332 MIPS_INVAL("loongson_lsdc2");
4333 gen_reserved_instruction(ctx
);
4338 t0
= tcg_temp_new();
4340 gen_base_offset_addr(ctx
, t0
, rs
, offset
);
4341 gen_op_addr_add(ctx
, t0
, cpu_gpr
[rd
], t0
);
4345 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_SB
);
4346 gen_store_gpr(t0
, rt
);
4349 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SW
|
4350 ctx
->default_tcg_memop_mask
);
4351 gen_store_gpr(t0
, rt
);
4354 gen_base_offset_addr(ctx
, t0
, rs
, offset
);
4356 gen_op_addr_add(ctx
, t0
, cpu_gpr
[rd
], t0
);
4358 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SL
|
4359 ctx
->default_tcg_memop_mask
);
4360 gen_store_gpr(t0
, rt
);
4362 #if defined(TARGET_MIPS64)
4364 gen_base_offset_addr(ctx
, t0
, rs
, offset
);
4366 gen_op_addr_add(ctx
, t0
, cpu_gpr
[rd
], t0
);
4368 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4369 ctx
->default_tcg_memop_mask
);
4370 gen_store_gpr(t0
, rt
);
4374 gen_base_offset_addr(ctx
, t0
, rs
, offset
);
4376 gen_op_addr_add(ctx
, t0
, cpu_gpr
[rd
], t0
);
4378 fp0
= tcg_temp_new_i32();
4379 tcg_gen_qemu_ld_i32(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SL
|
4380 ctx
->default_tcg_memop_mask
);
4381 gen_store_fpr32(ctx
, fp0
, rt
);
4383 #if defined(TARGET_MIPS64)
4385 gen_base_offset_addr(ctx
, t0
, rs
, offset
);
4387 gen_op_addr_add(ctx
, t0
, cpu_gpr
[rd
], t0
);
4389 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4390 ctx
->default_tcg_memop_mask
);
4391 gen_store_fpr64(ctx
, t0
, rt
);
4395 t1
= tcg_temp_new();
4396 gen_load_gpr(t1
, rt
);
4397 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, MO_SB
);
4400 t1
= tcg_temp_new();
4401 gen_load_gpr(t1
, rt
);
4402 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UW
|
4403 ctx
->default_tcg_memop_mask
);
4406 t1
= tcg_temp_new();
4407 gen_load_gpr(t1
, rt
);
4408 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UL
|
4409 ctx
->default_tcg_memop_mask
);
4411 #if defined(TARGET_MIPS64)
4413 t1
= tcg_temp_new();
4414 gen_load_gpr(t1
, rt
);
4415 tcg_gen_qemu_st_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4416 ctx
->default_tcg_memop_mask
);
4420 fp0
= tcg_temp_new_i32();
4421 gen_load_fpr32(ctx
, fp0
, rt
);
4422 tcg_gen_qemu_st_i32(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UL
|
4423 ctx
->default_tcg_memop_mask
);
4425 #if defined(TARGET_MIPS64)
4427 t1
= tcg_temp_new();
4428 gen_load_fpr64(ctx
, t1
, rt
);
4429 tcg_gen_qemu_st_i64(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
|
4430 ctx
->default_tcg_memop_mask
);
4439 static void gen_trap(DisasContext
*ctx
, uint32_t opc
,
4440 int rs
, int rt
, int16_t imm
, int code
)
4443 TCGv t0
= tcg_temp_new();
4444 TCGv t1
= tcg_temp_new();
4447 /* Load needed operands */
4455 /* Compare two registers */
4457 gen_load_gpr(t0
, rs
);
4458 gen_load_gpr(t1
, rt
);
4468 /* Compare register to immediate */
4469 if (rs
!= 0 || imm
!= 0) {
4470 gen_load_gpr(t0
, rs
);
4471 tcg_gen_movi_tl(t1
, (int32_t)imm
);
4478 case OPC_TEQ
: /* rs == rs */
4479 case OPC_TEQI
: /* r0 == 0 */
4480 case OPC_TGE
: /* rs >= rs */
4481 case OPC_TGEI
: /* r0 >= 0 */
4482 case OPC_TGEU
: /* rs >= rs unsigned */
4483 case OPC_TGEIU
: /* r0 >= 0 unsigned */
4485 #ifdef CONFIG_USER_ONLY
4486 /* Pass the break code along to cpu_loop. */
4487 tcg_gen_st_i32(tcg_constant_i32(code
), tcg_env
,
4488 offsetof(CPUMIPSState
, error_code
));
4490 generate_exception_end(ctx
, EXCP_TRAP
);
4492 case OPC_TLT
: /* rs < rs */
4493 case OPC_TLTI
: /* r0 < 0 */
4494 case OPC_TLTU
: /* rs < rs unsigned */
4495 case OPC_TLTIU
: /* r0 < 0 unsigned */
4496 case OPC_TNE
: /* rs != rs */
4497 case OPC_TNEI
: /* r0 != 0 */
4498 /* Never trap: treat as NOP. */
4502 TCGLabel
*l1
= gen_new_label();
4507 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
4511 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
4515 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
4519 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4523 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
4527 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
4530 #ifdef CONFIG_USER_ONLY
4531 /* Pass the break code along to cpu_loop. */
4532 tcg_gen_st_i32(tcg_constant_i32(code
), tcg_env
,
4533 offsetof(CPUMIPSState
, error_code
));
4535 /* Like save_cpu_state, only don't update saved values. */
4536 if (ctx
->base
.pc_next
!= ctx
->saved_pc
) {
4537 gen_save_pc(ctx
->base
.pc_next
);
4539 if (ctx
->hflags
!= ctx
->saved_hflags
) {
4540 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
4542 generate_exception(ctx
, EXCP_TRAP
);
4547 static void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
4549 if (translator_use_goto_tb(&ctx
->base
, dest
)) {
4552 tcg_gen_exit_tb(ctx
->base
.tb
, n
);
4555 tcg_gen_lookup_and_goto_ptr();
4559 /* Branches (before delay slot) */
4560 static void gen_compute_branch(DisasContext
*ctx
, uint32_t opc
,
4562 int rs
, int rt
, int32_t offset
,
4565 target_ulong btgt
= -1;
4567 int bcond_compute
= 0;
4568 TCGv t0
= tcg_temp_new();
4569 TCGv t1
= tcg_temp_new();
4571 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
4572 #ifdef MIPS_DEBUG_DISAS
4573 LOG_DISAS("Branch in delay / forbidden slot at PC 0x%016"
4574 VADDR_PRIx
"\n", ctx
->base
.pc_next
);
4576 gen_reserved_instruction(ctx
);
4580 /* Load needed operands */
4586 /* Compare two registers */
4588 gen_load_gpr(t0
, rs
);
4589 gen_load_gpr(t1
, rt
);
4592 btgt
= ctx
->base
.pc_next
+ insn_bytes
+ offset
;
4606 /* Compare to zero */
4608 gen_load_gpr(t0
, rs
);
4611 btgt
= ctx
->base
.pc_next
+ insn_bytes
+ offset
;
4614 #if defined(TARGET_MIPS64)
4616 tcg_gen_andi_tl(t0
, cpu_dspctrl
, 0x7F);
4618 tcg_gen_andi_tl(t0
, cpu_dspctrl
, 0x3F);
4621 btgt
= ctx
->base
.pc_next
+ insn_bytes
+ offset
;
4626 /* Jump to immediate */
4627 int jal_mask
= ctx
->hflags
& MIPS_HFLAG_M16
? 0xF8000000
4629 btgt
= ((ctx
->base
.pc_next
+ insn_bytes
) & jal_mask
)
4634 /* Jump to immediate */
4635 btgt
= ((ctx
->base
.pc_next
+ insn_bytes
) & (int32_t)0xF0000000) |
4640 /* Jump to register */
4641 if (offset
!= 0 && offset
!= 16) {
4643 * Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
4644 * others are reserved.
4646 MIPS_INVAL("jump hint");
4647 gen_reserved_instruction(ctx
);
4650 gen_load_gpr(btarget
, rs
);
4653 MIPS_INVAL("branch/jump");
4654 gen_reserved_instruction(ctx
);
4657 if (bcond_compute
== 0) {
4658 /* No condition to be computed */
4660 case OPC_BEQ
: /* rx == rx */
4661 case OPC_BEQL
: /* rx == rx likely */
4662 case OPC_BGEZ
: /* 0 >= 0 */
4663 case OPC_BGEZL
: /* 0 >= 0 likely */
4664 case OPC_BLEZ
: /* 0 <= 0 */
4665 case OPC_BLEZL
: /* 0 <= 0 likely */
4667 ctx
->hflags
|= MIPS_HFLAG_B
;
4669 case OPC_BGEZAL
: /* 0 >= 0 */
4670 case OPC_BGEZALL
: /* 0 >= 0 likely */
4671 /* Always take and link */
4673 ctx
->hflags
|= MIPS_HFLAG_B
;
4675 case OPC_BNE
: /* rx != rx */
4676 case OPC_BGTZ
: /* 0 > 0 */
4677 case OPC_BLTZ
: /* 0 < 0 */
4680 case OPC_BLTZAL
: /* 0 < 0 */
4682 * Handle as an unconditional branch to get correct delay
4686 btgt
= ctx
->base
.pc_next
+ insn_bytes
+ delayslot_size
;
4687 ctx
->hflags
|= MIPS_HFLAG_B
;
4689 case OPC_BLTZALL
: /* 0 < 0 likely */
4690 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->base
.pc_next
+ 8);
4691 /* Skip the instruction in the delay slot */
4692 ctx
->base
.pc_next
+= 4;
4694 case OPC_BNEL
: /* rx != rx likely */
4695 case OPC_BGTZL
: /* 0 > 0 likely */
4696 case OPC_BLTZL
: /* 0 < 0 likely */
4697 /* Skip the instruction in the delay slot */
4698 ctx
->base
.pc_next
+= 4;
4701 ctx
->hflags
|= MIPS_HFLAG_B
;
4704 ctx
->hflags
|= MIPS_HFLAG_BX
;
4708 ctx
->hflags
|= MIPS_HFLAG_B
;
4711 ctx
->hflags
|= MIPS_HFLAG_BR
;
4715 ctx
->hflags
|= MIPS_HFLAG_BR
;
4718 MIPS_INVAL("branch/jump");
4719 gen_reserved_instruction(ctx
);
4725 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
4728 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
4731 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
4734 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
4737 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
4740 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
4743 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
4747 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
4751 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
4754 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
4757 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
4760 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
4763 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
4766 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
4769 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 32);
4771 #if defined(TARGET_MIPS64)
4773 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 64);
4777 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
4780 ctx
->hflags
|= MIPS_HFLAG_BC
;
4783 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
4786 ctx
->hflags
|= MIPS_HFLAG_BL
;
4789 MIPS_INVAL("conditional branch/jump");
4790 gen_reserved_instruction(ctx
);
4795 ctx
->btarget
= btgt
;
4797 switch (delayslot_size
) {
4799 ctx
->hflags
|= MIPS_HFLAG_BDS16
;
4802 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
4807 int post_delay
= insn_bytes
+ delayslot_size
;
4808 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
4810 tcg_gen_movi_tl(cpu_gpr
[blink
],
4811 ctx
->base
.pc_next
+ post_delay
+ lowbit
);
4815 if (insn_bytes
== 2) {
4816 ctx
->hflags
|= MIPS_HFLAG_B16
;
4821 /* special3 bitfield operations */
4822 static void gen_bitops(DisasContext
*ctx
, uint32_t opc
, int rt
,
4823 int rs
, int lsb
, int msb
)
4825 TCGv t0
= tcg_temp_new();
4826 TCGv t1
= tcg_temp_new();
4828 gen_load_gpr(t1
, rs
);
4831 if (lsb
+ msb
> 31) {
4835 tcg_gen_extract_tl(t0
, t1
, lsb
, msb
+ 1);
4838 * The two checks together imply that lsb == 0,
4839 * so this is a simple sign-extension.
4841 tcg_gen_ext32s_tl(t0
, t1
);
4844 #if defined(TARGET_MIPS64)
4853 if (lsb
+ msb
> 63) {
4856 tcg_gen_extract_tl(t0
, t1
, lsb
, msb
+ 1);
4863 gen_load_gpr(t0
, rt
);
4864 tcg_gen_deposit_tl(t0
, t0
, t1
, lsb
, msb
- lsb
+ 1);
4865 tcg_gen_ext32s_tl(t0
, t0
);
4867 #if defined(TARGET_MIPS64)
4878 gen_load_gpr(t0
, rt
);
4879 tcg_gen_deposit_tl(t0
, t0
, t1
, lsb
, msb
- lsb
+ 1);
4884 MIPS_INVAL("bitops");
4885 gen_reserved_instruction(ctx
);
4888 gen_store_gpr(t0
, rt
);
4891 static void gen_bshfl(DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
4896 /* If no destination, treat it as a NOP. */
4900 t0
= tcg_temp_new();
4901 gen_load_gpr(t0
, rt
);
4905 TCGv t1
= tcg_temp_new();
4906 TCGv t2
= tcg_constant_tl(0x00FF00FF);
4908 tcg_gen_shri_tl(t1
, t0
, 8);
4909 tcg_gen_and_tl(t1
, t1
, t2
);
4910 tcg_gen_and_tl(t0
, t0
, t2
);
4911 tcg_gen_shli_tl(t0
, t0
, 8);
4912 tcg_gen_or_tl(t0
, t0
, t1
);
4913 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
4917 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
4920 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
4922 #if defined(TARGET_MIPS64)
4925 TCGv t1
= tcg_temp_new();
4926 TCGv t2
= tcg_constant_tl(0x00FF00FF00FF00FFULL
);
4928 tcg_gen_shri_tl(t1
, t0
, 8);
4929 tcg_gen_and_tl(t1
, t1
, t2
);
4930 tcg_gen_and_tl(t0
, t0
, t2
);
4931 tcg_gen_shli_tl(t0
, t0
, 8);
4932 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
4937 TCGv t1
= tcg_temp_new();
4938 TCGv t2
= tcg_constant_tl(0x0000FFFF0000FFFFULL
);
4940 tcg_gen_shri_tl(t1
, t0
, 16);
4941 tcg_gen_and_tl(t1
, t1
, t2
);
4942 tcg_gen_and_tl(t0
, t0
, t2
);
4943 tcg_gen_shli_tl(t0
, t0
, 16);
4944 tcg_gen_or_tl(t0
, t0
, t1
);
4945 tcg_gen_shri_tl(t1
, t0
, 32);
4946 tcg_gen_shli_tl(t0
, t0
, 32);
4947 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
4952 MIPS_INVAL("bsfhl");
4953 gen_reserved_instruction(ctx
);
4958 static void gen_align_bits(DisasContext
*ctx
, int wordsz
, int rd
, int rs
,
4966 t0
= tcg_temp_new();
4967 if (bits
== 0 || bits
== wordsz
) {
4969 gen_load_gpr(t0
, rt
);
4971 gen_load_gpr(t0
, rs
);
4975 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
4977 #if defined(TARGET_MIPS64)
4979 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
4984 TCGv t1
= tcg_temp_new();
4985 gen_load_gpr(t0
, rt
);
4986 gen_load_gpr(t1
, rs
);
4990 TCGv_i64 t2
= tcg_temp_new_i64();
4991 tcg_gen_concat_tl_i64(t2
, t1
, t0
);
4992 tcg_gen_shri_i64(t2
, t2
, 32 - bits
);
4993 gen_move_low32(cpu_gpr
[rd
], t2
);
4996 #if defined(TARGET_MIPS64)
4998 tcg_gen_shli_tl(t0
, t0
, bits
);
4999 tcg_gen_shri_tl(t1
, t1
, 64 - bits
);
5000 tcg_gen_or_tl(cpu_gpr
[rd
], t1
, t0
);
5007 void gen_align(DisasContext
*ctx
, int wordsz
, int rd
, int rs
, int rt
, int bp
)
5009 gen_align_bits(ctx
, wordsz
, rd
, rs
, rt
, bp
* 8);
5012 static void gen_bitswap(DisasContext
*ctx
, int opc
, int rd
, int rt
)
5019 t0
= tcg_temp_new();
5020 gen_load_gpr(t0
, rt
);
5023 gen_helper_bitswap(cpu_gpr
[rd
], t0
);
5025 #if defined(TARGET_MIPS64)
5027 gen_helper_dbitswap(cpu_gpr
[rd
], t0
);
5033 #ifndef CONFIG_USER_ONLY
5034 /* CP0 (MMU and control) */
5035 static inline void gen_mthc0_entrylo(TCGv arg
, target_ulong off
)
5037 TCGv_i64 t0
= tcg_temp_new_i64();
5038 TCGv_i64 t1
= tcg_temp_new_i64();
5040 tcg_gen_ext_tl_i64(t0
, arg
);
5041 tcg_gen_ld_i64(t1
, tcg_env
, off
);
5042 #if defined(TARGET_MIPS64)
5043 tcg_gen_deposit_i64(t1
, t1
, t0
, 30, 32);
5045 tcg_gen_concat32_i64(t1
, t1
, t0
);
5047 tcg_gen_st_i64(t1
, tcg_env
, off
);
5050 static inline void gen_mthc0_store64(TCGv arg
, target_ulong off
)
5052 TCGv_i64 t0
= tcg_temp_new_i64();
5053 TCGv_i64 t1
= tcg_temp_new_i64();
5055 tcg_gen_ext_tl_i64(t0
, arg
);
5056 tcg_gen_ld_i64(t1
, tcg_env
, off
);
5057 tcg_gen_concat32_i64(t1
, t1
, t0
);
5058 tcg_gen_st_i64(t1
, tcg_env
, off
);
5061 static inline void gen_mfhc0_entrylo(TCGv arg
, target_ulong off
)
5063 TCGv_i64 t0
= tcg_temp_new_i64();
5065 tcg_gen_ld_i64(t0
, tcg_env
, off
);
5066 #if defined(TARGET_MIPS64)
5067 tcg_gen_shri_i64(t0
, t0
, 30);
5069 tcg_gen_shri_i64(t0
, t0
, 32);
5071 gen_move_low32(arg
, t0
);
5074 static inline void gen_mfhc0_load64(TCGv arg
, target_ulong off
, int shift
)
5076 TCGv_i64 t0
= tcg_temp_new_i64();
5078 tcg_gen_ld_i64(t0
, tcg_env
, off
);
5079 tcg_gen_shri_i64(t0
, t0
, 32 + shift
);
5080 gen_move_low32(arg
, t0
);
5083 static inline void gen_mfc0_load32(TCGv arg
, target_ulong off
)
5085 TCGv_i32 t0
= tcg_temp_new_i32();
5087 tcg_gen_ld_i32(t0
, tcg_env
, off
);
5088 tcg_gen_ext_i32_tl(arg
, t0
);
5091 static inline void gen_mfc0_load64(TCGv arg
, target_ulong off
)
5093 tcg_gen_ld_tl(arg
, tcg_env
, off
);
5094 tcg_gen_ext32s_tl(arg
, arg
);
5097 static inline void gen_mtc0_store32(TCGv arg
, target_ulong off
)
5099 TCGv_i32 t0
= tcg_temp_new_i32();
5101 tcg_gen_trunc_tl_i32(t0
, arg
);
5102 tcg_gen_st_i32(t0
, tcg_env
, off
);
5105 #define CP0_CHECK(c) \
5108 goto cp0_unimplemented; \
5112 static void gen_mfhc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
5114 const char *register_name
= "invalid";
5117 case CP0_REGISTER_02
:
5120 CP0_CHECK(ctx
->hflags
& MIPS_HFLAG_ELPA
);
5121 gen_mfhc0_entrylo(arg
, offsetof(CPUMIPSState
, CP0_EntryLo0
));
5122 register_name
= "EntryLo0";
5125 goto cp0_unimplemented
;
5128 case CP0_REGISTER_03
:
5130 case CP0_REG03__ENTRYLO1
:
5131 CP0_CHECK(ctx
->hflags
& MIPS_HFLAG_ELPA
);
5132 gen_mfhc0_entrylo(arg
, offsetof(CPUMIPSState
, CP0_EntryLo1
));
5133 register_name
= "EntryLo1";
5136 goto cp0_unimplemented
;
5139 case CP0_REGISTER_17
:
5141 case CP0_REG17__LLADDR
:
5142 gen_mfhc0_load64(arg
, offsetof(CPUMIPSState
, CP0_LLAddr
),
5143 ctx
->CP0_LLAddr_shift
);
5144 register_name
= "LLAddr";
5146 case CP0_REG17__MAAR
:
5147 CP0_CHECK(ctx
->mrp
);
5148 gen_helper_mfhc0_maar(arg
, tcg_env
);
5149 register_name
= "MAAR";
5152 goto cp0_unimplemented
;
5155 case CP0_REGISTER_19
:
5157 case CP0_REG19__WATCHHI0
:
5158 case CP0_REG19__WATCHHI1
:
5159 case CP0_REG19__WATCHHI2
:
5160 case CP0_REG19__WATCHHI3
:
5161 case CP0_REG19__WATCHHI4
:
5162 case CP0_REG19__WATCHHI5
:
5163 case CP0_REG19__WATCHHI6
:
5164 case CP0_REG19__WATCHHI7
:
5165 /* upper 32 bits are only available when Config5MI != 0 */
5167 gen_mfhc0_load64(arg
, offsetof(CPUMIPSState
, CP0_WatchHi
[sel
]), 0);
5168 register_name
= "WatchHi";
5171 goto cp0_unimplemented
;
5174 case CP0_REGISTER_28
:
5180 gen_mfhc0_load64(arg
, offsetof(CPUMIPSState
, CP0_TagLo
), 0);
5181 register_name
= "TagLo";
5184 goto cp0_unimplemented
;
5188 goto cp0_unimplemented
;
5190 trace_mips_translate_c0("mfhc0", register_name
, reg
, sel
);
5194 qemu_log_mask(LOG_UNIMP
, "mfhc0 %s (reg %d sel %d)\n",
5195 register_name
, reg
, sel
);
5196 tcg_gen_movi_tl(arg
, 0);
5199 static void gen_mthc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
5201 const char *register_name
= "invalid";
5202 uint64_t mask
= ctx
->PAMask
>> 36;
5205 case CP0_REGISTER_02
:
5208 CP0_CHECK(ctx
->hflags
& MIPS_HFLAG_ELPA
);
5209 tcg_gen_andi_tl(arg
, arg
, mask
);
5210 gen_mthc0_entrylo(arg
, offsetof(CPUMIPSState
, CP0_EntryLo0
));
5211 register_name
= "EntryLo0";
5214 goto cp0_unimplemented
;
5217 case CP0_REGISTER_03
:
5219 case CP0_REG03__ENTRYLO1
:
5220 CP0_CHECK(ctx
->hflags
& MIPS_HFLAG_ELPA
);
5221 tcg_gen_andi_tl(arg
, arg
, mask
);
5222 gen_mthc0_entrylo(arg
, offsetof(CPUMIPSState
, CP0_EntryLo1
));
5223 register_name
= "EntryLo1";
5226 goto cp0_unimplemented
;
5229 case CP0_REGISTER_17
:
5231 case CP0_REG17__LLADDR
:
5233 * LLAddr is read-only (the only exception is bit 0 if LLB is
5234 * supported); the CP0_LLAddr_rw_bitmask does not seem to be
5235 * relevant for modern MIPS cores supporting MTHC0, therefore
5236 * treating MTHC0 to LLAddr as NOP.
5238 register_name
= "LLAddr";
5240 case CP0_REG17__MAAR
:
5241 CP0_CHECK(ctx
->mrp
);
5242 gen_helper_mthc0_maar(tcg_env
, arg
);
5243 register_name
= "MAAR";
5246 goto cp0_unimplemented
;
5249 case CP0_REGISTER_19
:
5251 case CP0_REG19__WATCHHI0
:
5252 case CP0_REG19__WATCHHI1
:
5253 case CP0_REG19__WATCHHI2
:
5254 case CP0_REG19__WATCHHI3
:
5255 case CP0_REG19__WATCHHI4
:
5256 case CP0_REG19__WATCHHI5
:
5257 case CP0_REG19__WATCHHI6
:
5258 case CP0_REG19__WATCHHI7
:
5259 /* upper 32 bits are only available when Config5MI != 0 */
5261 gen_helper_0e1i(mthc0_watchhi
, arg
, sel
);
5262 register_name
= "WatchHi";
5265 goto cp0_unimplemented
;
5268 case CP0_REGISTER_28
:
5274 tcg_gen_andi_tl(arg
, arg
, mask
);
5275 gen_mthc0_store64(arg
, offsetof(CPUMIPSState
, CP0_TagLo
));
5276 register_name
= "TagLo";
5279 goto cp0_unimplemented
;
5283 goto cp0_unimplemented
;
5285 trace_mips_translate_c0("mthc0", register_name
, reg
, sel
);
5289 qemu_log_mask(LOG_UNIMP
, "mthc0 %s (reg %d sel %d)\n",
5290 register_name
, reg
, sel
);
5293 static inline void gen_mfc0_unimplemented(DisasContext
*ctx
, TCGv arg
)
5295 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
5296 tcg_gen_movi_tl(arg
, 0);
5298 tcg_gen_movi_tl(arg
, ~0);
5302 static void gen_mfc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
5304 const char *register_name
= "invalid";
5307 check_insn(ctx
, ISA_MIPS_R1
);
5311 case CP0_REGISTER_00
:
5313 case CP0_REG00__INDEX
:
5314 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Index
));
5315 register_name
= "Index";
5317 case CP0_REG00__MVPCONTROL
:
5318 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5319 gen_helper_mfc0_mvpcontrol(arg
, tcg_env
);
5320 register_name
= "MVPControl";
5322 case CP0_REG00__MVPCONF0
:
5323 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5324 gen_helper_mfc0_mvpconf0(arg
, tcg_env
);
5325 register_name
= "MVPConf0";
5327 case CP0_REG00__MVPCONF1
:
5328 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5329 gen_helper_mfc0_mvpconf1(arg
, tcg_env
);
5330 register_name
= "MVPConf1";
5332 case CP0_REG00__VPCONTROL
:
5334 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPControl
));
5335 register_name
= "VPControl";
5338 goto cp0_unimplemented
;
5341 case CP0_REGISTER_01
:
5343 case CP0_REG01__RANDOM
:
5344 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS_R6
));
5345 gen_helper_mfc0_random(arg
, tcg_env
);
5346 register_name
= "Random";
5348 case CP0_REG01__VPECONTROL
:
5349 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5350 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEControl
));
5351 register_name
= "VPEControl";
5353 case CP0_REG01__VPECONF0
:
5354 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5355 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf0
));
5356 register_name
= "VPEConf0";
5358 case CP0_REG01__VPECONF1
:
5359 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5360 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf1
));
5361 register_name
= "VPEConf1";
5363 case CP0_REG01__YQMASK
:
5364 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5365 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_YQMask
));
5366 register_name
= "YQMask";
5368 case CP0_REG01__VPESCHEDULE
:
5369 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5370 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
5371 register_name
= "VPESchedule";
5373 case CP0_REG01__VPESCHEFBACK
:
5374 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5375 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
5376 register_name
= "VPEScheFBack";
5378 case CP0_REG01__VPEOPT
:
5379 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5380 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEOpt
));
5381 register_name
= "VPEOpt";
5384 goto cp0_unimplemented
;
5387 case CP0_REGISTER_02
:
5389 case CP0_REG02__ENTRYLO0
:
5391 TCGv_i64 tmp
= tcg_temp_new_i64();
5392 tcg_gen_ld_i64(tmp
, tcg_env
,
5393 offsetof(CPUMIPSState
, CP0_EntryLo0
));
5394 #if defined(TARGET_MIPS64)
5396 /* Move RI/XI fields to bits 31:30 */
5397 tcg_gen_shri_tl(arg
, tmp
, CP0EnLo_XI
);
5398 tcg_gen_deposit_tl(tmp
, tmp
, arg
, 30, 2);
5401 gen_move_low32(arg
, tmp
);
5403 register_name
= "EntryLo0";
5405 case CP0_REG02__TCSTATUS
:
5406 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5407 gen_helper_mfc0_tcstatus(arg
, tcg_env
);
5408 register_name
= "TCStatus";
5410 case CP0_REG02__TCBIND
:
5411 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5412 gen_helper_mfc0_tcbind(arg
, tcg_env
);
5413 register_name
= "TCBind";
5415 case CP0_REG02__TCRESTART
:
5416 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5417 gen_helper_mfc0_tcrestart(arg
, tcg_env
);
5418 register_name
= "TCRestart";
5420 case CP0_REG02__TCHALT
:
5421 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5422 gen_helper_mfc0_tchalt(arg
, tcg_env
);
5423 register_name
= "TCHalt";
5425 case CP0_REG02__TCCONTEXT
:
5426 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5427 gen_helper_mfc0_tccontext(arg
, tcg_env
);
5428 register_name
= "TCContext";
5430 case CP0_REG02__TCSCHEDULE
:
5431 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5432 gen_helper_mfc0_tcschedule(arg
, tcg_env
);
5433 register_name
= "TCSchedule";
5435 case CP0_REG02__TCSCHEFBACK
:
5436 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
5437 gen_helper_mfc0_tcschefback(arg
, tcg_env
);
5438 register_name
= "TCScheFBack";
5441 goto cp0_unimplemented
;
5444 case CP0_REGISTER_03
:
5446 case CP0_REG03__ENTRYLO1
:
5448 TCGv_i64 tmp
= tcg_temp_new_i64();
5449 tcg_gen_ld_i64(tmp
, tcg_env
,
5450 offsetof(CPUMIPSState
, CP0_EntryLo1
));
5451 #if defined(TARGET_MIPS64)
5453 /* Move RI/XI fields to bits 31:30 */
5454 tcg_gen_shri_tl(arg
, tmp
, CP0EnLo_XI
);
5455 tcg_gen_deposit_tl(tmp
, tmp
, arg
, 30, 2);
5458 gen_move_low32(arg
, tmp
);
5460 register_name
= "EntryLo1";
5462 case CP0_REG03__GLOBALNUM
:
5464 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_GlobalNumber
));
5465 register_name
= "GlobalNumber";
5468 goto cp0_unimplemented
;
5471 case CP0_REGISTER_04
:
5473 case CP0_REG04__CONTEXT
:
5474 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_Context
));
5475 tcg_gen_ext32s_tl(arg
, arg
);
5476 register_name
= "Context";
5478 case CP0_REG04__CONTEXTCONFIG
:
5480 /* gen_helper_mfc0_contextconfig(arg); */
5481 register_name
= "ContextConfig";
5482 goto cp0_unimplemented
;
5483 case CP0_REG04__USERLOCAL
:
5484 CP0_CHECK(ctx
->ulri
);
5485 tcg_gen_ld_tl(arg
, tcg_env
,
5486 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
5487 tcg_gen_ext32s_tl(arg
, arg
);
5488 register_name
= "UserLocal";
5490 case CP0_REG04__MMID
:
5492 gen_helper_mtc0_memorymapid(tcg_env
, arg
);
5493 register_name
= "MMID";
5496 goto cp0_unimplemented
;
5499 case CP0_REGISTER_05
:
5501 case CP0_REG05__PAGEMASK
:
5502 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageMask
));
5503 register_name
= "PageMask";
5505 case CP0_REG05__PAGEGRAIN
:
5506 check_insn(ctx
, ISA_MIPS_R2
);
5507 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageGrain
));
5508 register_name
= "PageGrain";
5510 case CP0_REG05__SEGCTL0
:
5512 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_SegCtl0
));
5513 tcg_gen_ext32s_tl(arg
, arg
);
5514 register_name
= "SegCtl0";
5516 case CP0_REG05__SEGCTL1
:
5518 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_SegCtl1
));
5519 tcg_gen_ext32s_tl(arg
, arg
);
5520 register_name
= "SegCtl1";
5522 case CP0_REG05__SEGCTL2
:
5524 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_SegCtl2
));
5525 tcg_gen_ext32s_tl(arg
, arg
);
5526 register_name
= "SegCtl2";
5528 case CP0_REG05__PWBASE
:
5530 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PWBase
));
5531 register_name
= "PWBase";
5533 case CP0_REG05__PWFIELD
:
5535 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PWField
));
5536 register_name
= "PWField";
5538 case CP0_REG05__PWSIZE
:
5540 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PWSize
));
5541 register_name
= "PWSize";
5544 goto cp0_unimplemented
;
5547 case CP0_REGISTER_06
:
5549 case CP0_REG06__WIRED
:
5550 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Wired
));
5551 register_name
= "Wired";
5553 case CP0_REG06__SRSCONF0
:
5554 check_insn(ctx
, ISA_MIPS_R2
);
5555 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf0
));
5556 register_name
= "SRSConf0";
5558 case CP0_REG06__SRSCONF1
:
5559 check_insn(ctx
, ISA_MIPS_R2
);
5560 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf1
));
5561 register_name
= "SRSConf1";
5563 case CP0_REG06__SRSCONF2
:
5564 check_insn(ctx
, ISA_MIPS_R2
);
5565 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf2
));
5566 register_name
= "SRSConf2";
5568 case CP0_REG06__SRSCONF3
:
5569 check_insn(ctx
, ISA_MIPS_R2
);
5570 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf3
));
5571 register_name
= "SRSConf3";
5573 case CP0_REG06__SRSCONF4
:
5574 check_insn(ctx
, ISA_MIPS_R2
);
5575 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf4
));
5576 register_name
= "SRSConf4";
5578 case CP0_REG06__PWCTL
:
5580 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PWCtl
));
5581 register_name
= "PWCtl";
5584 goto cp0_unimplemented
;
5587 case CP0_REGISTER_07
:
5589 case CP0_REG07__HWRENA
:
5590 check_insn(ctx
, ISA_MIPS_R2
);
5591 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_HWREna
));
5592 register_name
= "HWREna";
5595 goto cp0_unimplemented
;
5598 case CP0_REGISTER_08
:
5600 case CP0_REG08__BADVADDR
:
5601 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_BadVAddr
));
5602 tcg_gen_ext32s_tl(arg
, arg
);
5603 register_name
= "BadVAddr";
5605 case CP0_REG08__BADINSTR
:
5607 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstr
));
5608 register_name
= "BadInstr";
5610 case CP0_REG08__BADINSTRP
:
5612 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstrP
));
5613 register_name
= "BadInstrP";
5615 case CP0_REG08__BADINSTRX
:
5617 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstrX
));
5618 tcg_gen_andi_tl(arg
, arg
, ~0xffff);
5619 register_name
= "BadInstrX";
5622 goto cp0_unimplemented
;
5625 case CP0_REGISTER_09
:
5627 case CP0_REG09__COUNT
:
5628 /* Mark as an IO operation because we read the time. */
5629 translator_io_start(&ctx
->base
);
5631 gen_helper_mfc0_count(arg
, tcg_env
);
5633 * Break the TB to be able to take timer interrupts immediately
5634 * after reading count. DISAS_STOP isn't sufficient, we need to
5635 * ensure we break completely out of translated code.
5637 gen_save_pc(ctx
->base
.pc_next
+ 4);
5638 ctx
->base
.is_jmp
= DISAS_EXIT
;
5639 register_name
= "Count";
5642 goto cp0_unimplemented
;
5645 case CP0_REGISTER_10
:
5647 case CP0_REG10__ENTRYHI
:
5648 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EntryHi
));
5649 tcg_gen_ext32s_tl(arg
, arg
);
5650 register_name
= "EntryHi";
5653 goto cp0_unimplemented
;
5656 case CP0_REGISTER_11
:
5658 case CP0_REG11__COMPARE
:
5659 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Compare
));
5660 register_name
= "Compare";
5662 /* 6,7 are implementation dependent */
5664 goto cp0_unimplemented
;
5667 case CP0_REGISTER_12
:
5669 case CP0_REG12__STATUS
:
5670 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Status
));
5671 register_name
= "Status";
5673 case CP0_REG12__INTCTL
:
5674 check_insn(ctx
, ISA_MIPS_R2
);
5675 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_IntCtl
));
5676 register_name
= "IntCtl";
5678 case CP0_REG12__SRSCTL
:
5679 check_insn(ctx
, ISA_MIPS_R2
);
5680 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
5681 register_name
= "SRSCtl";
5683 case CP0_REG12__SRSMAP
:
5684 check_insn(ctx
, ISA_MIPS_R2
);
5685 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
5686 register_name
= "SRSMap";
5689 goto cp0_unimplemented
;
5692 case CP0_REGISTER_13
:
5694 case CP0_REG13__CAUSE
:
5695 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Cause
));
5696 register_name
= "Cause";
5699 goto cp0_unimplemented
;
5702 case CP0_REGISTER_14
:
5704 case CP0_REG14__EPC
:
5705 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EPC
));
5706 tcg_gen_ext32s_tl(arg
, arg
);
5707 register_name
= "EPC";
5710 goto cp0_unimplemented
;
5713 case CP0_REGISTER_15
:
5715 case CP0_REG15__PRID
:
5716 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PRid
));
5717 register_name
= "PRid";
5719 case CP0_REG15__EBASE
:
5720 check_insn(ctx
, ISA_MIPS_R2
);
5721 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EBase
));
5722 tcg_gen_ext32s_tl(arg
, arg
);
5723 register_name
= "EBase";
5725 case CP0_REG15__CMGCRBASE
:
5726 check_insn(ctx
, ISA_MIPS_R2
);
5727 CP0_CHECK(ctx
->cmgcr
);
5728 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_CMGCRBase
));
5729 tcg_gen_ext32s_tl(arg
, arg
);
5730 register_name
= "CMGCRBase";
5733 goto cp0_unimplemented
;
5736 case CP0_REGISTER_16
:
5738 case CP0_REG16__CONFIG
:
5739 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config0
));
5740 register_name
= "Config";
5742 case CP0_REG16__CONFIG1
:
5743 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config1
));
5744 register_name
= "Config1";
5746 case CP0_REG16__CONFIG2
:
5747 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config2
));
5748 register_name
= "Config2";
5750 case CP0_REG16__CONFIG3
:
5751 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config3
));
5752 register_name
= "Config3";
5754 case CP0_REG16__CONFIG4
:
5755 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config4
));
5756 register_name
= "Config4";
5758 case CP0_REG16__CONFIG5
:
5759 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config5
));
5760 register_name
= "Config5";
5762 /* 6,7 are implementation dependent */
5763 case CP0_REG16__CONFIG6
:
5764 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config6
));
5765 register_name
= "Config6";
5767 case CP0_REG16__CONFIG7
:
5768 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config7
));
5769 register_name
= "Config7";
5772 goto cp0_unimplemented
;
5775 case CP0_REGISTER_17
:
5777 case CP0_REG17__LLADDR
:
5778 gen_helper_mfc0_lladdr(arg
, tcg_env
);
5779 register_name
= "LLAddr";
5781 case CP0_REG17__MAAR
:
5782 CP0_CHECK(ctx
->mrp
);
5783 gen_helper_mfc0_maar(arg
, tcg_env
);
5784 register_name
= "MAAR";
5786 case CP0_REG17__MAARI
:
5787 CP0_CHECK(ctx
->mrp
);
5788 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_MAARI
));
5789 register_name
= "MAARI";
5792 goto cp0_unimplemented
;
5795 case CP0_REGISTER_18
:
5797 case CP0_REG18__WATCHLO0
:
5798 case CP0_REG18__WATCHLO1
:
5799 case CP0_REG18__WATCHLO2
:
5800 case CP0_REG18__WATCHLO3
:
5801 case CP0_REG18__WATCHLO4
:
5802 case CP0_REG18__WATCHLO5
:
5803 case CP0_REG18__WATCHLO6
:
5804 case CP0_REG18__WATCHLO7
:
5805 CP0_CHECK(ctx
->CP0_Config1
& (1 << CP0C1_WR
));
5806 gen_helper_1e0i(mfc0_watchlo
, arg
, sel
);
5807 register_name
= "WatchLo";
5810 goto cp0_unimplemented
;
5813 case CP0_REGISTER_19
:
5815 case CP0_REG19__WATCHHI0
:
5816 case CP0_REG19__WATCHHI1
:
5817 case CP0_REG19__WATCHHI2
:
5818 case CP0_REG19__WATCHHI3
:
5819 case CP0_REG19__WATCHHI4
:
5820 case CP0_REG19__WATCHHI5
:
5821 case CP0_REG19__WATCHHI6
:
5822 case CP0_REG19__WATCHHI7
:
5823 CP0_CHECK(ctx
->CP0_Config1
& (1 << CP0C1_WR
));
5824 gen_helper_1e0i(mfc0_watchhi
, arg
, sel
);
5825 register_name
= "WatchHi";
5828 goto cp0_unimplemented
;
5831 case CP0_REGISTER_20
:
5833 case CP0_REG20__XCONTEXT
:
5834 #if defined(TARGET_MIPS64)
5835 check_insn(ctx
, ISA_MIPS3
);
5836 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_XContext
));
5837 tcg_gen_ext32s_tl(arg
, arg
);
5838 register_name
= "XContext";
5842 goto cp0_unimplemented
;
5845 case CP0_REGISTER_21
:
5846 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5847 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS_R6
));
5850 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Framemask
));
5851 register_name
= "Framemask";
5854 goto cp0_unimplemented
;
5857 case CP0_REGISTER_22
:
5858 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
5859 register_name
= "'Diagnostic"; /* implementation dependent */
5861 case CP0_REGISTER_23
:
5863 case CP0_REG23__DEBUG
:
5864 gen_helper_mfc0_debug(arg
, tcg_env
); /* EJTAG support */
5865 register_name
= "Debug";
5867 case CP0_REG23__TRACECONTROL
:
5868 /* PDtrace support */
5869 /* gen_helper_mfc0_tracecontrol(arg); */
5870 register_name
= "TraceControl";
5871 goto cp0_unimplemented
;
5872 case CP0_REG23__TRACECONTROL2
:
5873 /* PDtrace support */
5874 /* gen_helper_mfc0_tracecontrol2(arg); */
5875 register_name
= "TraceControl2";
5876 goto cp0_unimplemented
;
5877 case CP0_REG23__USERTRACEDATA1
:
5878 /* PDtrace support */
5879 /* gen_helper_mfc0_usertracedata1(arg);*/
5880 register_name
= "UserTraceData1";
5881 goto cp0_unimplemented
;
5882 case CP0_REG23__TRACEIBPC
:
5883 /* PDtrace support */
5884 /* gen_helper_mfc0_traceibpc(arg); */
5885 register_name
= "TraceIBPC";
5886 goto cp0_unimplemented
;
5887 case CP0_REG23__TRACEDBPC
:
5888 /* PDtrace support */
5889 /* gen_helper_mfc0_tracedbpc(arg); */
5890 register_name
= "TraceDBPC";
5891 goto cp0_unimplemented
;
5893 goto cp0_unimplemented
;
5896 case CP0_REGISTER_24
:
5898 case CP0_REG24__DEPC
:
5900 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
5901 tcg_gen_ext32s_tl(arg
, arg
);
5902 register_name
= "DEPC";
5905 goto cp0_unimplemented
;
5908 case CP0_REGISTER_25
:
5910 case CP0_REG25__PERFCTL0
:
5911 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Performance0
));
5912 register_name
= "Performance0";
5914 case CP0_REG25__PERFCNT0
:
5915 /* gen_helper_mfc0_performance1(arg); */
5916 register_name
= "Performance1";
5917 goto cp0_unimplemented
;
5918 case CP0_REG25__PERFCTL1
:
5919 /* gen_helper_mfc0_performance2(arg); */
5920 register_name
= "Performance2";
5921 goto cp0_unimplemented
;
5922 case CP0_REG25__PERFCNT1
:
5923 /* gen_helper_mfc0_performance3(arg); */
5924 register_name
= "Performance3";
5925 goto cp0_unimplemented
;
5926 case CP0_REG25__PERFCTL2
:
5927 /* gen_helper_mfc0_performance4(arg); */
5928 register_name
= "Performance4";
5929 goto cp0_unimplemented
;
5930 case CP0_REG25__PERFCNT2
:
5931 /* gen_helper_mfc0_performance5(arg); */
5932 register_name
= "Performance5";
5933 goto cp0_unimplemented
;
5934 case CP0_REG25__PERFCTL3
:
5935 /* gen_helper_mfc0_performance6(arg); */
5936 register_name
= "Performance6";
5937 goto cp0_unimplemented
;
5938 case CP0_REG25__PERFCNT3
:
5939 /* gen_helper_mfc0_performance7(arg); */
5940 register_name
= "Performance7";
5941 goto cp0_unimplemented
;
5943 goto cp0_unimplemented
;
5946 case CP0_REGISTER_26
:
5948 case CP0_REG26__ERRCTL
:
5949 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_ErrCtl
));
5950 register_name
= "ErrCtl";
5953 goto cp0_unimplemented
;
5956 case CP0_REGISTER_27
:
5958 case CP0_REG27__CACHERR
:
5959 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
5960 register_name
= "CacheErr";
5963 goto cp0_unimplemented
;
5966 case CP0_REGISTER_28
:
5968 case CP0_REG28__TAGLO
:
5969 case CP0_REG28__TAGLO1
:
5970 case CP0_REG28__TAGLO2
:
5971 case CP0_REG28__TAGLO3
:
5973 TCGv_i64 tmp
= tcg_temp_new_i64();
5974 tcg_gen_ld_i64(tmp
, tcg_env
, offsetof(CPUMIPSState
, CP0_TagLo
));
5975 gen_move_low32(arg
, tmp
);
5977 register_name
= "TagLo";
5979 case CP0_REG28__DATALO
:
5980 case CP0_REG28__DATALO1
:
5981 case CP0_REG28__DATALO2
:
5982 case CP0_REG28__DATALO3
:
5983 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataLo
));
5984 register_name
= "DataLo";
5987 goto cp0_unimplemented
;
5990 case CP0_REGISTER_29
:
5992 case CP0_REG29__TAGHI
:
5993 case CP0_REG29__TAGHI1
:
5994 case CP0_REG29__TAGHI2
:
5995 case CP0_REG29__TAGHI3
:
5996 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagHi
));
5997 register_name
= "TagHi";
5999 case CP0_REG29__DATAHI
:
6000 case CP0_REG29__DATAHI1
:
6001 case CP0_REG29__DATAHI2
:
6002 case CP0_REG29__DATAHI3
:
6003 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataHi
));
6004 register_name
= "DataHi";
6007 goto cp0_unimplemented
;
6010 case CP0_REGISTER_30
:
6012 case CP0_REG30__ERROREPC
:
6013 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
6014 tcg_gen_ext32s_tl(arg
, arg
);
6015 register_name
= "ErrorEPC";
6018 goto cp0_unimplemented
;
6021 case CP0_REGISTER_31
:
6023 case CP0_REG31__DESAVE
:
6025 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
6026 register_name
= "DESAVE";
6028 case CP0_REG31__KSCRATCH1
:
6029 case CP0_REG31__KSCRATCH2
:
6030 case CP0_REG31__KSCRATCH3
:
6031 case CP0_REG31__KSCRATCH4
:
6032 case CP0_REG31__KSCRATCH5
:
6033 case CP0_REG31__KSCRATCH6
:
6034 CP0_CHECK(ctx
->kscrexist
& (1 << sel
));
6035 tcg_gen_ld_tl(arg
, tcg_env
,
6036 offsetof(CPUMIPSState
, CP0_KScratch
[sel
- 2]));
6037 tcg_gen_ext32s_tl(arg
, arg
);
6038 register_name
= "KScratch";
6041 goto cp0_unimplemented
;
6045 goto cp0_unimplemented
;
6047 trace_mips_translate_c0("mfc0", register_name
, reg
, sel
);
6051 qemu_log_mask(LOG_UNIMP
, "mfc0 %s (reg %d sel %d)\n",
6052 register_name
, reg
, sel
);
6053 gen_mfc0_unimplemented(ctx
, arg
);
6056 static void gen_mtc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
6058 const char *register_name
= "invalid";
6062 check_insn(ctx
, ISA_MIPS_R1
);
6065 icount
= translator_io_start(&ctx
->base
);
6068 case CP0_REGISTER_00
:
6070 case CP0_REG00__INDEX
:
6071 gen_helper_mtc0_index(tcg_env
, arg
);
6072 register_name
= "Index";
6074 case CP0_REG00__MVPCONTROL
:
6075 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6076 gen_helper_mtc0_mvpcontrol(tcg_env
, arg
);
6077 register_name
= "MVPControl";
6079 case CP0_REG00__MVPCONF0
:
6080 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6082 register_name
= "MVPConf0";
6084 case CP0_REG00__MVPCONF1
:
6085 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6087 register_name
= "MVPConf1";
6089 case CP0_REG00__VPCONTROL
:
6092 register_name
= "VPControl";
6095 goto cp0_unimplemented
;
6098 case CP0_REGISTER_01
:
6100 case CP0_REG01__RANDOM
:
6102 register_name
= "Random";
6104 case CP0_REG01__VPECONTROL
:
6105 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6106 gen_helper_mtc0_vpecontrol(tcg_env
, arg
);
6107 register_name
= "VPEControl";
6109 case CP0_REG01__VPECONF0
:
6110 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6111 gen_helper_mtc0_vpeconf0(tcg_env
, arg
);
6112 register_name
= "VPEConf0";
6114 case CP0_REG01__VPECONF1
:
6115 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6116 gen_helper_mtc0_vpeconf1(tcg_env
, arg
);
6117 register_name
= "VPEConf1";
6119 case CP0_REG01__YQMASK
:
6120 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6121 gen_helper_mtc0_yqmask(tcg_env
, arg
);
6122 register_name
= "YQMask";
6124 case CP0_REG01__VPESCHEDULE
:
6125 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6126 tcg_gen_st_tl(arg
, tcg_env
,
6127 offsetof(CPUMIPSState
, CP0_VPESchedule
));
6128 register_name
= "VPESchedule";
6130 case CP0_REG01__VPESCHEFBACK
:
6131 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6132 tcg_gen_st_tl(arg
, tcg_env
,
6133 offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
6134 register_name
= "VPEScheFBack";
6136 case CP0_REG01__VPEOPT
:
6137 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6138 gen_helper_mtc0_vpeopt(tcg_env
, arg
);
6139 register_name
= "VPEOpt";
6142 goto cp0_unimplemented
;
6145 case CP0_REGISTER_02
:
6147 case CP0_REG02__ENTRYLO0
:
6148 gen_helper_mtc0_entrylo0(tcg_env
, arg
);
6149 register_name
= "EntryLo0";
6151 case CP0_REG02__TCSTATUS
:
6152 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6153 gen_helper_mtc0_tcstatus(tcg_env
, arg
);
6154 register_name
= "TCStatus";
6156 case CP0_REG02__TCBIND
:
6157 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6158 gen_helper_mtc0_tcbind(tcg_env
, arg
);
6159 register_name
= "TCBind";
6161 case CP0_REG02__TCRESTART
:
6162 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6163 gen_helper_mtc0_tcrestart(tcg_env
, arg
);
6164 register_name
= "TCRestart";
6166 case CP0_REG02__TCHALT
:
6167 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6168 gen_helper_mtc0_tchalt(tcg_env
, arg
);
6169 register_name
= "TCHalt";
6171 case CP0_REG02__TCCONTEXT
:
6172 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6173 gen_helper_mtc0_tccontext(tcg_env
, arg
);
6174 register_name
= "TCContext";
6176 case CP0_REG02__TCSCHEDULE
:
6177 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6178 gen_helper_mtc0_tcschedule(tcg_env
, arg
);
6179 register_name
= "TCSchedule";
6181 case CP0_REG02__TCSCHEFBACK
:
6182 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6183 gen_helper_mtc0_tcschefback(tcg_env
, arg
);
6184 register_name
= "TCScheFBack";
6187 goto cp0_unimplemented
;
6190 case CP0_REGISTER_03
:
6192 case CP0_REG03__ENTRYLO1
:
6193 gen_helper_mtc0_entrylo1(tcg_env
, arg
);
6194 register_name
= "EntryLo1";
6196 case CP0_REG03__GLOBALNUM
:
6199 register_name
= "GlobalNumber";
6202 goto cp0_unimplemented
;
6205 case CP0_REGISTER_04
:
6207 case CP0_REG04__CONTEXT
:
6208 gen_helper_mtc0_context(tcg_env
, arg
);
6209 register_name
= "Context";
6211 case CP0_REG04__CONTEXTCONFIG
:
6213 /* gen_helper_mtc0_contextconfig(arg); */
6214 register_name
= "ContextConfig";
6215 goto cp0_unimplemented
;
6216 case CP0_REG04__USERLOCAL
:
6217 CP0_CHECK(ctx
->ulri
);
6218 tcg_gen_st_tl(arg
, tcg_env
,
6219 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
6220 register_name
= "UserLocal";
6222 case CP0_REG04__MMID
:
6224 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_MemoryMapID
));
6225 register_name
= "MMID";
6228 goto cp0_unimplemented
;
6231 case CP0_REGISTER_05
:
6233 case CP0_REG05__PAGEMASK
:
6234 gen_helper_mtc0_pagemask(tcg_env
, arg
);
6235 register_name
= "PageMask";
6237 case CP0_REG05__PAGEGRAIN
:
6238 check_insn(ctx
, ISA_MIPS_R2
);
6239 gen_helper_mtc0_pagegrain(tcg_env
, arg
);
6240 register_name
= "PageGrain";
6241 ctx
->base
.is_jmp
= DISAS_STOP
;
6243 case CP0_REG05__SEGCTL0
:
6245 gen_helper_mtc0_segctl0(tcg_env
, arg
);
6246 register_name
= "SegCtl0";
6248 case CP0_REG05__SEGCTL1
:
6250 gen_helper_mtc0_segctl1(tcg_env
, arg
);
6251 register_name
= "SegCtl1";
6253 case CP0_REG05__SEGCTL2
:
6255 gen_helper_mtc0_segctl2(tcg_env
, arg
);
6256 register_name
= "SegCtl2";
6258 case CP0_REG05__PWBASE
:
6260 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_PWBase
));
6261 register_name
= "PWBase";
6263 case CP0_REG05__PWFIELD
:
6265 gen_helper_mtc0_pwfield(tcg_env
, arg
);
6266 register_name
= "PWField";
6268 case CP0_REG05__PWSIZE
:
6270 gen_helper_mtc0_pwsize(tcg_env
, arg
);
6271 register_name
= "PWSize";
6274 goto cp0_unimplemented
;
6277 case CP0_REGISTER_06
:
6279 case CP0_REG06__WIRED
:
6280 gen_helper_mtc0_wired(tcg_env
, arg
);
6281 register_name
= "Wired";
6283 case CP0_REG06__SRSCONF0
:
6284 check_insn(ctx
, ISA_MIPS_R2
);
6285 gen_helper_mtc0_srsconf0(tcg_env
, arg
);
6286 register_name
= "SRSConf0";
6288 case CP0_REG06__SRSCONF1
:
6289 check_insn(ctx
, ISA_MIPS_R2
);
6290 gen_helper_mtc0_srsconf1(tcg_env
, arg
);
6291 register_name
= "SRSConf1";
6293 case CP0_REG06__SRSCONF2
:
6294 check_insn(ctx
, ISA_MIPS_R2
);
6295 gen_helper_mtc0_srsconf2(tcg_env
, arg
);
6296 register_name
= "SRSConf2";
6298 case CP0_REG06__SRSCONF3
:
6299 check_insn(ctx
, ISA_MIPS_R2
);
6300 gen_helper_mtc0_srsconf3(tcg_env
, arg
);
6301 register_name
= "SRSConf3";
6303 case CP0_REG06__SRSCONF4
:
6304 check_insn(ctx
, ISA_MIPS_R2
);
6305 gen_helper_mtc0_srsconf4(tcg_env
, arg
);
6306 register_name
= "SRSConf4";
6308 case CP0_REG06__PWCTL
:
6310 gen_helper_mtc0_pwctl(tcg_env
, arg
);
6311 register_name
= "PWCtl";
6314 goto cp0_unimplemented
;
6317 case CP0_REGISTER_07
:
6319 case CP0_REG07__HWRENA
:
6320 check_insn(ctx
, ISA_MIPS_R2
);
6321 gen_helper_mtc0_hwrena(tcg_env
, arg
);
6322 ctx
->base
.is_jmp
= DISAS_STOP
;
6323 register_name
= "HWREna";
6326 goto cp0_unimplemented
;
6329 case CP0_REGISTER_08
:
6331 case CP0_REG08__BADVADDR
:
6333 register_name
= "BadVAddr";
6335 case CP0_REG08__BADINSTR
:
6337 register_name
= "BadInstr";
6339 case CP0_REG08__BADINSTRP
:
6341 register_name
= "BadInstrP";
6343 case CP0_REG08__BADINSTRX
:
6345 register_name
= "BadInstrX";
6348 goto cp0_unimplemented
;
6351 case CP0_REGISTER_09
:
6353 case CP0_REG09__COUNT
:
6354 gen_helper_mtc0_count(tcg_env
, arg
);
6355 register_name
= "Count";
6358 goto cp0_unimplemented
;
6361 case CP0_REGISTER_10
:
6363 case CP0_REG10__ENTRYHI
:
6364 gen_helper_mtc0_entryhi(tcg_env
, arg
);
6365 register_name
= "EntryHi";
6368 goto cp0_unimplemented
;
6371 case CP0_REGISTER_11
:
6373 case CP0_REG11__COMPARE
:
6374 gen_helper_mtc0_compare(tcg_env
, arg
);
6375 register_name
= "Compare";
6377 /* 6,7 are implementation dependent */
6379 goto cp0_unimplemented
;
6382 case CP0_REGISTER_12
:
6384 case CP0_REG12__STATUS
:
6385 save_cpu_state(ctx
, 1);
6386 gen_helper_mtc0_status(tcg_env
, arg
);
6387 /* DISAS_STOP isn't good enough here, hflags may have changed. */
6388 gen_save_pc(ctx
->base
.pc_next
+ 4);
6389 ctx
->base
.is_jmp
= DISAS_EXIT
;
6390 register_name
= "Status";
6392 case CP0_REG12__INTCTL
:
6393 check_insn(ctx
, ISA_MIPS_R2
);
6394 gen_helper_mtc0_intctl(tcg_env
, arg
);
6395 /* Stop translation as we may have switched the execution mode */
6396 ctx
->base
.is_jmp
= DISAS_STOP
;
6397 register_name
= "IntCtl";
6399 case CP0_REG12__SRSCTL
:
6400 check_insn(ctx
, ISA_MIPS_R2
);
6401 gen_helper_mtc0_srsctl(tcg_env
, arg
);
6402 /* Stop translation as we may have switched the execution mode */
6403 ctx
->base
.is_jmp
= DISAS_STOP
;
6404 register_name
= "SRSCtl";
6406 case CP0_REG12__SRSMAP
:
6407 check_insn(ctx
, ISA_MIPS_R2
);
6408 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
6409 /* Stop translation as we may have switched the execution mode */
6410 ctx
->base
.is_jmp
= DISAS_STOP
;
6411 register_name
= "SRSMap";
6414 goto cp0_unimplemented
;
6417 case CP0_REGISTER_13
:
6419 case CP0_REG13__CAUSE
:
6420 save_cpu_state(ctx
, 1);
6421 gen_helper_mtc0_cause(tcg_env
, arg
);
6423 * Stop translation as we may have triggered an interrupt.
6424 * DISAS_STOP isn't sufficient, we need to ensure we break out of
6425 * translated code to check for pending interrupts.
6427 gen_save_pc(ctx
->base
.pc_next
+ 4);
6428 ctx
->base
.is_jmp
= DISAS_EXIT
;
6429 register_name
= "Cause";
6432 goto cp0_unimplemented
;
6435 case CP0_REGISTER_14
:
6437 case CP0_REG14__EPC
:
6438 tcg_gen_st_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EPC
));
6439 register_name
= "EPC";
6442 goto cp0_unimplemented
;
6445 case CP0_REGISTER_15
:
6447 case CP0_REG15__PRID
:
6449 register_name
= "PRid";
6451 case CP0_REG15__EBASE
:
6452 check_insn(ctx
, ISA_MIPS_R2
);
6453 gen_helper_mtc0_ebase(tcg_env
, arg
);
6454 register_name
= "EBase";
6457 goto cp0_unimplemented
;
6460 case CP0_REGISTER_16
:
6462 case CP0_REG16__CONFIG
:
6463 gen_helper_mtc0_config0(tcg_env
, arg
);
6464 register_name
= "Config";
6465 /* Stop translation as we may have switched the execution mode */
6466 ctx
->base
.is_jmp
= DISAS_STOP
;
6468 case CP0_REG16__CONFIG1
:
6469 /* ignored, read only */
6470 register_name
= "Config1";
6472 case CP0_REG16__CONFIG2
:
6473 gen_helper_mtc0_config2(tcg_env
, arg
);
6474 register_name
= "Config2";
6475 /* Stop translation as we may have switched the execution mode */
6476 ctx
->base
.is_jmp
= DISAS_STOP
;
6478 case CP0_REG16__CONFIG3
:
6479 gen_helper_mtc0_config3(tcg_env
, arg
);
6480 register_name
= "Config3";
6481 /* Stop translation as we may have switched the execution mode */
6482 ctx
->base
.is_jmp
= DISAS_STOP
;
6484 case CP0_REG16__CONFIG4
:
6485 gen_helper_mtc0_config4(tcg_env
, arg
);
6486 register_name
= "Config4";
6487 ctx
->base
.is_jmp
= DISAS_STOP
;
6489 case CP0_REG16__CONFIG5
:
6490 gen_helper_mtc0_config5(tcg_env
, arg
);
6491 register_name
= "Config5";
6492 /* Stop translation as we may have switched the execution mode */
6493 ctx
->base
.is_jmp
= DISAS_STOP
;
6495 /* 6,7 are implementation dependent */
6496 case CP0_REG16__CONFIG6
:
6498 register_name
= "Config6";
6500 case CP0_REG16__CONFIG7
:
6502 register_name
= "Config7";
6505 register_name
= "Invalid config selector";
6506 goto cp0_unimplemented
;
6509 case CP0_REGISTER_17
:
6511 case CP0_REG17__LLADDR
:
6512 gen_helper_mtc0_lladdr(tcg_env
, arg
);
6513 register_name
= "LLAddr";
6515 case CP0_REG17__MAAR
:
6516 CP0_CHECK(ctx
->mrp
);
6517 gen_helper_mtc0_maar(tcg_env
, arg
);
6518 register_name
= "MAAR";
6520 case CP0_REG17__MAARI
:
6521 CP0_CHECK(ctx
->mrp
);
6522 gen_helper_mtc0_maari(tcg_env
, arg
);
6523 register_name
= "MAARI";
6526 goto cp0_unimplemented
;
6529 case CP0_REGISTER_18
:
6531 case CP0_REG18__WATCHLO0
:
6532 case CP0_REG18__WATCHLO1
:
6533 case CP0_REG18__WATCHLO2
:
6534 case CP0_REG18__WATCHLO3
:
6535 case CP0_REG18__WATCHLO4
:
6536 case CP0_REG18__WATCHLO5
:
6537 case CP0_REG18__WATCHLO6
:
6538 case CP0_REG18__WATCHLO7
:
6539 CP0_CHECK(ctx
->CP0_Config1
& (1 << CP0C1_WR
));
6540 gen_helper_0e1i(mtc0_watchlo
, arg
, sel
);
6541 register_name
= "WatchLo";
6544 goto cp0_unimplemented
;
6547 case CP0_REGISTER_19
:
6549 case CP0_REG19__WATCHHI0
:
6550 case CP0_REG19__WATCHHI1
:
6551 case CP0_REG19__WATCHHI2
:
6552 case CP0_REG19__WATCHHI3
:
6553 case CP0_REG19__WATCHHI4
:
6554 case CP0_REG19__WATCHHI5
:
6555 case CP0_REG19__WATCHHI6
:
6556 case CP0_REG19__WATCHHI7
:
6557 CP0_CHECK(ctx
->CP0_Config1
& (1 << CP0C1_WR
));
6558 gen_helper_0e1i(mtc0_watchhi
, arg
, sel
);
6559 register_name
= "WatchHi";
6562 goto cp0_unimplemented
;
6565 case CP0_REGISTER_20
:
6567 case CP0_REG20__XCONTEXT
:
6568 #if defined(TARGET_MIPS64)
6569 check_insn(ctx
, ISA_MIPS3
);
6570 gen_helper_mtc0_xcontext(tcg_env
, arg
);
6571 register_name
= "XContext";
6575 goto cp0_unimplemented
;
6578 case CP0_REGISTER_21
:
6579 /* Officially reserved, but sel 0 is used for R1x000 framemask */
6580 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS_R6
));
6583 gen_helper_mtc0_framemask(tcg_env
, arg
);
6584 register_name
= "Framemask";
6587 goto cp0_unimplemented
;
6590 case CP0_REGISTER_22
:
6592 register_name
= "Diagnostic"; /* implementation dependent */
6594 case CP0_REGISTER_23
:
6596 case CP0_REG23__DEBUG
:
6597 gen_helper_mtc0_debug(tcg_env
, arg
); /* EJTAG support */
6598 /* DISAS_STOP isn't good enough here, hflags may have changed. */
6599 gen_save_pc(ctx
->base
.pc_next
+ 4);
6600 ctx
->base
.is_jmp
= DISAS_EXIT
;
6601 register_name
= "Debug";
6603 case CP0_REG23__TRACECONTROL
:
6604 /* PDtrace support */
6605 /* gen_helper_mtc0_tracecontrol(tcg_env, arg); */
6606 register_name
= "TraceControl";
6607 /* Stop translation as we may have switched the execution mode */
6608 ctx
->base
.is_jmp
= DISAS_STOP
;
6609 goto cp0_unimplemented
;
6610 case CP0_REG23__TRACECONTROL2
:
6611 /* PDtrace support */
6612 /* gen_helper_mtc0_tracecontrol2(tcg_env, arg); */
6613 register_name
= "TraceControl2";
6614 /* Stop translation as we may have switched the execution mode */
6615 ctx
->base
.is_jmp
= DISAS_STOP
;
6616 goto cp0_unimplemented
;
6617 case CP0_REG23__USERTRACEDATA1
:
6618 /* Stop translation as we may have switched the execution mode */
6619 ctx
->base
.is_jmp
= DISAS_STOP
;
6620 /* PDtrace support */
6621 /* gen_helper_mtc0_usertracedata1(tcg_env, arg);*/
6622 register_name
= "UserTraceData";
6623 /* Stop translation as we may have switched the execution mode */
6624 ctx
->base
.is_jmp
= DISAS_STOP
;
6625 goto cp0_unimplemented
;
6626 case CP0_REG23__TRACEIBPC
:
6627 /* PDtrace support */
6628 /* gen_helper_mtc0_traceibpc(tcg_env, arg); */
6629 /* Stop translation as we may have switched the execution mode */
6630 ctx
->base
.is_jmp
= DISAS_STOP
;
6631 register_name
= "TraceIBPC";
6632 goto cp0_unimplemented
;
6633 case CP0_REG23__TRACEDBPC
:
6634 /* PDtrace support */
6635 /* gen_helper_mtc0_tracedbpc(tcg_env, arg); */
6636 /* Stop translation as we may have switched the execution mode */
6637 ctx
->base
.is_jmp
= DISAS_STOP
;
6638 register_name
= "TraceDBPC";
6639 goto cp0_unimplemented
;
6641 goto cp0_unimplemented
;
6644 case CP0_REGISTER_24
:
6646 case CP0_REG24__DEPC
:
6648 tcg_gen_st_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
6649 register_name
= "DEPC";
6652 goto cp0_unimplemented
;
6655 case CP0_REGISTER_25
:
6657 case CP0_REG25__PERFCTL0
:
6658 gen_helper_mtc0_performance0(tcg_env
, arg
);
6659 register_name
= "Performance0";
6661 case CP0_REG25__PERFCNT0
:
6662 /* gen_helper_mtc0_performance1(arg); */
6663 register_name
= "Performance1";
6664 goto cp0_unimplemented
;
6665 case CP0_REG25__PERFCTL1
:
6666 /* gen_helper_mtc0_performance2(arg); */
6667 register_name
= "Performance2";
6668 goto cp0_unimplemented
;
6669 case CP0_REG25__PERFCNT1
:
6670 /* gen_helper_mtc0_performance3(arg); */
6671 register_name
= "Performance3";
6672 goto cp0_unimplemented
;
6673 case CP0_REG25__PERFCTL2
:
6674 /* gen_helper_mtc0_performance4(arg); */
6675 register_name
= "Performance4";
6676 goto cp0_unimplemented
;
6677 case CP0_REG25__PERFCNT2
:
6678 /* gen_helper_mtc0_performance5(arg); */
6679 register_name
= "Performance5";
6680 goto cp0_unimplemented
;
6681 case CP0_REG25__PERFCTL3
:
6682 /* gen_helper_mtc0_performance6(arg); */
6683 register_name
= "Performance6";
6684 goto cp0_unimplemented
;
6685 case CP0_REG25__PERFCNT3
:
6686 /* gen_helper_mtc0_performance7(arg); */
6687 register_name
= "Performance7";
6688 goto cp0_unimplemented
;
6690 goto cp0_unimplemented
;
6693 case CP0_REGISTER_26
:
6695 case CP0_REG26__ERRCTL
:
6696 gen_helper_mtc0_errctl(tcg_env
, arg
);
6697 ctx
->base
.is_jmp
= DISAS_STOP
;
6698 register_name
= "ErrCtl";
6701 goto cp0_unimplemented
;
6704 case CP0_REGISTER_27
:
6706 case CP0_REG27__CACHERR
:
6708 register_name
= "CacheErr";
6711 goto cp0_unimplemented
;
6714 case CP0_REGISTER_28
:
6716 case CP0_REG28__TAGLO
:
6717 case CP0_REG28__TAGLO1
:
6718 case CP0_REG28__TAGLO2
:
6719 case CP0_REG28__TAGLO3
:
6720 gen_helper_mtc0_taglo(tcg_env
, arg
);
6721 register_name
= "TagLo";
6723 case CP0_REG28__DATALO
:
6724 case CP0_REG28__DATALO1
:
6725 case CP0_REG28__DATALO2
:
6726 case CP0_REG28__DATALO3
:
6727 gen_helper_mtc0_datalo(tcg_env
, arg
);
6728 register_name
= "DataLo";
6731 goto cp0_unimplemented
;
6734 case CP0_REGISTER_29
:
6736 case CP0_REG29__TAGHI
:
6737 case CP0_REG29__TAGHI1
:
6738 case CP0_REG29__TAGHI2
:
6739 case CP0_REG29__TAGHI3
:
6740 gen_helper_mtc0_taghi(tcg_env
, arg
);
6741 register_name
= "TagHi";
6743 case CP0_REG29__DATAHI
:
6744 case CP0_REG29__DATAHI1
:
6745 case CP0_REG29__DATAHI2
:
6746 case CP0_REG29__DATAHI3
:
6747 gen_helper_mtc0_datahi(tcg_env
, arg
);
6748 register_name
= "DataHi";
6751 register_name
= "invalid sel";
6752 goto cp0_unimplemented
;
6755 case CP0_REGISTER_30
:
6757 case CP0_REG30__ERROREPC
:
6758 tcg_gen_st_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
6759 register_name
= "ErrorEPC";
6762 goto cp0_unimplemented
;
6765 case CP0_REGISTER_31
:
6767 case CP0_REG31__DESAVE
:
6769 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
6770 register_name
= "DESAVE";
6772 case CP0_REG31__KSCRATCH1
:
6773 case CP0_REG31__KSCRATCH2
:
6774 case CP0_REG31__KSCRATCH3
:
6775 case CP0_REG31__KSCRATCH4
:
6776 case CP0_REG31__KSCRATCH5
:
6777 case CP0_REG31__KSCRATCH6
:
6778 CP0_CHECK(ctx
->kscrexist
& (1 << sel
));
6779 tcg_gen_st_tl(arg
, tcg_env
,
6780 offsetof(CPUMIPSState
, CP0_KScratch
[sel
- 2]));
6781 register_name
= "KScratch";
6784 goto cp0_unimplemented
;
6788 goto cp0_unimplemented
;
6790 trace_mips_translate_c0("mtc0", register_name
, reg
, sel
);
6792 /* For simplicity assume that all writes can cause interrupts. */
6795 * DISAS_STOP isn't sufficient, we need to ensure we break out of
6796 * translated code to check for pending interrupts.
6798 gen_save_pc(ctx
->base
.pc_next
+ 4);
6799 ctx
->base
.is_jmp
= DISAS_EXIT
;
6804 qemu_log_mask(LOG_UNIMP
, "mtc0 %s (reg %d sel %d)\n",
6805 register_name
, reg
, sel
);
6808 #if defined(TARGET_MIPS64)
6809 static void gen_dmfc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
6811 const char *register_name
= "invalid";
6814 check_insn(ctx
, ISA_MIPS_R1
);
6818 case CP0_REGISTER_00
:
6820 case CP0_REG00__INDEX
:
6821 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Index
));
6822 register_name
= "Index";
6824 case CP0_REG00__MVPCONTROL
:
6825 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6826 gen_helper_mfc0_mvpcontrol(arg
, tcg_env
);
6827 register_name
= "MVPControl";
6829 case CP0_REG00__MVPCONF0
:
6830 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6831 gen_helper_mfc0_mvpconf0(arg
, tcg_env
);
6832 register_name
= "MVPConf0";
6834 case CP0_REG00__MVPCONF1
:
6835 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6836 gen_helper_mfc0_mvpconf1(arg
, tcg_env
);
6837 register_name
= "MVPConf1";
6839 case CP0_REG00__VPCONTROL
:
6841 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPControl
));
6842 register_name
= "VPControl";
6845 goto cp0_unimplemented
;
6848 case CP0_REGISTER_01
:
6850 case CP0_REG01__RANDOM
:
6851 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS_R6
));
6852 gen_helper_mfc0_random(arg
, tcg_env
);
6853 register_name
= "Random";
6855 case CP0_REG01__VPECONTROL
:
6856 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6857 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEControl
));
6858 register_name
= "VPEControl";
6860 case CP0_REG01__VPECONF0
:
6861 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6862 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf0
));
6863 register_name
= "VPEConf0";
6865 case CP0_REG01__VPECONF1
:
6866 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6867 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf1
));
6868 register_name
= "VPEConf1";
6870 case CP0_REG01__YQMASK
:
6871 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6872 tcg_gen_ld_tl(arg
, tcg_env
,
6873 offsetof(CPUMIPSState
, CP0_YQMask
));
6874 register_name
= "YQMask";
6876 case CP0_REG01__VPESCHEDULE
:
6877 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6878 tcg_gen_ld_tl(arg
, tcg_env
,
6879 offsetof(CPUMIPSState
, CP0_VPESchedule
));
6880 register_name
= "VPESchedule";
6882 case CP0_REG01__VPESCHEFBACK
:
6883 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6884 tcg_gen_ld_tl(arg
, tcg_env
,
6885 offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
6886 register_name
= "VPEScheFBack";
6888 case CP0_REG01__VPEOPT
:
6889 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6890 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEOpt
));
6891 register_name
= "VPEOpt";
6894 goto cp0_unimplemented
;
6897 case CP0_REGISTER_02
:
6899 case CP0_REG02__ENTRYLO0
:
6900 tcg_gen_ld_tl(arg
, tcg_env
,
6901 offsetof(CPUMIPSState
, CP0_EntryLo0
));
6902 register_name
= "EntryLo0";
6904 case CP0_REG02__TCSTATUS
:
6905 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6906 gen_helper_mfc0_tcstatus(arg
, tcg_env
);
6907 register_name
= "TCStatus";
6909 case CP0_REG02__TCBIND
:
6910 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6911 gen_helper_mfc0_tcbind(arg
, tcg_env
);
6912 register_name
= "TCBind";
6914 case CP0_REG02__TCRESTART
:
6915 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6916 gen_helper_dmfc0_tcrestart(arg
, tcg_env
);
6917 register_name
= "TCRestart";
6919 case CP0_REG02__TCHALT
:
6920 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6921 gen_helper_dmfc0_tchalt(arg
, tcg_env
);
6922 register_name
= "TCHalt";
6924 case CP0_REG02__TCCONTEXT
:
6925 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6926 gen_helper_dmfc0_tccontext(arg
, tcg_env
);
6927 register_name
= "TCContext";
6929 case CP0_REG02__TCSCHEDULE
:
6930 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6931 gen_helper_dmfc0_tcschedule(arg
, tcg_env
);
6932 register_name
= "TCSchedule";
6934 case CP0_REG02__TCSCHEFBACK
:
6935 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
6936 gen_helper_dmfc0_tcschefback(arg
, tcg_env
);
6937 register_name
= "TCScheFBack";
6940 goto cp0_unimplemented
;
6943 case CP0_REGISTER_03
:
6945 case CP0_REG03__ENTRYLO1
:
6946 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EntryLo1
));
6947 register_name
= "EntryLo1";
6949 case CP0_REG03__GLOBALNUM
:
6951 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_GlobalNumber
));
6952 register_name
= "GlobalNumber";
6955 goto cp0_unimplemented
;
6958 case CP0_REGISTER_04
:
6960 case CP0_REG04__CONTEXT
:
6961 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_Context
));
6962 register_name
= "Context";
6964 case CP0_REG04__CONTEXTCONFIG
:
6966 /* gen_helper_dmfc0_contextconfig(arg); */
6967 register_name
= "ContextConfig";
6968 goto cp0_unimplemented
;
6969 case CP0_REG04__USERLOCAL
:
6970 CP0_CHECK(ctx
->ulri
);
6971 tcg_gen_ld_tl(arg
, tcg_env
,
6972 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
6973 register_name
= "UserLocal";
6975 case CP0_REG04__MMID
:
6977 gen_helper_mtc0_memorymapid(tcg_env
, arg
);
6978 register_name
= "MMID";
6981 goto cp0_unimplemented
;
6984 case CP0_REGISTER_05
:
6986 case CP0_REG05__PAGEMASK
:
6987 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageMask
));
6988 register_name
= "PageMask";
6990 case CP0_REG05__PAGEGRAIN
:
6991 check_insn(ctx
, ISA_MIPS_R2
);
6992 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageGrain
));
6993 register_name
= "PageGrain";
6995 case CP0_REG05__SEGCTL0
:
6997 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_SegCtl0
));
6998 register_name
= "SegCtl0";
7000 case CP0_REG05__SEGCTL1
:
7002 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_SegCtl1
));
7003 register_name
= "SegCtl1";
7005 case CP0_REG05__SEGCTL2
:
7007 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_SegCtl2
));
7008 register_name
= "SegCtl2";
7010 case CP0_REG05__PWBASE
:
7012 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_PWBase
));
7013 register_name
= "PWBase";
7015 case CP0_REG05__PWFIELD
:
7017 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_PWField
));
7018 register_name
= "PWField";
7020 case CP0_REG05__PWSIZE
:
7022 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_PWSize
));
7023 register_name
= "PWSize";
7026 goto cp0_unimplemented
;
7029 case CP0_REGISTER_06
:
7031 case CP0_REG06__WIRED
:
7032 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Wired
));
7033 register_name
= "Wired";
7035 case CP0_REG06__SRSCONF0
:
7036 check_insn(ctx
, ISA_MIPS_R2
);
7037 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf0
));
7038 register_name
= "SRSConf0";
7040 case CP0_REG06__SRSCONF1
:
7041 check_insn(ctx
, ISA_MIPS_R2
);
7042 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf1
));
7043 register_name
= "SRSConf1";
7045 case CP0_REG06__SRSCONF2
:
7046 check_insn(ctx
, ISA_MIPS_R2
);
7047 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf2
));
7048 register_name
= "SRSConf2";
7050 case CP0_REG06__SRSCONF3
:
7051 check_insn(ctx
, ISA_MIPS_R2
);
7052 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf3
));
7053 register_name
= "SRSConf3";
7055 case CP0_REG06__SRSCONF4
:
7056 check_insn(ctx
, ISA_MIPS_R2
);
7057 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf4
));
7058 register_name
= "SRSConf4";
7060 case CP0_REG06__PWCTL
:
7062 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PWCtl
));
7063 register_name
= "PWCtl";
7066 goto cp0_unimplemented
;
7069 case CP0_REGISTER_07
:
7071 case CP0_REG07__HWRENA
:
7072 check_insn(ctx
, ISA_MIPS_R2
);
7073 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_HWREna
));
7074 register_name
= "HWREna";
7077 goto cp0_unimplemented
;
7080 case CP0_REGISTER_08
:
7082 case CP0_REG08__BADVADDR
:
7083 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_BadVAddr
));
7084 register_name
= "BadVAddr";
7086 case CP0_REG08__BADINSTR
:
7088 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstr
));
7089 register_name
= "BadInstr";
7091 case CP0_REG08__BADINSTRP
:
7093 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstrP
));
7094 register_name
= "BadInstrP";
7096 case CP0_REG08__BADINSTRX
:
7098 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_BadInstrX
));
7099 tcg_gen_andi_tl(arg
, arg
, ~0xffff);
7100 register_name
= "BadInstrX";
7103 goto cp0_unimplemented
;
7106 case CP0_REGISTER_09
:
7108 case CP0_REG09__COUNT
:
7109 /* Mark as an IO operation because we read the time. */
7110 translator_io_start(&ctx
->base
);
7111 gen_helper_mfc0_count(arg
, tcg_env
);
7113 * Break the TB to be able to take timer interrupts immediately
7114 * after reading count. DISAS_STOP isn't sufficient, we need to
7115 * ensure we break completely out of translated code.
7117 gen_save_pc(ctx
->base
.pc_next
+ 4);
7118 ctx
->base
.is_jmp
= DISAS_EXIT
;
7119 register_name
= "Count";
7122 goto cp0_unimplemented
;
7125 case CP0_REGISTER_10
:
7127 case CP0_REG10__ENTRYHI
:
7128 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EntryHi
));
7129 register_name
= "EntryHi";
7132 goto cp0_unimplemented
;
7135 case CP0_REGISTER_11
:
7137 case CP0_REG11__COMPARE
:
7138 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Compare
));
7139 register_name
= "Compare";
7141 /* 6,7 are implementation dependent */
7143 goto cp0_unimplemented
;
7146 case CP0_REGISTER_12
:
7148 case CP0_REG12__STATUS
:
7149 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Status
));
7150 register_name
= "Status";
7152 case CP0_REG12__INTCTL
:
7153 check_insn(ctx
, ISA_MIPS_R2
);
7154 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_IntCtl
));
7155 register_name
= "IntCtl";
7157 case CP0_REG12__SRSCTL
:
7158 check_insn(ctx
, ISA_MIPS_R2
);
7159 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
7160 register_name
= "SRSCtl";
7162 case CP0_REG12__SRSMAP
:
7163 check_insn(ctx
, ISA_MIPS_R2
);
7164 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
7165 register_name
= "SRSMap";
7168 goto cp0_unimplemented
;
7171 case CP0_REGISTER_13
:
7173 case CP0_REG13__CAUSE
:
7174 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Cause
));
7175 register_name
= "Cause";
7178 goto cp0_unimplemented
;
7181 case CP0_REGISTER_14
:
7183 case CP0_REG14__EPC
:
7184 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EPC
));
7185 register_name
= "EPC";
7188 goto cp0_unimplemented
;
7191 case CP0_REGISTER_15
:
7193 case CP0_REG15__PRID
:
7194 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PRid
));
7195 register_name
= "PRid";
7197 case CP0_REG15__EBASE
:
7198 check_insn(ctx
, ISA_MIPS_R2
);
7199 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EBase
));
7200 register_name
= "EBase";
7202 case CP0_REG15__CMGCRBASE
:
7203 check_insn(ctx
, ISA_MIPS_R2
);
7204 CP0_CHECK(ctx
->cmgcr
);
7205 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_CMGCRBase
));
7206 register_name
= "CMGCRBase";
7209 goto cp0_unimplemented
;
7212 case CP0_REGISTER_16
:
7214 case CP0_REG16__CONFIG
:
7215 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config0
));
7216 register_name
= "Config";
7218 case CP0_REG16__CONFIG1
:
7219 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config1
));
7220 register_name
= "Config1";
7222 case CP0_REG16__CONFIG2
:
7223 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config2
));
7224 register_name
= "Config2";
7226 case CP0_REG16__CONFIG3
:
7227 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config3
));
7228 register_name
= "Config3";
7230 case CP0_REG16__CONFIG4
:
7231 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config4
));
7232 register_name
= "Config4";
7234 case CP0_REG16__CONFIG5
:
7235 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config5
));
7236 register_name
= "Config5";
7238 /* 6,7 are implementation dependent */
7239 case CP0_REG16__CONFIG6
:
7240 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config6
));
7241 register_name
= "Config6";
7243 case CP0_REG16__CONFIG7
:
7244 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config7
));
7245 register_name
= "Config7";
7248 goto cp0_unimplemented
;
7251 case CP0_REGISTER_17
:
7253 case CP0_REG17__LLADDR
:
7254 gen_helper_dmfc0_lladdr(arg
, tcg_env
);
7255 register_name
= "LLAddr";
7257 case CP0_REG17__MAAR
:
7258 CP0_CHECK(ctx
->mrp
);
7259 gen_helper_dmfc0_maar(arg
, tcg_env
);
7260 register_name
= "MAAR";
7262 case CP0_REG17__MAARI
:
7263 CP0_CHECK(ctx
->mrp
);
7264 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_MAARI
));
7265 register_name
= "MAARI";
7268 goto cp0_unimplemented
;
7271 case CP0_REGISTER_18
:
7273 case CP0_REG18__WATCHLO0
:
7274 case CP0_REG18__WATCHLO1
:
7275 case CP0_REG18__WATCHLO2
:
7276 case CP0_REG18__WATCHLO3
:
7277 case CP0_REG18__WATCHLO4
:
7278 case CP0_REG18__WATCHLO5
:
7279 case CP0_REG18__WATCHLO6
:
7280 case CP0_REG18__WATCHLO7
:
7281 CP0_CHECK(ctx
->CP0_Config1
& (1 << CP0C1_WR
));
7282 gen_helper_1e0i(dmfc0_watchlo
, arg
, sel
);
7283 register_name
= "WatchLo";
7286 goto cp0_unimplemented
;
7289 case CP0_REGISTER_19
:
7291 case CP0_REG19__WATCHHI0
:
7292 case CP0_REG19__WATCHHI1
:
7293 case CP0_REG19__WATCHHI2
:
7294 case CP0_REG19__WATCHHI3
:
7295 case CP0_REG19__WATCHHI4
:
7296 case CP0_REG19__WATCHHI5
:
7297 case CP0_REG19__WATCHHI6
:
7298 case CP0_REG19__WATCHHI7
:
7299 CP0_CHECK(ctx
->CP0_Config1
& (1 << CP0C1_WR
));
7300 gen_helper_1e0i(dmfc0_watchhi
, arg
, sel
);
7301 register_name
= "WatchHi";
7304 goto cp0_unimplemented
;
7307 case CP0_REGISTER_20
:
7309 case CP0_REG20__XCONTEXT
:
7310 check_insn(ctx
, ISA_MIPS3
);
7311 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_XContext
));
7312 register_name
= "XContext";
7315 goto cp0_unimplemented
;
7318 case CP0_REGISTER_21
:
7319 /* Officially reserved, but sel 0 is used for R1x000 framemask */
7320 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS_R6
));
7323 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Framemask
));
7324 register_name
= "Framemask";
7327 goto cp0_unimplemented
;
7330 case CP0_REGISTER_22
:
7331 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
7332 register_name
= "'Diagnostic"; /* implementation dependent */
7334 case CP0_REGISTER_23
:
7336 case CP0_REG23__DEBUG
:
7337 gen_helper_mfc0_debug(arg
, tcg_env
); /* EJTAG support */
7338 register_name
= "Debug";
7340 case CP0_REG23__TRACECONTROL
:
7341 /* PDtrace support */
7342 /* gen_helper_dmfc0_tracecontrol(arg, tcg_env); */
7343 register_name
= "TraceControl";
7344 goto cp0_unimplemented
;
7345 case CP0_REG23__TRACECONTROL2
:
7346 /* PDtrace support */
7347 /* gen_helper_dmfc0_tracecontrol2(arg, tcg_env); */
7348 register_name
= "TraceControl2";
7349 goto cp0_unimplemented
;
7350 case CP0_REG23__USERTRACEDATA1
:
7351 /* PDtrace support */
7352 /* gen_helper_dmfc0_usertracedata1(arg, tcg_env);*/
7353 register_name
= "UserTraceData1";
7354 goto cp0_unimplemented
;
7355 case CP0_REG23__TRACEIBPC
:
7356 /* PDtrace support */
7357 /* gen_helper_dmfc0_traceibpc(arg, tcg_env); */
7358 register_name
= "TraceIBPC";
7359 goto cp0_unimplemented
;
7360 case CP0_REG23__TRACEDBPC
:
7361 /* PDtrace support */
7362 /* gen_helper_dmfc0_tracedbpc(arg, tcg_env); */
7363 register_name
= "TraceDBPC";
7364 goto cp0_unimplemented
;
7366 goto cp0_unimplemented
;
7369 case CP0_REGISTER_24
:
7371 case CP0_REG24__DEPC
:
7373 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
7374 register_name
= "DEPC";
7377 goto cp0_unimplemented
;
7380 case CP0_REGISTER_25
:
7382 case CP0_REG25__PERFCTL0
:
7383 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Performance0
));
7384 register_name
= "Performance0";
7386 case CP0_REG25__PERFCNT0
:
7387 /* gen_helper_dmfc0_performance1(arg); */
7388 register_name
= "Performance1";
7389 goto cp0_unimplemented
;
7390 case CP0_REG25__PERFCTL1
:
7391 /* gen_helper_dmfc0_performance2(arg); */
7392 register_name
= "Performance2";
7393 goto cp0_unimplemented
;
7394 case CP0_REG25__PERFCNT1
:
7395 /* gen_helper_dmfc0_performance3(arg); */
7396 register_name
= "Performance3";
7397 goto cp0_unimplemented
;
7398 case CP0_REG25__PERFCTL2
:
7399 /* gen_helper_dmfc0_performance4(arg); */
7400 register_name
= "Performance4";
7401 goto cp0_unimplemented
;
7402 case CP0_REG25__PERFCNT2
:
7403 /* gen_helper_dmfc0_performance5(arg); */
7404 register_name
= "Performance5";
7405 goto cp0_unimplemented
;
7406 case CP0_REG25__PERFCTL3
:
7407 /* gen_helper_dmfc0_performance6(arg); */
7408 register_name
= "Performance6";
7409 goto cp0_unimplemented
;
7410 case CP0_REG25__PERFCNT3
:
7411 /* gen_helper_dmfc0_performance7(arg); */
7412 register_name
= "Performance7";
7413 goto cp0_unimplemented
;
7415 goto cp0_unimplemented
;
7418 case CP0_REGISTER_26
:
7420 case CP0_REG26__ERRCTL
:
7421 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_ErrCtl
));
7422 register_name
= "ErrCtl";
7425 goto cp0_unimplemented
;
7428 case CP0_REGISTER_27
:
7431 case CP0_REG27__CACHERR
:
7432 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
7433 register_name
= "CacheErr";
7436 goto cp0_unimplemented
;
7439 case CP0_REGISTER_28
:
7441 case CP0_REG28__TAGLO
:
7442 case CP0_REG28__TAGLO1
:
7443 case CP0_REG28__TAGLO2
:
7444 case CP0_REG28__TAGLO3
:
7445 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagLo
));
7446 register_name
= "TagLo";
7448 case CP0_REG28__DATALO
:
7449 case CP0_REG28__DATALO1
:
7450 case CP0_REG28__DATALO2
:
7451 case CP0_REG28__DATALO3
:
7452 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataLo
));
7453 register_name
= "DataLo";
7456 goto cp0_unimplemented
;
7459 case CP0_REGISTER_29
:
7461 case CP0_REG29__TAGHI
:
7462 case CP0_REG29__TAGHI1
:
7463 case CP0_REG29__TAGHI2
:
7464 case CP0_REG29__TAGHI3
:
7465 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagHi
));
7466 register_name
= "TagHi";
7468 case CP0_REG29__DATAHI
:
7469 case CP0_REG29__DATAHI1
:
7470 case CP0_REG29__DATAHI2
:
7471 case CP0_REG29__DATAHI3
:
7472 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataHi
));
7473 register_name
= "DataHi";
7476 goto cp0_unimplemented
;
7479 case CP0_REGISTER_30
:
7481 case CP0_REG30__ERROREPC
:
7482 tcg_gen_ld_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
7483 register_name
= "ErrorEPC";
7486 goto cp0_unimplemented
;
7489 case CP0_REGISTER_31
:
7491 case CP0_REG31__DESAVE
:
7493 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
7494 register_name
= "DESAVE";
7496 case CP0_REG31__KSCRATCH1
:
7497 case CP0_REG31__KSCRATCH2
:
7498 case CP0_REG31__KSCRATCH3
:
7499 case CP0_REG31__KSCRATCH4
:
7500 case CP0_REG31__KSCRATCH5
:
7501 case CP0_REG31__KSCRATCH6
:
7502 CP0_CHECK(ctx
->kscrexist
& (1 << sel
));
7503 tcg_gen_ld_tl(arg
, tcg_env
,
7504 offsetof(CPUMIPSState
, CP0_KScratch
[sel
- 2]));
7505 register_name
= "KScratch";
7508 goto cp0_unimplemented
;
7512 goto cp0_unimplemented
;
7514 trace_mips_translate_c0("dmfc0", register_name
, reg
, sel
);
7518 qemu_log_mask(LOG_UNIMP
, "dmfc0 %s (reg %d sel %d)\n",
7519 register_name
, reg
, sel
);
7520 gen_mfc0_unimplemented(ctx
, arg
);
7523 static void gen_dmtc0(DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
7525 const char *register_name
= "invalid";
7529 check_insn(ctx
, ISA_MIPS_R1
);
7532 icount
= translator_io_start(&ctx
->base
);
7535 case CP0_REGISTER_00
:
7537 case CP0_REG00__INDEX
:
7538 gen_helper_mtc0_index(tcg_env
, arg
);
7539 register_name
= "Index";
7541 case CP0_REG00__MVPCONTROL
:
7542 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7543 gen_helper_mtc0_mvpcontrol(tcg_env
, arg
);
7544 register_name
= "MVPControl";
7546 case CP0_REG00__MVPCONF0
:
7547 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7549 register_name
= "MVPConf0";
7551 case CP0_REG00__MVPCONF1
:
7552 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7554 register_name
= "MVPConf1";
7556 case CP0_REG00__VPCONTROL
:
7559 register_name
= "VPControl";
7562 goto cp0_unimplemented
;
7565 case CP0_REGISTER_01
:
7567 case CP0_REG01__RANDOM
:
7569 register_name
= "Random";
7571 case CP0_REG01__VPECONTROL
:
7572 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7573 gen_helper_mtc0_vpecontrol(tcg_env
, arg
);
7574 register_name
= "VPEControl";
7576 case CP0_REG01__VPECONF0
:
7577 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7578 gen_helper_mtc0_vpeconf0(tcg_env
, arg
);
7579 register_name
= "VPEConf0";
7581 case CP0_REG01__VPECONF1
:
7582 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7583 gen_helper_mtc0_vpeconf1(tcg_env
, arg
);
7584 register_name
= "VPEConf1";
7586 case CP0_REG01__YQMASK
:
7587 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7588 gen_helper_mtc0_yqmask(tcg_env
, arg
);
7589 register_name
= "YQMask";
7591 case CP0_REG01__VPESCHEDULE
:
7592 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7593 tcg_gen_st_tl(arg
, tcg_env
,
7594 offsetof(CPUMIPSState
, CP0_VPESchedule
));
7595 register_name
= "VPESchedule";
7597 case CP0_REG01__VPESCHEFBACK
:
7598 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7599 tcg_gen_st_tl(arg
, tcg_env
,
7600 offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
7601 register_name
= "VPEScheFBack";
7603 case CP0_REG01__VPEOPT
:
7604 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7605 gen_helper_mtc0_vpeopt(tcg_env
, arg
);
7606 register_name
= "VPEOpt";
7609 goto cp0_unimplemented
;
7612 case CP0_REGISTER_02
:
7614 case CP0_REG02__ENTRYLO0
:
7615 gen_helper_dmtc0_entrylo0(tcg_env
, arg
);
7616 register_name
= "EntryLo0";
7618 case CP0_REG02__TCSTATUS
:
7619 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7620 gen_helper_mtc0_tcstatus(tcg_env
, arg
);
7621 register_name
= "TCStatus";
7623 case CP0_REG02__TCBIND
:
7624 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7625 gen_helper_mtc0_tcbind(tcg_env
, arg
);
7626 register_name
= "TCBind";
7628 case CP0_REG02__TCRESTART
:
7629 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7630 gen_helper_mtc0_tcrestart(tcg_env
, arg
);
7631 register_name
= "TCRestart";
7633 case CP0_REG02__TCHALT
:
7634 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7635 gen_helper_mtc0_tchalt(tcg_env
, arg
);
7636 register_name
= "TCHalt";
7638 case CP0_REG02__TCCONTEXT
:
7639 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7640 gen_helper_mtc0_tccontext(tcg_env
, arg
);
7641 register_name
= "TCContext";
7643 case CP0_REG02__TCSCHEDULE
:
7644 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7645 gen_helper_mtc0_tcschedule(tcg_env
, arg
);
7646 register_name
= "TCSchedule";
7648 case CP0_REG02__TCSCHEFBACK
:
7649 CP0_CHECK(ctx
->insn_flags
& ASE_MT
);
7650 gen_helper_mtc0_tcschefback(tcg_env
, arg
);
7651 register_name
= "TCScheFBack";
7654 goto cp0_unimplemented
;
7657 case CP0_REGISTER_03
:
7659 case CP0_REG03__ENTRYLO1
:
7660 gen_helper_dmtc0_entrylo1(tcg_env
, arg
);
7661 register_name
= "EntryLo1";
7663 case CP0_REG03__GLOBALNUM
:
7666 register_name
= "GlobalNumber";
7669 goto cp0_unimplemented
;
7672 case CP0_REGISTER_04
:
7674 case CP0_REG04__CONTEXT
:
7675 gen_helper_mtc0_context(tcg_env
, arg
);
7676 register_name
= "Context";
7678 case CP0_REG04__CONTEXTCONFIG
:
7680 /* gen_helper_dmtc0_contextconfig(arg); */
7681 register_name
= "ContextConfig";
7682 goto cp0_unimplemented
;
7683 case CP0_REG04__USERLOCAL
:
7684 CP0_CHECK(ctx
->ulri
);
7685 tcg_gen_st_tl(arg
, tcg_env
,
7686 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
7687 register_name
= "UserLocal";
7689 case CP0_REG04__MMID
:
7691 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_MemoryMapID
));
7692 register_name
= "MMID";
7695 goto cp0_unimplemented
;
7698 case CP0_REGISTER_05
:
7700 case CP0_REG05__PAGEMASK
:
7701 gen_helper_mtc0_pagemask(tcg_env
, arg
);
7702 register_name
= "PageMask";
7704 case CP0_REG05__PAGEGRAIN
:
7705 check_insn(ctx
, ISA_MIPS_R2
);
7706 gen_helper_mtc0_pagegrain(tcg_env
, arg
);
7707 register_name
= "PageGrain";
7709 case CP0_REG05__SEGCTL0
:
7711 gen_helper_mtc0_segctl0(tcg_env
, arg
);
7712 register_name
= "SegCtl0";
7714 case CP0_REG05__SEGCTL1
:
7716 gen_helper_mtc0_segctl1(tcg_env
, arg
);
7717 register_name
= "SegCtl1";
7719 case CP0_REG05__SEGCTL2
:
7721 gen_helper_mtc0_segctl2(tcg_env
, arg
);
7722 register_name
= "SegCtl2";
7724 case CP0_REG05__PWBASE
:
7726 tcg_gen_st_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_PWBase
));
7727 register_name
= "PWBase";
7729 case CP0_REG05__PWFIELD
:
7731 gen_helper_mtc0_pwfield(tcg_env
, arg
);
7732 register_name
= "PWField";
7734 case CP0_REG05__PWSIZE
:
7736 gen_helper_mtc0_pwsize(tcg_env
, arg
);
7737 register_name
= "PWSize";
7740 goto cp0_unimplemented
;
7743 case CP0_REGISTER_06
:
7745 case CP0_REG06__WIRED
:
7746 gen_helper_mtc0_wired(tcg_env
, arg
);
7747 register_name
= "Wired";
7749 case CP0_REG06__SRSCONF0
:
7750 check_insn(ctx
, ISA_MIPS_R2
);
7751 gen_helper_mtc0_srsconf0(tcg_env
, arg
);
7752 register_name
= "SRSConf0";
7754 case CP0_REG06__SRSCONF1
:
7755 check_insn(ctx
, ISA_MIPS_R2
);
7756 gen_helper_mtc0_srsconf1(tcg_env
, arg
);
7757 register_name
= "SRSConf1";
7759 case CP0_REG06__SRSCONF2
:
7760 check_insn(ctx
, ISA_MIPS_R2
);
7761 gen_helper_mtc0_srsconf2(tcg_env
, arg
);
7762 register_name
= "SRSConf2";
7764 case CP0_REG06__SRSCONF3
:
7765 check_insn(ctx
, ISA_MIPS_R2
);
7766 gen_helper_mtc0_srsconf3(tcg_env
, arg
);
7767 register_name
= "SRSConf3";
7769 case CP0_REG06__SRSCONF4
:
7770 check_insn(ctx
, ISA_MIPS_R2
);
7771 gen_helper_mtc0_srsconf4(tcg_env
, arg
);
7772 register_name
= "SRSConf4";
7774 case CP0_REG06__PWCTL
:
7776 gen_helper_mtc0_pwctl(tcg_env
, arg
);
7777 register_name
= "PWCtl";
7780 goto cp0_unimplemented
;
7783 case CP0_REGISTER_07
:
7785 case CP0_REG07__HWRENA
:
7786 check_insn(ctx
, ISA_MIPS_R2
);
7787 gen_helper_mtc0_hwrena(tcg_env
, arg
);
7788 ctx
->base
.is_jmp
= DISAS_STOP
;
7789 register_name
= "HWREna";
7792 goto cp0_unimplemented
;
7795 case CP0_REGISTER_08
:
7797 case CP0_REG08__BADVADDR
:
7799 register_name
= "BadVAddr";
7801 case CP0_REG08__BADINSTR
:
7803 register_name
= "BadInstr";
7805 case CP0_REG08__BADINSTRP
:
7807 register_name
= "BadInstrP";
7809 case CP0_REG08__BADINSTRX
:
7811 register_name
= "BadInstrX";
7814 goto cp0_unimplemented
;
7817 case CP0_REGISTER_09
:
7819 case CP0_REG09__COUNT
:
7820 gen_helper_mtc0_count(tcg_env
, arg
);
7821 register_name
= "Count";
7824 goto cp0_unimplemented
;
7826 /* Stop translation as we may have switched the execution mode */
7827 ctx
->base
.is_jmp
= DISAS_STOP
;
7829 case CP0_REGISTER_10
:
7831 case CP0_REG10__ENTRYHI
:
7832 gen_helper_mtc0_entryhi(tcg_env
, arg
);
7833 register_name
= "EntryHi";
7836 goto cp0_unimplemented
;
7839 case CP0_REGISTER_11
:
7841 case CP0_REG11__COMPARE
:
7842 gen_helper_mtc0_compare(tcg_env
, arg
);
7843 register_name
= "Compare";
7845 /* 6,7 are implementation dependent */
7847 goto cp0_unimplemented
;
7849 /* Stop translation as we may have switched the execution mode */
7850 ctx
->base
.is_jmp
= DISAS_STOP
;
7852 case CP0_REGISTER_12
:
7854 case CP0_REG12__STATUS
:
7855 save_cpu_state(ctx
, 1);
7856 gen_helper_mtc0_status(tcg_env
, arg
);
7857 /* DISAS_STOP isn't good enough here, hflags may have changed. */
7858 gen_save_pc(ctx
->base
.pc_next
+ 4);
7859 ctx
->base
.is_jmp
= DISAS_EXIT
;
7860 register_name
= "Status";
7862 case CP0_REG12__INTCTL
:
7863 check_insn(ctx
, ISA_MIPS_R2
);
7864 gen_helper_mtc0_intctl(tcg_env
, arg
);
7865 /* Stop translation as we may have switched the execution mode */
7866 ctx
->base
.is_jmp
= DISAS_STOP
;
7867 register_name
= "IntCtl";
7869 case CP0_REG12__SRSCTL
:
7870 check_insn(ctx
, ISA_MIPS_R2
);
7871 gen_helper_mtc0_srsctl(tcg_env
, arg
);
7872 /* Stop translation as we may have switched the execution mode */
7873 ctx
->base
.is_jmp
= DISAS_STOP
;
7874 register_name
= "SRSCtl";
7876 case CP0_REG12__SRSMAP
:
7877 check_insn(ctx
, ISA_MIPS_R2
);
7878 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
7879 /* Stop translation as we may have switched the execution mode */
7880 ctx
->base
.is_jmp
= DISAS_STOP
;
7881 register_name
= "SRSMap";
7884 goto cp0_unimplemented
;
7887 case CP0_REGISTER_13
:
7889 case CP0_REG13__CAUSE
:
7890 save_cpu_state(ctx
, 1);
7891 gen_helper_mtc0_cause(tcg_env
, arg
);
7893 * Stop translation as we may have triggered an interrupt.
7894 * DISAS_STOP isn't sufficient, we need to ensure we break out of
7895 * translated code to check for pending interrupts.
7897 gen_save_pc(ctx
->base
.pc_next
+ 4);
7898 ctx
->base
.is_jmp
= DISAS_EXIT
;
7899 register_name
= "Cause";
7902 goto cp0_unimplemented
;
7905 case CP0_REGISTER_14
:
7907 case CP0_REG14__EPC
:
7908 tcg_gen_st_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_EPC
));
7909 register_name
= "EPC";
7912 goto cp0_unimplemented
;
7915 case CP0_REGISTER_15
:
7917 case CP0_REG15__PRID
:
7919 register_name
= "PRid";
7921 case CP0_REG15__EBASE
:
7922 check_insn(ctx
, ISA_MIPS_R2
);
7923 gen_helper_mtc0_ebase(tcg_env
, arg
);
7924 register_name
= "EBase";
7927 goto cp0_unimplemented
;
7930 case CP0_REGISTER_16
:
7932 case CP0_REG16__CONFIG
:
7933 gen_helper_mtc0_config0(tcg_env
, arg
);
7934 register_name
= "Config";
7935 /* Stop translation as we may have switched the execution mode */
7936 ctx
->base
.is_jmp
= DISAS_STOP
;
7938 case CP0_REG16__CONFIG1
:
7939 /* ignored, read only */
7940 register_name
= "Config1";
7942 case CP0_REG16__CONFIG2
:
7943 gen_helper_mtc0_config2(tcg_env
, arg
);
7944 register_name
= "Config2";
7945 /* Stop translation as we may have switched the execution mode */
7946 ctx
->base
.is_jmp
= DISAS_STOP
;
7948 case CP0_REG16__CONFIG3
:
7949 gen_helper_mtc0_config3(tcg_env
, arg
);
7950 register_name
= "Config3";
7951 /* Stop translation as we may have switched the execution mode */
7952 ctx
->base
.is_jmp
= DISAS_STOP
;
7954 case CP0_REG16__CONFIG4
:
7955 /* currently ignored */
7956 register_name
= "Config4";
7958 case CP0_REG16__CONFIG5
:
7959 gen_helper_mtc0_config5(tcg_env
, arg
);
7960 register_name
= "Config5";
7961 /* Stop translation as we may have switched the execution mode */
7962 ctx
->base
.is_jmp
= DISAS_STOP
;
7964 /* 6,7 are implementation dependent */
7966 register_name
= "Invalid config selector";
7967 goto cp0_unimplemented
;
7970 case CP0_REGISTER_17
:
7972 case CP0_REG17__LLADDR
:
7973 gen_helper_mtc0_lladdr(tcg_env
, arg
);
7974 register_name
= "LLAddr";
7976 case CP0_REG17__MAAR
:
7977 CP0_CHECK(ctx
->mrp
);
7978 gen_helper_mtc0_maar(tcg_env
, arg
);
7979 register_name
= "MAAR";
7981 case CP0_REG17__MAARI
:
7982 CP0_CHECK(ctx
->mrp
);
7983 gen_helper_mtc0_maari(tcg_env
, arg
);
7984 register_name
= "MAARI";
7987 goto cp0_unimplemented
;
7990 case CP0_REGISTER_18
:
7992 case CP0_REG18__WATCHLO0
:
7993 case CP0_REG18__WATCHLO1
:
7994 case CP0_REG18__WATCHLO2
:
7995 case CP0_REG18__WATCHLO3
:
7996 case CP0_REG18__WATCHLO4
:
7997 case CP0_REG18__WATCHLO5
:
7998 case CP0_REG18__WATCHLO6
:
7999 case CP0_REG18__WATCHLO7
:
8000 CP0_CHECK(ctx
->CP0_Config1
& (1 << CP0C1_WR
));
8001 gen_helper_0e1i(mtc0_watchlo
, arg
, sel
);
8002 register_name
= "WatchLo";
8005 goto cp0_unimplemented
;
8008 case CP0_REGISTER_19
:
8010 case CP0_REG19__WATCHHI0
:
8011 case CP0_REG19__WATCHHI1
:
8012 case CP0_REG19__WATCHHI2
:
8013 case CP0_REG19__WATCHHI3
:
8014 case CP0_REG19__WATCHHI4
:
8015 case CP0_REG19__WATCHHI5
:
8016 case CP0_REG19__WATCHHI6
:
8017 case CP0_REG19__WATCHHI7
:
8018 CP0_CHECK(ctx
->CP0_Config1
& (1 << CP0C1_WR
));
8019 gen_helper_0e1i(mtc0_watchhi
, arg
, sel
);
8020 register_name
= "WatchHi";
8023 goto cp0_unimplemented
;
8026 case CP0_REGISTER_20
:
8028 case CP0_REG20__XCONTEXT
:
8029 check_insn(ctx
, ISA_MIPS3
);
8030 gen_helper_mtc0_xcontext(tcg_env
, arg
);
8031 register_name
= "XContext";
8034 goto cp0_unimplemented
;
8037 case CP0_REGISTER_21
:
8038 /* Officially reserved, but sel 0 is used for R1x000 framemask */
8039 CP0_CHECK(!(ctx
->insn_flags
& ISA_MIPS_R6
));
8042 gen_helper_mtc0_framemask(tcg_env
, arg
);
8043 register_name
= "Framemask";
8046 goto cp0_unimplemented
;
8049 case CP0_REGISTER_22
:
8051 register_name
= "Diagnostic"; /* implementation dependent */
8053 case CP0_REGISTER_23
:
8055 case CP0_REG23__DEBUG
:
8056 gen_helper_mtc0_debug(tcg_env
, arg
); /* EJTAG support */
8057 /* DISAS_STOP isn't good enough here, hflags may have changed. */
8058 gen_save_pc(ctx
->base
.pc_next
+ 4);
8059 ctx
->base
.is_jmp
= DISAS_EXIT
;
8060 register_name
= "Debug";
8062 case CP0_REG23__TRACECONTROL
:
8063 /* PDtrace support */
8064 /* gen_helper_mtc0_tracecontrol(tcg_env, arg); */
8065 /* Stop translation as we may have switched the execution mode */
8066 ctx
->base
.is_jmp
= DISAS_STOP
;
8067 register_name
= "TraceControl";
8068 goto cp0_unimplemented
;
8069 case CP0_REG23__TRACECONTROL2
:
8070 /* PDtrace support */
8071 /* gen_helper_mtc0_tracecontrol2(tcg_env, arg); */
8072 /* Stop translation as we may have switched the execution mode */
8073 ctx
->base
.is_jmp
= DISAS_STOP
;
8074 register_name
= "TraceControl2";
8075 goto cp0_unimplemented
;
8076 case CP0_REG23__USERTRACEDATA1
:
8077 /* PDtrace support */
8078 /* gen_helper_mtc0_usertracedata1(tcg_env, arg);*/
8079 /* Stop translation as we may have switched the execution mode */
8080 ctx
->base
.is_jmp
= DISAS_STOP
;
8081 register_name
= "UserTraceData1";
8082 goto cp0_unimplemented
;
8083 case CP0_REG23__TRACEIBPC
:
8084 /* PDtrace support */
8085 /* gen_helper_mtc0_traceibpc(tcg_env, arg); */
8086 /* Stop translation as we may have switched the execution mode */
8087 ctx
->base
.is_jmp
= DISAS_STOP
;
8088 register_name
= "TraceIBPC";
8089 goto cp0_unimplemented
;
8090 case CP0_REG23__TRACEDBPC
:
8091 /* PDtrace support */
8092 /* gen_helper_mtc0_tracedbpc(tcg_env, arg); */
8093 /* Stop translation as we may have switched the execution mode */
8094 ctx
->base
.is_jmp
= DISAS_STOP
;
8095 register_name
= "TraceDBPC";
8096 goto cp0_unimplemented
;
8098 goto cp0_unimplemented
;
8101 case CP0_REGISTER_24
:
8103 case CP0_REG24__DEPC
:
8105 tcg_gen_st_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
8106 register_name
= "DEPC";
8109 goto cp0_unimplemented
;
8112 case CP0_REGISTER_25
:
8114 case CP0_REG25__PERFCTL0
:
8115 gen_helper_mtc0_performance0(tcg_env
, arg
);
8116 register_name
= "Performance0";
8118 case CP0_REG25__PERFCNT0
:
8119 /* gen_helper_mtc0_performance1(tcg_env, arg); */
8120 register_name
= "Performance1";
8121 goto cp0_unimplemented
;
8122 case CP0_REG25__PERFCTL1
:
8123 /* gen_helper_mtc0_performance2(tcg_env, arg); */
8124 register_name
= "Performance2";
8125 goto cp0_unimplemented
;
8126 case CP0_REG25__PERFCNT1
:
8127 /* gen_helper_mtc0_performance3(tcg_env, arg); */
8128 register_name
= "Performance3";
8129 goto cp0_unimplemented
;
8130 case CP0_REG25__PERFCTL2
:
8131 /* gen_helper_mtc0_performance4(tcg_env, arg); */
8132 register_name
= "Performance4";
8133 goto cp0_unimplemented
;
8134 case CP0_REG25__PERFCNT2
:
8135 /* gen_helper_mtc0_performance5(tcg_env, arg); */
8136 register_name
= "Performance5";
8137 goto cp0_unimplemented
;
8138 case CP0_REG25__PERFCTL3
:
8139 /* gen_helper_mtc0_performance6(tcg_env, arg); */
8140 register_name
= "Performance6";
8141 goto cp0_unimplemented
;
8142 case CP0_REG25__PERFCNT3
:
8143 /* gen_helper_mtc0_performance7(tcg_env, arg); */
8144 register_name
= "Performance7";
8145 goto cp0_unimplemented
;
8147 goto cp0_unimplemented
;
8150 case CP0_REGISTER_26
:
8152 case CP0_REG26__ERRCTL
:
8153 gen_helper_mtc0_errctl(tcg_env
, arg
);
8154 ctx
->base
.is_jmp
= DISAS_STOP
;
8155 register_name
= "ErrCtl";
8158 goto cp0_unimplemented
;
8161 case CP0_REGISTER_27
:
8163 case CP0_REG27__CACHERR
:
8165 register_name
= "CacheErr";
8168 goto cp0_unimplemented
;
8171 case CP0_REGISTER_28
:
8173 case CP0_REG28__TAGLO
:
8174 case CP0_REG28__TAGLO1
:
8175 case CP0_REG28__TAGLO2
:
8176 case CP0_REG28__TAGLO3
:
8177 gen_helper_mtc0_taglo(tcg_env
, arg
);
8178 register_name
= "TagLo";
8180 case CP0_REG28__DATALO
:
8181 case CP0_REG28__DATALO1
:
8182 case CP0_REG28__DATALO2
:
8183 case CP0_REG28__DATALO3
:
8184 gen_helper_mtc0_datalo(tcg_env
, arg
);
8185 register_name
= "DataLo";
8188 goto cp0_unimplemented
;
8191 case CP0_REGISTER_29
:
8193 case CP0_REG29__TAGHI
:
8194 case CP0_REG29__TAGHI1
:
8195 case CP0_REG29__TAGHI2
:
8196 case CP0_REG29__TAGHI3
:
8197 gen_helper_mtc0_taghi(tcg_env
, arg
);
8198 register_name
= "TagHi";
8200 case CP0_REG29__DATAHI
:
8201 case CP0_REG29__DATAHI1
:
8202 case CP0_REG29__DATAHI2
:
8203 case CP0_REG29__DATAHI3
:
8204 gen_helper_mtc0_datahi(tcg_env
, arg
);
8205 register_name
= "DataHi";
8208 register_name
= "invalid sel";
8209 goto cp0_unimplemented
;
8212 case CP0_REGISTER_30
:
8214 case CP0_REG30__ERROREPC
:
8215 tcg_gen_st_tl(arg
, tcg_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
8216 register_name
= "ErrorEPC";
8219 goto cp0_unimplemented
;
8222 case CP0_REGISTER_31
:
8224 case CP0_REG31__DESAVE
:
8226 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
8227 register_name
= "DESAVE";
8229 case CP0_REG31__KSCRATCH1
:
8230 case CP0_REG31__KSCRATCH2
:
8231 case CP0_REG31__KSCRATCH3
:
8232 case CP0_REG31__KSCRATCH4
:
8233 case CP0_REG31__KSCRATCH5
:
8234 case CP0_REG31__KSCRATCH6
:
8235 CP0_CHECK(ctx
->kscrexist
& (1 << sel
));
8236 tcg_gen_st_tl(arg
, tcg_env
,
8237 offsetof(CPUMIPSState
, CP0_KScratch
[sel
- 2]));
8238 register_name
= "KScratch";
8241 goto cp0_unimplemented
;
8245 goto cp0_unimplemented
;
8247 trace_mips_translate_c0("dmtc0", register_name
, reg
, sel
);
8249 /* For simplicity assume that all writes can cause interrupts. */
8252 * DISAS_STOP isn't sufficient, we need to ensure we break out of
8253 * translated code to check for pending interrupts.
8255 gen_save_pc(ctx
->base
.pc_next
+ 4);
8256 ctx
->base
.is_jmp
= DISAS_EXIT
;
8261 qemu_log_mask(LOG_UNIMP
, "dmtc0 %s (reg %d sel %d)\n",
8262 register_name
, reg
, sel
);
8264 #endif /* TARGET_MIPS64 */
8266 static void gen_mftr(CPUMIPSState
*env
, DisasContext
*ctx
, int rt
, int rd
,
8267 int u
, int sel
, int h
)
8269 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
8270 TCGv t0
= tcg_temp_new();
8272 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
8273 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
8274 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)))) {
8275 tcg_gen_movi_tl(t0
, -1);
8276 } else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
8277 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
))) {
8278 tcg_gen_movi_tl(t0
, -1);
8279 } else if (u
== 0) {
8284 gen_helper_mftc0_vpecontrol(t0
, tcg_env
);
8287 gen_helper_mftc0_vpeconf0(t0
, tcg_env
);
8297 gen_helper_mftc0_tcstatus(t0
, tcg_env
);
8300 gen_helper_mftc0_tcbind(t0
, tcg_env
);
8303 gen_helper_mftc0_tcrestart(t0
, tcg_env
);
8306 gen_helper_mftc0_tchalt(t0
, tcg_env
);
8309 gen_helper_mftc0_tccontext(t0
, tcg_env
);
8312 gen_helper_mftc0_tcschedule(t0
, tcg_env
);
8315 gen_helper_mftc0_tcschefback(t0
, tcg_env
);
8318 gen_mfc0(ctx
, t0
, rt
, sel
);
8325 gen_helper_mftc0_entryhi(t0
, tcg_env
);
8328 gen_mfc0(ctx
, t0
, rt
, sel
);
8335 gen_helper_mftc0_status(t0
, tcg_env
);
8338 gen_mfc0(ctx
, t0
, rt
, sel
);
8345 gen_helper_mftc0_cause(t0
, tcg_env
);
8355 gen_helper_mftc0_epc(t0
, tcg_env
);
8365 gen_helper_mftc0_ebase(t0
, tcg_env
);
8382 gen_helper_mftc0_configx(t0
, tcg_env
, tcg_constant_tl(sel
));
8392 gen_helper_mftc0_debug(t0
, tcg_env
);
8395 gen_mfc0(ctx
, t0
, rt
, sel
);
8400 gen_mfc0(ctx
, t0
, rt
, sel
);
8404 /* GPR registers. */
8406 gen_helper_1e0i(mftgpr
, t0
, rt
);
8408 /* Auxiliary CPU registers */
8412 gen_helper_1e0i(mftlo
, t0
, 0);
8415 gen_helper_1e0i(mfthi
, t0
, 0);
8418 gen_helper_1e0i(mftacx
, t0
, 0);
8421 gen_helper_1e0i(mftlo
, t0
, 1);
8424 gen_helper_1e0i(mfthi
, t0
, 1);
8427 gen_helper_1e0i(mftacx
, t0
, 1);
8430 gen_helper_1e0i(mftlo
, t0
, 2);
8433 gen_helper_1e0i(mfthi
, t0
, 2);
8436 gen_helper_1e0i(mftacx
, t0
, 2);
8439 gen_helper_1e0i(mftlo
, t0
, 3);
8442 gen_helper_1e0i(mfthi
, t0
, 3);
8445 gen_helper_1e0i(mftacx
, t0
, 3);
8448 gen_helper_mftdsp(t0
, tcg_env
);
8454 /* Floating point (COP1). */
8456 /* XXX: For now we support only a single FPU context. */
8458 TCGv_i32 fp0
= tcg_temp_new_i32();
8460 gen_load_fpr32(ctx
, fp0
, rt
);
8461 tcg_gen_ext_i32_tl(t0
, fp0
);
8463 TCGv_i32 fp0
= tcg_temp_new_i32();
8465 gen_load_fpr32h(ctx
, fp0
, rt
);
8466 tcg_gen_ext_i32_tl(t0
, fp0
);
8470 /* XXX: For now we support only a single FPU context. */
8471 gen_helper_1e0i(cfc1
, t0
, rt
);
8473 /* COP2: Not implemented. */
8481 trace_mips_translate_tr("mftr", rt
, u
, sel
, h
);
8482 gen_store_gpr(t0
, rd
);
8486 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
8487 gen_reserved_instruction(ctx
);
8490 static void gen_mttr(CPUMIPSState
*env
, DisasContext
*ctx
, int rd
, int rt
,
8491 int u
, int sel
, int h
)
8493 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
8494 TCGv t0
= tcg_temp_new();
8496 gen_load_gpr(t0
, rt
);
8497 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
8498 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
8499 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)))) {
8502 } else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
8503 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
))) {
8506 } else if (u
== 0) {
8511 gen_helper_mttc0_vpecontrol(tcg_env
, t0
);
8514 gen_helper_mttc0_vpeconf0(tcg_env
, t0
);
8524 gen_helper_mttc0_tcstatus(tcg_env
, t0
);
8527 gen_helper_mttc0_tcbind(tcg_env
, t0
);
8530 gen_helper_mttc0_tcrestart(tcg_env
, t0
);
8533 gen_helper_mttc0_tchalt(tcg_env
, t0
);
8536 gen_helper_mttc0_tccontext(tcg_env
, t0
);
8539 gen_helper_mttc0_tcschedule(tcg_env
, t0
);
8542 gen_helper_mttc0_tcschefback(tcg_env
, t0
);
8545 gen_mtc0(ctx
, t0
, rd
, sel
);
8552 gen_helper_mttc0_entryhi(tcg_env
, t0
);
8555 gen_mtc0(ctx
, t0
, rd
, sel
);
8562 gen_helper_mttc0_status(tcg_env
, t0
);
8565 gen_mtc0(ctx
, t0
, rd
, sel
);
8572 gen_helper_mttc0_cause(tcg_env
, t0
);
8582 gen_helper_mttc0_ebase(tcg_env
, t0
);
8592 gen_helper_mttc0_debug(tcg_env
, t0
);
8595 gen_mtc0(ctx
, t0
, rd
, sel
);
8600 gen_mtc0(ctx
, t0
, rd
, sel
);
8604 /* GPR registers. */
8606 gen_helper_0e1i(mttgpr
, t0
, rd
);
8608 /* Auxiliary CPU registers */
8612 gen_helper_0e1i(mttlo
, t0
, 0);
8615 gen_helper_0e1i(mtthi
, t0
, 0);
8618 gen_helper_0e1i(mttacx
, t0
, 0);
8621 gen_helper_0e1i(mttlo
, t0
, 1);
8624 gen_helper_0e1i(mtthi
, t0
, 1);
8627 gen_helper_0e1i(mttacx
, t0
, 1);
8630 gen_helper_0e1i(mttlo
, t0
, 2);
8633 gen_helper_0e1i(mtthi
, t0
, 2);
8636 gen_helper_0e1i(mttacx
, t0
, 2);
8639 gen_helper_0e1i(mttlo
, t0
, 3);
8642 gen_helper_0e1i(mtthi
, t0
, 3);
8645 gen_helper_0e1i(mttacx
, t0
, 3);
8648 gen_helper_mttdsp(tcg_env
, t0
);
8654 /* Floating point (COP1). */
8656 /* XXX: For now we support only a single FPU context. */
8658 TCGv_i32 fp0
= tcg_temp_new_i32();
8660 tcg_gen_trunc_tl_i32(fp0
, t0
);
8661 gen_store_fpr32(ctx
, fp0
, rd
);
8663 TCGv_i32 fp0
= tcg_temp_new_i32();
8665 tcg_gen_trunc_tl_i32(fp0
, t0
);
8666 gen_store_fpr32h(ctx
, fp0
, rd
);
8670 /* XXX: For now we support only a single FPU context. */
8671 gen_helper_0e2i(ctc1
, t0
, tcg_constant_i32(rd
), rt
);
8672 /* Stop translation as we may have changed hflags */
8673 ctx
->base
.is_jmp
= DISAS_STOP
;
8675 /* COP2: Not implemented. */
8683 trace_mips_translate_tr("mttr", rd
, u
, sel
, h
);
8687 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
8688 gen_reserved_instruction(ctx
);
8691 static void gen_cp0(CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t opc
,
8694 const char *opn
= "ldst";
8696 check_cp0_enabled(ctx
);
8703 gen_mfc0(ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
8708 TCGv t0
= tcg_temp_new();
8710 gen_load_gpr(t0
, rt
);
8711 gen_mtc0(ctx
, t0
, rd
, ctx
->opcode
& 0x7);
8715 #if defined(TARGET_MIPS64)
8717 check_insn(ctx
, ISA_MIPS3
);
8722 gen_dmfc0(ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
8726 check_insn(ctx
, ISA_MIPS3
);
8728 TCGv t0
= tcg_temp_new();
8730 gen_load_gpr(t0
, rt
);
8731 gen_dmtc0(ctx
, t0
, rd
, ctx
->opcode
& 0x7);
8742 gen_mfhc0(ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
8748 TCGv t0
= tcg_temp_new();
8749 gen_load_gpr(t0
, rt
);
8750 gen_mthc0(ctx
, t0
, rd
, ctx
->opcode
& 0x7);
8755 check_cp0_enabled(ctx
);
8760 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
8761 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
8765 check_cp0_enabled(ctx
);
8766 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
8767 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
8772 if (!env
->tlb
->helper_tlbwi
) {
8775 gen_helper_tlbwi(tcg_env
);
8780 if (!env
->tlb
->helper_tlbinv
) {
8783 gen_helper_tlbinv(tcg_env
);
8784 } /* treat as nop if TLBINV not supported */
8789 if (!env
->tlb
->helper_tlbinvf
) {
8792 gen_helper_tlbinvf(tcg_env
);
8793 } /* treat as nop if TLBINV not supported */
8797 if (!env
->tlb
->helper_tlbwr
) {
8800 gen_helper_tlbwr(tcg_env
);
8804 if (!env
->tlb
->helper_tlbp
) {
8807 gen_helper_tlbp(tcg_env
);
8811 if (!env
->tlb
->helper_tlbr
) {
8814 gen_helper_tlbr(tcg_env
);
8816 case OPC_ERET
: /* OPC_ERETNC */
8817 if ((ctx
->insn_flags
& ISA_MIPS_R6
) &&
8818 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8821 int bit_shift
= (ctx
->hflags
& MIPS_HFLAG_M16
) ? 16 : 6;
8822 if (ctx
->opcode
& (1 << bit_shift
)) {
8825 check_insn(ctx
, ISA_MIPS_R5
);
8826 gen_helper_eretnc(tcg_env
);
8830 check_insn(ctx
, ISA_MIPS2
);
8831 gen_helper_eret(tcg_env
);
8833 ctx
->base
.is_jmp
= DISAS_EXIT
;
8838 check_insn(ctx
, ISA_MIPS_R1
);
8839 if ((ctx
->insn_flags
& ISA_MIPS_R6
) &&
8840 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8843 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8845 gen_reserved_instruction(ctx
);
8847 gen_helper_deret(tcg_env
);
8848 ctx
->base
.is_jmp
= DISAS_EXIT
;
8853 check_insn(ctx
, ISA_MIPS3
| ISA_MIPS_R1
);
8854 if ((ctx
->insn_flags
& ISA_MIPS_R6
) &&
8855 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8858 /* If we get an exception, we want to restart at next instruction */
8859 ctx
->base
.pc_next
+= 4;
8860 save_cpu_state(ctx
, 1);
8861 ctx
->base
.pc_next
-= 4;
8862 gen_helper_wait(tcg_env
);
8863 ctx
->base
.is_jmp
= DISAS_NORETURN
;
8868 gen_reserved_instruction(ctx
);
8871 (void)opn
; /* avoid a compiler warning */
8873 #endif /* !CONFIG_USER_ONLY */
8875 /* CP1 Branches (before delay slot) */
8876 static void gen_compute_branch1(DisasContext
*ctx
, uint32_t op
,
8877 int32_t cc
, int32_t offset
)
8879 target_ulong btarget
;
8880 TCGv_i32 t0
= tcg_temp_new_i32();
8882 if ((ctx
->insn_flags
& ISA_MIPS_R6
) && (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8883 gen_reserved_instruction(ctx
);
8888 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS_R1
);
8891 btarget
= ctx
->base
.pc_next
+ 4 + offset
;
8895 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8896 tcg_gen_not_i32(t0
, t0
);
8897 tcg_gen_andi_i32(t0
, t0
, 1);
8898 tcg_gen_extu_i32_tl(bcond
, t0
);
8901 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8902 tcg_gen_not_i32(t0
, t0
);
8903 tcg_gen_andi_i32(t0
, t0
, 1);
8904 tcg_gen_extu_i32_tl(bcond
, t0
);
8907 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8908 tcg_gen_andi_i32(t0
, t0
, 1);
8909 tcg_gen_extu_i32_tl(bcond
, t0
);
8912 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8913 tcg_gen_andi_i32(t0
, t0
, 1);
8914 tcg_gen_extu_i32_tl(bcond
, t0
);
8916 ctx
->hflags
|= MIPS_HFLAG_BL
;
8920 TCGv_i32 t1
= tcg_temp_new_i32();
8921 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8922 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+ 1));
8923 tcg_gen_nand_i32(t0
, t0
, t1
);
8924 tcg_gen_andi_i32(t0
, t0
, 1);
8925 tcg_gen_extu_i32_tl(bcond
, t0
);
8930 TCGv_i32 t1
= tcg_temp_new_i32();
8931 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8932 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+ 1));
8933 tcg_gen_or_i32(t0
, t0
, t1
);
8934 tcg_gen_andi_i32(t0
, t0
, 1);
8935 tcg_gen_extu_i32_tl(bcond
, t0
);
8940 TCGv_i32 t1
= tcg_temp_new_i32();
8941 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8942 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+ 1));
8943 tcg_gen_and_i32(t0
, t0
, t1
);
8944 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+ 2));
8945 tcg_gen_and_i32(t0
, t0
, t1
);
8946 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+ 3));
8947 tcg_gen_nand_i32(t0
, t0
, t1
);
8948 tcg_gen_andi_i32(t0
, t0
, 1);
8949 tcg_gen_extu_i32_tl(bcond
, t0
);
8954 TCGv_i32 t1
= tcg_temp_new_i32();
8955 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
8956 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+ 1));
8957 tcg_gen_or_i32(t0
, t0
, t1
);
8958 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+ 2));
8959 tcg_gen_or_i32(t0
, t0
, t1
);
8960 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+ 3));
8961 tcg_gen_or_i32(t0
, t0
, t1
);
8962 tcg_gen_andi_i32(t0
, t0
, 1);
8963 tcg_gen_extu_i32_tl(bcond
, t0
);
8966 ctx
->hflags
|= MIPS_HFLAG_BC
;
8969 MIPS_INVAL("cp1 cond branch");
8970 gen_reserved_instruction(ctx
);
8973 ctx
->btarget
= btarget
;
8974 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
8977 /* R6 CP1 Branches */
8978 static void gen_compute_branch1_r6(DisasContext
*ctx
, uint32_t op
,
8979 int32_t ft
, int32_t offset
,
8982 target_ulong btarget
;
8983 TCGv_i64 t0
= tcg_temp_new_i64();
8985 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8986 #ifdef MIPS_DEBUG_DISAS
8987 LOG_DISAS("Branch in delay / forbidden slot at PC 0x%016"
8988 VADDR_PRIx
"\n", ctx
->base
.pc_next
);
8990 gen_reserved_instruction(ctx
);
8994 gen_load_fpr64(ctx
, t0
, ft
);
8995 tcg_gen_andi_i64(t0
, t0
, 1);
8997 btarget
= addr_add(ctx
, ctx
->base
.pc_next
+ 4, offset
);
9001 tcg_gen_xori_i64(t0
, t0
, 1);
9002 ctx
->hflags
|= MIPS_HFLAG_BC
;
9005 /* t0 already set */
9006 ctx
->hflags
|= MIPS_HFLAG_BC
;
9009 MIPS_INVAL("cp1 cond branch");
9010 gen_reserved_instruction(ctx
);
9014 tcg_gen_trunc_i64_tl(bcond
, t0
);
9016 ctx
->btarget
= btarget
;
9018 switch (delayslot_size
) {
9020 ctx
->hflags
|= MIPS_HFLAG_BDS16
;
9023 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
9028 /* Coprocessor 1 (FPU) */
9030 #define FOP(func, fmt) (((fmt) << 21) | (func))
9033 OPC_ADD_S
= FOP(0, FMT_S
),
9034 OPC_SUB_S
= FOP(1, FMT_S
),
9035 OPC_MUL_S
= FOP(2, FMT_S
),
9036 OPC_DIV_S
= FOP(3, FMT_S
),
9037 OPC_SQRT_S
= FOP(4, FMT_S
),
9038 OPC_ABS_S
= FOP(5, FMT_S
),
9039 OPC_MOV_S
= FOP(6, FMT_S
),
9040 OPC_NEG_S
= FOP(7, FMT_S
),
9041 OPC_ROUND_L_S
= FOP(8, FMT_S
),
9042 OPC_TRUNC_L_S
= FOP(9, FMT_S
),
9043 OPC_CEIL_L_S
= FOP(10, FMT_S
),
9044 OPC_FLOOR_L_S
= FOP(11, FMT_S
),
9045 OPC_ROUND_W_S
= FOP(12, FMT_S
),
9046 OPC_TRUNC_W_S
= FOP(13, FMT_S
),
9047 OPC_CEIL_W_S
= FOP(14, FMT_S
),
9048 OPC_FLOOR_W_S
= FOP(15, FMT_S
),
9049 OPC_SEL_S
= FOP(16, FMT_S
),
9050 OPC_MOVCF_S
= FOP(17, FMT_S
),
9051 OPC_MOVZ_S
= FOP(18, FMT_S
),
9052 OPC_MOVN_S
= FOP(19, FMT_S
),
9053 OPC_SELEQZ_S
= FOP(20, FMT_S
),
9054 OPC_RECIP_S
= FOP(21, FMT_S
),
9055 OPC_RSQRT_S
= FOP(22, FMT_S
),
9056 OPC_SELNEZ_S
= FOP(23, FMT_S
),
9057 OPC_MADDF_S
= FOP(24, FMT_S
),
9058 OPC_MSUBF_S
= FOP(25, FMT_S
),
9059 OPC_RINT_S
= FOP(26, FMT_S
),
9060 OPC_CLASS_S
= FOP(27, FMT_S
),
9061 OPC_MIN_S
= FOP(28, FMT_S
),
9062 OPC_RECIP2_S
= FOP(28, FMT_S
),
9063 OPC_MINA_S
= FOP(29, FMT_S
),
9064 OPC_RECIP1_S
= FOP(29, FMT_S
),
9065 OPC_MAX_S
= FOP(30, FMT_S
),
9066 OPC_RSQRT1_S
= FOP(30, FMT_S
),
9067 OPC_MAXA_S
= FOP(31, FMT_S
),
9068 OPC_RSQRT2_S
= FOP(31, FMT_S
),
9069 OPC_CVT_D_S
= FOP(33, FMT_S
),
9070 OPC_CVT_W_S
= FOP(36, FMT_S
),
9071 OPC_CVT_L_S
= FOP(37, FMT_S
),
9072 OPC_CVT_PS_S
= FOP(38, FMT_S
),
9073 OPC_CMP_F_S
= FOP(48, FMT_S
),
9074 OPC_CMP_UN_S
= FOP(49, FMT_S
),
9075 OPC_CMP_EQ_S
= FOP(50, FMT_S
),
9076 OPC_CMP_UEQ_S
= FOP(51, FMT_S
),
9077 OPC_CMP_OLT_S
= FOP(52, FMT_S
),
9078 OPC_CMP_ULT_S
= FOP(53, FMT_S
),
9079 OPC_CMP_OLE_S
= FOP(54, FMT_S
),
9080 OPC_CMP_ULE_S
= FOP(55, FMT_S
),
9081 OPC_CMP_SF_S
= FOP(56, FMT_S
),
9082 OPC_CMP_NGLE_S
= FOP(57, FMT_S
),
9083 OPC_CMP_SEQ_S
= FOP(58, FMT_S
),
9084 OPC_CMP_NGL_S
= FOP(59, FMT_S
),
9085 OPC_CMP_LT_S
= FOP(60, FMT_S
),
9086 OPC_CMP_NGE_S
= FOP(61, FMT_S
),
9087 OPC_CMP_LE_S
= FOP(62, FMT_S
),
9088 OPC_CMP_NGT_S
= FOP(63, FMT_S
),
9090 OPC_ADD_D
= FOP(0, FMT_D
),
9091 OPC_SUB_D
= FOP(1, FMT_D
),
9092 OPC_MUL_D
= FOP(2, FMT_D
),
9093 OPC_DIV_D
= FOP(3, FMT_D
),
9094 OPC_SQRT_D
= FOP(4, FMT_D
),
9095 OPC_ABS_D
= FOP(5, FMT_D
),
9096 OPC_MOV_D
= FOP(6, FMT_D
),
9097 OPC_NEG_D
= FOP(7, FMT_D
),
9098 OPC_ROUND_L_D
= FOP(8, FMT_D
),
9099 OPC_TRUNC_L_D
= FOP(9, FMT_D
),
9100 OPC_CEIL_L_D
= FOP(10, FMT_D
),
9101 OPC_FLOOR_L_D
= FOP(11, FMT_D
),
9102 OPC_ROUND_W_D
= FOP(12, FMT_D
),
9103 OPC_TRUNC_W_D
= FOP(13, FMT_D
),
9104 OPC_CEIL_W_D
= FOP(14, FMT_D
),
9105 OPC_FLOOR_W_D
= FOP(15, FMT_D
),
9106 OPC_SEL_D
= FOP(16, FMT_D
),
9107 OPC_MOVCF_D
= FOP(17, FMT_D
),
9108 OPC_MOVZ_D
= FOP(18, FMT_D
),
9109 OPC_MOVN_D
= FOP(19, FMT_D
),
9110 OPC_SELEQZ_D
= FOP(20, FMT_D
),
9111 OPC_RECIP_D
= FOP(21, FMT_D
),
9112 OPC_RSQRT_D
= FOP(22, FMT_D
),
9113 OPC_SELNEZ_D
= FOP(23, FMT_D
),
9114 OPC_MADDF_D
= FOP(24, FMT_D
),
9115 OPC_MSUBF_D
= FOP(25, FMT_D
),
9116 OPC_RINT_D
= FOP(26, FMT_D
),
9117 OPC_CLASS_D
= FOP(27, FMT_D
),
9118 OPC_MIN_D
= FOP(28, FMT_D
),
9119 OPC_RECIP2_D
= FOP(28, FMT_D
),
9120 OPC_MINA_D
= FOP(29, FMT_D
),
9121 OPC_RECIP1_D
= FOP(29, FMT_D
),
9122 OPC_MAX_D
= FOP(30, FMT_D
),
9123 OPC_RSQRT1_D
= FOP(30, FMT_D
),
9124 OPC_MAXA_D
= FOP(31, FMT_D
),
9125 OPC_RSQRT2_D
= FOP(31, FMT_D
),
9126 OPC_CVT_S_D
= FOP(32, FMT_D
),
9127 OPC_CVT_W_D
= FOP(36, FMT_D
),
9128 OPC_CVT_L_D
= FOP(37, FMT_D
),
9129 OPC_CMP_F_D
= FOP(48, FMT_D
),
9130 OPC_CMP_UN_D
= FOP(49, FMT_D
),
9131 OPC_CMP_EQ_D
= FOP(50, FMT_D
),
9132 OPC_CMP_UEQ_D
= FOP(51, FMT_D
),
9133 OPC_CMP_OLT_D
= FOP(52, FMT_D
),
9134 OPC_CMP_ULT_D
= FOP(53, FMT_D
),
9135 OPC_CMP_OLE_D
= FOP(54, FMT_D
),
9136 OPC_CMP_ULE_D
= FOP(55, FMT_D
),
9137 OPC_CMP_SF_D
= FOP(56, FMT_D
),
9138 OPC_CMP_NGLE_D
= FOP(57, FMT_D
),
9139 OPC_CMP_SEQ_D
= FOP(58, FMT_D
),
9140 OPC_CMP_NGL_D
= FOP(59, FMT_D
),
9141 OPC_CMP_LT_D
= FOP(60, FMT_D
),
9142 OPC_CMP_NGE_D
= FOP(61, FMT_D
),
9143 OPC_CMP_LE_D
= FOP(62, FMT_D
),
9144 OPC_CMP_NGT_D
= FOP(63, FMT_D
),
9146 OPC_CVT_S_W
= FOP(32, FMT_W
),
9147 OPC_CVT_D_W
= FOP(33, FMT_W
),
9148 OPC_CVT_S_L
= FOP(32, FMT_L
),
9149 OPC_CVT_D_L
= FOP(33, FMT_L
),
9150 OPC_CVT_PS_PW
= FOP(38, FMT_W
),
9152 OPC_ADD_PS
= FOP(0, FMT_PS
),
9153 OPC_SUB_PS
= FOP(1, FMT_PS
),
9154 OPC_MUL_PS
= FOP(2, FMT_PS
),
9155 OPC_DIV_PS
= FOP(3, FMT_PS
),
9156 OPC_ABS_PS
= FOP(5, FMT_PS
),
9157 OPC_MOV_PS
= FOP(6, FMT_PS
),
9158 OPC_NEG_PS
= FOP(7, FMT_PS
),
9159 OPC_MOVCF_PS
= FOP(17, FMT_PS
),
9160 OPC_MOVZ_PS
= FOP(18, FMT_PS
),
9161 OPC_MOVN_PS
= FOP(19, FMT_PS
),
9162 OPC_ADDR_PS
= FOP(24, FMT_PS
),
9163 OPC_MULR_PS
= FOP(26, FMT_PS
),
9164 OPC_RECIP2_PS
= FOP(28, FMT_PS
),
9165 OPC_RECIP1_PS
= FOP(29, FMT_PS
),
9166 OPC_RSQRT1_PS
= FOP(30, FMT_PS
),
9167 OPC_RSQRT2_PS
= FOP(31, FMT_PS
),
9169 OPC_CVT_S_PU
= FOP(32, FMT_PS
),
9170 OPC_CVT_PW_PS
= FOP(36, FMT_PS
),
9171 OPC_CVT_S_PL
= FOP(40, FMT_PS
),
9172 OPC_PLL_PS
= FOP(44, FMT_PS
),
9173 OPC_PLU_PS
= FOP(45, FMT_PS
),
9174 OPC_PUL_PS
= FOP(46, FMT_PS
),
9175 OPC_PUU_PS
= FOP(47, FMT_PS
),
9176 OPC_CMP_F_PS
= FOP(48, FMT_PS
),
9177 OPC_CMP_UN_PS
= FOP(49, FMT_PS
),
9178 OPC_CMP_EQ_PS
= FOP(50, FMT_PS
),
9179 OPC_CMP_UEQ_PS
= FOP(51, FMT_PS
),
9180 OPC_CMP_OLT_PS
= FOP(52, FMT_PS
),
9181 OPC_CMP_ULT_PS
= FOP(53, FMT_PS
),
9182 OPC_CMP_OLE_PS
= FOP(54, FMT_PS
),
9183 OPC_CMP_ULE_PS
= FOP(55, FMT_PS
),
9184 OPC_CMP_SF_PS
= FOP(56, FMT_PS
),
9185 OPC_CMP_NGLE_PS
= FOP(57, FMT_PS
),
9186 OPC_CMP_SEQ_PS
= FOP(58, FMT_PS
),
9187 OPC_CMP_NGL_PS
= FOP(59, FMT_PS
),
9188 OPC_CMP_LT_PS
= FOP(60, FMT_PS
),
9189 OPC_CMP_NGE_PS
= FOP(61, FMT_PS
),
9190 OPC_CMP_LE_PS
= FOP(62, FMT_PS
),
9191 OPC_CMP_NGT_PS
= FOP(63, FMT_PS
),
9195 R6_OPC_CMP_AF_S
= FOP(0, FMT_W
),
9196 R6_OPC_CMP_UN_S
= FOP(1, FMT_W
),
9197 R6_OPC_CMP_EQ_S
= FOP(2, FMT_W
),
9198 R6_OPC_CMP_UEQ_S
= FOP(3, FMT_W
),
9199 R6_OPC_CMP_LT_S
= FOP(4, FMT_W
),
9200 R6_OPC_CMP_ULT_S
= FOP(5, FMT_W
),
9201 R6_OPC_CMP_LE_S
= FOP(6, FMT_W
),
9202 R6_OPC_CMP_ULE_S
= FOP(7, FMT_W
),
9203 R6_OPC_CMP_SAF_S
= FOP(8, FMT_W
),
9204 R6_OPC_CMP_SUN_S
= FOP(9, FMT_W
),
9205 R6_OPC_CMP_SEQ_S
= FOP(10, FMT_W
),
9206 R6_OPC_CMP_SEUQ_S
= FOP(11, FMT_W
),
9207 R6_OPC_CMP_SLT_S
= FOP(12, FMT_W
),
9208 R6_OPC_CMP_SULT_S
= FOP(13, FMT_W
),
9209 R6_OPC_CMP_SLE_S
= FOP(14, FMT_W
),
9210 R6_OPC_CMP_SULE_S
= FOP(15, FMT_W
),
9211 R6_OPC_CMP_OR_S
= FOP(17, FMT_W
),
9212 R6_OPC_CMP_UNE_S
= FOP(18, FMT_W
),
9213 R6_OPC_CMP_NE_S
= FOP(19, FMT_W
),
9214 R6_OPC_CMP_SOR_S
= FOP(25, FMT_W
),
9215 R6_OPC_CMP_SUNE_S
= FOP(26, FMT_W
),
9216 R6_OPC_CMP_SNE_S
= FOP(27, FMT_W
),
9218 R6_OPC_CMP_AF_D
= FOP(0, FMT_L
),
9219 R6_OPC_CMP_UN_D
= FOP(1, FMT_L
),
9220 R6_OPC_CMP_EQ_D
= FOP(2, FMT_L
),
9221 R6_OPC_CMP_UEQ_D
= FOP(3, FMT_L
),
9222 R6_OPC_CMP_LT_D
= FOP(4, FMT_L
),
9223 R6_OPC_CMP_ULT_D
= FOP(5, FMT_L
),
9224 R6_OPC_CMP_LE_D
= FOP(6, FMT_L
),
9225 R6_OPC_CMP_ULE_D
= FOP(7, FMT_L
),
9226 R6_OPC_CMP_SAF_D
= FOP(8, FMT_L
),
9227 R6_OPC_CMP_SUN_D
= FOP(9, FMT_L
),
9228 R6_OPC_CMP_SEQ_D
= FOP(10, FMT_L
),
9229 R6_OPC_CMP_SEUQ_D
= FOP(11, FMT_L
),
9230 R6_OPC_CMP_SLT_D
= FOP(12, FMT_L
),
9231 R6_OPC_CMP_SULT_D
= FOP(13, FMT_L
),
9232 R6_OPC_CMP_SLE_D
= FOP(14, FMT_L
),
9233 R6_OPC_CMP_SULE_D
= FOP(15, FMT_L
),
9234 R6_OPC_CMP_OR_D
= FOP(17, FMT_L
),
9235 R6_OPC_CMP_UNE_D
= FOP(18, FMT_L
),
9236 R6_OPC_CMP_NE_D
= FOP(19, FMT_L
),
9237 R6_OPC_CMP_SOR_D
= FOP(25, FMT_L
),
9238 R6_OPC_CMP_SUNE_D
= FOP(26, FMT_L
),
9239 R6_OPC_CMP_SNE_D
= FOP(27, FMT_L
),
9242 static void gen_cp1(DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
9244 TCGv t0
= tcg_temp_new();
9249 TCGv_i32 fp0
= tcg_temp_new_i32();
9251 gen_load_fpr32(ctx
, fp0
, fs
);
9252 tcg_gen_ext_i32_tl(t0
, fp0
);
9254 gen_store_gpr(t0
, rt
);
9257 gen_load_gpr(t0
, rt
);
9259 TCGv_i32 fp0
= tcg_temp_new_i32();
9261 tcg_gen_trunc_tl_i32(fp0
, t0
);
9262 gen_store_fpr32(ctx
, fp0
, fs
);
9266 gen_helper_1e0i(cfc1
, t0
, fs
);
9267 gen_store_gpr(t0
, rt
);
9270 gen_load_gpr(t0
, rt
);
9271 save_cpu_state(ctx
, 0);
9272 gen_helper_0e2i(ctc1
, t0
, tcg_constant_i32(fs
), rt
);
9273 /* Stop translation as we may have changed hflags */
9274 ctx
->base
.is_jmp
= DISAS_STOP
;
9276 #if defined(TARGET_MIPS64)
9278 gen_load_fpr64(ctx
, t0
, fs
);
9279 gen_store_gpr(t0
, rt
);
9282 gen_load_gpr(t0
, rt
);
9283 gen_store_fpr64(ctx
, t0
, fs
);
9288 TCGv_i32 fp0
= tcg_temp_new_i32();
9290 gen_load_fpr32h(ctx
, fp0
, fs
);
9291 tcg_gen_ext_i32_tl(t0
, fp0
);
9293 gen_store_gpr(t0
, rt
);
9296 gen_load_gpr(t0
, rt
);
9298 TCGv_i32 fp0
= tcg_temp_new_i32();
9300 tcg_gen_trunc_tl_i32(fp0
, t0
);
9301 gen_store_fpr32h(ctx
, fp0
, fs
);
9305 MIPS_INVAL("cp1 move");
9306 gen_reserved_instruction(ctx
);
9311 static void gen_movci(DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
9328 l1
= gen_new_label();
9329 t0
= tcg_temp_new_i32();
9330 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
9331 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
9332 gen_load_gpr(cpu_gpr
[rd
], rs
);
9336 static inline void gen_movcf_s(DisasContext
*ctx
, int fs
, int fd
, int cc
,
9340 TCGv_i32 t0
= tcg_temp_new_i32();
9341 TCGLabel
*l1
= gen_new_label();
9349 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
9350 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
9351 gen_load_fpr32(ctx
, t0
, fs
);
9352 gen_store_fpr32(ctx
, t0
, fd
);
9356 static inline void gen_movcf_d(DisasContext
*ctx
, int fs
, int fd
, int cc
,
9360 TCGv_i32 t0
= tcg_temp_new_i32();
9362 TCGLabel
*l1
= gen_new_label();
9370 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
9371 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
9372 fp0
= tcg_temp_new_i64();
9373 gen_load_fpr64(ctx
, fp0
, fs
);
9374 gen_store_fpr64(ctx
, fp0
, fd
);
9378 static inline void gen_movcf_ps(DisasContext
*ctx
, int fs
, int fd
,
9382 TCGv_i32 t0
= tcg_temp_new_i32();
9383 TCGLabel
*l1
= gen_new_label();
9384 TCGLabel
*l2
= gen_new_label();
9392 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
9393 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
9394 gen_load_fpr32(ctx
, t0
, fs
);
9395 gen_store_fpr32(ctx
, t0
, fd
);
9398 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+ 1));
9399 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
9400 gen_load_fpr32h(ctx
, t0
, fs
);
9401 gen_store_fpr32h(ctx
, t0
, fd
);
9405 static void gen_sel_s(DisasContext
*ctx
, enum fopcode op1
, int fd
, int ft
,
9408 TCGv_i32 t1
= tcg_constant_i32(0);
9409 TCGv_i32 fp0
= tcg_temp_new_i32();
9410 TCGv_i32 fp1
= tcg_temp_new_i32();
9411 TCGv_i32 fp2
= tcg_temp_new_i32();
9412 gen_load_fpr32(ctx
, fp0
, fd
);
9413 gen_load_fpr32(ctx
, fp1
, ft
);
9414 gen_load_fpr32(ctx
, fp2
, fs
);
9418 tcg_gen_andi_i32(fp0
, fp0
, 1);
9419 tcg_gen_movcond_i32(TCG_COND_NE
, fp0
, fp0
, t1
, fp1
, fp2
);
9422 tcg_gen_andi_i32(fp1
, fp1
, 1);
9423 tcg_gen_movcond_i32(TCG_COND_EQ
, fp0
, fp1
, t1
, fp2
, t1
);
9426 tcg_gen_andi_i32(fp1
, fp1
, 1);
9427 tcg_gen_movcond_i32(TCG_COND_NE
, fp0
, fp1
, t1
, fp2
, t1
);
9430 MIPS_INVAL("gen_sel_s");
9431 gen_reserved_instruction(ctx
);
9435 gen_store_fpr32(ctx
, fp0
, fd
);
9438 static void gen_sel_d(DisasContext
*ctx
, enum fopcode op1
, int fd
, int ft
,
9441 TCGv_i64 t1
= tcg_constant_i64(0);
9442 TCGv_i64 fp0
= tcg_temp_new_i64();
9443 TCGv_i64 fp1
= tcg_temp_new_i64();
9444 TCGv_i64 fp2
= tcg_temp_new_i64();
9445 gen_load_fpr64(ctx
, fp0
, fd
);
9446 gen_load_fpr64(ctx
, fp1
, ft
);
9447 gen_load_fpr64(ctx
, fp2
, fs
);
9451 tcg_gen_andi_i64(fp0
, fp0
, 1);
9452 tcg_gen_movcond_i64(TCG_COND_NE
, fp0
, fp0
, t1
, fp1
, fp2
);
9455 tcg_gen_andi_i64(fp1
, fp1
, 1);
9456 tcg_gen_movcond_i64(TCG_COND_EQ
, fp0
, fp1
, t1
, fp2
, t1
);
9459 tcg_gen_andi_i64(fp1
, fp1
, 1);
9460 tcg_gen_movcond_i64(TCG_COND_NE
, fp0
, fp1
, t1
, fp2
, t1
);
9463 MIPS_INVAL("gen_sel_d");
9464 gen_reserved_instruction(ctx
);
9468 gen_store_fpr64(ctx
, fp0
, fd
);
9471 static void gen_farith(DisasContext
*ctx
, enum fopcode op1
,
9472 int ft
, int fs
, int fd
, int cc
)
9474 uint32_t func
= ctx
->opcode
& 0x3f;
9478 TCGv_i32 fp0
= tcg_temp_new_i32();
9479 TCGv_i32 fp1
= tcg_temp_new_i32();
9481 gen_load_fpr32(ctx
, fp0
, fs
);
9482 gen_load_fpr32(ctx
, fp1
, ft
);
9483 gen_helper_float_add_s(fp0
, tcg_env
, fp0
, fp1
);
9484 gen_store_fpr32(ctx
, fp0
, fd
);
9489 TCGv_i32 fp0
= tcg_temp_new_i32();
9490 TCGv_i32 fp1
= tcg_temp_new_i32();
9492 gen_load_fpr32(ctx
, fp0
, fs
);
9493 gen_load_fpr32(ctx
, fp1
, ft
);
9494 gen_helper_float_sub_s(fp0
, tcg_env
, fp0
, fp1
);
9495 gen_store_fpr32(ctx
, fp0
, fd
);
9500 TCGv_i32 fp0
= tcg_temp_new_i32();
9501 TCGv_i32 fp1
= tcg_temp_new_i32();
9503 gen_load_fpr32(ctx
, fp0
, fs
);
9504 gen_load_fpr32(ctx
, fp1
, ft
);
9505 gen_helper_float_mul_s(fp0
, tcg_env
, fp0
, fp1
);
9506 gen_store_fpr32(ctx
, fp0
, fd
);
9511 TCGv_i32 fp0
= tcg_temp_new_i32();
9512 TCGv_i32 fp1
= tcg_temp_new_i32();
9514 gen_load_fpr32(ctx
, fp0
, fs
);
9515 gen_load_fpr32(ctx
, fp1
, ft
);
9516 gen_helper_float_div_s(fp0
, tcg_env
, fp0
, fp1
);
9517 gen_store_fpr32(ctx
, fp0
, fd
);
9522 TCGv_i32 fp0
= tcg_temp_new_i32();
9524 gen_load_fpr32(ctx
, fp0
, fs
);
9525 gen_helper_float_sqrt_s(fp0
, tcg_env
, fp0
);
9526 gen_store_fpr32(ctx
, fp0
, fd
);
9531 TCGv_i32 fp0
= tcg_temp_new_i32();
9533 gen_load_fpr32(ctx
, fp0
, fs
);
9535 tcg_gen_andi_i32(fp0
, fp0
, 0x7fffffffUL
);
9537 gen_helper_float_abs_s(fp0
, fp0
);
9539 gen_store_fpr32(ctx
, fp0
, fd
);
9544 TCGv_i32 fp0
= tcg_temp_new_i32();
9546 gen_load_fpr32(ctx
, fp0
, fs
);
9547 gen_store_fpr32(ctx
, fp0
, fd
);
9552 TCGv_i32 fp0
= tcg_temp_new_i32();
9554 gen_load_fpr32(ctx
, fp0
, fs
);
9556 tcg_gen_xori_i32(fp0
, fp0
, 1UL << 31);
9558 gen_helper_float_chs_s(fp0
, fp0
);
9560 gen_store_fpr32(ctx
, fp0
, fd
);
9564 check_cp1_64bitmode(ctx
);
9566 TCGv_i32 fp32
= tcg_temp_new_i32();
9567 TCGv_i64 fp64
= tcg_temp_new_i64();
9569 gen_load_fpr32(ctx
, fp32
, fs
);
9571 gen_helper_float_round_2008_l_s(fp64
, tcg_env
, fp32
);
9573 gen_helper_float_round_l_s(fp64
, tcg_env
, fp32
);
9575 gen_store_fpr64(ctx
, fp64
, fd
);
9579 check_cp1_64bitmode(ctx
);
9581 TCGv_i32 fp32
= tcg_temp_new_i32();
9582 TCGv_i64 fp64
= tcg_temp_new_i64();
9584 gen_load_fpr32(ctx
, fp32
, fs
);
9586 gen_helper_float_trunc_2008_l_s(fp64
, tcg_env
, fp32
);
9588 gen_helper_float_trunc_l_s(fp64
, tcg_env
, fp32
);
9590 gen_store_fpr64(ctx
, fp64
, fd
);
9594 check_cp1_64bitmode(ctx
);
9596 TCGv_i32 fp32
= tcg_temp_new_i32();
9597 TCGv_i64 fp64
= tcg_temp_new_i64();
9599 gen_load_fpr32(ctx
, fp32
, fs
);
9601 gen_helper_float_ceil_2008_l_s(fp64
, tcg_env
, fp32
);
9603 gen_helper_float_ceil_l_s(fp64
, tcg_env
, fp32
);
9605 gen_store_fpr64(ctx
, fp64
, fd
);
9609 check_cp1_64bitmode(ctx
);
9611 TCGv_i32 fp32
= tcg_temp_new_i32();
9612 TCGv_i64 fp64
= tcg_temp_new_i64();
9614 gen_load_fpr32(ctx
, fp32
, fs
);
9616 gen_helper_float_floor_2008_l_s(fp64
, tcg_env
, fp32
);
9618 gen_helper_float_floor_l_s(fp64
, tcg_env
, fp32
);
9620 gen_store_fpr64(ctx
, fp64
, fd
);
9625 TCGv_i32 fp0
= tcg_temp_new_i32();
9627 gen_load_fpr32(ctx
, fp0
, fs
);
9629 gen_helper_float_round_2008_w_s(fp0
, tcg_env
, fp0
);
9631 gen_helper_float_round_w_s(fp0
, tcg_env
, fp0
);
9633 gen_store_fpr32(ctx
, fp0
, fd
);
9638 TCGv_i32 fp0
= tcg_temp_new_i32();
9640 gen_load_fpr32(ctx
, fp0
, fs
);
9642 gen_helper_float_trunc_2008_w_s(fp0
, tcg_env
, fp0
);
9644 gen_helper_float_trunc_w_s(fp0
, tcg_env
, fp0
);
9646 gen_store_fpr32(ctx
, fp0
, fd
);
9651 TCGv_i32 fp0
= tcg_temp_new_i32();
9653 gen_load_fpr32(ctx
, fp0
, fs
);
9655 gen_helper_float_ceil_2008_w_s(fp0
, tcg_env
, fp0
);
9657 gen_helper_float_ceil_w_s(fp0
, tcg_env
, fp0
);
9659 gen_store_fpr32(ctx
, fp0
, fd
);
9664 TCGv_i32 fp0
= tcg_temp_new_i32();
9666 gen_load_fpr32(ctx
, fp0
, fs
);
9668 gen_helper_float_floor_2008_w_s(fp0
, tcg_env
, fp0
);
9670 gen_helper_float_floor_w_s(fp0
, tcg_env
, fp0
);
9672 gen_store_fpr32(ctx
, fp0
, fd
);
9676 check_insn(ctx
, ISA_MIPS_R6
);
9677 gen_sel_s(ctx
, op1
, fd
, ft
, fs
);
9680 check_insn(ctx
, ISA_MIPS_R6
);
9681 gen_sel_s(ctx
, op1
, fd
, ft
, fs
);
9684 check_insn(ctx
, ISA_MIPS_R6
);
9685 gen_sel_s(ctx
, op1
, fd
, ft
, fs
);
9688 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
9689 gen_movcf_s(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
9692 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
9694 TCGLabel
*l1
= gen_new_label();
9698 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
9700 fp0
= tcg_temp_new_i32();
9701 gen_load_fpr32(ctx
, fp0
, fs
);
9702 gen_store_fpr32(ctx
, fp0
, fd
);
9707 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
9709 TCGLabel
*l1
= gen_new_label();
9713 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
9714 fp0
= tcg_temp_new_i32();
9715 gen_load_fpr32(ctx
, fp0
, fs
);
9716 gen_store_fpr32(ctx
, fp0
, fd
);
9723 TCGv_i32 fp0
= tcg_temp_new_i32();
9725 gen_load_fpr32(ctx
, fp0
, fs
);
9726 gen_helper_float_recip_s(fp0
, tcg_env
, fp0
);
9727 gen_store_fpr32(ctx
, fp0
, fd
);
9732 TCGv_i32 fp0
= tcg_temp_new_i32();
9734 gen_load_fpr32(ctx
, fp0
, fs
);
9735 gen_helper_float_rsqrt_s(fp0
, tcg_env
, fp0
);
9736 gen_store_fpr32(ctx
, fp0
, fd
);
9740 check_insn(ctx
, ISA_MIPS_R6
);
9742 TCGv_i32 fp0
= tcg_temp_new_i32();
9743 TCGv_i32 fp1
= tcg_temp_new_i32();
9744 TCGv_i32 fp2
= tcg_temp_new_i32();
9745 gen_load_fpr32(ctx
, fp0
, fs
);
9746 gen_load_fpr32(ctx
, fp1
, ft
);
9747 gen_load_fpr32(ctx
, fp2
, fd
);
9748 gen_helper_float_maddf_s(fp2
, tcg_env
, fp0
, fp1
, fp2
);
9749 gen_store_fpr32(ctx
, fp2
, fd
);
9753 check_insn(ctx
, ISA_MIPS_R6
);
9755 TCGv_i32 fp0
= tcg_temp_new_i32();
9756 TCGv_i32 fp1
= tcg_temp_new_i32();
9757 TCGv_i32 fp2
= tcg_temp_new_i32();
9758 gen_load_fpr32(ctx
, fp0
, fs
);
9759 gen_load_fpr32(ctx
, fp1
, ft
);
9760 gen_load_fpr32(ctx
, fp2
, fd
);
9761 gen_helper_float_msubf_s(fp2
, tcg_env
, fp0
, fp1
, fp2
);
9762 gen_store_fpr32(ctx
, fp2
, fd
);
9766 check_insn(ctx
, ISA_MIPS_R6
);
9768 TCGv_i32 fp0
= tcg_temp_new_i32();
9769 gen_load_fpr32(ctx
, fp0
, fs
);
9770 gen_helper_float_rint_s(fp0
, tcg_env
, fp0
);
9771 gen_store_fpr32(ctx
, fp0
, fd
);
9775 check_insn(ctx
, ISA_MIPS_R6
);
9777 TCGv_i32 fp0
= tcg_temp_new_i32();
9778 gen_load_fpr32(ctx
, fp0
, fs
);
9779 gen_helper_float_class_s(fp0
, tcg_env
, fp0
);
9780 gen_store_fpr32(ctx
, fp0
, fd
);
9783 case OPC_MIN_S
: /* OPC_RECIP2_S */
9784 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
9786 TCGv_i32 fp0
= tcg_temp_new_i32();
9787 TCGv_i32 fp1
= tcg_temp_new_i32();
9788 TCGv_i32 fp2
= tcg_temp_new_i32();
9789 gen_load_fpr32(ctx
, fp0
, fs
);
9790 gen_load_fpr32(ctx
, fp1
, ft
);
9791 gen_helper_float_min_s(fp2
, tcg_env
, fp0
, fp1
);
9792 gen_store_fpr32(ctx
, fp2
, fd
);
9795 check_cp1_64bitmode(ctx
);
9797 TCGv_i32 fp0
= tcg_temp_new_i32();
9798 TCGv_i32 fp1
= tcg_temp_new_i32();
9800 gen_load_fpr32(ctx
, fp0
, fs
);
9801 gen_load_fpr32(ctx
, fp1
, ft
);
9802 gen_helper_float_recip2_s(fp0
, tcg_env
, fp0
, fp1
);
9803 gen_store_fpr32(ctx
, fp0
, fd
);
9807 case OPC_MINA_S
: /* OPC_RECIP1_S */
9808 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
9810 TCGv_i32 fp0
= tcg_temp_new_i32();
9811 TCGv_i32 fp1
= tcg_temp_new_i32();
9812 TCGv_i32 fp2
= tcg_temp_new_i32();
9813 gen_load_fpr32(ctx
, fp0
, fs
);
9814 gen_load_fpr32(ctx
, fp1
, ft
);
9815 gen_helper_float_mina_s(fp2
, tcg_env
, fp0
, fp1
);
9816 gen_store_fpr32(ctx
, fp2
, fd
);
9819 check_cp1_64bitmode(ctx
);
9821 TCGv_i32 fp0
= tcg_temp_new_i32();
9823 gen_load_fpr32(ctx
, fp0
, fs
);
9824 gen_helper_float_recip1_s(fp0
, tcg_env
, fp0
);
9825 gen_store_fpr32(ctx
, fp0
, fd
);
9829 case OPC_MAX_S
: /* OPC_RSQRT1_S */
9830 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
9832 TCGv_i32 fp0
= tcg_temp_new_i32();
9833 TCGv_i32 fp1
= tcg_temp_new_i32();
9834 gen_load_fpr32(ctx
, fp0
, fs
);
9835 gen_load_fpr32(ctx
, fp1
, ft
);
9836 gen_helper_float_max_s(fp1
, tcg_env
, fp0
, fp1
);
9837 gen_store_fpr32(ctx
, fp1
, fd
);
9840 check_cp1_64bitmode(ctx
);
9842 TCGv_i32 fp0
= tcg_temp_new_i32();
9844 gen_load_fpr32(ctx
, fp0
, fs
);
9845 gen_helper_float_rsqrt1_s(fp0
, tcg_env
, fp0
);
9846 gen_store_fpr32(ctx
, fp0
, fd
);
9850 case OPC_MAXA_S
: /* OPC_RSQRT2_S */
9851 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
9853 TCGv_i32 fp0
= tcg_temp_new_i32();
9854 TCGv_i32 fp1
= tcg_temp_new_i32();
9855 gen_load_fpr32(ctx
, fp0
, fs
);
9856 gen_load_fpr32(ctx
, fp1
, ft
);
9857 gen_helper_float_maxa_s(fp1
, tcg_env
, fp0
, fp1
);
9858 gen_store_fpr32(ctx
, fp1
, fd
);
9861 check_cp1_64bitmode(ctx
);
9863 TCGv_i32 fp0
= tcg_temp_new_i32();
9864 TCGv_i32 fp1
= tcg_temp_new_i32();
9866 gen_load_fpr32(ctx
, fp0
, fs
);
9867 gen_load_fpr32(ctx
, fp1
, ft
);
9868 gen_helper_float_rsqrt2_s(fp0
, tcg_env
, fp0
, fp1
);
9869 gen_store_fpr32(ctx
, fp0
, fd
);
9874 check_cp1_registers(ctx
, fd
);
9876 TCGv_i32 fp32
= tcg_temp_new_i32();
9877 TCGv_i64 fp64
= tcg_temp_new_i64();
9879 gen_load_fpr32(ctx
, fp32
, fs
);
9880 gen_helper_float_cvtd_s(fp64
, tcg_env
, fp32
);
9881 gen_store_fpr64(ctx
, fp64
, fd
);
9886 TCGv_i32 fp0
= tcg_temp_new_i32();
9888 gen_load_fpr32(ctx
, fp0
, fs
);
9890 gen_helper_float_cvt_2008_w_s(fp0
, tcg_env
, fp0
);
9892 gen_helper_float_cvt_w_s(fp0
, tcg_env
, fp0
);
9894 gen_store_fpr32(ctx
, fp0
, fd
);
9898 check_cp1_64bitmode(ctx
);
9900 TCGv_i32 fp32
= tcg_temp_new_i32();
9901 TCGv_i64 fp64
= tcg_temp_new_i64();
9903 gen_load_fpr32(ctx
, fp32
, fs
);
9905 gen_helper_float_cvt_2008_l_s(fp64
, tcg_env
, fp32
);
9907 gen_helper_float_cvt_l_s(fp64
, tcg_env
, fp32
);
9909 gen_store_fpr64(ctx
, fp64
, fd
);
9915 TCGv_i64 fp64
= tcg_temp_new_i64();
9916 TCGv_i32 fp32_0
= tcg_temp_new_i32();
9917 TCGv_i32 fp32_1
= tcg_temp_new_i32();
9919 gen_load_fpr32(ctx
, fp32_0
, fs
);
9920 gen_load_fpr32(ctx
, fp32_1
, ft
);
9921 tcg_gen_concat_i32_i64(fp64
, fp32_1
, fp32_0
);
9922 gen_store_fpr64(ctx
, fp64
, fd
);
9934 case OPC_CMP_NGLE_S
:
9941 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
9942 if (ctx
->opcode
& (1 << 6)) {
9943 gen_cmpabs_s(ctx
, func
- 48, ft
, fs
, cc
);
9945 gen_cmp_s(ctx
, func
- 48, ft
, fs
, cc
);
9949 check_cp1_registers(ctx
, fs
| ft
| fd
);
9951 TCGv_i64 fp0
= tcg_temp_new_i64();
9952 TCGv_i64 fp1
= tcg_temp_new_i64();
9954 gen_load_fpr64(ctx
, fp0
, fs
);
9955 gen_load_fpr64(ctx
, fp1
, ft
);
9956 gen_helper_float_add_d(fp0
, tcg_env
, fp0
, fp1
);
9957 gen_store_fpr64(ctx
, fp0
, fd
);
9961 check_cp1_registers(ctx
, fs
| ft
| fd
);
9963 TCGv_i64 fp0
= tcg_temp_new_i64();
9964 TCGv_i64 fp1
= tcg_temp_new_i64();
9966 gen_load_fpr64(ctx
, fp0
, fs
);
9967 gen_load_fpr64(ctx
, fp1
, ft
);
9968 gen_helper_float_sub_d(fp0
, tcg_env
, fp0
, fp1
);
9969 gen_store_fpr64(ctx
, fp0
, fd
);
9973 check_cp1_registers(ctx
, fs
| ft
| fd
);
9975 TCGv_i64 fp0
= tcg_temp_new_i64();
9976 TCGv_i64 fp1
= tcg_temp_new_i64();
9978 gen_load_fpr64(ctx
, fp0
, fs
);
9979 gen_load_fpr64(ctx
, fp1
, ft
);
9980 gen_helper_float_mul_d(fp0
, tcg_env
, fp0
, fp1
);
9981 gen_store_fpr64(ctx
, fp0
, fd
);
9985 check_cp1_registers(ctx
, fs
| ft
| fd
);
9987 TCGv_i64 fp0
= tcg_temp_new_i64();
9988 TCGv_i64 fp1
= tcg_temp_new_i64();
9990 gen_load_fpr64(ctx
, fp0
, fs
);
9991 gen_load_fpr64(ctx
, fp1
, ft
);
9992 gen_helper_float_div_d(fp0
, tcg_env
, fp0
, fp1
);
9993 gen_store_fpr64(ctx
, fp0
, fd
);
9997 check_cp1_registers(ctx
, fs
| fd
);
9999 TCGv_i64 fp0
= tcg_temp_new_i64();
10001 gen_load_fpr64(ctx
, fp0
, fs
);
10002 gen_helper_float_sqrt_d(fp0
, tcg_env
, fp0
);
10003 gen_store_fpr64(ctx
, fp0
, fd
);
10007 check_cp1_registers(ctx
, fs
| fd
);
10009 TCGv_i64 fp0
= tcg_temp_new_i64();
10011 gen_load_fpr64(ctx
, fp0
, fs
);
10012 if (ctx
->abs2008
) {
10013 tcg_gen_andi_i64(fp0
, fp0
, 0x7fffffffffffffffULL
);
10015 gen_helper_float_abs_d(fp0
, fp0
);
10017 gen_store_fpr64(ctx
, fp0
, fd
);
10021 check_cp1_registers(ctx
, fs
| fd
);
10023 TCGv_i64 fp0
= tcg_temp_new_i64();
10025 gen_load_fpr64(ctx
, fp0
, fs
);
10026 gen_store_fpr64(ctx
, fp0
, fd
);
10030 check_cp1_registers(ctx
, fs
| fd
);
10032 TCGv_i64 fp0
= tcg_temp_new_i64();
10034 gen_load_fpr64(ctx
, fp0
, fs
);
10035 if (ctx
->abs2008
) {
10036 tcg_gen_xori_i64(fp0
, fp0
, 1ULL << 63);
10038 gen_helper_float_chs_d(fp0
, fp0
);
10040 gen_store_fpr64(ctx
, fp0
, fd
);
10043 case OPC_ROUND_L_D
:
10044 check_cp1_64bitmode(ctx
);
10046 TCGv_i64 fp0
= tcg_temp_new_i64();
10048 gen_load_fpr64(ctx
, fp0
, fs
);
10049 if (ctx
->nan2008
) {
10050 gen_helper_float_round_2008_l_d(fp0
, tcg_env
, fp0
);
10052 gen_helper_float_round_l_d(fp0
, tcg_env
, fp0
);
10054 gen_store_fpr64(ctx
, fp0
, fd
);
10057 case OPC_TRUNC_L_D
:
10058 check_cp1_64bitmode(ctx
);
10060 TCGv_i64 fp0
= tcg_temp_new_i64();
10062 gen_load_fpr64(ctx
, fp0
, fs
);
10063 if (ctx
->nan2008
) {
10064 gen_helper_float_trunc_2008_l_d(fp0
, tcg_env
, fp0
);
10066 gen_helper_float_trunc_l_d(fp0
, tcg_env
, fp0
);
10068 gen_store_fpr64(ctx
, fp0
, fd
);
10072 check_cp1_64bitmode(ctx
);
10074 TCGv_i64 fp0
= tcg_temp_new_i64();
10076 gen_load_fpr64(ctx
, fp0
, fs
);
10077 if (ctx
->nan2008
) {
10078 gen_helper_float_ceil_2008_l_d(fp0
, tcg_env
, fp0
);
10080 gen_helper_float_ceil_l_d(fp0
, tcg_env
, fp0
);
10082 gen_store_fpr64(ctx
, fp0
, fd
);
10085 case OPC_FLOOR_L_D
:
10086 check_cp1_64bitmode(ctx
);
10088 TCGv_i64 fp0
= tcg_temp_new_i64();
10090 gen_load_fpr64(ctx
, fp0
, fs
);
10091 if (ctx
->nan2008
) {
10092 gen_helper_float_floor_2008_l_d(fp0
, tcg_env
, fp0
);
10094 gen_helper_float_floor_l_d(fp0
, tcg_env
, fp0
);
10096 gen_store_fpr64(ctx
, fp0
, fd
);
10099 case OPC_ROUND_W_D
:
10100 check_cp1_registers(ctx
, fs
);
10102 TCGv_i32 fp32
= tcg_temp_new_i32();
10103 TCGv_i64 fp64
= tcg_temp_new_i64();
10105 gen_load_fpr64(ctx
, fp64
, fs
);
10106 if (ctx
->nan2008
) {
10107 gen_helper_float_round_2008_w_d(fp32
, tcg_env
, fp64
);
10109 gen_helper_float_round_w_d(fp32
, tcg_env
, fp64
);
10111 gen_store_fpr32(ctx
, fp32
, fd
);
10114 case OPC_TRUNC_W_D
:
10115 check_cp1_registers(ctx
, fs
);
10117 TCGv_i32 fp32
= tcg_temp_new_i32();
10118 TCGv_i64 fp64
= tcg_temp_new_i64();
10120 gen_load_fpr64(ctx
, fp64
, fs
);
10121 if (ctx
->nan2008
) {
10122 gen_helper_float_trunc_2008_w_d(fp32
, tcg_env
, fp64
);
10124 gen_helper_float_trunc_w_d(fp32
, tcg_env
, fp64
);
10126 gen_store_fpr32(ctx
, fp32
, fd
);
10130 check_cp1_registers(ctx
, fs
);
10132 TCGv_i32 fp32
= tcg_temp_new_i32();
10133 TCGv_i64 fp64
= tcg_temp_new_i64();
10135 gen_load_fpr64(ctx
, fp64
, fs
);
10136 if (ctx
->nan2008
) {
10137 gen_helper_float_ceil_2008_w_d(fp32
, tcg_env
, fp64
);
10139 gen_helper_float_ceil_w_d(fp32
, tcg_env
, fp64
);
10141 gen_store_fpr32(ctx
, fp32
, fd
);
10144 case OPC_FLOOR_W_D
:
10145 check_cp1_registers(ctx
, fs
);
10147 TCGv_i32 fp32
= tcg_temp_new_i32();
10148 TCGv_i64 fp64
= tcg_temp_new_i64();
10150 gen_load_fpr64(ctx
, fp64
, fs
);
10151 if (ctx
->nan2008
) {
10152 gen_helper_float_floor_2008_w_d(fp32
, tcg_env
, fp64
);
10154 gen_helper_float_floor_w_d(fp32
, tcg_env
, fp64
);
10156 gen_store_fpr32(ctx
, fp32
, fd
);
10160 check_insn(ctx
, ISA_MIPS_R6
);
10161 gen_sel_d(ctx
, op1
, fd
, ft
, fs
);
10164 check_insn(ctx
, ISA_MIPS_R6
);
10165 gen_sel_d(ctx
, op1
, fd
, ft
, fs
);
10168 check_insn(ctx
, ISA_MIPS_R6
);
10169 gen_sel_d(ctx
, op1
, fd
, ft
, fs
);
10172 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
10173 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
10176 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
10178 TCGLabel
*l1
= gen_new_label();
10182 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
10184 fp0
= tcg_temp_new_i64();
10185 gen_load_fpr64(ctx
, fp0
, fs
);
10186 gen_store_fpr64(ctx
, fp0
, fd
);
10191 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
10193 TCGLabel
*l1
= gen_new_label();
10197 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
10198 fp0
= tcg_temp_new_i64();
10199 gen_load_fpr64(ctx
, fp0
, fs
);
10200 gen_store_fpr64(ctx
, fp0
, fd
);
10206 check_cp1_registers(ctx
, fs
| fd
);
10208 TCGv_i64 fp0
= tcg_temp_new_i64();
10210 gen_load_fpr64(ctx
, fp0
, fs
);
10211 gen_helper_float_recip_d(fp0
, tcg_env
, fp0
);
10212 gen_store_fpr64(ctx
, fp0
, fd
);
10216 check_cp1_registers(ctx
, fs
| fd
);
10218 TCGv_i64 fp0
= tcg_temp_new_i64();
10220 gen_load_fpr64(ctx
, fp0
, fs
);
10221 gen_helper_float_rsqrt_d(fp0
, tcg_env
, fp0
);
10222 gen_store_fpr64(ctx
, fp0
, fd
);
10226 check_insn(ctx
, ISA_MIPS_R6
);
10228 TCGv_i64 fp0
= tcg_temp_new_i64();
10229 TCGv_i64 fp1
= tcg_temp_new_i64();
10230 TCGv_i64 fp2
= tcg_temp_new_i64();
10231 gen_load_fpr64(ctx
, fp0
, fs
);
10232 gen_load_fpr64(ctx
, fp1
, ft
);
10233 gen_load_fpr64(ctx
, fp2
, fd
);
10234 gen_helper_float_maddf_d(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10235 gen_store_fpr64(ctx
, fp2
, fd
);
10239 check_insn(ctx
, ISA_MIPS_R6
);
10241 TCGv_i64 fp0
= tcg_temp_new_i64();
10242 TCGv_i64 fp1
= tcg_temp_new_i64();
10243 TCGv_i64 fp2
= tcg_temp_new_i64();
10244 gen_load_fpr64(ctx
, fp0
, fs
);
10245 gen_load_fpr64(ctx
, fp1
, ft
);
10246 gen_load_fpr64(ctx
, fp2
, fd
);
10247 gen_helper_float_msubf_d(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10248 gen_store_fpr64(ctx
, fp2
, fd
);
10252 check_insn(ctx
, ISA_MIPS_R6
);
10254 TCGv_i64 fp0
= tcg_temp_new_i64();
10255 gen_load_fpr64(ctx
, fp0
, fs
);
10256 gen_helper_float_rint_d(fp0
, tcg_env
, fp0
);
10257 gen_store_fpr64(ctx
, fp0
, fd
);
10261 check_insn(ctx
, ISA_MIPS_R6
);
10263 TCGv_i64 fp0
= tcg_temp_new_i64();
10264 gen_load_fpr64(ctx
, fp0
, fs
);
10265 gen_helper_float_class_d(fp0
, tcg_env
, fp0
);
10266 gen_store_fpr64(ctx
, fp0
, fd
);
10269 case OPC_MIN_D
: /* OPC_RECIP2_D */
10270 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
10272 TCGv_i64 fp0
= tcg_temp_new_i64();
10273 TCGv_i64 fp1
= tcg_temp_new_i64();
10274 gen_load_fpr64(ctx
, fp0
, fs
);
10275 gen_load_fpr64(ctx
, fp1
, ft
);
10276 gen_helper_float_min_d(fp1
, tcg_env
, fp0
, fp1
);
10277 gen_store_fpr64(ctx
, fp1
, fd
);
10280 check_cp1_64bitmode(ctx
);
10282 TCGv_i64 fp0
= tcg_temp_new_i64();
10283 TCGv_i64 fp1
= tcg_temp_new_i64();
10285 gen_load_fpr64(ctx
, fp0
, fs
);
10286 gen_load_fpr64(ctx
, fp1
, ft
);
10287 gen_helper_float_recip2_d(fp0
, tcg_env
, fp0
, fp1
);
10288 gen_store_fpr64(ctx
, fp0
, fd
);
10292 case OPC_MINA_D
: /* OPC_RECIP1_D */
10293 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
10295 TCGv_i64 fp0
= tcg_temp_new_i64();
10296 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_mina_d(fp1
, tcg_env
, fp0
, fp1
);
10300 gen_store_fpr64(ctx
, fp1
, fd
);
10303 check_cp1_64bitmode(ctx
);
10305 TCGv_i64 fp0
= tcg_temp_new_i64();
10307 gen_load_fpr64(ctx
, fp0
, fs
);
10308 gen_helper_float_recip1_d(fp0
, tcg_env
, fp0
);
10309 gen_store_fpr64(ctx
, fp0
, fd
);
10313 case OPC_MAX_D
: /* OPC_RSQRT1_D */
10314 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
10316 TCGv_i64 fp0
= tcg_temp_new_i64();
10317 TCGv_i64 fp1
= tcg_temp_new_i64();
10318 gen_load_fpr64(ctx
, fp0
, fs
);
10319 gen_load_fpr64(ctx
, fp1
, ft
);
10320 gen_helper_float_max_d(fp1
, tcg_env
, fp0
, fp1
);
10321 gen_store_fpr64(ctx
, fp1
, fd
);
10324 check_cp1_64bitmode(ctx
);
10326 TCGv_i64 fp0
= tcg_temp_new_i64();
10328 gen_load_fpr64(ctx
, fp0
, fs
);
10329 gen_helper_float_rsqrt1_d(fp0
, tcg_env
, fp0
);
10330 gen_store_fpr64(ctx
, fp0
, fd
);
10334 case OPC_MAXA_D
: /* OPC_RSQRT2_D */
10335 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
10337 TCGv_i64 fp0
= tcg_temp_new_i64();
10338 TCGv_i64 fp1
= tcg_temp_new_i64();
10339 gen_load_fpr64(ctx
, fp0
, fs
);
10340 gen_load_fpr64(ctx
, fp1
, ft
);
10341 gen_helper_float_maxa_d(fp1
, tcg_env
, fp0
, fp1
);
10342 gen_store_fpr64(ctx
, fp1
, fd
);
10345 check_cp1_64bitmode(ctx
);
10347 TCGv_i64 fp0
= tcg_temp_new_i64();
10348 TCGv_i64 fp1
= tcg_temp_new_i64();
10350 gen_load_fpr64(ctx
, fp0
, fs
);
10351 gen_load_fpr64(ctx
, fp1
, ft
);
10352 gen_helper_float_rsqrt2_d(fp0
, tcg_env
, fp0
, fp1
);
10353 gen_store_fpr64(ctx
, fp0
, fd
);
10360 case OPC_CMP_UEQ_D
:
10361 case OPC_CMP_OLT_D
:
10362 case OPC_CMP_ULT_D
:
10363 case OPC_CMP_OLE_D
:
10364 case OPC_CMP_ULE_D
:
10366 case OPC_CMP_NGLE_D
:
10367 case OPC_CMP_SEQ_D
:
10368 case OPC_CMP_NGL_D
:
10370 case OPC_CMP_NGE_D
:
10372 case OPC_CMP_NGT_D
:
10373 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
10374 if (ctx
->opcode
& (1 << 6)) {
10375 gen_cmpabs_d(ctx
, func
- 48, ft
, fs
, cc
);
10377 gen_cmp_d(ctx
, func
- 48, ft
, fs
, cc
);
10381 check_cp1_registers(ctx
, fs
);
10383 TCGv_i32 fp32
= tcg_temp_new_i32();
10384 TCGv_i64 fp64
= tcg_temp_new_i64();
10386 gen_load_fpr64(ctx
, fp64
, fs
);
10387 gen_helper_float_cvts_d(fp32
, tcg_env
, fp64
);
10388 gen_store_fpr32(ctx
, fp32
, fd
);
10392 check_cp1_registers(ctx
, fs
);
10394 TCGv_i32 fp32
= tcg_temp_new_i32();
10395 TCGv_i64 fp64
= tcg_temp_new_i64();
10397 gen_load_fpr64(ctx
, fp64
, fs
);
10398 if (ctx
->nan2008
) {
10399 gen_helper_float_cvt_2008_w_d(fp32
, tcg_env
, fp64
);
10401 gen_helper_float_cvt_w_d(fp32
, tcg_env
, fp64
);
10403 gen_store_fpr32(ctx
, fp32
, fd
);
10407 check_cp1_64bitmode(ctx
);
10409 TCGv_i64 fp0
= tcg_temp_new_i64();
10411 gen_load_fpr64(ctx
, fp0
, fs
);
10412 if (ctx
->nan2008
) {
10413 gen_helper_float_cvt_2008_l_d(fp0
, tcg_env
, fp0
);
10415 gen_helper_float_cvt_l_d(fp0
, tcg_env
, fp0
);
10417 gen_store_fpr64(ctx
, fp0
, fd
);
10422 TCGv_i32 fp0
= tcg_temp_new_i32();
10424 gen_load_fpr32(ctx
, fp0
, fs
);
10425 gen_helper_float_cvts_w(fp0
, tcg_env
, fp0
);
10426 gen_store_fpr32(ctx
, fp0
, fd
);
10430 check_cp1_registers(ctx
, fd
);
10432 TCGv_i32 fp32
= tcg_temp_new_i32();
10433 TCGv_i64 fp64
= tcg_temp_new_i64();
10435 gen_load_fpr32(ctx
, fp32
, fs
);
10436 gen_helper_float_cvtd_w(fp64
, tcg_env
, fp32
);
10437 gen_store_fpr64(ctx
, fp64
, fd
);
10441 check_cp1_64bitmode(ctx
);
10443 TCGv_i32 fp32
= tcg_temp_new_i32();
10444 TCGv_i64 fp64
= tcg_temp_new_i64();
10446 gen_load_fpr64(ctx
, fp64
, fs
);
10447 gen_helper_float_cvts_l(fp32
, tcg_env
, fp64
);
10448 gen_store_fpr32(ctx
, fp32
, fd
);
10452 check_cp1_64bitmode(ctx
);
10454 TCGv_i64 fp0
= tcg_temp_new_i64();
10456 gen_load_fpr64(ctx
, fp0
, fs
);
10457 gen_helper_float_cvtd_l(fp0
, tcg_env
, fp0
);
10458 gen_store_fpr64(ctx
, fp0
, fd
);
10461 case OPC_CVT_PS_PW
:
10464 TCGv_i64 fp0
= tcg_temp_new_i64();
10466 gen_load_fpr64(ctx
, fp0
, fs
);
10467 gen_helper_float_cvtps_pw(fp0
, tcg_env
, fp0
);
10468 gen_store_fpr64(ctx
, fp0
, fd
);
10474 TCGv_i64 fp0
= tcg_temp_new_i64();
10475 TCGv_i64 fp1
= tcg_temp_new_i64();
10477 gen_load_fpr64(ctx
, fp0
, fs
);
10478 gen_load_fpr64(ctx
, fp1
, ft
);
10479 gen_helper_float_add_ps(fp0
, tcg_env
, fp0
, fp1
);
10480 gen_store_fpr64(ctx
, fp0
, fd
);
10486 TCGv_i64 fp0
= tcg_temp_new_i64();
10487 TCGv_i64 fp1
= tcg_temp_new_i64();
10489 gen_load_fpr64(ctx
, fp0
, fs
);
10490 gen_load_fpr64(ctx
, fp1
, ft
);
10491 gen_helper_float_sub_ps(fp0
, tcg_env
, fp0
, fp1
);
10492 gen_store_fpr64(ctx
, fp0
, fd
);
10498 TCGv_i64 fp0
= tcg_temp_new_i64();
10499 TCGv_i64 fp1
= tcg_temp_new_i64();
10501 gen_load_fpr64(ctx
, fp0
, fs
);
10502 gen_load_fpr64(ctx
, fp1
, ft
);
10503 gen_helper_float_mul_ps(fp0
, tcg_env
, fp0
, fp1
);
10504 gen_store_fpr64(ctx
, fp0
, fd
);
10510 TCGv_i64 fp0
= tcg_temp_new_i64();
10512 gen_load_fpr64(ctx
, fp0
, fs
);
10513 gen_helper_float_abs_ps(fp0
, fp0
);
10514 gen_store_fpr64(ctx
, fp0
, fd
);
10520 TCGv_i64 fp0
= tcg_temp_new_i64();
10522 gen_load_fpr64(ctx
, fp0
, fs
);
10523 gen_store_fpr64(ctx
, fp0
, fd
);
10529 TCGv_i64 fp0
= tcg_temp_new_i64();
10531 gen_load_fpr64(ctx
, fp0
, fs
);
10532 gen_helper_float_chs_ps(fp0
, fp0
);
10533 gen_store_fpr64(ctx
, fp0
, fd
);
10538 gen_movcf_ps(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
10543 TCGLabel
*l1
= gen_new_label();
10547 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
10549 fp0
= tcg_temp_new_i64();
10550 gen_load_fpr64(ctx
, fp0
, fs
);
10551 gen_store_fpr64(ctx
, fp0
, fd
);
10558 TCGLabel
*l1
= gen_new_label();
10562 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
10563 fp0
= tcg_temp_new_i64();
10564 gen_load_fpr64(ctx
, fp0
, fs
);
10565 gen_store_fpr64(ctx
, fp0
, fd
);
10573 TCGv_i64 fp0
= tcg_temp_new_i64();
10574 TCGv_i64 fp1
= tcg_temp_new_i64();
10576 gen_load_fpr64(ctx
, fp0
, ft
);
10577 gen_load_fpr64(ctx
, fp1
, fs
);
10578 gen_helper_float_addr_ps(fp0
, tcg_env
, fp0
, fp1
);
10579 gen_store_fpr64(ctx
, fp0
, fd
);
10585 TCGv_i64 fp0
= tcg_temp_new_i64();
10586 TCGv_i64 fp1
= tcg_temp_new_i64();
10588 gen_load_fpr64(ctx
, fp0
, ft
);
10589 gen_load_fpr64(ctx
, fp1
, fs
);
10590 gen_helper_float_mulr_ps(fp0
, tcg_env
, fp0
, fp1
);
10591 gen_store_fpr64(ctx
, fp0
, fd
);
10594 case OPC_RECIP2_PS
:
10597 TCGv_i64 fp0
= tcg_temp_new_i64();
10598 TCGv_i64 fp1
= tcg_temp_new_i64();
10600 gen_load_fpr64(ctx
, fp0
, fs
);
10601 gen_load_fpr64(ctx
, fp1
, ft
);
10602 gen_helper_float_recip2_ps(fp0
, tcg_env
, fp0
, fp1
);
10603 gen_store_fpr64(ctx
, fp0
, fd
);
10606 case OPC_RECIP1_PS
:
10609 TCGv_i64 fp0
= tcg_temp_new_i64();
10611 gen_load_fpr64(ctx
, fp0
, fs
);
10612 gen_helper_float_recip1_ps(fp0
, tcg_env
, fp0
);
10613 gen_store_fpr64(ctx
, fp0
, fd
);
10616 case OPC_RSQRT1_PS
:
10619 TCGv_i64 fp0
= tcg_temp_new_i64();
10621 gen_load_fpr64(ctx
, fp0
, fs
);
10622 gen_helper_float_rsqrt1_ps(fp0
, tcg_env
, fp0
);
10623 gen_store_fpr64(ctx
, fp0
, fd
);
10626 case OPC_RSQRT2_PS
:
10629 TCGv_i64 fp0
= tcg_temp_new_i64();
10630 TCGv_i64 fp1
= tcg_temp_new_i64();
10632 gen_load_fpr64(ctx
, fp0
, fs
);
10633 gen_load_fpr64(ctx
, fp1
, ft
);
10634 gen_helper_float_rsqrt2_ps(fp0
, tcg_env
, fp0
, fp1
);
10635 gen_store_fpr64(ctx
, fp0
, fd
);
10639 check_cp1_64bitmode(ctx
);
10641 TCGv_i32 fp0
= tcg_temp_new_i32();
10643 gen_load_fpr32h(ctx
, fp0
, fs
);
10644 gen_helper_float_cvts_pu(fp0
, tcg_env
, fp0
);
10645 gen_store_fpr32(ctx
, fp0
, fd
);
10648 case OPC_CVT_PW_PS
:
10651 TCGv_i64 fp0
= tcg_temp_new_i64();
10653 gen_load_fpr64(ctx
, fp0
, fs
);
10654 gen_helper_float_cvtpw_ps(fp0
, tcg_env
, fp0
);
10655 gen_store_fpr64(ctx
, fp0
, fd
);
10659 check_cp1_64bitmode(ctx
);
10661 TCGv_i32 fp0
= tcg_temp_new_i32();
10663 gen_load_fpr32(ctx
, fp0
, fs
);
10664 gen_helper_float_cvts_pl(fp0
, tcg_env
, fp0
);
10665 gen_store_fpr32(ctx
, fp0
, fd
);
10671 TCGv_i32 fp0
= tcg_temp_new_i32();
10672 TCGv_i32 fp1
= tcg_temp_new_i32();
10674 gen_load_fpr32(ctx
, fp0
, fs
);
10675 gen_load_fpr32(ctx
, fp1
, ft
);
10676 gen_store_fpr32h(ctx
, fp0
, fd
);
10677 gen_store_fpr32(ctx
, fp1
, fd
);
10683 TCGv_i32 fp0
= tcg_temp_new_i32();
10684 TCGv_i32 fp1
= tcg_temp_new_i32();
10686 gen_load_fpr32(ctx
, fp0
, fs
);
10687 gen_load_fpr32h(ctx
, fp1
, ft
);
10688 gen_store_fpr32(ctx
, fp1
, fd
);
10689 gen_store_fpr32h(ctx
, fp0
, fd
);
10695 TCGv_i32 fp0
= tcg_temp_new_i32();
10696 TCGv_i32 fp1
= tcg_temp_new_i32();
10698 gen_load_fpr32h(ctx
, fp0
, fs
);
10699 gen_load_fpr32(ctx
, fp1
, ft
);
10700 gen_store_fpr32(ctx
, fp1
, fd
);
10701 gen_store_fpr32h(ctx
, fp0
, fd
);
10707 TCGv_i32 fp0
= tcg_temp_new_i32();
10708 TCGv_i32 fp1
= tcg_temp_new_i32();
10710 gen_load_fpr32h(ctx
, fp0
, fs
);
10711 gen_load_fpr32h(ctx
, fp1
, ft
);
10712 gen_store_fpr32(ctx
, fp1
, fd
);
10713 gen_store_fpr32h(ctx
, fp0
, fd
);
10717 case OPC_CMP_UN_PS
:
10718 case OPC_CMP_EQ_PS
:
10719 case OPC_CMP_UEQ_PS
:
10720 case OPC_CMP_OLT_PS
:
10721 case OPC_CMP_ULT_PS
:
10722 case OPC_CMP_OLE_PS
:
10723 case OPC_CMP_ULE_PS
:
10724 case OPC_CMP_SF_PS
:
10725 case OPC_CMP_NGLE_PS
:
10726 case OPC_CMP_SEQ_PS
:
10727 case OPC_CMP_NGL_PS
:
10728 case OPC_CMP_LT_PS
:
10729 case OPC_CMP_NGE_PS
:
10730 case OPC_CMP_LE_PS
:
10731 case OPC_CMP_NGT_PS
:
10732 if (ctx
->opcode
& (1 << 6)) {
10733 gen_cmpabs_ps(ctx
, func
- 48, ft
, fs
, cc
);
10735 gen_cmp_ps(ctx
, func
- 48, ft
, fs
, cc
);
10739 MIPS_INVAL("farith");
10740 gen_reserved_instruction(ctx
);
10745 /* Coprocessor 3 (FPU) */
10746 static void gen_flt3_ldst(DisasContext
*ctx
, uint32_t opc
,
10747 int fd
, int fs
, int base
, int index
)
10749 TCGv t0
= tcg_temp_new();
10752 gen_load_gpr(t0
, index
);
10753 } else if (index
== 0) {
10754 gen_load_gpr(t0
, base
);
10756 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], cpu_gpr
[index
]);
10759 * Don't do NOP if destination is zero: we must perform the actual
10766 TCGv_i32 fp0
= tcg_temp_new_i32();
10768 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SL
);
10769 tcg_gen_trunc_tl_i32(fp0
, t0
);
10770 gen_store_fpr32(ctx
, fp0
, fd
);
10775 check_cp1_registers(ctx
, fd
);
10777 TCGv_i64 fp0
= tcg_temp_new_i64();
10778 tcg_gen_qemu_ld_i64(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
);
10779 gen_store_fpr64(ctx
, fp0
, fd
);
10783 check_cp1_64bitmode(ctx
);
10784 tcg_gen_andi_tl(t0
, t0
, ~0x7);
10786 TCGv_i64 fp0
= tcg_temp_new_i64();
10788 tcg_gen_qemu_ld_i64(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
);
10789 gen_store_fpr64(ctx
, fp0
, fd
);
10795 TCGv_i32 fp0
= tcg_temp_new_i32();
10796 gen_load_fpr32(ctx
, fp0
, fs
);
10797 tcg_gen_qemu_st_i32(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UL
);
10802 check_cp1_registers(ctx
, fs
);
10804 TCGv_i64 fp0
= tcg_temp_new_i64();
10805 gen_load_fpr64(ctx
, fp0
, fs
);
10806 tcg_gen_qemu_st_i64(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
);
10810 check_cp1_64bitmode(ctx
);
10811 tcg_gen_andi_tl(t0
, t0
, ~0x7);
10813 TCGv_i64 fp0
= tcg_temp_new_i64();
10814 gen_load_fpr64(ctx
, fp0
, fs
);
10815 tcg_gen_qemu_st_i64(fp0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
);
10821 static void gen_flt3_arith(DisasContext
*ctx
, uint32_t opc
,
10822 int fd
, int fr
, int fs
, int ft
)
10828 TCGv t0
= tcg_temp_new();
10829 TCGv_i32 fp
= tcg_temp_new_i32();
10830 TCGv_i32 fph
= tcg_temp_new_i32();
10831 TCGLabel
*l1
= gen_new_label();
10832 TCGLabel
*l2
= gen_new_label();
10834 gen_load_gpr(t0
, fr
);
10835 tcg_gen_andi_tl(t0
, t0
, 0x7);
10837 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
10838 gen_load_fpr32(ctx
, fp
, fs
);
10839 gen_load_fpr32h(ctx
, fph
, fs
);
10840 gen_store_fpr32(ctx
, fp
, fd
);
10841 gen_store_fpr32h(ctx
, fph
, fd
);
10844 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
10845 if (disas_is_bigendian(ctx
)) {
10846 gen_load_fpr32(ctx
, fp
, fs
);
10847 gen_load_fpr32h(ctx
, fph
, ft
);
10848 gen_store_fpr32h(ctx
, fp
, fd
);
10849 gen_store_fpr32(ctx
, fph
, fd
);
10851 gen_load_fpr32h(ctx
, fph
, fs
);
10852 gen_load_fpr32(ctx
, fp
, ft
);
10853 gen_store_fpr32(ctx
, fph
, fd
);
10854 gen_store_fpr32h(ctx
, fp
, fd
);
10862 TCGv_i32 fp0
= tcg_temp_new_i32();
10863 TCGv_i32 fp1
= tcg_temp_new_i32();
10864 TCGv_i32 fp2
= tcg_temp_new_i32();
10866 gen_load_fpr32(ctx
, fp0
, fs
);
10867 gen_load_fpr32(ctx
, fp1
, ft
);
10868 gen_load_fpr32(ctx
, fp2
, fr
);
10869 gen_helper_float_madd_s(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10870 gen_store_fpr32(ctx
, fp2
, fd
);
10875 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
10877 TCGv_i64 fp0
= tcg_temp_new_i64();
10878 TCGv_i64 fp1
= tcg_temp_new_i64();
10879 TCGv_i64 fp2
= tcg_temp_new_i64();
10881 gen_load_fpr64(ctx
, fp0
, fs
);
10882 gen_load_fpr64(ctx
, fp1
, ft
);
10883 gen_load_fpr64(ctx
, fp2
, fr
);
10884 gen_helper_float_madd_d(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10885 gen_store_fpr64(ctx
, fp2
, fd
);
10891 TCGv_i64 fp0
= tcg_temp_new_i64();
10892 TCGv_i64 fp1
= tcg_temp_new_i64();
10893 TCGv_i64 fp2
= tcg_temp_new_i64();
10895 gen_load_fpr64(ctx
, fp0
, fs
);
10896 gen_load_fpr64(ctx
, fp1
, ft
);
10897 gen_load_fpr64(ctx
, fp2
, fr
);
10898 gen_helper_float_madd_ps(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10899 gen_store_fpr64(ctx
, fp2
, fd
);
10905 TCGv_i32 fp0
= tcg_temp_new_i32();
10906 TCGv_i32 fp1
= tcg_temp_new_i32();
10907 TCGv_i32 fp2
= tcg_temp_new_i32();
10909 gen_load_fpr32(ctx
, fp0
, fs
);
10910 gen_load_fpr32(ctx
, fp1
, ft
);
10911 gen_load_fpr32(ctx
, fp2
, fr
);
10912 gen_helper_float_msub_s(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10913 gen_store_fpr32(ctx
, fp2
, fd
);
10918 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
10920 TCGv_i64 fp0
= tcg_temp_new_i64();
10921 TCGv_i64 fp1
= tcg_temp_new_i64();
10922 TCGv_i64 fp2
= tcg_temp_new_i64();
10924 gen_load_fpr64(ctx
, fp0
, fs
);
10925 gen_load_fpr64(ctx
, fp1
, ft
);
10926 gen_load_fpr64(ctx
, fp2
, fr
);
10927 gen_helper_float_msub_d(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10928 gen_store_fpr64(ctx
, fp2
, fd
);
10934 TCGv_i64 fp0
= tcg_temp_new_i64();
10935 TCGv_i64 fp1
= tcg_temp_new_i64();
10936 TCGv_i64 fp2
= tcg_temp_new_i64();
10938 gen_load_fpr64(ctx
, fp0
, fs
);
10939 gen_load_fpr64(ctx
, fp1
, ft
);
10940 gen_load_fpr64(ctx
, fp2
, fr
);
10941 gen_helper_float_msub_ps(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10942 gen_store_fpr64(ctx
, fp2
, fd
);
10948 TCGv_i32 fp0
= tcg_temp_new_i32();
10949 TCGv_i32 fp1
= tcg_temp_new_i32();
10950 TCGv_i32 fp2
= tcg_temp_new_i32();
10952 gen_load_fpr32(ctx
, fp0
, fs
);
10953 gen_load_fpr32(ctx
, fp1
, ft
);
10954 gen_load_fpr32(ctx
, fp2
, fr
);
10955 gen_helper_float_nmadd_s(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10956 gen_store_fpr32(ctx
, fp2
, fd
);
10961 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
10963 TCGv_i64 fp0
= tcg_temp_new_i64();
10964 TCGv_i64 fp1
= tcg_temp_new_i64();
10965 TCGv_i64 fp2
= tcg_temp_new_i64();
10967 gen_load_fpr64(ctx
, fp0
, fs
);
10968 gen_load_fpr64(ctx
, fp1
, ft
);
10969 gen_load_fpr64(ctx
, fp2
, fr
);
10970 gen_helper_float_nmadd_d(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10971 gen_store_fpr64(ctx
, fp2
, fd
);
10977 TCGv_i64 fp0
= tcg_temp_new_i64();
10978 TCGv_i64 fp1
= tcg_temp_new_i64();
10979 TCGv_i64 fp2
= tcg_temp_new_i64();
10981 gen_load_fpr64(ctx
, fp0
, fs
);
10982 gen_load_fpr64(ctx
, fp1
, ft
);
10983 gen_load_fpr64(ctx
, fp2
, fr
);
10984 gen_helper_float_nmadd_ps(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10985 gen_store_fpr64(ctx
, fp2
, fd
);
10991 TCGv_i32 fp0
= tcg_temp_new_i32();
10992 TCGv_i32 fp1
= tcg_temp_new_i32();
10993 TCGv_i32 fp2
= tcg_temp_new_i32();
10995 gen_load_fpr32(ctx
, fp0
, fs
);
10996 gen_load_fpr32(ctx
, fp1
, ft
);
10997 gen_load_fpr32(ctx
, fp2
, fr
);
10998 gen_helper_float_nmsub_s(fp2
, tcg_env
, fp0
, fp1
, fp2
);
10999 gen_store_fpr32(ctx
, fp2
, fd
);
11004 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
11006 TCGv_i64 fp0
= tcg_temp_new_i64();
11007 TCGv_i64 fp1
= tcg_temp_new_i64();
11008 TCGv_i64 fp2
= tcg_temp_new_i64();
11010 gen_load_fpr64(ctx
, fp0
, fs
);
11011 gen_load_fpr64(ctx
, fp1
, ft
);
11012 gen_load_fpr64(ctx
, fp2
, fr
);
11013 gen_helper_float_nmsub_d(fp2
, tcg_env
, fp0
, fp1
, fp2
);
11014 gen_store_fpr64(ctx
, fp2
, fd
);
11020 TCGv_i64 fp0
= tcg_temp_new_i64();
11021 TCGv_i64 fp1
= tcg_temp_new_i64();
11022 TCGv_i64 fp2
= tcg_temp_new_i64();
11024 gen_load_fpr64(ctx
, fp0
, fs
);
11025 gen_load_fpr64(ctx
, fp1
, ft
);
11026 gen_load_fpr64(ctx
, fp2
, fr
);
11027 gen_helper_float_nmsub_ps(fp2
, tcg_env
, fp0
, fp1
, fp2
);
11028 gen_store_fpr64(ctx
, fp2
, fd
);
11032 MIPS_INVAL("flt3_arith");
11033 gen_reserved_instruction(ctx
);
11038 void gen_rdhwr(DisasContext
*ctx
, int rt
, int rd
, int sel
)
11042 #if !defined(CONFIG_USER_ONLY)
11044 * The Linux kernel will emulate rdhwr if it's not supported natively.
11045 * Therefore only check the ISA in system mode.
11047 check_insn(ctx
, ISA_MIPS_R2
);
11049 t0
= tcg_temp_new();
11053 gen_helper_rdhwr_cpunum(t0
, tcg_env
);
11054 gen_store_gpr(t0
, rt
);
11057 gen_helper_rdhwr_synci_step(t0
, tcg_env
);
11058 gen_store_gpr(t0
, rt
);
11061 translator_io_start(&ctx
->base
);
11062 gen_helper_rdhwr_cc(t0
, tcg_env
);
11063 gen_store_gpr(t0
, rt
);
11065 * Break the TB to be able to take timer interrupts immediately
11066 * after reading count. DISAS_STOP isn't sufficient, we need to ensure
11067 * we break completely out of translated code.
11069 gen_save_pc(ctx
->base
.pc_next
+ 4);
11070 ctx
->base
.is_jmp
= DISAS_EXIT
;
11073 gen_helper_rdhwr_ccres(t0
, tcg_env
);
11074 gen_store_gpr(t0
, rt
);
11077 check_insn(ctx
, ISA_MIPS_R6
);
11080 * Performance counter registers are not implemented other than
11081 * control register 0.
11083 generate_exception(ctx
, EXCP_RI
);
11085 gen_helper_rdhwr_performance(t0
, tcg_env
);
11086 gen_store_gpr(t0
, rt
);
11089 check_insn(ctx
, ISA_MIPS_R6
);
11090 gen_helper_rdhwr_xnp(t0
, tcg_env
);
11091 gen_store_gpr(t0
, rt
);
11094 #if defined(CONFIG_USER_ONLY)
11095 tcg_gen_ld_tl(t0
, tcg_env
,
11096 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
11097 gen_store_gpr(t0
, rt
);
11100 if ((ctx
->hflags
& MIPS_HFLAG_CP0
) ||
11101 (ctx
->hflags
& MIPS_HFLAG_HWRENA_ULR
)) {
11102 tcg_gen_ld_tl(t0
, tcg_env
,
11103 offsetof(CPUMIPSState
, active_tc
.CP0_UserLocal
));
11104 gen_store_gpr(t0
, rt
);
11106 gen_reserved_instruction(ctx
);
11110 default: /* Invalid */
11111 MIPS_INVAL("rdhwr");
11112 gen_reserved_instruction(ctx
);
11117 static inline void clear_branch_hflags(DisasContext
*ctx
)
11119 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
11120 if (ctx
->base
.is_jmp
== DISAS_NEXT
) {
11121 save_cpu_state(ctx
, 0);
11124 * It is not safe to save ctx->hflags as hflags may be changed
11125 * in execution time by the instruction in delay / forbidden slot.
11127 tcg_gen_andi_i32(hflags
, hflags
, ~MIPS_HFLAG_BMASK
);
11131 static void gen_branch(DisasContext
*ctx
, int insn_bytes
)
11133 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
11134 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
11135 /* Branches completion */
11136 clear_branch_hflags(ctx
);
11137 ctx
->base
.is_jmp
= DISAS_NORETURN
;
11138 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
11139 case MIPS_HFLAG_FBNSLOT
:
11140 gen_goto_tb(ctx
, 0, ctx
->base
.pc_next
+ insn_bytes
);
11143 /* unconditional branch */
11144 if (proc_hflags
& MIPS_HFLAG_BX
) {
11145 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
11147 gen_goto_tb(ctx
, 0, ctx
->btarget
);
11149 case MIPS_HFLAG_BL
:
11150 /* blikely taken case */
11151 gen_goto_tb(ctx
, 0, ctx
->btarget
);
11153 case MIPS_HFLAG_BC
:
11154 /* Conditional branch */
11156 TCGLabel
*l1
= gen_new_label();
11158 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
11159 gen_goto_tb(ctx
, 1, ctx
->base
.pc_next
+ insn_bytes
);
11161 gen_goto_tb(ctx
, 0, ctx
->btarget
);
11164 case MIPS_HFLAG_BR
:
11165 /* unconditional branch to register */
11166 if (ctx
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
11167 TCGv t0
= tcg_temp_new();
11168 TCGv_i32 t1
= tcg_temp_new_i32();
11170 tcg_gen_andi_tl(t0
, btarget
, 0x1);
11171 tcg_gen_trunc_tl_i32(t1
, t0
);
11172 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
11173 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
11174 tcg_gen_or_i32(hflags
, hflags
, t1
);
11176 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
11178 tcg_gen_mov_tl(cpu_PC
, btarget
);
11180 tcg_gen_lookup_and_goto_ptr();
11183 LOG_DISAS("unknown branch 0x%x\n", proc_hflags
);
11184 gen_reserved_instruction(ctx
);
11189 /* Compact Branches */
11190 static void gen_compute_compact_branch(DisasContext
*ctx
, uint32_t opc
,
11191 int rs
, int rt
, int32_t offset
)
11193 int bcond_compute
= 0;
11194 TCGv t0
= tcg_temp_new();
11195 TCGv t1
= tcg_temp_new();
11196 int m16_lowbit
= (ctx
->hflags
& MIPS_HFLAG_M16
) != 0;
11198 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
11199 #ifdef MIPS_DEBUG_DISAS
11200 LOG_DISAS("Branch in delay / forbidden slot at PC 0x%016"
11201 VADDR_PRIx
"\n", ctx
->base
.pc_next
);
11203 gen_reserved_instruction(ctx
);
11207 /* Load needed operands and calculate btarget */
11209 /* compact branch */
11210 case OPC_BOVC
: /* OPC_BEQZALC, OPC_BEQC */
11211 case OPC_BNVC
: /* OPC_BNEZALC, OPC_BNEC */
11212 gen_load_gpr(t0
, rs
);
11213 gen_load_gpr(t1
, rt
);
11215 ctx
->btarget
= addr_add(ctx
, ctx
->base
.pc_next
+ 4, offset
);
11216 if (rs
<= rt
&& rs
== 0) {
11217 /* OPC_BEQZALC, OPC_BNEZALC */
11218 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->base
.pc_next
+ 4 + m16_lowbit
);
11221 case OPC_BLEZC
: /* OPC_BGEZC, OPC_BGEC */
11222 case OPC_BGTZC
: /* OPC_BLTZC, OPC_BLTC */
11223 gen_load_gpr(t0
, rs
);
11224 gen_load_gpr(t1
, rt
);
11226 ctx
->btarget
= addr_add(ctx
, ctx
->base
.pc_next
+ 4, offset
);
11228 case OPC_BLEZALC
: /* OPC_BGEZALC, OPC_BGEUC */
11229 case OPC_BGTZALC
: /* OPC_BLTZALC, OPC_BLTUC */
11230 if (rs
== 0 || rs
== rt
) {
11231 /* OPC_BLEZALC, OPC_BGEZALC */
11232 /* OPC_BGTZALC, OPC_BLTZALC */
11233 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->base
.pc_next
+ 4 + m16_lowbit
);
11235 gen_load_gpr(t0
, rs
);
11236 gen_load_gpr(t1
, rt
);
11238 ctx
->btarget
= addr_add(ctx
, ctx
->base
.pc_next
+ 4, offset
);
11242 ctx
->btarget
= addr_add(ctx
, ctx
->base
.pc_next
+ 4, offset
);
11247 /* OPC_BEQZC, OPC_BNEZC */
11248 gen_load_gpr(t0
, rs
);
11250 ctx
->btarget
= addr_add(ctx
, ctx
->base
.pc_next
+ 4, offset
);
11252 /* OPC_JIC, OPC_JIALC */
11253 TCGv tbase
= tcg_temp_new();
11255 gen_load_gpr(tbase
, rt
);
11256 gen_op_addr_addi(ctx
, btarget
, tbase
, offset
);
11260 MIPS_INVAL("Compact branch/jump");
11261 gen_reserved_instruction(ctx
);
11265 if (bcond_compute
== 0) {
11266 /* Unconditional compact branch */
11269 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->base
.pc_next
+ 4 + m16_lowbit
);
11272 ctx
->hflags
|= MIPS_HFLAG_BR
;
11275 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->base
.pc_next
+ 4 + m16_lowbit
);
11278 ctx
->hflags
|= MIPS_HFLAG_B
;
11281 MIPS_INVAL("Compact branch/jump");
11282 gen_reserved_instruction(ctx
);
11286 /* Generating branch here as compact branches don't have delay slot */
11287 gen_branch(ctx
, 4);
11289 /* Conditional compact branch */
11290 TCGLabel
*fs
= gen_new_label();
11291 save_cpu_state(ctx
, 0);
11294 case OPC_BLEZALC
: /* OPC_BGEZALC, OPC_BGEUC */
11295 if (rs
== 0 && rt
!= 0) {
11297 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LE
), t1
, 0, fs
);
11298 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
11300 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GE
), t1
, 0, fs
);
11303 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_GEU
), t0
, t1
, fs
);
11306 case OPC_BGTZALC
: /* OPC_BLTZALC, OPC_BLTUC */
11307 if (rs
== 0 && rt
!= 0) {
11309 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GT
), t1
, 0, fs
);
11310 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
11312 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LT
), t1
, 0, fs
);
11315 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_LTU
), t0
, t1
, fs
);
11318 case OPC_BLEZC
: /* OPC_BGEZC, OPC_BGEC */
11319 if (rs
== 0 && rt
!= 0) {
11321 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LE
), t1
, 0, fs
);
11322 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
11324 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GE
), t1
, 0, fs
);
11327 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_GE
), t0
, t1
, fs
);
11330 case OPC_BGTZC
: /* OPC_BLTZC, OPC_BLTC */
11331 if (rs
== 0 && rt
!= 0) {
11333 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GT
), t1
, 0, fs
);
11334 } else if (rs
!= 0 && rt
!= 0 && rs
== rt
) {
11336 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LT
), t1
, 0, fs
);
11339 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_LT
), t0
, t1
, fs
);
11342 case OPC_BOVC
: /* OPC_BEQZALC, OPC_BEQC */
11343 case OPC_BNVC
: /* OPC_BNEZALC, OPC_BNEC */
11345 /* OPC_BOVC, OPC_BNVC */
11346 TCGv t2
= tcg_temp_new();
11347 TCGv t3
= tcg_temp_new();
11348 TCGv t4
= tcg_temp_new();
11349 TCGv input_overflow
= tcg_temp_new();
11351 gen_load_gpr(t0
, rs
);
11352 gen_load_gpr(t1
, rt
);
11353 tcg_gen_ext32s_tl(t2
, t0
);
11354 tcg_gen_setcond_tl(TCG_COND_NE
, input_overflow
, t2
, t0
);
11355 tcg_gen_ext32s_tl(t3
, t1
);
11356 tcg_gen_setcond_tl(TCG_COND_NE
, t4
, t3
, t1
);
11357 tcg_gen_or_tl(input_overflow
, input_overflow
, t4
);
11359 tcg_gen_add_tl(t4
, t2
, t3
);
11360 tcg_gen_ext32s_tl(t4
, t4
);
11361 tcg_gen_xor_tl(t2
, t2
, t3
);
11362 tcg_gen_xor_tl(t3
, t4
, t3
);
11363 tcg_gen_andc_tl(t2
, t3
, t2
);
11364 tcg_gen_setcondi_tl(TCG_COND_LT
, t4
, t2
, 0);
11365 tcg_gen_or_tl(t4
, t4
, input_overflow
);
11366 if (opc
== OPC_BOVC
) {
11368 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_NE
), t4
, 0, fs
);
11371 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_EQ
), t4
, 0, fs
);
11373 } else if (rs
< rt
&& rs
== 0) {
11374 /* OPC_BEQZALC, OPC_BNEZALC */
11375 if (opc
== OPC_BEQZALC
) {
11377 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_EQ
), t1
, 0, fs
);
11380 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_NE
), t1
, 0, fs
);
11383 /* OPC_BEQC, OPC_BNEC */
11384 if (opc
== OPC_BEQC
) {
11386 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_EQ
), t0
, t1
, fs
);
11389 tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_NE
), t0
, t1
, fs
);
11394 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_EQ
), t0
, 0, fs
);
11397 tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_NE
), t0
, 0, fs
);
11400 MIPS_INVAL("Compact conditional branch/jump");
11401 gen_reserved_instruction(ctx
);
11405 /* Generating branch here as compact branches don't have delay slot */
11406 gen_goto_tb(ctx
, 1, ctx
->btarget
);
11409 ctx
->hflags
|= MIPS_HFLAG_FBNSLOT
;
11413 void gen_addiupc(DisasContext
*ctx
, int rx
, int imm
,
11414 int is_64_bit
, int extended
)
11418 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
11419 gen_reserved_instruction(ctx
);
11423 npc
= pc_relative_pc(ctx
) + imm
;
11425 npc
= (int32_t)npc
;
11427 tcg_gen_movi_tl(cpu_gpr
[rx
], npc
);
11430 static void gen_cache_operation(DisasContext
*ctx
, uint32_t op
, int base
,
11433 TCGv_i32 t0
= tcg_constant_i32(op
);
11434 TCGv t1
= tcg_temp_new();
11435 gen_base_offset_addr(ctx
, t1
, base
, offset
);
11436 gen_helper_cache(tcg_env
, t1
, t0
);
11439 static inline bool is_uhi(DisasContext
*ctx
, int sdbbp_code
)
11441 #ifdef CONFIG_USER_ONLY
11444 bool is_user
= (ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
;
11445 return semihosting_enabled(is_user
) && sdbbp_code
== 1;
11449 void gen_ldxs(DisasContext
*ctx
, int base
, int index
, int rd
)
11451 TCGv t0
= tcg_temp_new();
11452 TCGv t1
= tcg_temp_new();
11454 gen_load_gpr(t0
, base
);
11457 gen_load_gpr(t1
, index
);
11458 tcg_gen_shli_tl(t1
, t1
, 2);
11459 gen_op_addr_add(ctx
, t0
, t1
, t0
);
11462 tcg_gen_qemu_ld_tl(t1
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SL
);
11463 gen_store_gpr(t1
, rd
);
11466 static void gen_sync(int stype
)
11468 TCGBar tcg_mo
= TCG_BAR_SC
;
11471 case 0x4: /* SYNC_WMB */
11472 tcg_mo
|= TCG_MO_ST_ST
;
11474 case 0x10: /* SYNC_MB */
11475 tcg_mo
|= TCG_MO_ALL
;
11477 case 0x11: /* SYNC_ACQUIRE */
11478 tcg_mo
|= TCG_MO_LD_LD
| TCG_MO_LD_ST
;
11480 case 0x12: /* SYNC_RELEASE */
11481 tcg_mo
|= TCG_MO_ST_ST
| TCG_MO_LD_ST
;
11483 case 0x13: /* SYNC_RMB */
11484 tcg_mo
|= TCG_MO_LD_LD
;
11487 tcg_mo
|= TCG_MO_ALL
;
11491 tcg_gen_mb(tcg_mo
);
11494 /* ISA extensions (ASEs) */
11496 /* MIPS16 extension to MIPS32 */
11497 #include "mips16e_translate.c.inc"
11499 /* microMIPS extension to MIPS32/MIPS64 */
11502 * Values for microMIPS fmt field. Variable-width, depending on which
11503 * formats the instruction supports.
11522 #include "micromips_translate.c.inc"
11524 #include "nanomips_translate.c.inc"
11526 /* MIPSDSP functions. */
11528 /* Indexed load is not for DSP only */
11529 static void gen_mips_lx(DisasContext
*ctx
, uint32_t opc
,
11530 int rd
, int base
, int offset
)
11534 if (!(ctx
->insn_flags
& INSN_OCTEON
)) {
11537 t0
= tcg_temp_new();
11540 gen_load_gpr(t0
, offset
);
11541 } else if (offset
== 0) {
11542 gen_load_gpr(t0
, base
);
11544 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], cpu_gpr
[offset
]);
11549 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, MO_UB
);
11550 gen_store_gpr(t0
, rd
);
11553 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SW
);
11554 gen_store_gpr(t0
, rd
);
11557 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_SL
);
11558 gen_store_gpr(t0
, rd
);
11560 #if defined(TARGET_MIPS64)
11562 tcg_gen_qemu_ld_tl(t0
, t0
, ctx
->mem_idx
, mo_endian(ctx
) | MO_UQ
);
11563 gen_store_gpr(t0
, rd
);
11569 static void gen_mipsdsp_arith(DisasContext
*ctx
, uint32_t op1
, uint32_t op2
,
11570 int ret
, int v1
, int v2
)
11576 /* Treat as NOP. */
11580 v1_t
= tcg_temp_new();
11581 v2_t
= tcg_temp_new();
11583 gen_load_gpr(v1_t
, v1
);
11584 gen_load_gpr(v2_t
, v2
);
11587 /* OPC_MULT_G_2E is equal OPC_ADDUH_QB_DSP */
11588 case OPC_MULT_G_2E
:
11592 gen_helper_adduh_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
11594 case OPC_ADDUH_R_QB
:
11595 gen_helper_adduh_r_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
11598 gen_helper_addqh_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
11600 case OPC_ADDQH_R_PH
:
11601 gen_helper_addqh_r_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
11604 gen_helper_addqh_w(cpu_gpr
[ret
], v1_t
, v2_t
);
11606 case OPC_ADDQH_R_W
:
11607 gen_helper_addqh_r_w(cpu_gpr
[ret
], v1_t
, v2_t
);
11610 gen_helper_subuh_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
11612 case OPC_SUBUH_R_QB
:
11613 gen_helper_subuh_r_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
11616 gen_helper_subqh_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
11618 case OPC_SUBQH_R_PH
:
11619 gen_helper_subqh_r_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
11622 gen_helper_subqh_w(cpu_gpr
[ret
], v1_t
, v2_t
);
11624 case OPC_SUBQH_R_W
:
11625 gen_helper_subqh_r_w(cpu_gpr
[ret
], v1_t
, v2_t
);
11629 case OPC_ABSQ_S_PH_DSP
:
11631 case OPC_ABSQ_S_QB
:
11633 gen_helper_absq_s_qb(cpu_gpr
[ret
], v2_t
, tcg_env
);
11635 case OPC_ABSQ_S_PH
:
11637 gen_helper_absq_s_ph(cpu_gpr
[ret
], v2_t
, tcg_env
);
11641 gen_helper_absq_s_w(cpu_gpr
[ret
], v2_t
, tcg_env
);
11643 case OPC_PRECEQ_W_PHL
:
11645 tcg_gen_andi_tl(cpu_gpr
[ret
], v2_t
, 0xFFFF0000);
11646 tcg_gen_ext32s_tl(cpu_gpr
[ret
], cpu_gpr
[ret
]);
11648 case OPC_PRECEQ_W_PHR
:
11650 tcg_gen_andi_tl(cpu_gpr
[ret
], v2_t
, 0x0000FFFF);
11651 tcg_gen_shli_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], 16);
11652 tcg_gen_ext32s_tl(cpu_gpr
[ret
], cpu_gpr
[ret
]);
11654 case OPC_PRECEQU_PH_QBL
:
11656 gen_helper_precequ_ph_qbl(cpu_gpr
[ret
], v2_t
);
11658 case OPC_PRECEQU_PH_QBR
:
11660 gen_helper_precequ_ph_qbr(cpu_gpr
[ret
], v2_t
);
11662 case OPC_PRECEQU_PH_QBLA
:
11664 gen_helper_precequ_ph_qbla(cpu_gpr
[ret
], v2_t
);
11666 case OPC_PRECEQU_PH_QBRA
:
11668 gen_helper_precequ_ph_qbra(cpu_gpr
[ret
], v2_t
);
11670 case OPC_PRECEU_PH_QBL
:
11672 gen_helper_preceu_ph_qbl(cpu_gpr
[ret
], v2_t
);
11674 case OPC_PRECEU_PH_QBR
:
11676 gen_helper_preceu_ph_qbr(cpu_gpr
[ret
], v2_t
);
11678 case OPC_PRECEU_PH_QBLA
:
11680 gen_helper_preceu_ph_qbla(cpu_gpr
[ret
], v2_t
);
11682 case OPC_PRECEU_PH_QBRA
:
11684 gen_helper_preceu_ph_qbra(cpu_gpr
[ret
], v2_t
);
11688 case OPC_ADDU_QB_DSP
:
11692 gen_helper_addq_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11694 case OPC_ADDQ_S_PH
:
11696 gen_helper_addq_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11700 gen_helper_addq_s_w(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11704 gen_helper_addu_qb(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11706 case OPC_ADDU_S_QB
:
11708 gen_helper_addu_s_qb(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11712 gen_helper_addu_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11714 case OPC_ADDU_S_PH
:
11716 gen_helper_addu_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11720 gen_helper_subq_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11722 case OPC_SUBQ_S_PH
:
11724 gen_helper_subq_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11728 gen_helper_subq_s_w(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11732 gen_helper_subu_qb(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11734 case OPC_SUBU_S_QB
:
11736 gen_helper_subu_s_qb(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11740 gen_helper_subu_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11742 case OPC_SUBU_S_PH
:
11744 gen_helper_subu_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11748 gen_helper_addsc(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11752 gen_helper_addwc(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11756 gen_helper_modsub(cpu_gpr
[ret
], v1_t
, v2_t
);
11758 case OPC_RADDU_W_QB
:
11760 gen_helper_raddu_w_qb(cpu_gpr
[ret
], v1_t
);
11764 case OPC_CMPU_EQ_QB_DSP
:
11766 case OPC_PRECR_QB_PH
:
11768 gen_helper_precr_qb_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
11770 case OPC_PRECRQ_QB_PH
:
11772 gen_helper_precrq_qb_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
11774 case OPC_PRECR_SRA_PH_W
:
11777 TCGv_i32 sa_t
= tcg_constant_i32(v2
);
11778 gen_helper_precr_sra_ph_w(cpu_gpr
[ret
], sa_t
, v1_t
,
11782 case OPC_PRECR_SRA_R_PH_W
:
11785 TCGv_i32 sa_t
= tcg_constant_i32(v2
);
11786 gen_helper_precr_sra_r_ph_w(cpu_gpr
[ret
], sa_t
, v1_t
,
11790 case OPC_PRECRQ_PH_W
:
11792 gen_helper_precrq_ph_w(cpu_gpr
[ret
], v1_t
, v2_t
);
11794 case OPC_PRECRQ_RS_PH_W
:
11796 gen_helper_precrq_rs_ph_w(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11798 case OPC_PRECRQU_S_QB_PH
:
11800 gen_helper_precrqu_s_qb_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11804 #ifdef TARGET_MIPS64
11805 case OPC_ABSQ_S_QH_DSP
:
11807 case OPC_PRECEQ_L_PWL
:
11809 tcg_gen_andi_tl(cpu_gpr
[ret
], v2_t
, 0xFFFFFFFF00000000ull
);
11811 case OPC_PRECEQ_L_PWR
:
11813 tcg_gen_shli_tl(cpu_gpr
[ret
], v2_t
, 32);
11815 case OPC_PRECEQ_PW_QHL
:
11817 gen_helper_preceq_pw_qhl(cpu_gpr
[ret
], v2_t
);
11819 case OPC_PRECEQ_PW_QHR
:
11821 gen_helper_preceq_pw_qhr(cpu_gpr
[ret
], v2_t
);
11823 case OPC_PRECEQ_PW_QHLA
:
11825 gen_helper_preceq_pw_qhla(cpu_gpr
[ret
], v2_t
);
11827 case OPC_PRECEQ_PW_QHRA
:
11829 gen_helper_preceq_pw_qhra(cpu_gpr
[ret
], v2_t
);
11831 case OPC_PRECEQU_QH_OBL
:
11833 gen_helper_precequ_qh_obl(cpu_gpr
[ret
], v2_t
);
11835 case OPC_PRECEQU_QH_OBR
:
11837 gen_helper_precequ_qh_obr(cpu_gpr
[ret
], v2_t
);
11839 case OPC_PRECEQU_QH_OBLA
:
11841 gen_helper_precequ_qh_obla(cpu_gpr
[ret
], v2_t
);
11843 case OPC_PRECEQU_QH_OBRA
:
11845 gen_helper_precequ_qh_obra(cpu_gpr
[ret
], v2_t
);
11847 case OPC_PRECEU_QH_OBL
:
11849 gen_helper_preceu_qh_obl(cpu_gpr
[ret
], v2_t
);
11851 case OPC_PRECEU_QH_OBR
:
11853 gen_helper_preceu_qh_obr(cpu_gpr
[ret
], v2_t
);
11855 case OPC_PRECEU_QH_OBLA
:
11857 gen_helper_preceu_qh_obla(cpu_gpr
[ret
], v2_t
);
11859 case OPC_PRECEU_QH_OBRA
:
11861 gen_helper_preceu_qh_obra(cpu_gpr
[ret
], v2_t
);
11863 case OPC_ABSQ_S_OB
:
11865 gen_helper_absq_s_ob(cpu_gpr
[ret
], v2_t
, tcg_env
);
11867 case OPC_ABSQ_S_PW
:
11869 gen_helper_absq_s_pw(cpu_gpr
[ret
], v2_t
, tcg_env
);
11871 case OPC_ABSQ_S_QH
:
11873 gen_helper_absq_s_qh(cpu_gpr
[ret
], v2_t
, tcg_env
);
11877 case OPC_ADDU_OB_DSP
:
11879 case OPC_RADDU_L_OB
:
11881 gen_helper_raddu_l_ob(cpu_gpr
[ret
], v1_t
);
11885 gen_helper_subq_pw(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11887 case OPC_SUBQ_S_PW
:
11889 gen_helper_subq_s_pw(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11893 gen_helper_subq_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11895 case OPC_SUBQ_S_QH
:
11897 gen_helper_subq_s_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11901 gen_helper_subu_ob(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11903 case OPC_SUBU_S_OB
:
11905 gen_helper_subu_s_ob(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11909 gen_helper_subu_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11911 case OPC_SUBU_S_QH
:
11913 gen_helper_subu_s_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11917 gen_helper_subuh_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
11919 case OPC_SUBUH_R_OB
:
11921 gen_helper_subuh_r_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
11925 gen_helper_addq_pw(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11927 case OPC_ADDQ_S_PW
:
11929 gen_helper_addq_s_pw(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11933 gen_helper_addq_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11935 case OPC_ADDQ_S_QH
:
11937 gen_helper_addq_s_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11941 gen_helper_addu_ob(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11943 case OPC_ADDU_S_OB
:
11945 gen_helper_addu_s_ob(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11949 gen_helper_addu_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11951 case OPC_ADDU_S_QH
:
11953 gen_helper_addu_s_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
11957 gen_helper_adduh_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
11959 case OPC_ADDUH_R_OB
:
11961 gen_helper_adduh_r_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
11965 case OPC_CMPU_EQ_OB_DSP
:
11967 case OPC_PRECR_OB_QH
:
11969 gen_helper_precr_ob_qh(cpu_gpr
[ret
], v1_t
, v2_t
);
11971 case OPC_PRECR_SRA_QH_PW
:
11974 TCGv_i32 ret_t
= tcg_constant_i32(ret
);
11975 gen_helper_precr_sra_qh_pw(v2_t
, v1_t
, v2_t
, ret_t
);
11978 case OPC_PRECR_SRA_R_QH_PW
:
11981 TCGv_i32 sa_v
= tcg_constant_i32(ret
);
11982 gen_helper_precr_sra_r_qh_pw(v2_t
, v1_t
, v2_t
, sa_v
);
11985 case OPC_PRECRQ_OB_QH
:
11987 gen_helper_precrq_ob_qh(cpu_gpr
[ret
], v1_t
, v2_t
);
11989 case OPC_PRECRQ_PW_L
:
11991 gen_helper_precrq_pw_l(cpu_gpr
[ret
], v1_t
, v2_t
);
11993 case OPC_PRECRQ_QH_PW
:
11995 gen_helper_precrq_qh_pw(cpu_gpr
[ret
], v1_t
, v2_t
);
11997 case OPC_PRECRQ_RS_QH_PW
:
11999 gen_helper_precrq_rs_qh_pw(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12001 case OPC_PRECRQU_S_OB_QH
:
12003 gen_helper_precrqu_s_ob_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12011 static void gen_mipsdsp_shift(DisasContext
*ctx
, uint32_t opc
,
12012 int ret
, int v1
, int v2
)
12020 /* Treat as NOP. */
12024 t0
= tcg_temp_new();
12025 v1_t
= tcg_temp_new();
12026 v2_t
= tcg_temp_new();
12028 tcg_gen_movi_tl(t0
, v1
);
12029 gen_load_gpr(v1_t
, v1
);
12030 gen_load_gpr(v2_t
, v2
);
12033 case OPC_SHLL_QB_DSP
:
12035 op2
= MASK_SHLL_QB(ctx
->opcode
);
12039 gen_helper_shll_qb(cpu_gpr
[ret
], t0
, v2_t
, tcg_env
);
12043 gen_helper_shll_qb(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12047 gen_helper_shll_ph(cpu_gpr
[ret
], t0
, v2_t
, tcg_env
);
12051 gen_helper_shll_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12053 case OPC_SHLL_S_PH
:
12055 gen_helper_shll_s_ph(cpu_gpr
[ret
], t0
, v2_t
, tcg_env
);
12057 case OPC_SHLLV_S_PH
:
12059 gen_helper_shll_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12063 gen_helper_shll_s_w(cpu_gpr
[ret
], t0
, v2_t
, tcg_env
);
12065 case OPC_SHLLV_S_W
:
12067 gen_helper_shll_s_w(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12071 gen_helper_shrl_qb(cpu_gpr
[ret
], t0
, v2_t
);
12075 gen_helper_shrl_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
12079 gen_helper_shrl_ph(cpu_gpr
[ret
], t0
, v2_t
);
12083 gen_helper_shrl_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
12087 gen_helper_shra_qb(cpu_gpr
[ret
], t0
, v2_t
);
12089 case OPC_SHRA_R_QB
:
12091 gen_helper_shra_r_qb(cpu_gpr
[ret
], t0
, v2_t
);
12095 gen_helper_shra_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
12097 case OPC_SHRAV_R_QB
:
12099 gen_helper_shra_r_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
12103 gen_helper_shra_ph(cpu_gpr
[ret
], t0
, v2_t
);
12105 case OPC_SHRA_R_PH
:
12107 gen_helper_shra_r_ph(cpu_gpr
[ret
], t0
, v2_t
);
12111 gen_helper_shra_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
12113 case OPC_SHRAV_R_PH
:
12115 gen_helper_shra_r_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
12119 gen_helper_shra_r_w(cpu_gpr
[ret
], t0
, v2_t
);
12121 case OPC_SHRAV_R_W
:
12123 gen_helper_shra_r_w(cpu_gpr
[ret
], v1_t
, v2_t
);
12125 default: /* Invalid */
12126 MIPS_INVAL("MASK SHLL.QB");
12127 gen_reserved_instruction(ctx
);
12132 #ifdef TARGET_MIPS64
12133 case OPC_SHLL_OB_DSP
:
12134 op2
= MASK_SHLL_OB(ctx
->opcode
);
12138 gen_helper_shll_pw(cpu_gpr
[ret
], v2_t
, t0
, tcg_env
);
12142 gen_helper_shll_pw(cpu_gpr
[ret
], v2_t
, v1_t
, tcg_env
);
12144 case OPC_SHLL_S_PW
:
12146 gen_helper_shll_s_pw(cpu_gpr
[ret
], v2_t
, t0
, tcg_env
);
12148 case OPC_SHLLV_S_PW
:
12150 gen_helper_shll_s_pw(cpu_gpr
[ret
], v2_t
, v1_t
, tcg_env
);
12154 gen_helper_shll_ob(cpu_gpr
[ret
], v2_t
, t0
, tcg_env
);
12158 gen_helper_shll_ob(cpu_gpr
[ret
], v2_t
, v1_t
, tcg_env
);
12162 gen_helper_shll_qh(cpu_gpr
[ret
], v2_t
, t0
, tcg_env
);
12166 gen_helper_shll_qh(cpu_gpr
[ret
], v2_t
, v1_t
, tcg_env
);
12168 case OPC_SHLL_S_QH
:
12170 gen_helper_shll_s_qh(cpu_gpr
[ret
], v2_t
, t0
, tcg_env
);
12172 case OPC_SHLLV_S_QH
:
12174 gen_helper_shll_s_qh(cpu_gpr
[ret
], v2_t
, v1_t
, tcg_env
);
12178 gen_helper_shra_ob(cpu_gpr
[ret
], v2_t
, t0
);
12182 gen_helper_shra_ob(cpu_gpr
[ret
], v2_t
, v1_t
);
12184 case OPC_SHRA_R_OB
:
12186 gen_helper_shra_r_ob(cpu_gpr
[ret
], v2_t
, t0
);
12188 case OPC_SHRAV_R_OB
:
12190 gen_helper_shra_r_ob(cpu_gpr
[ret
], v2_t
, v1_t
);
12194 gen_helper_shra_pw(cpu_gpr
[ret
], v2_t
, t0
);
12198 gen_helper_shra_pw(cpu_gpr
[ret
], v2_t
, v1_t
);
12200 case OPC_SHRA_R_PW
:
12202 gen_helper_shra_r_pw(cpu_gpr
[ret
], v2_t
, t0
);
12204 case OPC_SHRAV_R_PW
:
12206 gen_helper_shra_r_pw(cpu_gpr
[ret
], v2_t
, v1_t
);
12210 gen_helper_shra_qh(cpu_gpr
[ret
], v2_t
, t0
);
12214 gen_helper_shra_qh(cpu_gpr
[ret
], v2_t
, v1_t
);
12216 case OPC_SHRA_R_QH
:
12218 gen_helper_shra_r_qh(cpu_gpr
[ret
], v2_t
, t0
);
12220 case OPC_SHRAV_R_QH
:
12222 gen_helper_shra_r_qh(cpu_gpr
[ret
], v2_t
, v1_t
);
12226 gen_helper_shrl_ob(cpu_gpr
[ret
], v2_t
, t0
);
12230 gen_helper_shrl_ob(cpu_gpr
[ret
], v2_t
, v1_t
);
12234 gen_helper_shrl_qh(cpu_gpr
[ret
], v2_t
, t0
);
12238 gen_helper_shrl_qh(cpu_gpr
[ret
], v2_t
, v1_t
);
12240 default: /* Invalid */
12241 MIPS_INVAL("MASK SHLL.OB");
12242 gen_reserved_instruction(ctx
);
12250 static void gen_mipsdsp_multiply(DisasContext
*ctx
, uint32_t op1
, uint32_t op2
,
12251 int ret
, int v1
, int v2
, int check_ret
)
12257 if ((ret
== 0) && (check_ret
== 1)) {
12258 /* Treat as NOP. */
12262 t0
= tcg_temp_new_i32();
12263 v1_t
= tcg_temp_new();
12264 v2_t
= tcg_temp_new();
12266 tcg_gen_movi_i32(t0
, ret
);
12267 gen_load_gpr(v1_t
, v1
);
12268 gen_load_gpr(v2_t
, v2
);
12272 * OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have
12273 * the same mask and op1.
12275 case OPC_MULT_G_2E
:
12279 gen_helper_mul_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12282 gen_helper_mul_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12285 gen_helper_mulq_s_w(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12287 case OPC_MULQ_RS_W
:
12288 gen_helper_mulq_rs_w(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12292 case OPC_DPA_W_PH_DSP
:
12294 case OPC_DPAU_H_QBL
:
12296 gen_helper_dpau_h_qbl(t0
, v1_t
, v2_t
, tcg_env
);
12298 case OPC_DPAU_H_QBR
:
12300 gen_helper_dpau_h_qbr(t0
, v1_t
, v2_t
, tcg_env
);
12302 case OPC_DPSU_H_QBL
:
12304 gen_helper_dpsu_h_qbl(t0
, v1_t
, v2_t
, tcg_env
);
12306 case OPC_DPSU_H_QBR
:
12308 gen_helper_dpsu_h_qbr(t0
, v1_t
, v2_t
, tcg_env
);
12312 gen_helper_dpa_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12314 case OPC_DPAX_W_PH
:
12316 gen_helper_dpax_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12318 case OPC_DPAQ_S_W_PH
:
12320 gen_helper_dpaq_s_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12322 case OPC_DPAQX_S_W_PH
:
12324 gen_helper_dpaqx_s_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12326 case OPC_DPAQX_SA_W_PH
:
12328 gen_helper_dpaqx_sa_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12332 gen_helper_dps_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12334 case OPC_DPSX_W_PH
:
12336 gen_helper_dpsx_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12338 case OPC_DPSQ_S_W_PH
:
12340 gen_helper_dpsq_s_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12342 case OPC_DPSQX_S_W_PH
:
12344 gen_helper_dpsqx_s_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12346 case OPC_DPSQX_SA_W_PH
:
12348 gen_helper_dpsqx_sa_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12350 case OPC_MULSAQ_S_W_PH
:
12352 gen_helper_mulsaq_s_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12354 case OPC_DPAQ_SA_L_W
:
12356 gen_helper_dpaq_sa_l_w(t0
, v1_t
, v2_t
, tcg_env
);
12358 case OPC_DPSQ_SA_L_W
:
12360 gen_helper_dpsq_sa_l_w(t0
, v1_t
, v2_t
, tcg_env
);
12362 case OPC_MAQ_S_W_PHL
:
12364 gen_helper_maq_s_w_phl(t0
, v1_t
, v2_t
, tcg_env
);
12366 case OPC_MAQ_S_W_PHR
:
12368 gen_helper_maq_s_w_phr(t0
, v1_t
, v2_t
, tcg_env
);
12370 case OPC_MAQ_SA_W_PHL
:
12372 gen_helper_maq_sa_w_phl(t0
, v1_t
, v2_t
, tcg_env
);
12374 case OPC_MAQ_SA_W_PHR
:
12376 gen_helper_maq_sa_w_phr(t0
, v1_t
, v2_t
, tcg_env
);
12378 case OPC_MULSA_W_PH
:
12380 gen_helper_mulsa_w_ph(t0
, v1_t
, v2_t
, tcg_env
);
12384 #ifdef TARGET_MIPS64
12385 case OPC_DPAQ_W_QH_DSP
:
12387 int ac
= ret
& 0x03;
12388 tcg_gen_movi_i32(t0
, ac
);
12393 gen_helper_dmadd(v1_t
, v2_t
, t0
, tcg_env
);
12397 gen_helper_dmaddu(v1_t
, v2_t
, t0
, tcg_env
);
12401 gen_helper_dmsub(v1_t
, v2_t
, t0
, tcg_env
);
12405 gen_helper_dmsubu(v1_t
, v2_t
, t0
, tcg_env
);
12409 gen_helper_dpa_w_qh(v1_t
, v2_t
, t0
, tcg_env
);
12411 case OPC_DPAQ_S_W_QH
:
12413 gen_helper_dpaq_s_w_qh(v1_t
, v2_t
, t0
, tcg_env
);
12415 case OPC_DPAQ_SA_L_PW
:
12417 gen_helper_dpaq_sa_l_pw(v1_t
, v2_t
, t0
, tcg_env
);
12419 case OPC_DPAU_H_OBL
:
12421 gen_helper_dpau_h_obl(v1_t
, v2_t
, t0
, tcg_env
);
12423 case OPC_DPAU_H_OBR
:
12425 gen_helper_dpau_h_obr(v1_t
, v2_t
, t0
, tcg_env
);
12429 gen_helper_dps_w_qh(v1_t
, v2_t
, t0
, tcg_env
);
12431 case OPC_DPSQ_S_W_QH
:
12433 gen_helper_dpsq_s_w_qh(v1_t
, v2_t
, t0
, tcg_env
);
12435 case OPC_DPSQ_SA_L_PW
:
12437 gen_helper_dpsq_sa_l_pw(v1_t
, v2_t
, t0
, tcg_env
);
12439 case OPC_DPSU_H_OBL
:
12441 gen_helper_dpsu_h_obl(v1_t
, v2_t
, t0
, tcg_env
);
12443 case OPC_DPSU_H_OBR
:
12445 gen_helper_dpsu_h_obr(v1_t
, v2_t
, t0
, tcg_env
);
12447 case OPC_MAQ_S_L_PWL
:
12449 gen_helper_maq_s_l_pwl(v1_t
, v2_t
, t0
, tcg_env
);
12451 case OPC_MAQ_S_L_PWR
:
12453 gen_helper_maq_s_l_pwr(v1_t
, v2_t
, t0
, tcg_env
);
12455 case OPC_MAQ_S_W_QHLL
:
12457 gen_helper_maq_s_w_qhll(v1_t
, v2_t
, t0
, tcg_env
);
12459 case OPC_MAQ_SA_W_QHLL
:
12461 gen_helper_maq_sa_w_qhll(v1_t
, v2_t
, t0
, tcg_env
);
12463 case OPC_MAQ_S_W_QHLR
:
12465 gen_helper_maq_s_w_qhlr(v1_t
, v2_t
, t0
, tcg_env
);
12467 case OPC_MAQ_SA_W_QHLR
:
12469 gen_helper_maq_sa_w_qhlr(v1_t
, v2_t
, t0
, tcg_env
);
12471 case OPC_MAQ_S_W_QHRL
:
12473 gen_helper_maq_s_w_qhrl(v1_t
, v2_t
, t0
, tcg_env
);
12475 case OPC_MAQ_SA_W_QHRL
:
12477 gen_helper_maq_sa_w_qhrl(v1_t
, v2_t
, t0
, tcg_env
);
12479 case OPC_MAQ_S_W_QHRR
:
12481 gen_helper_maq_s_w_qhrr(v1_t
, v2_t
, t0
, tcg_env
);
12483 case OPC_MAQ_SA_W_QHRR
:
12485 gen_helper_maq_sa_w_qhrr(v1_t
, v2_t
, t0
, tcg_env
);
12487 case OPC_MULSAQ_S_L_PW
:
12489 gen_helper_mulsaq_s_l_pw(v1_t
, v2_t
, t0
, tcg_env
);
12491 case OPC_MULSAQ_S_W_QH
:
12493 gen_helper_mulsaq_s_w_qh(v1_t
, v2_t
, t0
, tcg_env
);
12499 case OPC_ADDU_QB_DSP
:
12501 case OPC_MULEU_S_PH_QBL
:
12503 gen_helper_muleu_s_ph_qbl(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12505 case OPC_MULEU_S_PH_QBR
:
12507 gen_helper_muleu_s_ph_qbr(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12509 case OPC_MULQ_RS_PH
:
12511 gen_helper_mulq_rs_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12513 case OPC_MULEQ_S_W_PHL
:
12515 gen_helper_muleq_s_w_phl(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12517 case OPC_MULEQ_S_W_PHR
:
12519 gen_helper_muleq_s_w_phr(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12521 case OPC_MULQ_S_PH
:
12523 gen_helper_mulq_s_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12527 #ifdef TARGET_MIPS64
12528 case OPC_ADDU_OB_DSP
:
12530 case OPC_MULEQ_S_PW_QHL
:
12532 gen_helper_muleq_s_pw_qhl(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12534 case OPC_MULEQ_S_PW_QHR
:
12536 gen_helper_muleq_s_pw_qhr(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12538 case OPC_MULEU_S_QH_OBL
:
12540 gen_helper_muleu_s_qh_obl(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12542 case OPC_MULEU_S_QH_OBR
:
12544 gen_helper_muleu_s_qh_obr(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12546 case OPC_MULQ_RS_QH
:
12548 gen_helper_mulq_rs_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12556 static void gen_mipsdsp_bitinsn(DisasContext
*ctx
, uint32_t op1
, uint32_t op2
,
12564 /* Treat as NOP. */
12568 t0
= tcg_temp_new();
12569 val_t
= tcg_temp_new();
12570 gen_load_gpr(val_t
, val
);
12573 case OPC_ABSQ_S_PH_DSP
:
12577 gen_helper_bitrev(cpu_gpr
[ret
], val_t
);
12582 target_long result
;
12583 imm
= (ctx
->opcode
>> 16) & 0xFF;
12584 result
= (uint32_t)imm
<< 24 |
12585 (uint32_t)imm
<< 16 |
12586 (uint32_t)imm
<< 8 |
12588 result
= (int32_t)result
;
12589 tcg_gen_movi_tl(cpu_gpr
[ret
], result
);
12594 tcg_gen_ext8u_tl(cpu_gpr
[ret
], val_t
);
12595 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 8);
12596 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12597 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 16);
12598 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12599 tcg_gen_ext32s_tl(cpu_gpr
[ret
], cpu_gpr
[ret
]);
12604 imm
= (ctx
->opcode
>> 16) & 0x03FF;
12605 imm
= (int16_t)(imm
<< 6) >> 6;
12606 tcg_gen_movi_tl(cpu_gpr
[ret
], \
12607 (target_long
)((int32_t)imm
<< 16 | \
12613 tcg_gen_ext16u_tl(cpu_gpr
[ret
], val_t
);
12614 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 16);
12615 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12616 tcg_gen_ext32s_tl(cpu_gpr
[ret
], cpu_gpr
[ret
]);
12620 #ifdef TARGET_MIPS64
12621 case OPC_ABSQ_S_QH_DSP
:
12628 imm
= (ctx
->opcode
>> 16) & 0xFF;
12629 temp
= ((uint64_t)imm
<< 8) | (uint64_t)imm
;
12630 temp
= (temp
<< 16) | temp
;
12631 temp
= (temp
<< 32) | temp
;
12632 tcg_gen_movi_tl(cpu_gpr
[ret
], temp
);
12640 imm
= (ctx
->opcode
>> 16) & 0x03FF;
12641 imm
= (int16_t)(imm
<< 6) >> 6;
12642 temp
= ((target_long
)imm
<< 32) \
12643 | ((target_long
)imm
& 0xFFFFFFFF);
12644 tcg_gen_movi_tl(cpu_gpr
[ret
], temp
);
12652 imm
= (ctx
->opcode
>> 16) & 0x03FF;
12653 imm
= (int16_t)(imm
<< 6) >> 6;
12655 temp
= ((uint64_t)(uint16_t)imm
<< 48) |
12656 ((uint64_t)(uint16_t)imm
<< 32) |
12657 ((uint64_t)(uint16_t)imm
<< 16) |
12658 (uint64_t)(uint16_t)imm
;
12659 tcg_gen_movi_tl(cpu_gpr
[ret
], temp
);
12664 tcg_gen_ext8u_tl(cpu_gpr
[ret
], val_t
);
12665 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 8);
12666 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12667 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 16);
12668 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12669 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 32);
12670 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12674 tcg_gen_ext32u_i64(cpu_gpr
[ret
], val_t
);
12675 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 32);
12676 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12680 tcg_gen_ext16u_tl(cpu_gpr
[ret
], val_t
);
12681 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 16);
12682 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12683 tcg_gen_shli_tl(t0
, cpu_gpr
[ret
], 32);
12684 tcg_gen_or_tl(cpu_gpr
[ret
], cpu_gpr
[ret
], t0
);
12692 static void gen_mipsdsp_add_cmp_pick(DisasContext
*ctx
,
12693 uint32_t op1
, uint32_t op2
,
12694 int ret
, int v1
, int v2
, int check_ret
)
12700 if ((ret
== 0) && (check_ret
== 1)) {
12701 /* Treat as NOP. */
12705 t1
= tcg_temp_new();
12706 v1_t
= tcg_temp_new();
12707 v2_t
= tcg_temp_new();
12709 gen_load_gpr(v1_t
, v1
);
12710 gen_load_gpr(v2_t
, v2
);
12713 case OPC_CMPU_EQ_QB_DSP
:
12715 case OPC_CMPU_EQ_QB
:
12717 gen_helper_cmpu_eq_qb(v1_t
, v2_t
, tcg_env
);
12719 case OPC_CMPU_LT_QB
:
12721 gen_helper_cmpu_lt_qb(v1_t
, v2_t
, tcg_env
);
12723 case OPC_CMPU_LE_QB
:
12725 gen_helper_cmpu_le_qb(v1_t
, v2_t
, tcg_env
);
12727 case OPC_CMPGU_EQ_QB
:
12729 gen_helper_cmpgu_eq_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
12731 case OPC_CMPGU_LT_QB
:
12733 gen_helper_cmpgu_lt_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
12735 case OPC_CMPGU_LE_QB
:
12737 gen_helper_cmpgu_le_qb(cpu_gpr
[ret
], v1_t
, v2_t
);
12739 case OPC_CMPGDU_EQ_QB
:
12741 gen_helper_cmpgu_eq_qb(t1
, v1_t
, v2_t
);
12742 tcg_gen_mov_tl(cpu_gpr
[ret
], t1
);
12743 tcg_gen_andi_tl(cpu_dspctrl
, cpu_dspctrl
, 0xF0FFFFFF);
12744 tcg_gen_shli_tl(t1
, t1
, 24);
12745 tcg_gen_or_tl(cpu_dspctrl
, cpu_dspctrl
, t1
);
12747 case OPC_CMPGDU_LT_QB
:
12749 gen_helper_cmpgu_lt_qb(t1
, v1_t
, v2_t
);
12750 tcg_gen_mov_tl(cpu_gpr
[ret
], t1
);
12751 tcg_gen_andi_tl(cpu_dspctrl
, cpu_dspctrl
, 0xF0FFFFFF);
12752 tcg_gen_shli_tl(t1
, t1
, 24);
12753 tcg_gen_or_tl(cpu_dspctrl
, cpu_dspctrl
, t1
);
12755 case OPC_CMPGDU_LE_QB
:
12757 gen_helper_cmpgu_le_qb(t1
, v1_t
, v2_t
);
12758 tcg_gen_mov_tl(cpu_gpr
[ret
], t1
);
12759 tcg_gen_andi_tl(cpu_dspctrl
, cpu_dspctrl
, 0xF0FFFFFF);
12760 tcg_gen_shli_tl(t1
, t1
, 24);
12761 tcg_gen_or_tl(cpu_dspctrl
, cpu_dspctrl
, t1
);
12763 case OPC_CMP_EQ_PH
:
12765 gen_helper_cmp_eq_ph(v1_t
, v2_t
, tcg_env
);
12767 case OPC_CMP_LT_PH
:
12769 gen_helper_cmp_lt_ph(v1_t
, v2_t
, tcg_env
);
12771 case OPC_CMP_LE_PH
:
12773 gen_helper_cmp_le_ph(v1_t
, v2_t
, tcg_env
);
12777 gen_helper_pick_qb(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12781 gen_helper_pick_ph(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12783 case OPC_PACKRL_PH
:
12785 gen_helper_packrl_ph(cpu_gpr
[ret
], v1_t
, v2_t
);
12789 #ifdef TARGET_MIPS64
12790 case OPC_CMPU_EQ_OB_DSP
:
12792 case OPC_CMP_EQ_PW
:
12794 gen_helper_cmp_eq_pw(v1_t
, v2_t
, tcg_env
);
12796 case OPC_CMP_LT_PW
:
12798 gen_helper_cmp_lt_pw(v1_t
, v2_t
, tcg_env
);
12800 case OPC_CMP_LE_PW
:
12802 gen_helper_cmp_le_pw(v1_t
, v2_t
, tcg_env
);
12804 case OPC_CMP_EQ_QH
:
12806 gen_helper_cmp_eq_qh(v1_t
, v2_t
, tcg_env
);
12808 case OPC_CMP_LT_QH
:
12810 gen_helper_cmp_lt_qh(v1_t
, v2_t
, tcg_env
);
12812 case OPC_CMP_LE_QH
:
12814 gen_helper_cmp_le_qh(v1_t
, v2_t
, tcg_env
);
12816 case OPC_CMPGDU_EQ_OB
:
12818 gen_helper_cmpgdu_eq_ob(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12820 case OPC_CMPGDU_LT_OB
:
12822 gen_helper_cmpgdu_lt_ob(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12824 case OPC_CMPGDU_LE_OB
:
12826 gen_helper_cmpgdu_le_ob(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12828 case OPC_CMPGU_EQ_OB
:
12830 gen_helper_cmpgu_eq_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
12832 case OPC_CMPGU_LT_OB
:
12834 gen_helper_cmpgu_lt_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
12836 case OPC_CMPGU_LE_OB
:
12838 gen_helper_cmpgu_le_ob(cpu_gpr
[ret
], v1_t
, v2_t
);
12840 case OPC_CMPU_EQ_OB
:
12842 gen_helper_cmpu_eq_ob(v1_t
, v2_t
, tcg_env
);
12844 case OPC_CMPU_LT_OB
:
12846 gen_helper_cmpu_lt_ob(v1_t
, v2_t
, tcg_env
);
12848 case OPC_CMPU_LE_OB
:
12850 gen_helper_cmpu_le_ob(v1_t
, v2_t
, tcg_env
);
12852 case OPC_PACKRL_PW
:
12854 gen_helper_packrl_pw(cpu_gpr
[ret
], v1_t
, v2_t
);
12858 gen_helper_pick_ob(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12862 gen_helper_pick_pw(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12866 gen_helper_pick_qh(cpu_gpr
[ret
], v1_t
, v2_t
, tcg_env
);
12874 static void gen_mipsdsp_append(CPUMIPSState
*env
, DisasContext
*ctx
,
12875 uint32_t op1
, int rt
, int rs
, int sa
)
12882 /* Treat as NOP. */
12886 t0
= tcg_temp_new();
12887 gen_load_gpr(t0
, rs
);
12890 case OPC_APPEND_DSP
:
12891 switch (MASK_APPEND(ctx
->opcode
)) {
12894 tcg_gen_deposit_tl(cpu_gpr
[rt
], t0
, cpu_gpr
[rt
], sa
, 32 - sa
);
12896 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
12900 tcg_gen_ext32u_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
12901 tcg_gen_shri_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], sa
);
12902 tcg_gen_shli_tl(t0
, t0
, 32 - sa
);
12903 tcg_gen_or_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], t0
);
12905 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
12909 if (sa
!= 0 && sa
!= 2) {
12910 tcg_gen_shli_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], 8 * sa
);
12911 tcg_gen_ext32u_tl(t0
, t0
);
12912 tcg_gen_shri_tl(t0
, t0
, 8 * (4 - sa
));
12913 tcg_gen_or_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], t0
);
12915 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
12917 default: /* Invalid */
12918 MIPS_INVAL("MASK APPEND");
12919 gen_reserved_instruction(ctx
);
12923 #ifdef TARGET_MIPS64
12924 case OPC_DAPPEND_DSP
:
12925 switch (MASK_DAPPEND(ctx
->opcode
)) {
12928 tcg_gen_deposit_tl(cpu_gpr
[rt
], t0
, cpu_gpr
[rt
], sa
, 64 - sa
);
12932 tcg_gen_shri_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], 0x20 | sa
);
12933 tcg_gen_shli_tl(t0
, t0
, 64 - (0x20 | sa
));
12934 tcg_gen_or_tl(cpu_gpr
[rt
], t0
, t0
);
12938 tcg_gen_shri_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], sa
);
12939 tcg_gen_shli_tl(t0
, t0
, 64 - sa
);
12940 tcg_gen_or_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], t0
);
12945 if (sa
!= 0 && sa
!= 2 && sa
!= 4) {
12946 tcg_gen_shli_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], 8 * sa
);
12947 tcg_gen_shri_tl(t0
, t0
, 8 * (8 - sa
));
12948 tcg_gen_or_tl(cpu_gpr
[rt
], cpu_gpr
[rt
], t0
);
12951 default: /* Invalid */
12952 MIPS_INVAL("MASK DAPPEND");
12953 gen_reserved_instruction(ctx
);
12961 static void gen_mipsdsp_accinsn(DisasContext
*ctx
, uint32_t op1
, uint32_t op2
,
12962 int ret
, int v1
, int v2
, int check_ret
)
12970 if ((ret
== 0) && (check_ret
== 1)) {
12971 /* Treat as NOP. */
12975 t0
= tcg_temp_new();
12976 t1
= tcg_temp_new();
12977 v1_t
= tcg_temp_new();
12979 gen_load_gpr(v1_t
, v1
);
12982 case OPC_EXTR_W_DSP
:
12986 tcg_gen_movi_tl(t0
, v2
);
12987 tcg_gen_movi_tl(t1
, v1
);
12988 gen_helper_extr_w(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
12991 tcg_gen_movi_tl(t0
, v2
);
12992 tcg_gen_movi_tl(t1
, v1
);
12993 gen_helper_extr_r_w(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
12995 case OPC_EXTR_RS_W
:
12996 tcg_gen_movi_tl(t0
, v2
);
12997 tcg_gen_movi_tl(t1
, v1
);
12998 gen_helper_extr_rs_w(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13001 tcg_gen_movi_tl(t0
, v2
);
13002 tcg_gen_movi_tl(t1
, v1
);
13003 gen_helper_extr_s_h(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13005 case OPC_EXTRV_S_H
:
13006 tcg_gen_movi_tl(t0
, v2
);
13007 gen_helper_extr_s_h(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13010 tcg_gen_movi_tl(t0
, v2
);
13011 gen_helper_extr_w(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13013 case OPC_EXTRV_R_W
:
13014 tcg_gen_movi_tl(t0
, v2
);
13015 gen_helper_extr_r_w(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13017 case OPC_EXTRV_RS_W
:
13018 tcg_gen_movi_tl(t0
, v2
);
13019 gen_helper_extr_rs_w(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13022 tcg_gen_movi_tl(t0
, v2
);
13023 tcg_gen_movi_tl(t1
, v1
);
13024 gen_helper_extp(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13027 tcg_gen_movi_tl(t0
, v2
);
13028 gen_helper_extp(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13031 tcg_gen_movi_tl(t0
, v2
);
13032 tcg_gen_movi_tl(t1
, v1
);
13033 gen_helper_extpdp(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13036 tcg_gen_movi_tl(t0
, v2
);
13037 gen_helper_extpdp(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13040 imm
= (ctx
->opcode
>> 20) & 0x3F;
13041 tcg_gen_movi_tl(t0
, ret
);
13042 tcg_gen_movi_tl(t1
, imm
);
13043 gen_helper_shilo(t0
, t1
, tcg_env
);
13046 tcg_gen_movi_tl(t0
, ret
);
13047 gen_helper_shilo(t0
, v1_t
, tcg_env
);
13050 tcg_gen_movi_tl(t0
, ret
);
13051 gen_helper_mthlip(t0
, v1_t
, tcg_env
);
13054 imm
= (ctx
->opcode
>> 11) & 0x3FF;
13055 tcg_gen_movi_tl(t0
, imm
);
13056 gen_helper_wrdsp(v1_t
, t0
, tcg_env
);
13059 imm
= (ctx
->opcode
>> 16) & 0x03FF;
13060 tcg_gen_movi_tl(t0
, imm
);
13061 gen_helper_rddsp(cpu_gpr
[ret
], t0
, tcg_env
);
13065 #ifdef TARGET_MIPS64
13066 case OPC_DEXTR_W_DSP
:
13070 tcg_gen_movi_tl(t0
, ret
);
13071 gen_helper_dmthlip(v1_t
, t0
, tcg_env
);
13075 int shift
= (ctx
->opcode
>> 19) & 0x7F;
13076 int ac
= (ctx
->opcode
>> 11) & 0x03;
13077 tcg_gen_movi_tl(t0
, shift
);
13078 tcg_gen_movi_tl(t1
, ac
);
13079 gen_helper_dshilo(t0
, t1
, tcg_env
);
13084 int ac
= (ctx
->opcode
>> 11) & 0x03;
13085 tcg_gen_movi_tl(t0
, ac
);
13086 gen_helper_dshilo(v1_t
, t0
, tcg_env
);
13090 tcg_gen_movi_tl(t0
, v2
);
13091 tcg_gen_movi_tl(t1
, v1
);
13093 gen_helper_dextp(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13096 tcg_gen_movi_tl(t0
, v2
);
13097 gen_helper_dextp(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13100 tcg_gen_movi_tl(t0
, v2
);
13101 tcg_gen_movi_tl(t1
, v1
);
13102 gen_helper_dextpdp(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13105 tcg_gen_movi_tl(t0
, v2
);
13106 gen_helper_dextpdp(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13109 tcg_gen_movi_tl(t0
, v2
);
13110 tcg_gen_movi_tl(t1
, v1
);
13111 gen_helper_dextr_l(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13113 case OPC_DEXTR_R_L
:
13114 tcg_gen_movi_tl(t0
, v2
);
13115 tcg_gen_movi_tl(t1
, v1
);
13116 gen_helper_dextr_r_l(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13118 case OPC_DEXTR_RS_L
:
13119 tcg_gen_movi_tl(t0
, v2
);
13120 tcg_gen_movi_tl(t1
, v1
);
13121 gen_helper_dextr_rs_l(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13124 tcg_gen_movi_tl(t0
, v2
);
13125 tcg_gen_movi_tl(t1
, v1
);
13126 gen_helper_dextr_w(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13128 case OPC_DEXTR_R_W
:
13129 tcg_gen_movi_tl(t0
, v2
);
13130 tcg_gen_movi_tl(t1
, v1
);
13131 gen_helper_dextr_r_w(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13133 case OPC_DEXTR_RS_W
:
13134 tcg_gen_movi_tl(t0
, v2
);
13135 tcg_gen_movi_tl(t1
, v1
);
13136 gen_helper_dextr_rs_w(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13138 case OPC_DEXTR_S_H
:
13139 tcg_gen_movi_tl(t0
, v2
);
13140 tcg_gen_movi_tl(t1
, v1
);
13141 gen_helper_dextr_s_h(cpu_gpr
[ret
], t0
, t1
, tcg_env
);
13143 case OPC_DEXTRV_S_H
:
13144 tcg_gen_movi_tl(t0
, v2
);
13145 gen_helper_dextr_s_h(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13148 tcg_gen_movi_tl(t0
, v2
);
13149 gen_helper_dextr_l(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13151 case OPC_DEXTRV_R_L
:
13152 tcg_gen_movi_tl(t0
, v2
);
13153 gen_helper_dextr_r_l(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13155 case OPC_DEXTRV_RS_L
:
13156 tcg_gen_movi_tl(t0
, v2
);
13157 gen_helper_dextr_rs_l(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13160 tcg_gen_movi_tl(t0
, v2
);
13161 gen_helper_dextr_w(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13163 case OPC_DEXTRV_R_W
:
13164 tcg_gen_movi_tl(t0
, v2
);
13165 gen_helper_dextr_r_w(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13167 case OPC_DEXTRV_RS_W
:
13168 tcg_gen_movi_tl(t0
, v2
);
13169 gen_helper_dextr_rs_w(cpu_gpr
[ret
], t0
, v1_t
, tcg_env
);
13177 /* End MIPSDSP functions. */
13179 static void decode_opc_special_r6(CPUMIPSState
*env
, DisasContext
*ctx
)
13181 int rs
, rt
, rd
, sa
;
13184 rs
= (ctx
->opcode
>> 21) & 0x1f;
13185 rt
= (ctx
->opcode
>> 16) & 0x1f;
13186 rd
= (ctx
->opcode
>> 11) & 0x1f;
13187 sa
= (ctx
->opcode
>> 6) & 0x1f;
13189 op1
= MASK_SPECIAL(ctx
->opcode
);
13195 op2
= MASK_R6_MULDIV(ctx
->opcode
);
13205 gen_r6_muldiv(ctx
, op2
, rd
, rs
, rt
);
13208 MIPS_INVAL("special_r6 muldiv");
13209 gen_reserved_instruction(ctx
);
13215 gen_cond_move(ctx
, op1
, rd
, rs
, rt
);
13219 if (rt
== 0 && sa
== 1) {
13221 * Major opcode and function field is shared with preR6 MFHI/MTHI.
13222 * We need additionally to check other fields.
13224 gen_cl(ctx
, op1
, rd
, rs
);
13226 gen_reserved_instruction(ctx
);
13230 if (is_uhi(ctx
, extract32(ctx
->opcode
, 6, 20))) {
13231 ctx
->base
.is_jmp
= DISAS_SEMIHOST
;
13233 if (ctx
->hflags
& MIPS_HFLAG_SBRI
) {
13234 gen_reserved_instruction(ctx
);
13236 generate_exception_end(ctx
, EXCP_DBp
);
13240 #if defined(TARGET_MIPS64)
13243 if (rt
== 0 && sa
== 1) {
13245 * Major opcode and function field is shared with preR6 MFHI/MTHI.
13246 * We need additionally to check other fields.
13248 check_mips_64(ctx
);
13249 gen_cl(ctx
, op1
, rd
, rs
);
13251 gen_reserved_instruction(ctx
);
13259 op2
= MASK_R6_MULDIV(ctx
->opcode
);
13269 check_mips_64(ctx
);
13270 gen_r6_muldiv(ctx
, op2
, rd
, rs
, rt
);
13273 MIPS_INVAL("special_r6 muldiv");
13274 gen_reserved_instruction(ctx
);
13279 default: /* Invalid */
13280 MIPS_INVAL("special_r6");
13281 gen_reserved_instruction(ctx
);
13286 static void decode_opc_special_tx79(CPUMIPSState
*env
, DisasContext
*ctx
)
13288 int rs
= extract32(ctx
->opcode
, 21, 5);
13289 int rt
= extract32(ctx
->opcode
, 16, 5);
13290 int rd
= extract32(ctx
->opcode
, 11, 5);
13291 uint32_t op1
= MASK_SPECIAL(ctx
->opcode
);
13294 case OPC_MOVN
: /* Conditional move */
13296 gen_cond_move(ctx
, op1
, rd
, rs
, rt
);
13298 case OPC_MFHI
: /* Move from HI/LO */
13300 gen_HILO(ctx
, op1
, 0, rd
);
13303 case OPC_MTLO
: /* Move to HI/LO */
13304 gen_HILO(ctx
, op1
, 0, rs
);
13308 gen_mul_txx9(ctx
, op1
, rd
, rs
, rt
);
13312 gen_muldiv(ctx
, op1
, 0, rs
, rt
);
13314 #if defined(TARGET_MIPS64)
13319 check_insn_opc_user_only(ctx
, INSN_R5900
);
13320 gen_muldiv(ctx
, op1
, 0, rs
, rt
);
13324 gen_compute_branch(ctx
, op1
, 4, rs
, 0, 0, 4);
13326 default: /* Invalid */
13327 MIPS_INVAL("special_tx79");
13328 gen_reserved_instruction(ctx
);
13333 static void decode_opc_special_legacy(CPUMIPSState
*env
, DisasContext
*ctx
)
13338 rs
= (ctx
->opcode
>> 21) & 0x1f;
13339 rt
= (ctx
->opcode
>> 16) & 0x1f;
13340 rd
= (ctx
->opcode
>> 11) & 0x1f;
13342 op1
= MASK_SPECIAL(ctx
->opcode
);
13344 case OPC_MOVN
: /* Conditional move */
13346 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS_R1
|
13347 INSN_LOONGSON2E
| INSN_LOONGSON2F
);
13348 gen_cond_move(ctx
, op1
, rd
, rs
, rt
);
13350 case OPC_MFHI
: /* Move from HI/LO */
13352 gen_HILO(ctx
, op1
, rs
& 3, rd
);
13355 case OPC_MTLO
: /* Move to HI/LO */
13356 gen_HILO(ctx
, op1
, rd
& 3, rs
);
13359 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS_R1
);
13360 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
13361 check_cp1_enabled(ctx
);
13362 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
13363 (ctx
->opcode
>> 16) & 1);
13365 generate_exception_err(ctx
, EXCP_CpU
, 1);
13370 gen_muldiv(ctx
, op1
, rd
& 3, rs
, rt
);
13374 gen_muldiv(ctx
, op1
, 0, rs
, rt
);
13376 #if defined(TARGET_MIPS64)
13381 check_insn(ctx
, ISA_MIPS3
);
13382 check_mips_64(ctx
);
13383 gen_muldiv(ctx
, op1
, 0, rs
, rt
);
13387 gen_compute_branch(ctx
, op1
, 4, rs
, 0, 0, 4);
13390 #ifdef MIPS_STRICT_STANDARD
13391 MIPS_INVAL("SPIM");
13392 gen_reserved_instruction(ctx
);
13394 /* Implemented as RI exception for now. */
13395 MIPS_INVAL("spim (unofficial)");
13396 gen_reserved_instruction(ctx
);
13399 default: /* Invalid */
13400 MIPS_INVAL("special_legacy");
13401 gen_reserved_instruction(ctx
);
13406 static void decode_opc_special(CPUMIPSState
*env
, DisasContext
*ctx
)
13408 int rs
, rt
, rd
, sa
;
13411 rs
= (ctx
->opcode
>> 21) & 0x1f;
13412 rt
= (ctx
->opcode
>> 16) & 0x1f;
13413 rd
= (ctx
->opcode
>> 11) & 0x1f;
13414 sa
= (ctx
->opcode
>> 6) & 0x1f;
13416 op1
= MASK_SPECIAL(ctx
->opcode
);
13418 case OPC_SLL
: /* Shift with immediate */
13419 if (sa
== 5 && rd
== 0 &&
13420 rs
== 0 && rt
== 0) { /* PAUSE */
13421 if ((ctx
->insn_flags
& ISA_MIPS_R6
) &&
13422 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
13423 gen_reserved_instruction(ctx
);
13429 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
13432 switch ((ctx
->opcode
>> 21) & 0x1f) {
13434 /* rotr is decoded as srl on non-R2 CPUs */
13435 if (ctx
->insn_flags
& ISA_MIPS_R2
) {
13440 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
13443 gen_reserved_instruction(ctx
);
13451 gen_arith(ctx
, op1
, rd
, rs
, rt
);
13453 case OPC_SLLV
: /* Shifts */
13455 gen_shift(ctx
, op1
, rd
, rs
, rt
);
13458 switch ((ctx
->opcode
>> 6) & 0x1f) {
13460 /* rotrv is decoded as srlv on non-R2 CPUs */
13461 if (ctx
->insn_flags
& ISA_MIPS_R2
) {
13466 gen_shift(ctx
, op1
, rd
, rs
, rt
);
13469 gen_reserved_instruction(ctx
);
13473 case OPC_SLT
: /* Set on less than */
13475 gen_slt(ctx
, op1
, rd
, rs
, rt
);
13477 case OPC_AND
: /* Logic*/
13481 gen_logic(ctx
, op1
, rd
, rs
, rt
);
13484 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
, 4);
13486 case OPC_TGE
: /* Traps */
13492 check_insn(ctx
, ISA_MIPS2
);
13493 gen_trap(ctx
, op1
, rs
, rt
, -1, extract32(ctx
->opcode
, 6, 10));
13496 /* Pmon entry point, also R4010 selsl */
13497 #ifdef MIPS_STRICT_STANDARD
13498 MIPS_INVAL("PMON / selsl");
13499 gen_reserved_instruction(ctx
);
13501 gen_helper_pmon(tcg_env
, tcg_constant_i32(sa
));
13505 generate_exception_end(ctx
, EXCP_SYSCALL
);
13508 generate_exception_break(ctx
, extract32(ctx
->opcode
, 6, 20));
13511 check_insn(ctx
, ISA_MIPS2
);
13512 gen_sync(extract32(ctx
->opcode
, 6, 5));
13515 #if defined(TARGET_MIPS64)
13516 /* MIPS64 specific opcodes */
13521 check_insn(ctx
, ISA_MIPS3
);
13522 check_mips_64(ctx
);
13523 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
13526 switch ((ctx
->opcode
>> 21) & 0x1f) {
13528 /* drotr is decoded as dsrl on non-R2 CPUs */
13529 if (ctx
->insn_flags
& ISA_MIPS_R2
) {
13534 check_insn(ctx
, ISA_MIPS3
);
13535 check_mips_64(ctx
);
13536 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
13539 gen_reserved_instruction(ctx
);
13544 switch ((ctx
->opcode
>> 21) & 0x1f) {
13546 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
13547 if (ctx
->insn_flags
& ISA_MIPS_R2
) {
13552 check_insn(ctx
, ISA_MIPS3
);
13553 check_mips_64(ctx
);
13554 gen_shift_imm(ctx
, op1
, rd
, rt
, sa
);
13557 gen_reserved_instruction(ctx
);
13565 check_insn(ctx
, ISA_MIPS3
);
13566 check_mips_64(ctx
);
13567 gen_arith(ctx
, op1
, rd
, rs
, rt
);
13571 check_insn(ctx
, ISA_MIPS3
);
13572 check_mips_64(ctx
);
13573 gen_shift(ctx
, op1
, rd
, rs
, rt
);
13576 switch ((ctx
->opcode
>> 6) & 0x1f) {
13578 /* drotrv is decoded as dsrlv on non-R2 CPUs */
13579 if (ctx
->insn_flags
& ISA_MIPS_R2
) {
13584 check_insn(ctx
, ISA_MIPS3
);
13585 check_mips_64(ctx
);
13586 gen_shift(ctx
, op1
, rd
, rs
, rt
);
13589 gen_reserved_instruction(ctx
);
13595 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
13596 decode_opc_special_r6(env
, ctx
);
13597 } else if (ctx
->insn_flags
& INSN_R5900
) {
13598 decode_opc_special_tx79(env
, ctx
);
13600 decode_opc_special_legacy(env
, ctx
);
13606 static void decode_opc_special2_legacy(CPUMIPSState
*env
, DisasContext
*ctx
)
13611 rs
= (ctx
->opcode
>> 21) & 0x1f;
13612 rt
= (ctx
->opcode
>> 16) & 0x1f;
13613 rd
= (ctx
->opcode
>> 11) & 0x1f;
13615 op1
= MASK_SPECIAL2(ctx
->opcode
);
13617 case OPC_MADD
: /* Multiply and add/sub */
13621 check_insn(ctx
, ISA_MIPS_R1
);
13622 gen_muldiv(ctx
, op1
, rd
& 3, rs
, rt
);
13625 gen_arith(ctx
, op1
, rd
, rs
, rt
);
13628 case OPC_DIVU_G_2F
:
13629 case OPC_MULT_G_2F
:
13630 case OPC_MULTU_G_2F
:
13632 case OPC_MODU_G_2F
:
13633 check_insn(ctx
, INSN_LOONGSON2F
| ASE_LEXT
);
13634 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
13638 check_insn(ctx
, ISA_MIPS_R1
);
13639 gen_cl(ctx
, op1
, rd
, rs
);
13642 if (is_uhi(ctx
, extract32(ctx
->opcode
, 6, 20))) {
13643 ctx
->base
.is_jmp
= DISAS_SEMIHOST
;
13646 * XXX: not clear which exception should be raised
13647 * when in debug mode...
13649 check_insn(ctx
, ISA_MIPS_R1
);
13650 generate_exception_end(ctx
, EXCP_DBp
);
13653 #if defined(TARGET_MIPS64)
13656 check_insn(ctx
, ISA_MIPS_R1
);
13657 check_mips_64(ctx
);
13658 gen_cl(ctx
, op1
, rd
, rs
);
13660 case OPC_DMULT_G_2F
:
13661 case OPC_DMULTU_G_2F
:
13662 case OPC_DDIV_G_2F
:
13663 case OPC_DDIVU_G_2F
:
13664 case OPC_DMOD_G_2F
:
13665 case OPC_DMODU_G_2F
:
13666 check_insn(ctx
, INSN_LOONGSON2F
| ASE_LEXT
);
13667 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
13670 default: /* Invalid */
13671 MIPS_INVAL("special2_legacy");
13672 gen_reserved_instruction(ctx
);
13677 static void decode_opc_special3_r6(CPUMIPSState
*env
, DisasContext
*ctx
)
13679 int rs
, rt
, rd
, sa
;
13683 rs
= (ctx
->opcode
>> 21) & 0x1f;
13684 rt
= (ctx
->opcode
>> 16) & 0x1f;
13685 rd
= (ctx
->opcode
>> 11) & 0x1f;
13686 sa
= (ctx
->opcode
>> 6) & 0x1f;
13687 imm
= (int16_t)ctx
->opcode
>> 7;
13689 op1
= MASK_SPECIAL3(ctx
->opcode
);
13693 /* hint codes 24-31 are reserved and signal RI */
13694 gen_reserved_instruction(ctx
);
13696 /* Treat as NOP. */
13699 check_cp0_enabled(ctx
);
13700 if (ctx
->hflags
& MIPS_HFLAG_ITC_CACHE
) {
13701 gen_cache_operation(ctx
, rt
, rs
, imm
);
13705 gen_st_cond(ctx
, rt
, rs
, imm
, mo_endian(ctx
) | MO_SL
, false);
13708 gen_ld(ctx
, op1
, rt
, rs
, imm
);
13713 /* Treat as NOP. */
13716 op2
= MASK_BSHFL(ctx
->opcode
);
13722 gen_align(ctx
, 32, rd
, rs
, rt
, sa
& 3);
13725 gen_bitswap(ctx
, op2
, rd
, rt
);
13730 #ifndef CONFIG_USER_ONLY
13732 if (unlikely(ctx
->gi
<= 1)) {
13733 gen_reserved_instruction(ctx
);
13735 check_cp0_enabled(ctx
);
13736 switch ((ctx
->opcode
>> 6) & 3) {
13737 case 0: /* GINVI */
13738 /* Treat as NOP. */
13740 case 2: /* GINVT */
13741 gen_helper_0e1i(ginvt
, cpu_gpr
[rs
], extract32(ctx
->opcode
, 8, 2));
13744 gen_reserved_instruction(ctx
);
13749 #if defined(TARGET_MIPS64)
13751 gen_st_cond(ctx
, rt
, rs
, imm
, mo_endian(ctx
) | MO_UQ
, false);
13754 gen_ld(ctx
, op1
, rt
, rs
, imm
);
13757 check_mips_64(ctx
);
13760 /* Treat as NOP. */
13763 op2
= MASK_DBSHFL(ctx
->opcode
);
13773 gen_align(ctx
, 64, rd
, rs
, rt
, sa
& 7);
13776 gen_bitswap(ctx
, op2
, rd
, rt
);
13783 default: /* Invalid */
13784 MIPS_INVAL("special3_r6");
13785 gen_reserved_instruction(ctx
);
13790 static void decode_opc_special3_legacy(CPUMIPSState
*env
, DisasContext
*ctx
)
13795 rs
= (ctx
->opcode
>> 21) & 0x1f;
13796 rt
= (ctx
->opcode
>> 16) & 0x1f;
13797 rd
= (ctx
->opcode
>> 11) & 0x1f;
13799 op1
= MASK_SPECIAL3(ctx
->opcode
);
13802 case OPC_DIVU_G_2E
:
13804 case OPC_MODU_G_2E
:
13805 case OPC_MULT_G_2E
:
13806 case OPC_MULTU_G_2E
:
13808 * OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have
13809 * the same mask and op1.
13811 if ((ctx
->insn_flags
& ASE_DSP_R2
) && (op1
== OPC_MULT_G_2E
)) {
13812 op2
= MASK_ADDUH_QB(ctx
->opcode
);
13815 case OPC_ADDUH_R_QB
:
13817 case OPC_ADDQH_R_PH
:
13819 case OPC_ADDQH_R_W
:
13821 case OPC_SUBUH_R_QB
:
13823 case OPC_SUBQH_R_PH
:
13825 case OPC_SUBQH_R_W
:
13826 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
13831 case OPC_MULQ_RS_W
:
13832 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
13835 MIPS_INVAL("MASK ADDUH.QB");
13836 gen_reserved_instruction(ctx
);
13839 } else if (ctx
->insn_flags
& INSN_LOONGSON2E
) {
13840 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
13842 gen_reserved_instruction(ctx
);
13846 op2
= MASK_LX(ctx
->opcode
);
13848 #if defined(TARGET_MIPS64)
13854 gen_mips_lx(ctx
, op2
, rd
, rs
, rt
);
13856 default: /* Invalid */
13857 MIPS_INVAL("MASK LX");
13858 gen_reserved_instruction(ctx
);
13862 case OPC_ABSQ_S_PH_DSP
:
13863 op2
= MASK_ABSQ_S_PH(ctx
->opcode
);
13865 case OPC_ABSQ_S_QB
:
13866 case OPC_ABSQ_S_PH
:
13868 case OPC_PRECEQ_W_PHL
:
13869 case OPC_PRECEQ_W_PHR
:
13870 case OPC_PRECEQU_PH_QBL
:
13871 case OPC_PRECEQU_PH_QBR
:
13872 case OPC_PRECEQU_PH_QBLA
:
13873 case OPC_PRECEQU_PH_QBRA
:
13874 case OPC_PRECEU_PH_QBL
:
13875 case OPC_PRECEU_PH_QBR
:
13876 case OPC_PRECEU_PH_QBLA
:
13877 case OPC_PRECEU_PH_QBRA
:
13878 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
13885 gen_mipsdsp_bitinsn(ctx
, op1
, op2
, rd
, rt
);
13888 MIPS_INVAL("MASK ABSQ_S.PH");
13889 gen_reserved_instruction(ctx
);
13893 case OPC_ADDU_QB_DSP
:
13894 op2
= MASK_ADDU_QB(ctx
->opcode
);
13897 case OPC_ADDQ_S_PH
:
13900 case OPC_ADDU_S_QB
:
13902 case OPC_ADDU_S_PH
:
13904 case OPC_SUBQ_S_PH
:
13907 case OPC_SUBU_S_QB
:
13909 case OPC_SUBU_S_PH
:
13913 case OPC_RADDU_W_QB
:
13914 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
13916 case OPC_MULEU_S_PH_QBL
:
13917 case OPC_MULEU_S_PH_QBR
:
13918 case OPC_MULQ_RS_PH
:
13919 case OPC_MULEQ_S_W_PHL
:
13920 case OPC_MULEQ_S_W_PHR
:
13921 case OPC_MULQ_S_PH
:
13922 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
13924 default: /* Invalid */
13925 MIPS_INVAL("MASK ADDU.QB");
13926 gen_reserved_instruction(ctx
);
13931 case OPC_CMPU_EQ_QB_DSP
:
13932 op2
= MASK_CMPU_EQ_QB(ctx
->opcode
);
13934 case OPC_PRECR_SRA_PH_W
:
13935 case OPC_PRECR_SRA_R_PH_W
:
13936 gen_mipsdsp_arith(ctx
, op1
, op2
, rt
, rs
, rd
);
13938 case OPC_PRECR_QB_PH
:
13939 case OPC_PRECRQ_QB_PH
:
13940 case OPC_PRECRQ_PH_W
:
13941 case OPC_PRECRQ_RS_PH_W
:
13942 case OPC_PRECRQU_S_QB_PH
:
13943 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
13945 case OPC_CMPU_EQ_QB
:
13946 case OPC_CMPU_LT_QB
:
13947 case OPC_CMPU_LE_QB
:
13948 case OPC_CMP_EQ_PH
:
13949 case OPC_CMP_LT_PH
:
13950 case OPC_CMP_LE_PH
:
13951 gen_mipsdsp_add_cmp_pick(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
13953 case OPC_CMPGU_EQ_QB
:
13954 case OPC_CMPGU_LT_QB
:
13955 case OPC_CMPGU_LE_QB
:
13956 case OPC_CMPGDU_EQ_QB
:
13957 case OPC_CMPGDU_LT_QB
:
13958 case OPC_CMPGDU_LE_QB
:
13961 case OPC_PACKRL_PH
:
13962 gen_mipsdsp_add_cmp_pick(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
13964 default: /* Invalid */
13965 MIPS_INVAL("MASK CMPU.EQ.QB");
13966 gen_reserved_instruction(ctx
);
13970 case OPC_SHLL_QB_DSP
:
13971 gen_mipsdsp_shift(ctx
, op1
, rd
, rs
, rt
);
13973 case OPC_DPA_W_PH_DSP
:
13974 op2
= MASK_DPA_W_PH(ctx
->opcode
);
13976 case OPC_DPAU_H_QBL
:
13977 case OPC_DPAU_H_QBR
:
13978 case OPC_DPSU_H_QBL
:
13979 case OPC_DPSU_H_QBR
:
13981 case OPC_DPAX_W_PH
:
13982 case OPC_DPAQ_S_W_PH
:
13983 case OPC_DPAQX_S_W_PH
:
13984 case OPC_DPAQX_SA_W_PH
:
13986 case OPC_DPSX_W_PH
:
13987 case OPC_DPSQ_S_W_PH
:
13988 case OPC_DPSQX_S_W_PH
:
13989 case OPC_DPSQX_SA_W_PH
:
13990 case OPC_MULSAQ_S_W_PH
:
13991 case OPC_DPAQ_SA_L_W
:
13992 case OPC_DPSQ_SA_L_W
:
13993 case OPC_MAQ_S_W_PHL
:
13994 case OPC_MAQ_S_W_PHR
:
13995 case OPC_MAQ_SA_W_PHL
:
13996 case OPC_MAQ_SA_W_PHR
:
13997 case OPC_MULSA_W_PH
:
13998 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
14000 default: /* Invalid */
14001 MIPS_INVAL("MASK DPAW.PH");
14002 gen_reserved_instruction(ctx
);
14007 op2
= MASK_INSV(ctx
->opcode
);
14018 t0
= tcg_temp_new();
14019 t1
= tcg_temp_new();
14021 gen_load_gpr(t0
, rt
);
14022 gen_load_gpr(t1
, rs
);
14024 gen_helper_insv(cpu_gpr
[rt
], tcg_env
, t1
, t0
);
14027 default: /* Invalid */
14028 MIPS_INVAL("MASK INSV");
14029 gen_reserved_instruction(ctx
);
14033 case OPC_APPEND_DSP
:
14034 gen_mipsdsp_append(env
, ctx
, op1
, rt
, rs
, rd
);
14036 case OPC_EXTR_W_DSP
:
14037 op2
= MASK_EXTR_W(ctx
->opcode
);
14041 case OPC_EXTR_RS_W
:
14043 case OPC_EXTRV_S_H
:
14045 case OPC_EXTRV_R_W
:
14046 case OPC_EXTRV_RS_W
:
14051 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rt
, rs
, rd
, 1);
14054 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
14060 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
14062 default: /* Invalid */
14063 MIPS_INVAL("MASK EXTR.W");
14064 gen_reserved_instruction(ctx
);
14068 #if defined(TARGET_MIPS64)
14069 case OPC_DDIV_G_2E
:
14070 case OPC_DDIVU_G_2E
:
14071 case OPC_DMULT_G_2E
:
14072 case OPC_DMULTU_G_2E
:
14073 case OPC_DMOD_G_2E
:
14074 case OPC_DMODU_G_2E
:
14075 check_insn(ctx
, INSN_LOONGSON2E
);
14076 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
14078 case OPC_ABSQ_S_QH_DSP
:
14079 op2
= MASK_ABSQ_S_QH(ctx
->opcode
);
14081 case OPC_PRECEQ_L_PWL
:
14082 case OPC_PRECEQ_L_PWR
:
14083 case OPC_PRECEQ_PW_QHL
:
14084 case OPC_PRECEQ_PW_QHR
:
14085 case OPC_PRECEQ_PW_QHLA
:
14086 case OPC_PRECEQ_PW_QHRA
:
14087 case OPC_PRECEQU_QH_OBL
:
14088 case OPC_PRECEQU_QH_OBR
:
14089 case OPC_PRECEQU_QH_OBLA
:
14090 case OPC_PRECEQU_QH_OBRA
:
14091 case OPC_PRECEU_QH_OBL
:
14092 case OPC_PRECEU_QH_OBR
:
14093 case OPC_PRECEU_QH_OBLA
:
14094 case OPC_PRECEU_QH_OBRA
:
14095 case OPC_ABSQ_S_OB
:
14096 case OPC_ABSQ_S_PW
:
14097 case OPC_ABSQ_S_QH
:
14098 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
14106 gen_mipsdsp_bitinsn(ctx
, op1
, op2
, rd
, rt
);
14108 default: /* Invalid */
14109 MIPS_INVAL("MASK ABSQ_S.QH");
14110 gen_reserved_instruction(ctx
);
14114 case OPC_ADDU_OB_DSP
:
14115 op2
= MASK_ADDU_OB(ctx
->opcode
);
14117 case OPC_RADDU_L_OB
:
14119 case OPC_SUBQ_S_PW
:
14121 case OPC_SUBQ_S_QH
:
14123 case OPC_SUBU_S_OB
:
14125 case OPC_SUBU_S_QH
:
14127 case OPC_SUBUH_R_OB
:
14129 case OPC_ADDQ_S_PW
:
14131 case OPC_ADDQ_S_QH
:
14133 case OPC_ADDU_S_OB
:
14135 case OPC_ADDU_S_QH
:
14137 case OPC_ADDUH_R_OB
:
14138 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
14140 case OPC_MULEQ_S_PW_QHL
:
14141 case OPC_MULEQ_S_PW_QHR
:
14142 case OPC_MULEU_S_QH_OBL
:
14143 case OPC_MULEU_S_QH_OBR
:
14144 case OPC_MULQ_RS_QH
:
14145 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
14147 default: /* Invalid */
14148 MIPS_INVAL("MASK ADDU.OB");
14149 gen_reserved_instruction(ctx
);
14153 case OPC_CMPU_EQ_OB_DSP
:
14154 op2
= MASK_CMPU_EQ_OB(ctx
->opcode
);
14156 case OPC_PRECR_SRA_QH_PW
:
14157 case OPC_PRECR_SRA_R_QH_PW
:
14158 /* Return value is rt. */
14159 gen_mipsdsp_arith(ctx
, op1
, op2
, rt
, rs
, rd
);
14161 case OPC_PRECR_OB_QH
:
14162 case OPC_PRECRQ_OB_QH
:
14163 case OPC_PRECRQ_PW_L
:
14164 case OPC_PRECRQ_QH_PW
:
14165 case OPC_PRECRQ_RS_QH_PW
:
14166 case OPC_PRECRQU_S_OB_QH
:
14167 gen_mipsdsp_arith(ctx
, op1
, op2
, rd
, rs
, rt
);
14169 case OPC_CMPU_EQ_OB
:
14170 case OPC_CMPU_LT_OB
:
14171 case OPC_CMPU_LE_OB
:
14172 case OPC_CMP_EQ_QH
:
14173 case OPC_CMP_LT_QH
:
14174 case OPC_CMP_LE_QH
:
14175 case OPC_CMP_EQ_PW
:
14176 case OPC_CMP_LT_PW
:
14177 case OPC_CMP_LE_PW
:
14178 gen_mipsdsp_add_cmp_pick(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
14180 case OPC_CMPGDU_EQ_OB
:
14181 case OPC_CMPGDU_LT_OB
:
14182 case OPC_CMPGDU_LE_OB
:
14183 case OPC_CMPGU_EQ_OB
:
14184 case OPC_CMPGU_LT_OB
:
14185 case OPC_CMPGU_LE_OB
:
14186 case OPC_PACKRL_PW
:
14190 gen_mipsdsp_add_cmp_pick(ctx
, op1
, op2
, rd
, rs
, rt
, 1);
14192 default: /* Invalid */
14193 MIPS_INVAL("MASK CMPU_EQ.OB");
14194 gen_reserved_instruction(ctx
);
14198 case OPC_DAPPEND_DSP
:
14199 gen_mipsdsp_append(env
, ctx
, op1
, rt
, rs
, rd
);
14201 case OPC_DEXTR_W_DSP
:
14202 op2
= MASK_DEXTR_W(ctx
->opcode
);
14209 case OPC_DEXTR_R_L
:
14210 case OPC_DEXTR_RS_L
:
14212 case OPC_DEXTR_R_W
:
14213 case OPC_DEXTR_RS_W
:
14214 case OPC_DEXTR_S_H
:
14216 case OPC_DEXTRV_R_L
:
14217 case OPC_DEXTRV_RS_L
:
14218 case OPC_DEXTRV_S_H
:
14220 case OPC_DEXTRV_R_W
:
14221 case OPC_DEXTRV_RS_W
:
14222 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rt
, rs
, rd
, 1);
14227 gen_mipsdsp_accinsn(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
14229 default: /* Invalid */
14230 MIPS_INVAL("MASK EXTR.W");
14231 gen_reserved_instruction(ctx
);
14235 case OPC_DPAQ_W_QH_DSP
:
14236 op2
= MASK_DPAQ_W_QH(ctx
->opcode
);
14238 case OPC_DPAU_H_OBL
:
14239 case OPC_DPAU_H_OBR
:
14240 case OPC_DPSU_H_OBL
:
14241 case OPC_DPSU_H_OBR
:
14243 case OPC_DPAQ_S_W_QH
:
14245 case OPC_DPSQ_S_W_QH
:
14246 case OPC_MULSAQ_S_W_QH
:
14247 case OPC_DPAQ_SA_L_PW
:
14248 case OPC_DPSQ_SA_L_PW
:
14249 case OPC_MULSAQ_S_L_PW
:
14250 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
14252 case OPC_MAQ_S_W_QHLL
:
14253 case OPC_MAQ_S_W_QHLR
:
14254 case OPC_MAQ_S_W_QHRL
:
14255 case OPC_MAQ_S_W_QHRR
:
14256 case OPC_MAQ_SA_W_QHLL
:
14257 case OPC_MAQ_SA_W_QHLR
:
14258 case OPC_MAQ_SA_W_QHRL
:
14259 case OPC_MAQ_SA_W_QHRR
:
14260 case OPC_MAQ_S_L_PWL
:
14261 case OPC_MAQ_S_L_PWR
:
14266 gen_mipsdsp_multiply(ctx
, op1
, op2
, rd
, rs
, rt
, 0);
14268 default: /* Invalid */
14269 MIPS_INVAL("MASK DPAQ.W.QH");
14270 gen_reserved_instruction(ctx
);
14274 case OPC_DINSV_DSP
:
14275 op2
= MASK_INSV(ctx
->opcode
);
14287 t0
= tcg_temp_new();
14288 t1
= tcg_temp_new();
14290 gen_load_gpr(t0
, rt
);
14291 gen_load_gpr(t1
, rs
);
14293 gen_helper_dinsv(cpu_gpr
[rt
], tcg_env
, t1
, t0
);
14296 default: /* Invalid */
14297 MIPS_INVAL("MASK DINSV");
14298 gen_reserved_instruction(ctx
);
14302 case OPC_SHLL_OB_DSP
:
14303 gen_mipsdsp_shift(ctx
, op1
, rd
, rs
, rt
);
14306 default: /* Invalid */
14307 MIPS_INVAL("special3_legacy");
14308 gen_reserved_instruction(ctx
);
14314 #if defined(TARGET_MIPS64)
14316 static void decode_mmi(CPUMIPSState
*env
, DisasContext
*ctx
)
14318 uint32_t opc
= MASK_MMI(ctx
->opcode
);
14319 int rs
= extract32(ctx
->opcode
, 21, 5);
14320 int rt
= extract32(ctx
->opcode
, 16, 5);
14321 int rd
= extract32(ctx
->opcode
, 11, 5);
14324 case MMI_OPC_MULT1
:
14325 case MMI_OPC_MULTU1
:
14327 case MMI_OPC_MADDU
:
14328 case MMI_OPC_MADD1
:
14329 case MMI_OPC_MADDU1
:
14330 gen_mul_txx9(ctx
, opc
, rd
, rs
, rt
);
14333 case MMI_OPC_DIVU1
:
14334 gen_div1_tx79(ctx
, opc
, rs
, rt
);
14337 MIPS_INVAL("TX79 MMI class");
14338 gen_reserved_instruction(ctx
);
14343 static void gen_mmi_sq(DisasContext
*ctx
, int base
, int rt
, int offset
)
14345 gen_reserved_instruction(ctx
); /* TODO: MMI_OPC_SQ */
14349 * The TX79-specific instruction Store Quadword
14351 * +--------+-------+-------+------------------------+
14352 * | 011111 | base | rt | offset | SQ
14353 * +--------+-------+-------+------------------------+
14356 * has the same opcode as the Read Hardware Register instruction
14358 * +--------+-------+-------+-------+-------+--------+
14359 * | 011111 | 00000 | rt | rd | 00000 | 111011 | RDHWR
14360 * +--------+-------+-------+-------+-------+--------+
14363 * that is required, trapped and emulated by the Linux kernel. However, all
14364 * RDHWR encodings yield address error exceptions on the TX79 since the SQ
14365 * offset is odd. Therefore all valid SQ instructions can execute normally.
14366 * In user mode, QEMU must verify the upper and lower 11 bits to distinguish
14367 * between SQ and RDHWR, as the Linux kernel does.
14369 static void decode_mmi_sq(CPUMIPSState
*env
, DisasContext
*ctx
)
14371 int base
= extract32(ctx
->opcode
, 21, 5);
14372 int rt
= extract32(ctx
->opcode
, 16, 5);
14373 int offset
= extract32(ctx
->opcode
, 0, 16);
14375 #ifdef CONFIG_USER_ONLY
14376 uint32_t op1
= MASK_SPECIAL3(ctx
->opcode
);
14377 uint32_t op2
= extract32(ctx
->opcode
, 6, 5);
14379 if (base
== 0 && op2
== 0 && op1
== OPC_RDHWR
) {
14380 int rd
= extract32(ctx
->opcode
, 11, 5);
14382 gen_rdhwr(ctx
, rt
, rd
, 0);
14387 gen_mmi_sq(ctx
, base
, rt
, offset
);
14392 static void decode_opc_special3(CPUMIPSState
*env
, DisasContext
*ctx
)
14394 int rs
, rt
, rd
, sa
;
14398 rs
= (ctx
->opcode
>> 21) & 0x1f;
14399 rt
= (ctx
->opcode
>> 16) & 0x1f;
14400 rd
= (ctx
->opcode
>> 11) & 0x1f;
14401 sa
= (ctx
->opcode
>> 6) & 0x1f;
14402 imm
= sextract32(ctx
->opcode
, 7, 9);
14404 op1
= MASK_SPECIAL3(ctx
->opcode
);
14407 * EVA loads and stores overlap Loongson 2E instructions decoded by
14408 * decode_opc_special3_legacy(), so be careful to allow their decoding when
14421 check_cp0_enabled(ctx
);
14422 gen_ld(ctx
, op1
, rt
, rs
, imm
);
14429 check_cp0_enabled(ctx
);
14430 gen_st(ctx
, op1
, rt
, rs
, imm
);
14433 check_cp0_enabled(ctx
);
14434 gen_st_cond(ctx
, rt
, rs
, imm
, mo_endian(ctx
) | MO_SL
, true);
14438 check_cp0_enabled(ctx
);
14439 if (ctx
->hflags
& MIPS_HFLAG_ITC_CACHE
) {
14440 gen_cache_operation(ctx
, rt
, rs
, imm
);
14444 check_cp0_enabled(ctx
);
14445 /* Treat as NOP. */
14453 check_insn(ctx
, ISA_MIPS_R2
);
14454 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
14457 op2
= MASK_BSHFL(ctx
->opcode
);
14464 check_insn(ctx
, ISA_MIPS_R6
);
14465 decode_opc_special3_r6(env
, ctx
);
14468 check_insn(ctx
, ISA_MIPS_R2
);
14469 gen_bshfl(ctx
, op2
, rt
, rd
);
14473 #if defined(TARGET_MIPS64)
14480 check_insn(ctx
, ISA_MIPS_R2
);
14481 check_mips_64(ctx
);
14482 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
14485 op2
= MASK_DBSHFL(ctx
->opcode
);
14496 check_insn(ctx
, ISA_MIPS_R6
);
14497 decode_opc_special3_r6(env
, ctx
);
14500 check_insn(ctx
, ISA_MIPS_R2
);
14501 check_mips_64(ctx
);
14502 op2
= MASK_DBSHFL(ctx
->opcode
);
14503 gen_bshfl(ctx
, op2
, rt
, rd
);
14509 gen_rdhwr(ctx
, rt
, rd
, extract32(ctx
->opcode
, 6, 3));
14514 TCGv t0
= tcg_temp_new();
14515 TCGv t1
= tcg_temp_new();
14517 gen_load_gpr(t0
, rt
);
14518 gen_load_gpr(t1
, rs
);
14519 gen_helper_fork(t0
, t1
);
14525 TCGv t0
= tcg_temp_new();
14527 gen_load_gpr(t0
, rs
);
14528 gen_helper_yield(t0
, tcg_env
, t0
);
14529 gen_store_gpr(t0
, rd
);
14533 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
14534 decode_opc_special3_r6(env
, ctx
);
14536 decode_opc_special3_legacy(env
, ctx
);
14541 static bool decode_opc_legacy(CPUMIPSState
*env
, DisasContext
*ctx
)
14544 int rs
, rt
, rd
, sa
;
14548 op
= MASK_OP_MAJOR(ctx
->opcode
);
14549 rs
= (ctx
->opcode
>> 21) & 0x1f;
14550 rt
= (ctx
->opcode
>> 16) & 0x1f;
14551 rd
= (ctx
->opcode
>> 11) & 0x1f;
14552 sa
= (ctx
->opcode
>> 6) & 0x1f;
14553 imm
= (int16_t)ctx
->opcode
;
14556 decode_opc_special(env
, ctx
);
14559 #if defined(TARGET_MIPS64)
14560 if ((ctx
->insn_flags
& INSN_R5900
) && (ctx
->insn_flags
& ASE_MMI
)) {
14561 decode_mmi(env
, ctx
);
14565 if (TARGET_LONG_BITS
== 32 && (ctx
->insn_flags
& ASE_MXU
)) {
14566 if (decode_ase_mxu(ctx
, ctx
->opcode
)) {
14570 decode_opc_special2_legacy(env
, ctx
);
14573 #if defined(TARGET_MIPS64)
14574 if (ctx
->insn_flags
& INSN_R5900
) {
14575 decode_mmi_sq(env
, ctx
); /* MMI_OPC_SQ */
14577 decode_opc_special3(env
, ctx
);
14580 decode_opc_special3(env
, ctx
);
14584 op1
= MASK_REGIMM(ctx
->opcode
);
14586 case OPC_BLTZL
: /* REGIMM branches */
14590 check_insn(ctx
, ISA_MIPS2
);
14591 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
14595 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2, 4);
14599 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
14601 /* OPC_NAL, OPC_BAL */
14602 gen_compute_branch(ctx
, op1
, 4, 0, -1, imm
<< 2, 4);
14604 gen_reserved_instruction(ctx
);
14607 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2, 4);
14610 case OPC_TGEI
: /* REGIMM traps */
14616 check_insn(ctx
, ISA_MIPS2
);
14617 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
14618 gen_trap(ctx
, op1
, rs
, -1, imm
, 0);
14621 check_insn(ctx
, ISA_MIPS_R6
);
14622 gen_reserved_instruction(ctx
);
14625 check_insn(ctx
, ISA_MIPS_R2
);
14627 * Break the TB to be able to sync copied instructions
14630 ctx
->base
.is_jmp
= DISAS_STOP
;
14632 case OPC_BPOSGE32
: /* MIPS DSP branch */
14633 #if defined(TARGET_MIPS64)
14637 gen_compute_branch(ctx
, op1
, 4, -1, -2, (int32_t)imm
<< 2, 4);
14639 #if defined(TARGET_MIPS64)
14641 check_insn(ctx
, ISA_MIPS_R6
);
14642 check_mips_64(ctx
);
14644 tcg_gen_addi_tl(cpu_gpr
[rs
], cpu_gpr
[rs
], (int64_t)imm
<< 32);
14648 check_insn(ctx
, ISA_MIPS_R6
);
14649 check_mips_64(ctx
);
14651 tcg_gen_addi_tl(cpu_gpr
[rs
], cpu_gpr
[rs
], (int64_t)imm
<< 48);
14655 default: /* Invalid */
14656 MIPS_INVAL("regimm");
14657 gen_reserved_instruction(ctx
);
14662 check_cp0_enabled(ctx
);
14663 op1
= MASK_CP0(ctx
->opcode
);
14671 #if defined(TARGET_MIPS64)
14675 #ifndef CONFIG_USER_ONLY
14676 gen_cp0(env
, ctx
, op1
, rt
, rd
);
14677 #endif /* !CONFIG_USER_ONLY */
14695 #ifndef CONFIG_USER_ONLY
14696 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
14697 #endif /* !CONFIG_USER_ONLY */
14700 #ifndef CONFIG_USER_ONLY
14703 TCGv t0
= tcg_temp_new();
14705 op2
= MASK_MFMC0(ctx
->opcode
);
14709 gen_helper_dmt(t0
);
14710 gen_store_gpr(t0
, rt
);
14714 gen_helper_emt(t0
);
14715 gen_store_gpr(t0
, rt
);
14719 gen_helper_dvpe(t0
, tcg_env
);
14720 gen_store_gpr(t0
, rt
);
14724 gen_helper_evpe(t0
, tcg_env
);
14725 gen_store_gpr(t0
, rt
);
14728 check_insn(ctx
, ISA_MIPS_R6
);
14730 gen_helper_dvp(t0
, tcg_env
);
14731 gen_store_gpr(t0
, rt
);
14735 check_insn(ctx
, ISA_MIPS_R6
);
14737 gen_helper_evp(t0
, tcg_env
);
14738 gen_store_gpr(t0
, rt
);
14742 check_insn(ctx
, ISA_MIPS_R2
);
14743 save_cpu_state(ctx
, 1);
14744 gen_helper_di(t0
, tcg_env
);
14745 gen_store_gpr(t0
, rt
);
14747 * Stop translation as we may have switched
14748 * the execution mode.
14750 ctx
->base
.is_jmp
= DISAS_STOP
;
14753 check_insn(ctx
, ISA_MIPS_R2
);
14754 save_cpu_state(ctx
, 1);
14755 gen_helper_ei(t0
, tcg_env
);
14756 gen_store_gpr(t0
, rt
);
14758 * DISAS_STOP isn't sufficient, we need to ensure we break
14759 * out of translated code to check for pending interrupts.
14761 gen_save_pc(ctx
->base
.pc_next
+ 4);
14762 ctx
->base
.is_jmp
= DISAS_EXIT
;
14764 default: /* Invalid */
14765 MIPS_INVAL("mfmc0");
14766 gen_reserved_instruction(ctx
);
14770 #endif /* !CONFIG_USER_ONLY */
14773 check_insn(ctx
, ISA_MIPS_R2
);
14774 gen_load_srsgpr(rt
, rd
);
14777 check_insn(ctx
, ISA_MIPS_R2
);
14778 gen_store_srsgpr(rt
, rd
);
14782 gen_reserved_instruction(ctx
);
14786 case OPC_BOVC
: /* OPC_BEQZALC, OPC_BEQC, OPC_ADDI */
14787 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
14788 /* OPC_BOVC, OPC_BEQZALC, OPC_BEQC */
14789 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
14792 /* Arithmetic with immediate opcode */
14793 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
14797 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
14799 case OPC_SLTI
: /* Set on less than with immediate opcode */
14801 gen_slt_imm(ctx
, op
, rt
, rs
, imm
);
14803 case OPC_ANDI
: /* Arithmetic with immediate opcode */
14804 case OPC_LUI
: /* OPC_AUI */
14807 gen_logic_imm(ctx
, op
, rt
, rs
, imm
);
14809 case OPC_J
: /* Jump */
14811 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
14812 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
, 4);
14815 case OPC_BLEZC
: /* OPC_BGEZC, OPC_BGEC, OPC_BLEZL */
14816 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
14818 gen_reserved_instruction(ctx
);
14821 /* OPC_BLEZC, OPC_BGEZC, OPC_BGEC */
14822 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
14825 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
14828 case OPC_BGTZC
: /* OPC_BLTZC, OPC_BLTC, OPC_BGTZL */
14829 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
14831 gen_reserved_instruction(ctx
);
14834 /* OPC_BGTZC, OPC_BLTZC, OPC_BLTC */
14835 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
14838 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
14841 case OPC_BLEZALC
: /* OPC_BGEZALC, OPC_BGEUC, OPC_BLEZ */
14844 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
14846 check_insn(ctx
, ISA_MIPS_R6
);
14847 /* OPC_BLEZALC, OPC_BGEZALC, OPC_BGEUC */
14848 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
14851 case OPC_BGTZALC
: /* OPC_BLTZALC, OPC_BLTUC, OPC_BGTZ */
14854 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
14856 check_insn(ctx
, ISA_MIPS_R6
);
14857 /* OPC_BGTZALC, OPC_BLTZALC, OPC_BLTUC */
14858 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
14863 check_insn(ctx
, ISA_MIPS2
);
14864 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
14868 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2, 4);
14870 case OPC_LL
: /* Load and stores */
14871 check_insn(ctx
, ISA_MIPS2
);
14872 if (ctx
->insn_flags
& INSN_R5900
) {
14873 check_insn_opc_user_only(ctx
, INSN_R5900
);
14884 gen_ld(ctx
, op
, rt
, rs
, imm
);
14891 gen_st(ctx
, op
, rt
, rs
, imm
);
14894 check_insn(ctx
, ISA_MIPS2
);
14895 if (ctx
->insn_flags
& INSN_R5900
) {
14896 check_insn_opc_user_only(ctx
, INSN_R5900
);
14898 gen_st_cond(ctx
, rt
, rs
, imm
, mo_endian(ctx
) | MO_SL
, false);
14901 check_cp0_enabled(ctx
);
14902 check_insn(ctx
, ISA_MIPS3
| ISA_MIPS_R1
);
14903 if (ctx
->hflags
& MIPS_HFLAG_ITC_CACHE
) {
14904 gen_cache_operation(ctx
, rt
, rs
, imm
);
14906 /* Treat as NOP. */
14909 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS_R1
| INSN_R5900
);
14910 /* Treat as NOP. */
14913 /* Floating point (COP1). */
14918 gen_cop1_ldst(ctx
, op
, rt
, rs
, imm
);
14922 op1
= MASK_CP1(ctx
->opcode
);
14927 check_cp1_enabled(ctx
);
14928 check_insn(ctx
, ISA_MIPS_R2
);
14934 check_cp1_enabled(ctx
);
14935 gen_cp1(ctx
, op1
, rt
, rd
);
14937 #if defined(TARGET_MIPS64)
14940 check_cp1_enabled(ctx
);
14941 check_insn(ctx
, ISA_MIPS3
);
14942 check_mips_64(ctx
);
14943 gen_cp1(ctx
, op1
, rt
, rd
);
14946 case OPC_BC1EQZ
: /* OPC_BC1ANY2 */
14947 check_cp1_enabled(ctx
);
14948 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
14950 gen_compute_branch1_r6(ctx
, MASK_CP1(ctx
->opcode
),
14955 check_insn(ctx
, ASE_MIPS3D
);
14956 gen_compute_branch1(ctx
, MASK_BC1(ctx
->opcode
),
14957 (rt
>> 2) & 0x7, imm
<< 2);
14961 check_cp1_enabled(ctx
);
14962 check_insn(ctx
, ISA_MIPS_R6
);
14963 gen_compute_branch1_r6(ctx
, MASK_CP1(ctx
->opcode
),
14967 check_cp1_enabled(ctx
);
14968 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
14970 check_insn(ctx
, ASE_MIPS3D
);
14973 check_cp1_enabled(ctx
);
14974 check_insn_opc_removed(ctx
, ISA_MIPS_R6
);
14975 gen_compute_branch1(ctx
, MASK_BC1(ctx
->opcode
),
14976 (rt
>> 2) & 0x7, imm
<< 2);
14983 check_cp1_enabled(ctx
);
14984 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
14990 int r6_op
= ctx
->opcode
& FOP(0x3f, 0x1f);
14991 check_cp1_enabled(ctx
);
14992 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
14994 case R6_OPC_CMP_AF_S
:
14995 case R6_OPC_CMP_UN_S
:
14996 case R6_OPC_CMP_EQ_S
:
14997 case R6_OPC_CMP_UEQ_S
:
14998 case R6_OPC_CMP_LT_S
:
14999 case R6_OPC_CMP_ULT_S
:
15000 case R6_OPC_CMP_LE_S
:
15001 case R6_OPC_CMP_ULE_S
:
15002 case R6_OPC_CMP_SAF_S
:
15003 case R6_OPC_CMP_SUN_S
:
15004 case R6_OPC_CMP_SEQ_S
:
15005 case R6_OPC_CMP_SEUQ_S
:
15006 case R6_OPC_CMP_SLT_S
:
15007 case R6_OPC_CMP_SULT_S
:
15008 case R6_OPC_CMP_SLE_S
:
15009 case R6_OPC_CMP_SULE_S
:
15010 case R6_OPC_CMP_OR_S
:
15011 case R6_OPC_CMP_UNE_S
:
15012 case R6_OPC_CMP_NE_S
:
15013 case R6_OPC_CMP_SOR_S
:
15014 case R6_OPC_CMP_SUNE_S
:
15015 case R6_OPC_CMP_SNE_S
:
15016 gen_r6_cmp_s(ctx
, ctx
->opcode
& 0x1f, rt
, rd
, sa
);
15018 case R6_OPC_CMP_AF_D
:
15019 case R6_OPC_CMP_UN_D
:
15020 case R6_OPC_CMP_EQ_D
:
15021 case R6_OPC_CMP_UEQ_D
:
15022 case R6_OPC_CMP_LT_D
:
15023 case R6_OPC_CMP_ULT_D
:
15024 case R6_OPC_CMP_LE_D
:
15025 case R6_OPC_CMP_ULE_D
:
15026 case R6_OPC_CMP_SAF_D
:
15027 case R6_OPC_CMP_SUN_D
:
15028 case R6_OPC_CMP_SEQ_D
:
15029 case R6_OPC_CMP_SEUQ_D
:
15030 case R6_OPC_CMP_SLT_D
:
15031 case R6_OPC_CMP_SULT_D
:
15032 case R6_OPC_CMP_SLE_D
:
15033 case R6_OPC_CMP_SULE_D
:
15034 case R6_OPC_CMP_OR_D
:
15035 case R6_OPC_CMP_UNE_D
:
15036 case R6_OPC_CMP_NE_D
:
15037 case R6_OPC_CMP_SOR_D
:
15038 case R6_OPC_CMP_SUNE_D
:
15039 case R6_OPC_CMP_SNE_D
:
15040 gen_r6_cmp_d(ctx
, ctx
->opcode
& 0x1f, rt
, rd
, sa
);
15043 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f),
15044 rt
, rd
, sa
, (imm
>> 8) & 0x7);
15049 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
15056 gen_reserved_instruction(ctx
);
15061 /* Compact branches [R6] and COP2 [non-R6] */
15062 case OPC_BC
: /* OPC_LWC2 */
15063 case OPC_BALC
: /* OPC_SWC2 */
15064 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
15065 /* OPC_BC, OPC_BALC */
15066 gen_compute_compact_branch(ctx
, op
, 0, 0,
15067 sextract32(ctx
->opcode
<< 2, 0, 28));
15068 } else if (ctx
->insn_flags
& ASE_LEXT
) {
15069 gen_loongson_lswc2(ctx
, rt
, rs
, rd
);
15071 /* OPC_LWC2, OPC_SWC2 */
15072 /* COP2: Not implemented. */
15073 generate_exception_err(ctx
, EXCP_CpU
, 2);
15076 case OPC_BEQZC
: /* OPC_JIC, OPC_LDC2 */
15077 case OPC_BNEZC
: /* OPC_JIALC, OPC_SDC2 */
15078 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
15080 /* OPC_BEQZC, OPC_BNEZC */
15081 gen_compute_compact_branch(ctx
, op
, rs
, 0,
15082 sextract32(ctx
->opcode
<< 2, 0, 23));
15084 /* OPC_JIC, OPC_JIALC */
15085 gen_compute_compact_branch(ctx
, op
, 0, rt
, imm
);
15087 } else if (ctx
->insn_flags
& ASE_LEXT
) {
15088 gen_loongson_lsdc2(ctx
, rt
, rs
, rd
);
15090 /* OPC_LWC2, OPC_SWC2 */
15091 /* COP2: Not implemented. */
15092 generate_exception_err(ctx
, EXCP_CpU
, 2);
15096 check_insn(ctx
, ASE_LMMI
);
15097 /* Note that these instructions use different fields. */
15098 gen_loongson_multimedia(ctx
, sa
, rd
, rt
);
15102 if (ctx
->CP0_Config1
& (1 << CP0C1_FP
)) {
15103 check_cp1_enabled(ctx
);
15104 op1
= MASK_CP3(ctx
->opcode
);
15108 check_insn(ctx
, ISA_MIPS5
| ISA_MIPS_R2
);
15114 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS_R2
);
15115 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
15118 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS_R2
);
15119 /* Treat as NOP. */
15122 check_insn(ctx
, ISA_MIPS5
| ISA_MIPS_R2
);
15136 check_insn(ctx
, ISA_MIPS4
| ISA_MIPS_R2
);
15137 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
15141 gen_reserved_instruction(ctx
);
15145 generate_exception_err(ctx
, EXCP_CpU
, 1);
15149 #if defined(TARGET_MIPS64)
15150 /* MIPS64 opcodes */
15152 if (ctx
->insn_flags
& INSN_R5900
) {
15153 check_insn_opc_user_only(ctx
, INSN_R5900
);
15160 check_insn(ctx
, ISA_MIPS3
);
15161 check_mips_64(ctx
);
15162 gen_ld(ctx
, op
, rt
, rs
, imm
);
15167 check_insn(ctx
, ISA_MIPS3
);
15168 check_mips_64(ctx
);
15169 gen_st(ctx
, op
, rt
, rs
, imm
);
15172 check_insn(ctx
, ISA_MIPS3
);
15173 if (ctx
->insn_flags
& INSN_R5900
) {
15174 check_insn_opc_user_only(ctx
, INSN_R5900
);
15176 check_mips_64(ctx
);
15177 gen_st_cond(ctx
, rt
, rs
, imm
, mo_endian(ctx
) | MO_UQ
, false);
15179 case OPC_BNVC
: /* OPC_BNEZALC, OPC_BNEC, OPC_DADDI */
15180 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
15181 /* OPC_BNVC, OPC_BNEZALC, OPC_BNEC */
15182 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
15185 check_insn(ctx
, ISA_MIPS3
);
15186 check_mips_64(ctx
);
15187 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
15191 check_insn(ctx
, ISA_MIPS3
);
15192 check_mips_64(ctx
);
15193 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
15196 case OPC_BNVC
: /* OPC_BNEZALC, OPC_BNEC */
15197 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
15198 gen_compute_compact_branch(ctx
, op
, rs
, rt
, imm
<< 2);
15200 MIPS_INVAL("major opcode");
15201 gen_reserved_instruction(ctx
);
15205 case OPC_DAUI
: /* OPC_JALX */
15206 if (ctx
->insn_flags
& ISA_MIPS_R6
) {
15207 #if defined(TARGET_MIPS64)
15209 check_mips_64(ctx
);
15211 generate_exception(ctx
, EXCP_RI
);
15212 } else if (rt
!= 0) {
15213 TCGv t0
= tcg_temp_new();
15214 gen_load_gpr(t0
, rs
);
15215 tcg_gen_addi_tl(cpu_gpr
[rt
], t0
, imm
<< 16);
15218 gen_reserved_instruction(ctx
);
15219 MIPS_INVAL("major opcode");
15223 check_insn(ctx
, ASE_MIPS16
| ASE_MICROMIPS
);
15224 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
15225 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
, 4);
15229 /* MDMX: Not implemented. */
15232 check_insn(ctx
, ISA_MIPS_R6
);
15233 gen_pcrel(ctx
, ctx
->opcode
, ctx
->base
.pc_next
, rs
);
15235 default: /* Invalid */
15236 MIPS_INVAL("major opcode");
15242 static void decode_opc(CPUMIPSState
*env
, DisasContext
*ctx
)
15244 /* make sure instructions are on a word boundary */
15245 if (ctx
->base
.pc_next
& 0x3) {
15246 env
->CP0_BadVAddr
= ctx
->base
.pc_next
;
15247 generate_exception_err(ctx
, EXCP_AdEL
, EXCP_INST_NOTAVAIL
);
15251 /* Handle blikely not taken case */
15252 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
15253 TCGLabel
*l1
= gen_new_label();
15255 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
15256 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
15257 gen_goto_tb(ctx
, 1, ctx
->base
.pc_next
+ 4);
15261 /* Transition to the auto-generated decoder. */
15263 /* Vendor specific extensions */
15264 if (cpu_supports_isa(env
, INSN_R5900
) && decode_ext_txx9(ctx
, ctx
->opcode
)) {
15267 if (cpu_supports_isa(env
, INSN_VR54XX
) && decode_ext_vr54xx(ctx
, ctx
->opcode
)) {
15270 #if defined(TARGET_MIPS64)
15271 if (ase_lcsr_available(env
) && decode_ase_lcsr(ctx
, ctx
->opcode
)) {
15274 if (cpu_supports_isa(env
, INSN_OCTEON
) && decode_ext_octeon(ctx
, ctx
->opcode
)) {
15279 /* ISA extensions */
15280 if (ase_msa_available(env
) && decode_ase_msa(ctx
, ctx
->opcode
)) {
15284 /* ISA (from latest to oldest) */
15285 if (cpu_supports_isa(env
, ISA_MIPS_R6
) && decode_isa_rel6(ctx
, ctx
->opcode
)) {
15289 if (decode_opc_legacy(env
, ctx
)) {
15293 gen_reserved_instruction(ctx
);
15296 static void mips_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
15298 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
15299 CPUMIPSState
*env
= cpu_env(cs
);
15301 ctx
->page_start
= ctx
->base
.pc_first
& TARGET_PAGE_MASK
;
15302 ctx
->saved_pc
= -1;
15303 ctx
->insn_flags
= env
->insn_flags
;
15304 ctx
->CP0_Config0
= env
->CP0_Config0
;
15305 ctx
->CP0_Config1
= env
->CP0_Config1
;
15306 ctx
->CP0_Config2
= env
->CP0_Config2
;
15307 ctx
->CP0_Config3
= env
->CP0_Config3
;
15308 ctx
->CP0_Config5
= env
->CP0_Config5
;
15310 ctx
->kscrexist
= (env
->CP0_Config4
>> CP0C4_KScrExist
) & 0xff;
15311 ctx
->rxi
= (env
->CP0_Config3
>> CP0C3_RXI
) & 1;
15312 ctx
->ie
= (env
->CP0_Config4
>> CP0C4_IE
) & 3;
15313 ctx
->bi
= (env
->CP0_Config3
>> CP0C3_BI
) & 1;
15314 ctx
->bp
= (env
->CP0_Config3
>> CP0C3_BP
) & 1;
15315 ctx
->PAMask
= env
->PAMask
;
15316 ctx
->mvh
= (env
->CP0_Config5
>> CP0C5_MVH
) & 1;
15317 ctx
->eva
= (env
->CP0_Config5
>> CP0C5_EVA
) & 1;
15318 ctx
->sc
= (env
->CP0_Config3
>> CP0C3_SC
) & 1;
15319 ctx
->CP0_LLAddr_shift
= env
->CP0_LLAddr_shift
;
15320 ctx
->cmgcr
= (env
->CP0_Config3
>> CP0C3_CMGCR
) & 1;
15321 /* Restore delay slot state from the tb context. */
15322 ctx
->hflags
= (uint32_t)ctx
->base
.tb
->flags
; /* FIXME: maybe use 64 bits? */
15323 ctx
->ulri
= (env
->CP0_Config3
>> CP0C3_ULRI
) & 1;
15324 ctx
->ps
= ((env
->active_fpu
.fcr0
>> FCR0_PS
) & 1) ||
15325 (env
->insn_flags
& (INSN_LOONGSON2E
| INSN_LOONGSON2F
));
15326 ctx
->vp
= (env
->CP0_Config5
>> CP0C5_VP
) & 1;
15327 ctx
->mrp
= (env
->CP0_Config5
>> CP0C5_MRP
) & 1;
15328 ctx
->nan2008
= (env
->active_fpu
.fcr31
>> FCR31_NAN2008
) & 1;
15329 ctx
->abs2008
= (env
->active_fpu
.fcr31
>> FCR31_ABS2008
) & 1;
15330 ctx
->mi
= (env
->CP0_Config5
>> CP0C5_MI
) & 1;
15331 ctx
->gi
= (env
->CP0_Config5
>> CP0C5_GI
) & 3;
15332 restore_cpu_state(env
, ctx
);
15333 #ifdef CONFIG_USER_ONLY
15334 ctx
->mem_idx
= MIPS_HFLAG_UM
;
15336 ctx
->mem_idx
= hflags_mmu_index(ctx
->hflags
);
15338 ctx
->default_tcg_memop_mask
= (!(ctx
->insn_flags
& ISA_NANOMIPS32
) &&
15339 (ctx
->insn_flags
& (ISA_MIPS_R6
|
15340 INSN_LOONGSON3A
))) ? MO_UNALN
: MO_ALIGN
;
15343 * Execute a branch and its delay slot as a single instruction.
15344 * This is what GDB expects and is consistent with what the
15345 * hardware does (e.g. if a delay slot instruction faults, the
15346 * reported PC is the PC of the branch).
15348 if ((tb_cflags(ctx
->base
.tb
) & CF_SINGLE_STEP
) &&
15349 (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
15350 ctx
->base
.max_insns
= 2;
15353 LOG_DISAS("\ntb %p idx %d hflags %04x\n", ctx
->base
.tb
, ctx
->mem_idx
,
15357 static void mips_tr_tb_start(DisasContextBase
*dcbase
, CPUState
*cs
)
15361 static void mips_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
15363 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
15365 tcg_gen_insn_start(ctx
->base
.pc_next
, ctx
->hflags
& MIPS_HFLAG_BMASK
,
15369 static void mips_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
15371 CPUMIPSState
*env
= cpu_env(cs
);
15372 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
15376 is_slot
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
15377 if (ctx
->insn_flags
& ISA_NANOMIPS32
) {
15378 ctx
->opcode
= translator_lduw(env
, &ctx
->base
, ctx
->base
.pc_next
);
15379 insn_bytes
= decode_isa_nanomips(env
, ctx
);
15380 } else if (!(ctx
->hflags
& MIPS_HFLAG_M16
)) {
15381 ctx
->opcode
= translator_ldl(env
, &ctx
->base
, ctx
->base
.pc_next
);
15383 decode_opc(env
, ctx
);
15384 } else if (ctx
->insn_flags
& ASE_MICROMIPS
) {
15385 ctx
->opcode
= translator_lduw(env
, &ctx
->base
, ctx
->base
.pc_next
);
15386 insn_bytes
= decode_isa_micromips(env
, ctx
);
15387 } else if (ctx
->insn_flags
& ASE_MIPS16
) {
15388 ctx
->opcode
= translator_lduw(env
, &ctx
->base
, ctx
->base
.pc_next
);
15389 insn_bytes
= decode_ase_mips16e(env
, ctx
);
15391 gen_reserved_instruction(ctx
);
15392 g_assert(ctx
->base
.is_jmp
== DISAS_NORETURN
);
15396 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
15397 if (!(ctx
->hflags
& (MIPS_HFLAG_BDS16
| MIPS_HFLAG_BDS32
|
15398 MIPS_HFLAG_FBNSLOT
))) {
15400 * Force to generate branch as there is neither delay nor
15405 if ((ctx
->hflags
& MIPS_HFLAG_M16
) &&
15406 (ctx
->hflags
& MIPS_HFLAG_FBNSLOT
)) {
15408 * Force to generate branch as microMIPS R6 doesn't restrict
15409 * branches in the forbidden slot.
15415 gen_branch(ctx
, insn_bytes
);
15417 if (ctx
->base
.is_jmp
== DISAS_SEMIHOST
) {
15418 generate_exception_err(ctx
, EXCP_SEMIHOST
, insn_bytes
);
15420 ctx
->base
.pc_next
+= insn_bytes
;
15422 if (ctx
->base
.is_jmp
!= DISAS_NEXT
) {
15427 * End the TB on (most) page crossings.
15428 * See mips_tr_init_disas_context about single-stepping a branch
15429 * together with its delay slot.
15431 if (ctx
->base
.pc_next
- ctx
->page_start
>= TARGET_PAGE_SIZE
15432 && !(tb_cflags(ctx
->base
.tb
) & CF_SINGLE_STEP
)) {
15433 ctx
->base
.is_jmp
= DISAS_TOO_MANY
;
15437 static void mips_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
15439 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
15441 switch (ctx
->base
.is_jmp
) {
15443 gen_save_pc(ctx
->base
.pc_next
);
15444 tcg_gen_lookup_and_goto_ptr();
15447 case DISAS_TOO_MANY
:
15448 save_cpu_state(ctx
, 0);
15449 gen_goto_tb(ctx
, 0, ctx
->base
.pc_next
);
15452 tcg_gen_exit_tb(NULL
, 0);
15454 case DISAS_NORETURN
:
15457 g_assert_not_reached();
15461 static const TranslatorOps mips_tr_ops
= {
15462 .init_disas_context
= mips_tr_init_disas_context
,
15463 .tb_start
= mips_tr_tb_start
,
15464 .insn_start
= mips_tr_insn_start
,
15465 .translate_insn
= mips_tr_translate_insn
,
15466 .tb_stop
= mips_tr_tb_stop
,
15469 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int *max_insns
,
15470 vaddr pc
, void *host_pc
)
15474 translator_loop(cs
, tb
, max_insns
, pc
, host_pc
, &mips_tr_ops
, &ctx
.base
);
15477 void mips_tcg_init(void)
15480 for (unsigned i
= 1; i
< 32; i
++)
15481 cpu_gpr
[i
] = tcg_global_mem_new(tcg_env
,
15482 offsetof(CPUMIPSState
,
15485 #if defined(TARGET_MIPS64)
15486 cpu_gpr_hi
[0] = NULL
;
15488 for (unsigned i
= 1; i
< 32; i
++) {
15489 g_autofree
char *rname
= g_strdup_printf("%s[hi]", regnames
[i
]);
15491 cpu_gpr_hi
[i
] = tcg_global_mem_new_i64(tcg_env
,
15492 offsetof(CPUMIPSState
,
15493 active_tc
.gpr_hi
[i
]),
15496 #endif /* !TARGET_MIPS64 */
15497 for (unsigned i
= 0; i
< 32; i
++) {
15498 int off
= offsetof(CPUMIPSState
, active_fpu
.fpr
[i
].wr
.d
[0]);
15500 fpu_f64
[i
] = tcg_global_mem_new_i64(tcg_env
, off
, fregnames
[i
]);
15502 msa_translate_init();
15503 cpu_PC
= tcg_global_mem_new(tcg_env
,
15504 offsetof(CPUMIPSState
, active_tc
.PC
), "PC");
15505 for (unsigned i
= 0; i
< MIPS_DSP_ACC
; i
++) {
15506 cpu_HI
[i
] = tcg_global_mem_new(tcg_env
,
15507 offsetof(CPUMIPSState
, active_tc
.HI
[i
]),
15509 cpu_LO
[i
] = tcg_global_mem_new(tcg_env
,
15510 offsetof(CPUMIPSState
, active_tc
.LO
[i
]),
15513 cpu_dspctrl
= tcg_global_mem_new(tcg_env
,
15514 offsetof(CPUMIPSState
,
15515 active_tc
.DSPControl
),
15517 bcond
= tcg_global_mem_new(tcg_env
,
15518 offsetof(CPUMIPSState
, bcond
), "bcond");
15519 btarget
= tcg_global_mem_new(tcg_env
,
15520 offsetof(CPUMIPSState
, btarget
), "btarget");
15521 hflags
= tcg_global_mem_new_i32(tcg_env
,
15522 offsetof(CPUMIPSState
, hflags
), "hflags");
15524 fpu_fcr0
= tcg_global_mem_new_i32(tcg_env
,
15525 offsetof(CPUMIPSState
, active_fpu
.fcr0
),
15527 fpu_fcr31
= tcg_global_mem_new_i32(tcg_env
,
15528 offsetof(CPUMIPSState
, active_fpu
.fcr31
),
15530 cpu_lladdr
= tcg_global_mem_new(tcg_env
, offsetof(CPUMIPSState
, lladdr
),
15532 cpu_llval
= tcg_global_mem_new(tcg_env
, offsetof(CPUMIPSState
, llval
),
15535 if (TARGET_LONG_BITS
== 32) {
15536 mxu_translate_init();
15540 void mips_restore_state_to_opc(CPUState
*cs
,
15541 const TranslationBlock
*tb
,
15542 const uint64_t *data
)
15544 CPUMIPSState
*env
= cpu_env(cs
);
15546 env
->active_tc
.PC
= data
[0];
15547 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
15548 env
->hflags
|= data
[1];
15549 switch (env
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
15550 case MIPS_HFLAG_BR
:
15552 case MIPS_HFLAG_BC
:
15553 case MIPS_HFLAG_BL
:
15555 env
->btarget
= data
[2];