2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
7 * Copyright (c) 2009 CodeSourcery (MIPS16 and microMIPS support)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
33 #include "qemu-common.h"
39 //#define MIPS_DEBUG_DISAS
40 //#define MIPS_DEBUG_SIGN_EXTENSIONS
42 /* MIPS major opcodes */
43 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
46 /* indirect opcode tables */
47 OPC_SPECIAL
= (0x00 << 26),
48 OPC_REGIMM
= (0x01 << 26),
49 OPC_CP0
= (0x10 << 26),
50 OPC_CP1
= (0x11 << 26),
51 OPC_CP2
= (0x12 << 26),
52 OPC_CP3
= (0x13 << 26),
53 OPC_SPECIAL2
= (0x1C << 26),
54 OPC_SPECIAL3
= (0x1F << 26),
55 /* arithmetic with immediate */
56 OPC_ADDI
= (0x08 << 26),
57 OPC_ADDIU
= (0x09 << 26),
58 OPC_SLTI
= (0x0A << 26),
59 OPC_SLTIU
= (0x0B << 26),
60 /* logic with immediate */
61 OPC_ANDI
= (0x0C << 26),
62 OPC_ORI
= (0x0D << 26),
63 OPC_XORI
= (0x0E << 26),
64 OPC_LUI
= (0x0F << 26),
65 /* arithmetic with immediate */
66 OPC_DADDI
= (0x18 << 26),
67 OPC_DADDIU
= (0x19 << 26),
68 /* Jump and branches */
70 OPC_JAL
= (0x03 << 26),
71 OPC_JALS
= OPC_JAL
| 0x5,
72 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
73 OPC_BEQL
= (0x14 << 26),
74 OPC_BNE
= (0x05 << 26),
75 OPC_BNEL
= (0x15 << 26),
76 OPC_BLEZ
= (0x06 << 26),
77 OPC_BLEZL
= (0x16 << 26),
78 OPC_BGTZ
= (0x07 << 26),
79 OPC_BGTZL
= (0x17 << 26),
80 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
81 OPC_JALXS
= OPC_JALX
| 0x5,
83 OPC_LDL
= (0x1A << 26),
84 OPC_LDR
= (0x1B << 26),
85 OPC_LB
= (0x20 << 26),
86 OPC_LH
= (0x21 << 26),
87 OPC_LWL
= (0x22 << 26),
88 OPC_LW
= (0x23 << 26),
89 OPC_LWPC
= OPC_LW
| 0x5,
90 OPC_LBU
= (0x24 << 26),
91 OPC_LHU
= (0x25 << 26),
92 OPC_LWR
= (0x26 << 26),
93 OPC_LWU
= (0x27 << 26),
94 OPC_SB
= (0x28 << 26),
95 OPC_SH
= (0x29 << 26),
96 OPC_SWL
= (0x2A << 26),
97 OPC_SW
= (0x2B << 26),
98 OPC_SDL
= (0x2C << 26),
99 OPC_SDR
= (0x2D << 26),
100 OPC_SWR
= (0x2E << 26),
101 OPC_LL
= (0x30 << 26),
102 OPC_LLD
= (0x34 << 26),
103 OPC_LD
= (0x37 << 26),
104 OPC_LDPC
= OPC_LD
| 0x5,
105 OPC_SC
= (0x38 << 26),
106 OPC_SCD
= (0x3C << 26),
107 OPC_SD
= (0x3F << 26),
108 /* Floating point load/store */
109 OPC_LWC1
= (0x31 << 26),
110 OPC_LWC2
= (0x32 << 26),
111 OPC_LDC1
= (0x35 << 26),
112 OPC_LDC2
= (0x36 << 26),
113 OPC_SWC1
= (0x39 << 26),
114 OPC_SWC2
= (0x3A << 26),
115 OPC_SDC1
= (0x3D << 26),
116 OPC_SDC2
= (0x3E << 26),
117 /* MDMX ASE specific */
118 OPC_MDMX
= (0x1E << 26),
119 /* Cache and prefetch */
120 OPC_CACHE
= (0x2F << 26),
121 OPC_PREF
= (0x33 << 26),
122 /* Reserved major opcode */
123 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
126 /* MIPS special opcodes */
127 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
131 OPC_SLL
= 0x00 | OPC_SPECIAL
,
132 /* NOP is SLL r0, r0, 0 */
133 /* SSNOP is SLL r0, r0, 1 */
134 /* EHB is SLL r0, r0, 3 */
135 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
136 OPC_ROTR
= OPC_SRL
| (1 << 21),
137 OPC_SRA
= 0x03 | OPC_SPECIAL
,
138 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
139 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
140 OPC_ROTRV
= OPC_SRLV
| (1 << 6),
141 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
142 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
143 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
144 OPC_DROTRV
= OPC_DSRLV
| (1 << 6),
145 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
146 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
147 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
148 OPC_DROTR
= OPC_DSRL
| (1 << 21),
149 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
150 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
151 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
152 OPC_DROTR32
= OPC_DSRL32
| (1 << 21),
153 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
154 /* Multiplication / division */
155 OPC_MULT
= 0x18 | OPC_SPECIAL
,
156 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
157 OPC_DIV
= 0x1A | OPC_SPECIAL
,
158 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
159 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
160 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
161 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
162 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
163 /* 2 registers arithmetic / logic */
164 OPC_ADD
= 0x20 | OPC_SPECIAL
,
165 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
166 OPC_SUB
= 0x22 | OPC_SPECIAL
,
167 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
168 OPC_AND
= 0x24 | OPC_SPECIAL
,
169 OPC_OR
= 0x25 | OPC_SPECIAL
,
170 OPC_XOR
= 0x26 | OPC_SPECIAL
,
171 OPC_NOR
= 0x27 | OPC_SPECIAL
,
172 OPC_SLT
= 0x2A | OPC_SPECIAL
,
173 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
174 OPC_DADD
= 0x2C | OPC_SPECIAL
,
175 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
176 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
177 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
179 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
180 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
181 OPC_JALRC
= OPC_JALR
| (0x5 << 6),
182 OPC_JALRS
= 0x10 | OPC_SPECIAL
| (0x5 << 6),
184 OPC_TGE
= 0x30 | OPC_SPECIAL
,
185 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
186 OPC_TLT
= 0x32 | OPC_SPECIAL
,
187 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
188 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
189 OPC_TNE
= 0x36 | OPC_SPECIAL
,
190 /* HI / LO registers load & stores */
191 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
192 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
193 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
194 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
195 /* Conditional moves */
196 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
197 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
199 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
202 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* unofficial */
203 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
204 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
205 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
206 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
208 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
209 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
210 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
211 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
212 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
213 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
214 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
217 /* Multiplication variants of the vr54xx. */
218 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
221 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
222 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
223 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
224 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
225 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
226 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
227 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
228 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
229 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
230 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
231 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
232 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
233 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
234 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
237 /* REGIMM (rt field) opcodes */
238 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
241 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
242 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
243 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
244 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
245 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
246 OPC_BLTZALS
= OPC_BLTZAL
| 0x5, /* microMIPS */
247 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
248 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
249 OPC_BGEZALS
= OPC_BGEZAL
| 0x5, /* microMIPS */
250 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
251 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
252 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
253 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
254 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
255 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
256 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
257 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
260 /* Special2 opcodes */
261 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
264 /* Multiply & xxx operations */
265 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
266 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
267 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
268 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
269 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
271 OPC_MULT_G_2F
= 0x10 | OPC_SPECIAL2
,
272 OPC_DMULT_G_2F
= 0x11 | OPC_SPECIAL2
,
273 OPC_MULTU_G_2F
= 0x12 | OPC_SPECIAL2
,
274 OPC_DMULTU_G_2F
= 0x13 | OPC_SPECIAL2
,
275 OPC_DIV_G_2F
= 0x14 | OPC_SPECIAL2
,
276 OPC_DDIV_G_2F
= 0x15 | OPC_SPECIAL2
,
277 OPC_DIVU_G_2F
= 0x16 | OPC_SPECIAL2
,
278 OPC_DDIVU_G_2F
= 0x17 | OPC_SPECIAL2
,
279 OPC_MOD_G_2F
= 0x1c | OPC_SPECIAL2
,
280 OPC_DMOD_G_2F
= 0x1d | OPC_SPECIAL2
,
281 OPC_MODU_G_2F
= 0x1e | OPC_SPECIAL2
,
282 OPC_DMODU_G_2F
= 0x1f | OPC_SPECIAL2
,
284 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
285 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
286 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
287 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
289 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
292 /* Special3 opcodes */
293 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
296 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
297 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
298 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
299 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
300 OPC_INS
= 0x04 | OPC_SPECIAL3
,
301 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
302 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
303 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
304 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
305 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
306 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
307 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
308 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
311 OPC_MULT_G_2E
= 0x18 | OPC_SPECIAL3
,
312 OPC_MULTU_G_2E
= 0x19 | OPC_SPECIAL3
,
313 OPC_DIV_G_2E
= 0x1A | OPC_SPECIAL3
,
314 OPC_DIVU_G_2E
= 0x1B | OPC_SPECIAL3
,
315 OPC_DMULT_G_2E
= 0x1C | OPC_SPECIAL3
,
316 OPC_DMULTU_G_2E
= 0x1D | OPC_SPECIAL3
,
317 OPC_DDIV_G_2E
= 0x1E | OPC_SPECIAL3
,
318 OPC_DDIVU_G_2E
= 0x1F | OPC_SPECIAL3
,
319 OPC_MOD_G_2E
= 0x22 | OPC_SPECIAL3
,
320 OPC_MODU_G_2E
= 0x23 | OPC_SPECIAL3
,
321 OPC_DMOD_G_2E
= 0x26 | OPC_SPECIAL3
,
322 OPC_DMODU_G_2E
= 0x27 | OPC_SPECIAL3
,
326 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
329 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
330 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
331 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
335 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
338 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
339 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
342 /* Coprocessor 0 (rs field) */
343 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
347 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
348 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
349 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
350 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
351 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
352 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
353 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
354 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
355 OPC_C0
= (0x10 << 21) | OPC_CP0
,
356 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
357 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
361 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
364 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
365 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
366 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
367 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
368 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
369 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
372 /* Coprocessor 0 (with rs == C0) */
373 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
376 OPC_TLBR
= 0x01 | OPC_C0
,
377 OPC_TLBWI
= 0x02 | OPC_C0
,
378 OPC_TLBWR
= 0x06 | OPC_C0
,
379 OPC_TLBP
= 0x08 | OPC_C0
,
380 OPC_RFE
= 0x10 | OPC_C0
,
381 OPC_ERET
= 0x18 | OPC_C0
,
382 OPC_DERET
= 0x1F | OPC_C0
,
383 OPC_WAIT
= 0x20 | OPC_C0
,
386 /* Coprocessor 1 (rs field) */
387 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 /* Values for the fmt field in FP instructions */
391 /* 0 - 15 are reserved */
392 FMT_S
= 16, /* single fp */
393 FMT_D
= 17, /* double fp */
394 FMT_E
= 18, /* extended fp */
395 FMT_Q
= 19, /* quad fp */
396 FMT_W
= 20, /* 32-bit fixed */
397 FMT_L
= 21, /* 64-bit fixed */
398 FMT_PS
= 22, /* paired single fp */
399 /* 23 - 31 are reserved */
403 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
404 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
405 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
406 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
407 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
408 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
409 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
410 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
411 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
412 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
413 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
414 OPC_S_FMT
= (FMT_S
<< 21) | OPC_CP1
,
415 OPC_D_FMT
= (FMT_D
<< 21) | OPC_CP1
,
416 OPC_E_FMT
= (FMT_E
<< 21) | OPC_CP1
,
417 OPC_Q_FMT
= (FMT_Q
<< 21) | OPC_CP1
,
418 OPC_W_FMT
= (FMT_W
<< 21) | OPC_CP1
,
419 OPC_L_FMT
= (FMT_L
<< 21) | OPC_CP1
,
420 OPC_PS_FMT
= (FMT_PS
<< 21) | OPC_CP1
,
423 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
424 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
427 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
428 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
429 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
430 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
434 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
435 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
439 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
440 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
443 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
446 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
447 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
448 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
449 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
450 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
451 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
452 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
453 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
454 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
457 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
460 OPC_LWXC1
= 0x00 | OPC_CP3
,
461 OPC_LDXC1
= 0x01 | OPC_CP3
,
462 OPC_LUXC1
= 0x05 | OPC_CP3
,
463 OPC_SWXC1
= 0x08 | OPC_CP3
,
464 OPC_SDXC1
= 0x09 | OPC_CP3
,
465 OPC_SUXC1
= 0x0D | OPC_CP3
,
466 OPC_PREFX
= 0x0F | OPC_CP3
,
467 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
468 OPC_MADD_S
= 0x20 | OPC_CP3
,
469 OPC_MADD_D
= 0x21 | OPC_CP3
,
470 OPC_MADD_PS
= 0x26 | OPC_CP3
,
471 OPC_MSUB_S
= 0x28 | OPC_CP3
,
472 OPC_MSUB_D
= 0x29 | OPC_CP3
,
473 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
474 OPC_NMADD_S
= 0x30 | OPC_CP3
,
475 OPC_NMADD_D
= 0x31 | OPC_CP3
,
476 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
477 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
478 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
479 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
482 /* global register indices */
483 static TCGv_ptr cpu_env
;
484 static TCGv cpu_gpr
[32], cpu_PC
;
485 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
486 static TCGv cpu_dspctrl
, btarget
, bcond
;
487 static TCGv_i32 hflags
;
488 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
490 static uint32_t gen_opc_hflags
[OPC_BUF_SIZE
];
492 #include "gen-icount.h"
494 #define gen_helper_0i(name, arg) do { \
495 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
496 gen_helper_##name(helper_tmp); \
497 tcg_temp_free_i32(helper_tmp); \
500 #define gen_helper_1i(name, arg1, arg2) do { \
501 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
502 gen_helper_##name(arg1, helper_tmp); \
503 tcg_temp_free_i32(helper_tmp); \
506 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
507 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
508 gen_helper_##name(arg1, arg2, helper_tmp); \
509 tcg_temp_free_i32(helper_tmp); \
512 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
513 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
514 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
515 tcg_temp_free_i32(helper_tmp); \
518 typedef struct DisasContext
{
519 struct TranslationBlock
*tb
;
520 target_ulong pc
, saved_pc
;
522 int singlestep_enabled
;
523 /* Routine used to access memory */
525 uint32_t hflags
, saved_hflags
;
527 target_ulong btarget
;
531 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
532 * exception condition */
533 BS_STOP
= 1, /* We want to stop translation for any reason */
534 BS_BRANCH
= 2, /* We reached a branch condition */
535 BS_EXCP
= 3, /* We reached an exception condition */
538 static const char *regnames
[] =
539 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
540 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
541 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
542 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
544 static const char *regnames_HI
[] =
545 { "HI0", "HI1", "HI2", "HI3", };
547 static const char *regnames_LO
[] =
548 { "LO0", "LO1", "LO2", "LO3", };
550 static const char *regnames_ACX
[] =
551 { "ACX0", "ACX1", "ACX2", "ACX3", };
553 static const char *fregnames
[] =
554 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
555 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
556 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
557 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
559 #ifdef MIPS_DEBUG_DISAS
560 #define MIPS_DEBUG(fmt, ...) \
561 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
562 TARGET_FMT_lx ": %08x " fmt "\n", \
563 ctx->pc, ctx->opcode , ## __VA_ARGS__)
564 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
566 #define MIPS_DEBUG(fmt, ...) do { } while(0)
567 #define LOG_DISAS(...) do { } while (0)
570 #define MIPS_INVAL(op) \
572 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
573 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
576 /* General purpose registers moves. */
577 static inline void gen_load_gpr (TCGv t
, int reg
)
580 tcg_gen_movi_tl(t
, 0);
582 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
585 static inline void gen_store_gpr (TCGv t
, int reg
)
588 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
591 /* Moves to/from ACX register. */
592 static inline void gen_load_ACX (TCGv t
, int reg
)
594 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
597 static inline void gen_store_ACX (TCGv t
, int reg
)
599 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
602 /* Moves to/from shadow registers. */
603 static inline void gen_load_srsgpr (int from
, int to
)
605 TCGv t0
= tcg_temp_new();
608 tcg_gen_movi_tl(t0
, 0);
610 TCGv_i32 t2
= tcg_temp_new_i32();
611 TCGv_ptr addr
= tcg_temp_new_ptr();
613 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
614 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
615 tcg_gen_andi_i32(t2
, t2
, 0xf);
616 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
617 tcg_gen_ext_i32_ptr(addr
, t2
);
618 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
620 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
621 tcg_temp_free_ptr(addr
);
622 tcg_temp_free_i32(t2
);
624 gen_store_gpr(t0
, to
);
628 static inline void gen_store_srsgpr (int from
, int to
)
631 TCGv t0
= tcg_temp_new();
632 TCGv_i32 t2
= tcg_temp_new_i32();
633 TCGv_ptr addr
= tcg_temp_new_ptr();
635 gen_load_gpr(t0
, from
);
636 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
637 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
638 tcg_gen_andi_i32(t2
, t2
, 0xf);
639 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
640 tcg_gen_ext_i32_ptr(addr
, t2
);
641 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
643 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
644 tcg_temp_free_ptr(addr
);
645 tcg_temp_free_i32(t2
);
650 /* Floating point register moves. */
651 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
653 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
656 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
658 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
661 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
663 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
666 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
668 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
671 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
673 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
674 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
676 TCGv_i32 t0
= tcg_temp_new_i32();
677 TCGv_i32 t1
= tcg_temp_new_i32();
678 gen_load_fpr32(t0
, reg
& ~1);
679 gen_load_fpr32(t1
, reg
| 1);
680 tcg_gen_concat_i32_i64(t
, t0
, t1
);
681 tcg_temp_free_i32(t0
);
682 tcg_temp_free_i32(t1
);
686 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
688 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
689 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
691 TCGv_i64 t0
= tcg_temp_new_i64();
692 TCGv_i32 t1
= tcg_temp_new_i32();
693 tcg_gen_trunc_i64_i32(t1
, t
);
694 gen_store_fpr32(t1
, reg
& ~1);
695 tcg_gen_shri_i64(t0
, t
, 32);
696 tcg_gen_trunc_i64_i32(t1
, t0
);
697 gen_store_fpr32(t1
, reg
| 1);
698 tcg_temp_free_i32(t1
);
699 tcg_temp_free_i64(t0
);
703 static inline int get_fp_bit (int cc
)
712 static inline void gen_save_pc(target_ulong pc
)
714 tcg_gen_movi_tl(cpu_PC
, pc
);
717 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
719 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
720 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
721 gen_save_pc(ctx
->pc
);
722 ctx
->saved_pc
= ctx
->pc
;
724 if (ctx
->hflags
!= ctx
->saved_hflags
) {
725 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
726 ctx
->saved_hflags
= ctx
->hflags
;
727 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
733 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
739 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
741 ctx
->saved_hflags
= ctx
->hflags
;
742 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
748 ctx
->btarget
= env
->btarget
;
754 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
756 TCGv_i32 texcp
= tcg_const_i32(excp
);
757 TCGv_i32 terr
= tcg_const_i32(err
);
758 save_cpu_state(ctx
, 1);
759 gen_helper_raise_exception_err(texcp
, terr
);
760 tcg_temp_free_i32(terr
);
761 tcg_temp_free_i32(texcp
);
765 generate_exception (DisasContext
*ctx
, int excp
)
767 save_cpu_state(ctx
, 1);
768 gen_helper_0i(raise_exception
, excp
);
771 /* Addresses computation */
772 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
774 tcg_gen_add_tl(ret
, arg0
, arg1
);
776 #if defined(TARGET_MIPS64)
777 /* For compatibility with 32-bit code, data reference in user mode
778 with Status_UX = 0 should be casted to 32-bit and sign extended.
779 See the MIPS64 PRA manual, section 4.10. */
780 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
781 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
782 tcg_gen_ext32s_i64(ret
, ret
);
787 static inline void check_cp0_enabled(DisasContext
*ctx
)
789 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
790 generate_exception_err(ctx
, EXCP_CpU
, 0);
793 static inline void check_cp1_enabled(DisasContext
*ctx
)
795 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
796 generate_exception_err(ctx
, EXCP_CpU
, 1);
799 /* Verify that the processor is running with COP1X instructions enabled.
800 This is associated with the nabla symbol in the MIPS32 and MIPS64
803 static inline void check_cop1x(DisasContext
*ctx
)
805 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
806 generate_exception(ctx
, EXCP_RI
);
809 /* Verify that the processor is running with 64-bit floating-point
810 operations enabled. */
812 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
814 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
815 generate_exception(ctx
, EXCP_RI
);
819 * Verify if floating point register is valid; an operation is not defined
820 * if bit 0 of any register specification is set and the FR bit in the
821 * Status register equals zero, since the register numbers specify an
822 * even-odd pair of adjacent coprocessor general registers. When the FR bit
823 * in the Status register equals one, both even and odd register numbers
824 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
826 * Multiple 64 bit wide registers can be checked by calling
827 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
829 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
831 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
832 generate_exception(ctx
, EXCP_RI
);
835 /* This code generates a "reserved instruction" exception if the
836 CPU does not support the instruction set corresponding to flags. */
837 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
839 if (unlikely(!(env
->insn_flags
& flags
)))
840 generate_exception(ctx
, EXCP_RI
);
843 /* This code generates a "reserved instruction" exception if 64-bit
844 instructions are not enabled. */
845 static inline void check_mips_64(DisasContext
*ctx
)
847 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
848 generate_exception(ctx
, EXCP_RI
);
851 /* Define small wrappers for gen_load_fpr* so that we have a uniform
852 calling interface for 32 and 64-bit FPRs. No sense in changing
853 all callers for gen_load_fpr32 when we need the CTX parameter for
855 #define gen_ldcmp_fpr32(ctx, x, y) gen_load_fpr32(x, y)
856 #define gen_ldcmp_fpr64(ctx, x, y) gen_load_fpr64(ctx, x, y)
857 #define FOP_CONDS(type, abs, fmt, ifmt, bits) \
858 static inline void gen_cmp ## type ## _ ## fmt(DisasContext *ctx, int n, \
859 int ft, int fs, int cc) \
861 TCGv_i##bits fp0 = tcg_temp_new_i##bits (); \
862 TCGv_i##bits fp1 = tcg_temp_new_i##bits (); \
865 check_cp1_64bitmode(ctx); \
871 check_cp1_registers(ctx, fs | ft); \
879 gen_ldcmp_fpr##bits (ctx, fp0, fs); \
880 gen_ldcmp_fpr##bits (ctx, fp1, ft); \
882 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, fp0, fp1, cc); break;\
883 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, fp0, fp1, cc); break;\
884 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, fp0, fp1, cc); break;\
885 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, fp0, fp1, cc); break;\
886 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, fp0, fp1, cc); break;\
887 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, fp0, fp1, cc); break;\
888 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, fp0, fp1, cc); break;\
889 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, fp0, fp1, cc); break;\
890 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, fp0, fp1, cc); break;\
891 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, fp0, fp1, cc); break;\
892 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, fp0, fp1, cc); break;\
893 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, fp0, fp1, cc); break;\
894 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, fp0, fp1, cc); break;\
895 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, fp0, fp1, cc); break;\
896 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, fp0, fp1, cc); break;\
897 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, fp0, fp1, cc); break;\
900 tcg_temp_free_i##bits (fp0); \
901 tcg_temp_free_i##bits (fp1); \
904 FOP_CONDS(, 0, d
, FMT_D
, 64)
905 FOP_CONDS(abs
, 1, d
, FMT_D
, 64)
906 FOP_CONDS(, 0, s
, FMT_S
, 32)
907 FOP_CONDS(abs
, 1, s
, FMT_S
, 32)
908 FOP_CONDS(, 0, ps
, FMT_PS
, 64)
909 FOP_CONDS(abs
, 1, ps
, FMT_PS
, 64)
911 #undef gen_ldcmp_fpr32
912 #undef gen_ldcmp_fpr64
914 /* load/store instructions. */
915 #define OP_LD(insn,fname) \
916 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
918 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
925 #if defined(TARGET_MIPS64)
931 #define OP_ST(insn,fname) \
932 static inline void op_st_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
934 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
939 #if defined(TARGET_MIPS64)
944 #ifdef CONFIG_USER_ONLY
945 #define OP_LD_ATOMIC(insn,fname) \
946 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
948 TCGv t0 = tcg_temp_new(); \
949 tcg_gen_mov_tl(t0, arg1); \
950 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
951 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
952 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
956 #define OP_LD_ATOMIC(insn,fname) \
957 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
959 gen_helper_2i(insn, ret, arg1, ctx->mem_idx); \
962 OP_LD_ATOMIC(ll
,ld32s
);
963 #if defined(TARGET_MIPS64)
964 OP_LD_ATOMIC(lld
,ld64
);
968 #ifdef CONFIG_USER_ONLY
969 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
970 static inline void op_st_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
972 TCGv t0 = tcg_temp_new(); \
973 int l1 = gen_new_label(); \
974 int l2 = gen_new_label(); \
976 tcg_gen_andi_tl(t0, arg2, almask); \
977 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
978 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
979 generate_exception(ctx, EXCP_AdES); \
981 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
982 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
983 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
984 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
985 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
986 gen_helper_0i(raise_exception, EXCP_SC); \
988 tcg_gen_movi_tl(t0, 0); \
989 gen_store_gpr(t0, rt); \
993 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
994 static inline void op_st_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
996 TCGv t0 = tcg_temp_new(); \
997 gen_helper_3i(insn, t0, arg1, arg2, ctx->mem_idx); \
998 gen_store_gpr(t0, rt); \
1002 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
1003 #if defined(TARGET_MIPS64)
1004 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
1008 static void gen_base_offset_addr (DisasContext
*ctx
, TCGv addr
,
1009 int base
, int16_t offset
)
1012 tcg_gen_movi_tl(addr
, offset
);
1013 } else if (offset
== 0) {
1014 gen_load_gpr(addr
, base
);
1016 tcg_gen_movi_tl(addr
, offset
);
1017 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
1021 static target_ulong
pc_relative_pc (DisasContext
*ctx
)
1023 target_ulong pc
= ctx
->pc
;
1025 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1026 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
1031 pc
&= ~(target_ulong
)3;
1036 static void gen_ld (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1037 int rt
, int base
, int16_t offset
)
1039 const char *opn
= "ld";
1042 if (rt
== 0 && env
->insn_flags
& (INSN_LOONGSON2E
| INSN_LOONGSON2F
)) {
1043 /* Loongson CPU uses a load to zero register for prefetch.
1044 We emulate it as a NOP. On other CPU we must perform the
1045 actual memory access. */
1050 t0
= tcg_temp_new();
1051 t1
= tcg_temp_new();
1052 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1055 #if defined(TARGET_MIPS64)
1057 save_cpu_state(ctx
, 0);
1058 op_ld_lwu(t0
, t0
, ctx
);
1059 gen_store_gpr(t0
, rt
);
1063 save_cpu_state(ctx
, 0);
1064 op_ld_ld(t0
, t0
, ctx
);
1065 gen_store_gpr(t0
, rt
);
1069 save_cpu_state(ctx
, 1);
1070 op_ld_lld(t0
, t0
, ctx
);
1071 gen_store_gpr(t0
, rt
);
1075 save_cpu_state(ctx
, 1);
1076 gen_load_gpr(t1
, rt
);
1077 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1078 gen_store_gpr(t1
, rt
);
1082 save_cpu_state(ctx
, 1);
1083 gen_load_gpr(t1
, rt
);
1084 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1085 gen_store_gpr(t1
, rt
);
1089 save_cpu_state(ctx
, 0);
1090 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1091 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1092 op_ld_ld(t0
, t0
, ctx
);
1093 gen_store_gpr(t0
, rt
);
1098 save_cpu_state(ctx
, 0);
1099 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1100 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1101 op_ld_lw(t0
, t0
, ctx
);
1102 gen_store_gpr(t0
, rt
);
1106 save_cpu_state(ctx
, 0);
1107 op_ld_lw(t0
, t0
, ctx
);
1108 gen_store_gpr(t0
, rt
);
1112 save_cpu_state(ctx
, 0);
1113 op_ld_lh(t0
, t0
, ctx
);
1114 gen_store_gpr(t0
, rt
);
1118 save_cpu_state(ctx
, 0);
1119 op_ld_lhu(t0
, t0
, ctx
);
1120 gen_store_gpr(t0
, rt
);
1124 save_cpu_state(ctx
, 0);
1125 op_ld_lb(t0
, t0
, ctx
);
1126 gen_store_gpr(t0
, rt
);
1130 save_cpu_state(ctx
, 0);
1131 op_ld_lbu(t0
, t0
, ctx
);
1132 gen_store_gpr(t0
, rt
);
1136 save_cpu_state(ctx
, 1);
1137 gen_load_gpr(t1
, rt
);
1138 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1139 gen_store_gpr(t1
, rt
);
1143 save_cpu_state(ctx
, 1);
1144 gen_load_gpr(t1
, rt
);
1145 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1146 gen_store_gpr(t1
, rt
);
1150 save_cpu_state(ctx
, 1);
1151 op_ld_ll(t0
, t0
, ctx
);
1152 gen_store_gpr(t0
, rt
);
1156 (void)opn
; /* avoid a compiler warning */
1157 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1163 static void gen_st (DisasContext
*ctx
, uint32_t opc
, int rt
,
1164 int base
, int16_t offset
)
1166 const char *opn
= "st";
1167 TCGv t0
= tcg_temp_new();
1168 TCGv t1
= tcg_temp_new();
1170 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1171 gen_load_gpr(t1
, rt
);
1173 #if defined(TARGET_MIPS64)
1175 save_cpu_state(ctx
, 0);
1176 op_st_sd(t1
, t0
, ctx
);
1180 save_cpu_state(ctx
, 1);
1181 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1185 save_cpu_state(ctx
, 1);
1186 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1191 save_cpu_state(ctx
, 0);
1192 op_st_sw(t1
, t0
, ctx
);
1196 save_cpu_state(ctx
, 0);
1197 op_st_sh(t1
, t0
, ctx
);
1201 save_cpu_state(ctx
, 0);
1202 op_st_sb(t1
, t0
, ctx
);
1206 save_cpu_state(ctx
, 1);
1207 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1211 save_cpu_state(ctx
, 1);
1212 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1216 (void)opn
; /* avoid a compiler warning */
1217 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1223 /* Store conditional */
1224 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1225 int base
, int16_t offset
)
1227 const char *opn
= "st_cond";
1230 t0
= tcg_temp_local_new();
1232 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1233 /* Don't do NOP if destination is zero: we must perform the actual
1236 t1
= tcg_temp_local_new();
1237 gen_load_gpr(t1
, rt
);
1239 #if defined(TARGET_MIPS64)
1241 save_cpu_state(ctx
, 1);
1242 op_st_scd(t1
, t0
, rt
, ctx
);
1247 save_cpu_state(ctx
, 1);
1248 op_st_sc(t1
, t0
, rt
, ctx
);
1252 (void)opn
; /* avoid a compiler warning */
1253 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1258 /* Load and store */
1259 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1260 int base
, int16_t offset
)
1262 const char *opn
= "flt_ldst";
1263 TCGv t0
= tcg_temp_new();
1265 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1266 /* Don't do NOP if destination is zero: we must perform the actual
1271 TCGv_i32 fp0
= tcg_temp_new_i32();
1273 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1274 tcg_gen_trunc_tl_i32(fp0
, t0
);
1275 gen_store_fpr32(fp0
, ft
);
1276 tcg_temp_free_i32(fp0
);
1282 TCGv_i32 fp0
= tcg_temp_new_i32();
1283 TCGv t1
= tcg_temp_new();
1285 gen_load_fpr32(fp0
, ft
);
1286 tcg_gen_extu_i32_tl(t1
, fp0
);
1287 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1289 tcg_temp_free_i32(fp0
);
1295 TCGv_i64 fp0
= tcg_temp_new_i64();
1297 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1298 gen_store_fpr64(ctx
, fp0
, ft
);
1299 tcg_temp_free_i64(fp0
);
1305 TCGv_i64 fp0
= tcg_temp_new_i64();
1307 gen_load_fpr64(ctx
, fp0
, ft
);
1308 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1309 tcg_temp_free_i64(fp0
);
1315 generate_exception(ctx
, EXCP_RI
);
1318 (void)opn
; /* avoid a compiler warning */
1319 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1324 static void gen_cop1_ldst(CPUState
*env
, DisasContext
*ctx
,
1325 uint32_t op
, int rt
, int rs
, int16_t imm
)
1327 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
1328 check_cp1_enabled(ctx
);
1329 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
1331 generate_exception_err(ctx
, EXCP_CpU
, 1);
1335 /* Arithmetic with immediate operand */
1336 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1337 int rt
, int rs
, int16_t imm
)
1339 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1340 const char *opn
= "imm arith";
1342 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1343 /* If no destination, treat it as a NOP.
1344 For addi, we must generate the overflow exception when needed. */
1351 TCGv t0
= tcg_temp_local_new();
1352 TCGv t1
= tcg_temp_new();
1353 TCGv t2
= tcg_temp_new();
1354 int l1
= gen_new_label();
1356 gen_load_gpr(t1
, rs
);
1357 tcg_gen_addi_tl(t0
, t1
, uimm
);
1358 tcg_gen_ext32s_tl(t0
, t0
);
1360 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1361 tcg_gen_xori_tl(t2
, t0
, uimm
);
1362 tcg_gen_and_tl(t1
, t1
, t2
);
1364 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1366 /* operands of same sign, result different sign */
1367 generate_exception(ctx
, EXCP_OVERFLOW
);
1369 tcg_gen_ext32s_tl(t0
, t0
);
1370 gen_store_gpr(t0
, rt
);
1377 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1378 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1380 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1384 #if defined(TARGET_MIPS64)
1387 TCGv t0
= tcg_temp_local_new();
1388 TCGv t1
= tcg_temp_new();
1389 TCGv t2
= tcg_temp_new();
1390 int l1
= gen_new_label();
1392 gen_load_gpr(t1
, rs
);
1393 tcg_gen_addi_tl(t0
, t1
, uimm
);
1395 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1396 tcg_gen_xori_tl(t2
, t0
, uimm
);
1397 tcg_gen_and_tl(t1
, t1
, t2
);
1399 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1401 /* operands of same sign, result different sign */
1402 generate_exception(ctx
, EXCP_OVERFLOW
);
1404 gen_store_gpr(t0
, rt
);
1411 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1413 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1419 (void)opn
; /* avoid a compiler warning */
1420 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1423 /* Logic with immediate operand */
1424 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1427 const char *opn
= "imm logic";
1430 /* If no destination, treat it as a NOP. */
1434 uimm
= (uint16_t)imm
;
1437 if (likely(rs
!= 0))
1438 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1440 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1445 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1447 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1451 if (likely(rs
!= 0))
1452 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1454 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1458 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1462 (void)opn
; /* avoid a compiler warning */
1463 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1466 /* Set on less than with immediate operand */
1467 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1469 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1470 const char *opn
= "imm arith";
1474 /* If no destination, treat it as a NOP. */
1478 t0
= tcg_temp_new();
1479 gen_load_gpr(t0
, rs
);
1482 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
1486 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
1490 (void)opn
; /* avoid a compiler warning */
1491 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1495 /* Shifts with immediate operand */
1496 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1497 int rt
, int rs
, int16_t imm
)
1499 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1500 const char *opn
= "imm shift";
1504 /* If no destination, treat it as a NOP. */
1509 t0
= tcg_temp_new();
1510 gen_load_gpr(t0
, rs
);
1513 tcg_gen_shli_tl(t0
, t0
, uimm
);
1514 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1518 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1523 tcg_gen_ext32u_tl(t0
, t0
);
1524 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1526 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1532 TCGv_i32 t1
= tcg_temp_new_i32();
1534 tcg_gen_trunc_tl_i32(t1
, t0
);
1535 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1536 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1537 tcg_temp_free_i32(t1
);
1539 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1543 #if defined(TARGET_MIPS64)
1545 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1549 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1553 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1558 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1560 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
1565 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1569 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1573 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1577 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1582 (void)opn
; /* avoid a compiler warning */
1583 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1588 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1589 int rd
, int rs
, int rt
)
1591 const char *opn
= "arith";
1593 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1594 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1595 /* If no destination, treat it as a NOP.
1596 For add & sub, we must generate the overflow exception when needed. */
1604 TCGv t0
= tcg_temp_local_new();
1605 TCGv t1
= tcg_temp_new();
1606 TCGv t2
= tcg_temp_new();
1607 int l1
= gen_new_label();
1609 gen_load_gpr(t1
, rs
);
1610 gen_load_gpr(t2
, rt
);
1611 tcg_gen_add_tl(t0
, t1
, t2
);
1612 tcg_gen_ext32s_tl(t0
, t0
);
1613 tcg_gen_xor_tl(t1
, t1
, t2
);
1614 tcg_gen_xor_tl(t2
, t0
, t2
);
1615 tcg_gen_andc_tl(t1
, t2
, t1
);
1617 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1619 /* operands of same sign, result different sign */
1620 generate_exception(ctx
, EXCP_OVERFLOW
);
1622 gen_store_gpr(t0
, rd
);
1628 if (rs
!= 0 && rt
!= 0) {
1629 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1630 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1631 } else if (rs
== 0 && rt
!= 0) {
1632 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1633 } else if (rs
!= 0 && rt
== 0) {
1634 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1636 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1642 TCGv t0
= tcg_temp_local_new();
1643 TCGv t1
= tcg_temp_new();
1644 TCGv t2
= tcg_temp_new();
1645 int l1
= gen_new_label();
1647 gen_load_gpr(t1
, rs
);
1648 gen_load_gpr(t2
, rt
);
1649 tcg_gen_sub_tl(t0
, t1
, t2
);
1650 tcg_gen_ext32s_tl(t0
, t0
);
1651 tcg_gen_xor_tl(t2
, t1
, t2
);
1652 tcg_gen_xor_tl(t1
, t0
, t1
);
1653 tcg_gen_and_tl(t1
, t1
, t2
);
1655 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1657 /* operands of different sign, first operand and result different sign */
1658 generate_exception(ctx
, EXCP_OVERFLOW
);
1660 gen_store_gpr(t0
, rd
);
1666 if (rs
!= 0 && rt
!= 0) {
1667 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1668 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1669 } else if (rs
== 0 && rt
!= 0) {
1670 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1671 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1672 } else if (rs
!= 0 && rt
== 0) {
1673 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1675 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1679 #if defined(TARGET_MIPS64)
1682 TCGv t0
= tcg_temp_local_new();
1683 TCGv t1
= tcg_temp_new();
1684 TCGv t2
= tcg_temp_new();
1685 int l1
= gen_new_label();
1687 gen_load_gpr(t1
, rs
);
1688 gen_load_gpr(t2
, rt
);
1689 tcg_gen_add_tl(t0
, t1
, t2
);
1690 tcg_gen_xor_tl(t1
, t1
, t2
);
1691 tcg_gen_xor_tl(t2
, t0
, t2
);
1692 tcg_gen_andc_tl(t1
, t2
, t1
);
1694 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1696 /* operands of same sign, result different sign */
1697 generate_exception(ctx
, EXCP_OVERFLOW
);
1699 gen_store_gpr(t0
, rd
);
1705 if (rs
!= 0 && rt
!= 0) {
1706 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1707 } else if (rs
== 0 && rt
!= 0) {
1708 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1709 } else if (rs
!= 0 && rt
== 0) {
1710 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1712 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1718 TCGv t0
= tcg_temp_local_new();
1719 TCGv t1
= tcg_temp_new();
1720 TCGv t2
= tcg_temp_new();
1721 int l1
= gen_new_label();
1723 gen_load_gpr(t1
, rs
);
1724 gen_load_gpr(t2
, rt
);
1725 tcg_gen_sub_tl(t0
, t1
, t2
);
1726 tcg_gen_xor_tl(t2
, t1
, t2
);
1727 tcg_gen_xor_tl(t1
, t0
, t1
);
1728 tcg_gen_and_tl(t1
, t1
, t2
);
1730 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1732 /* operands of different sign, first operand and result different sign */
1733 generate_exception(ctx
, EXCP_OVERFLOW
);
1735 gen_store_gpr(t0
, rd
);
1741 if (rs
!= 0 && rt
!= 0) {
1742 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1743 } else if (rs
== 0 && rt
!= 0) {
1744 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1745 } else if (rs
!= 0 && rt
== 0) {
1746 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1748 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1754 if (likely(rs
!= 0 && rt
!= 0)) {
1755 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1756 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1758 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1763 (void)opn
; /* avoid a compiler warning */
1764 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1767 /* Conditional move */
1768 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1770 const char *opn
= "cond move";
1774 /* If no destination, treat it as a NOP.
1775 For add & sub, we must generate the overflow exception when needed. */
1780 l1
= gen_new_label();
1783 if (likely(rt
!= 0))
1784 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1790 if (likely(rt
!= 0))
1791 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1796 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1798 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1801 (void)opn
; /* avoid a compiler warning */
1802 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1806 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1808 const char *opn
= "logic";
1811 /* If no destination, treat it as a NOP. */
1818 if (likely(rs
!= 0 && rt
!= 0)) {
1819 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1821 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1826 if (rs
!= 0 && rt
!= 0) {
1827 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1828 } else if (rs
== 0 && rt
!= 0) {
1829 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1830 } else if (rs
!= 0 && rt
== 0) {
1831 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1833 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1838 if (likely(rs
!= 0 && rt
!= 0)) {
1839 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1840 } else if (rs
== 0 && rt
!= 0) {
1841 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1842 } else if (rs
!= 0 && rt
== 0) {
1843 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1845 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1850 if (likely(rs
!= 0 && rt
!= 0)) {
1851 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1852 } else if (rs
== 0 && rt
!= 0) {
1853 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1854 } else if (rs
!= 0 && rt
== 0) {
1855 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1857 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1862 (void)opn
; /* avoid a compiler warning */
1863 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1866 /* Set on lower than */
1867 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1869 const char *opn
= "slt";
1873 /* If no destination, treat it as a NOP. */
1878 t0
= tcg_temp_new();
1879 t1
= tcg_temp_new();
1880 gen_load_gpr(t0
, rs
);
1881 gen_load_gpr(t1
, rt
);
1884 tcg_gen_setcond_tl(TCG_COND_LT
, cpu_gpr
[rd
], t0
, t1
);
1888 tcg_gen_setcond_tl(TCG_COND_LTU
, cpu_gpr
[rd
], t0
, t1
);
1892 (void)opn
; /* avoid a compiler warning */
1893 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1899 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1900 int rd
, int rs
, int rt
)
1902 const char *opn
= "shifts";
1906 /* If no destination, treat it as a NOP.
1907 For add & sub, we must generate the overflow exception when needed. */
1912 t0
= tcg_temp_new();
1913 t1
= tcg_temp_new();
1914 gen_load_gpr(t0
, rs
);
1915 gen_load_gpr(t1
, rt
);
1918 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1919 tcg_gen_shl_tl(t0
, t1
, t0
);
1920 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1924 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1925 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1929 tcg_gen_ext32u_tl(t1
, t1
);
1930 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1931 tcg_gen_shr_tl(t0
, t1
, t0
);
1932 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1937 TCGv_i32 t2
= tcg_temp_new_i32();
1938 TCGv_i32 t3
= tcg_temp_new_i32();
1940 tcg_gen_trunc_tl_i32(t2
, t0
);
1941 tcg_gen_trunc_tl_i32(t3
, t1
);
1942 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1943 tcg_gen_rotr_i32(t2
, t3
, t2
);
1944 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1945 tcg_temp_free_i32(t2
);
1946 tcg_temp_free_i32(t3
);
1950 #if defined(TARGET_MIPS64)
1952 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1953 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1957 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1958 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1962 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1963 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1967 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1968 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1973 (void)opn
; /* avoid a compiler warning */
1974 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1979 /* Arithmetic on HI/LO registers */
1980 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1982 const char *opn
= "hilo";
1984 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1991 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1995 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
2000 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
2002 tcg_gen_movi_tl(cpu_HI
[0], 0);
2007 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
2009 tcg_gen_movi_tl(cpu_LO
[0], 0);
2013 (void)opn
; /* avoid a compiler warning */
2014 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
2017 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
2020 const char *opn
= "mul/div";
2026 #if defined(TARGET_MIPS64)
2030 t0
= tcg_temp_local_new();
2031 t1
= tcg_temp_local_new();
2034 t0
= tcg_temp_new();
2035 t1
= tcg_temp_new();
2039 gen_load_gpr(t0
, rs
);
2040 gen_load_gpr(t1
, rt
);
2044 int l1
= gen_new_label();
2045 int l2
= gen_new_label();
2047 tcg_gen_ext32s_tl(t0
, t0
);
2048 tcg_gen_ext32s_tl(t1
, t1
);
2049 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2050 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2051 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2053 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2054 tcg_gen_movi_tl(cpu_HI
[0], 0);
2057 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
2058 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
2059 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2060 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2067 int l1
= gen_new_label();
2069 tcg_gen_ext32u_tl(t0
, t0
);
2070 tcg_gen_ext32u_tl(t1
, t1
);
2071 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2072 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2073 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2074 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2075 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2082 TCGv_i64 t2
= tcg_temp_new_i64();
2083 TCGv_i64 t3
= tcg_temp_new_i64();
2085 tcg_gen_ext_tl_i64(t2
, t0
);
2086 tcg_gen_ext_tl_i64(t3
, t1
);
2087 tcg_gen_mul_i64(t2
, t2
, t3
);
2088 tcg_temp_free_i64(t3
);
2089 tcg_gen_trunc_i64_tl(t0
, t2
);
2090 tcg_gen_shri_i64(t2
, t2
, 32);
2091 tcg_gen_trunc_i64_tl(t1
, t2
);
2092 tcg_temp_free_i64(t2
);
2093 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2094 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2100 TCGv_i64 t2
= tcg_temp_new_i64();
2101 TCGv_i64 t3
= tcg_temp_new_i64();
2103 tcg_gen_ext32u_tl(t0
, t0
);
2104 tcg_gen_ext32u_tl(t1
, t1
);
2105 tcg_gen_extu_tl_i64(t2
, t0
);
2106 tcg_gen_extu_tl_i64(t3
, t1
);
2107 tcg_gen_mul_i64(t2
, t2
, t3
);
2108 tcg_temp_free_i64(t3
);
2109 tcg_gen_trunc_i64_tl(t0
, t2
);
2110 tcg_gen_shri_i64(t2
, t2
, 32);
2111 tcg_gen_trunc_i64_tl(t1
, t2
);
2112 tcg_temp_free_i64(t2
);
2113 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2114 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2118 #if defined(TARGET_MIPS64)
2121 int l1
= gen_new_label();
2122 int l2
= gen_new_label();
2124 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2125 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2126 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2127 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2128 tcg_gen_movi_tl(cpu_HI
[0], 0);
2131 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2132 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2139 int l1
= gen_new_label();
2141 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2142 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2143 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2149 gen_helper_dmult(t0
, t1
);
2153 gen_helper_dmultu(t0
, t1
);
2159 TCGv_i64 t2
= tcg_temp_new_i64();
2160 TCGv_i64 t3
= tcg_temp_new_i64();
2162 tcg_gen_ext_tl_i64(t2
, t0
);
2163 tcg_gen_ext_tl_i64(t3
, t1
);
2164 tcg_gen_mul_i64(t2
, t2
, t3
);
2165 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2166 tcg_gen_add_i64(t2
, t2
, t3
);
2167 tcg_temp_free_i64(t3
);
2168 tcg_gen_trunc_i64_tl(t0
, t2
);
2169 tcg_gen_shri_i64(t2
, t2
, 32);
2170 tcg_gen_trunc_i64_tl(t1
, t2
);
2171 tcg_temp_free_i64(t2
);
2172 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2173 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2179 TCGv_i64 t2
= tcg_temp_new_i64();
2180 TCGv_i64 t3
= tcg_temp_new_i64();
2182 tcg_gen_ext32u_tl(t0
, t0
);
2183 tcg_gen_ext32u_tl(t1
, t1
);
2184 tcg_gen_extu_tl_i64(t2
, t0
);
2185 tcg_gen_extu_tl_i64(t3
, t1
);
2186 tcg_gen_mul_i64(t2
, t2
, t3
);
2187 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2188 tcg_gen_add_i64(t2
, t2
, t3
);
2189 tcg_temp_free_i64(t3
);
2190 tcg_gen_trunc_i64_tl(t0
, t2
);
2191 tcg_gen_shri_i64(t2
, t2
, 32);
2192 tcg_gen_trunc_i64_tl(t1
, t2
);
2193 tcg_temp_free_i64(t2
);
2194 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2195 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2201 TCGv_i64 t2
= tcg_temp_new_i64();
2202 TCGv_i64 t3
= tcg_temp_new_i64();
2204 tcg_gen_ext_tl_i64(t2
, t0
);
2205 tcg_gen_ext_tl_i64(t3
, t1
);
2206 tcg_gen_mul_i64(t2
, t2
, t3
);
2207 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2208 tcg_gen_sub_i64(t2
, t3
, t2
);
2209 tcg_temp_free_i64(t3
);
2210 tcg_gen_trunc_i64_tl(t0
, t2
);
2211 tcg_gen_shri_i64(t2
, t2
, 32);
2212 tcg_gen_trunc_i64_tl(t1
, t2
);
2213 tcg_temp_free_i64(t2
);
2214 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2215 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2221 TCGv_i64 t2
= tcg_temp_new_i64();
2222 TCGv_i64 t3
= tcg_temp_new_i64();
2224 tcg_gen_ext32u_tl(t0
, t0
);
2225 tcg_gen_ext32u_tl(t1
, t1
);
2226 tcg_gen_extu_tl_i64(t2
, t0
);
2227 tcg_gen_extu_tl_i64(t3
, t1
);
2228 tcg_gen_mul_i64(t2
, t2
, t3
);
2229 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2230 tcg_gen_sub_i64(t2
, t3
, t2
);
2231 tcg_temp_free_i64(t3
);
2232 tcg_gen_trunc_i64_tl(t0
, t2
);
2233 tcg_gen_shri_i64(t2
, t2
, 32);
2234 tcg_gen_trunc_i64_tl(t1
, t2
);
2235 tcg_temp_free_i64(t2
);
2236 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2237 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2243 generate_exception(ctx
, EXCP_RI
);
2246 (void)opn
; /* avoid a compiler warning */
2247 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2253 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2254 int rd
, int rs
, int rt
)
2256 const char *opn
= "mul vr54xx";
2257 TCGv t0
= tcg_temp_new();
2258 TCGv t1
= tcg_temp_new();
2260 gen_load_gpr(t0
, rs
);
2261 gen_load_gpr(t1
, rt
);
2264 case OPC_VR54XX_MULS
:
2265 gen_helper_muls(t0
, t0
, t1
);
2268 case OPC_VR54XX_MULSU
:
2269 gen_helper_mulsu(t0
, t0
, t1
);
2272 case OPC_VR54XX_MACC
:
2273 gen_helper_macc(t0
, t0
, t1
);
2276 case OPC_VR54XX_MACCU
:
2277 gen_helper_maccu(t0
, t0
, t1
);
2280 case OPC_VR54XX_MSAC
:
2281 gen_helper_msac(t0
, t0
, t1
);
2284 case OPC_VR54XX_MSACU
:
2285 gen_helper_msacu(t0
, t0
, t1
);
2288 case OPC_VR54XX_MULHI
:
2289 gen_helper_mulhi(t0
, t0
, t1
);
2292 case OPC_VR54XX_MULHIU
:
2293 gen_helper_mulhiu(t0
, t0
, t1
);
2296 case OPC_VR54XX_MULSHI
:
2297 gen_helper_mulshi(t0
, t0
, t1
);
2300 case OPC_VR54XX_MULSHIU
:
2301 gen_helper_mulshiu(t0
, t0
, t1
);
2304 case OPC_VR54XX_MACCHI
:
2305 gen_helper_macchi(t0
, t0
, t1
);
2308 case OPC_VR54XX_MACCHIU
:
2309 gen_helper_macchiu(t0
, t0
, t1
);
2312 case OPC_VR54XX_MSACHI
:
2313 gen_helper_msachi(t0
, t0
, t1
);
2316 case OPC_VR54XX_MSACHIU
:
2317 gen_helper_msachiu(t0
, t0
, t1
);
2321 MIPS_INVAL("mul vr54xx");
2322 generate_exception(ctx
, EXCP_RI
);
2325 gen_store_gpr(t0
, rd
);
2326 (void)opn
; /* avoid a compiler warning */
2327 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2334 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2337 const char *opn
= "CLx";
2345 t0
= tcg_temp_new();
2346 gen_load_gpr(t0
, rs
);
2349 gen_helper_clo(cpu_gpr
[rd
], t0
);
2353 gen_helper_clz(cpu_gpr
[rd
], t0
);
2356 #if defined(TARGET_MIPS64)
2358 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2362 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2367 (void)opn
; /* avoid a compiler warning */
2368 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2372 /* Godson integer instructions */
2373 static void gen_loongson_integer (DisasContext
*ctx
, uint32_t opc
,
2374 int rd
, int rs
, int rt
)
2376 const char *opn
= "loongson";
2388 case OPC_MULTU_G_2E
:
2389 case OPC_MULTU_G_2F
:
2390 #if defined(TARGET_MIPS64)
2391 case OPC_DMULT_G_2E
:
2392 case OPC_DMULT_G_2F
:
2393 case OPC_DMULTU_G_2E
:
2394 case OPC_DMULTU_G_2F
:
2396 t0
= tcg_temp_new();
2397 t1
= tcg_temp_new();
2400 t0
= tcg_temp_local_new();
2401 t1
= tcg_temp_local_new();
2405 gen_load_gpr(t0
, rs
);
2406 gen_load_gpr(t1
, rt
);
2411 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2412 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2415 case OPC_MULTU_G_2E
:
2416 case OPC_MULTU_G_2F
:
2417 tcg_gen_ext32u_tl(t0
, t0
);
2418 tcg_gen_ext32u_tl(t1
, t1
);
2419 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2420 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2426 int l1
= gen_new_label();
2427 int l2
= gen_new_label();
2428 int l3
= gen_new_label();
2429 tcg_gen_ext32s_tl(t0
, t0
);
2430 tcg_gen_ext32s_tl(t1
, t1
);
2431 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2432 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2435 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2436 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2437 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
2440 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
2441 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2449 int l1
= gen_new_label();
2450 int l2
= gen_new_label();
2451 tcg_gen_ext32u_tl(t0
, t0
);
2452 tcg_gen_ext32u_tl(t1
, t1
);
2453 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2454 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2457 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
2458 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2466 int l1
= gen_new_label();
2467 int l2
= gen_new_label();
2468 int l3
= gen_new_label();
2469 tcg_gen_ext32u_tl(t0
, t0
);
2470 tcg_gen_ext32u_tl(t1
, t1
);
2471 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2472 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2473 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2475 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2478 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
2479 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2487 int l1
= gen_new_label();
2488 int l2
= gen_new_label();
2489 tcg_gen_ext32u_tl(t0
, t0
);
2490 tcg_gen_ext32u_tl(t1
, t1
);
2491 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2492 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2495 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
2496 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2501 #if defined(TARGET_MIPS64)
2502 case OPC_DMULT_G_2E
:
2503 case OPC_DMULT_G_2F
:
2504 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2507 case OPC_DMULTU_G_2E
:
2508 case OPC_DMULTU_G_2F
:
2509 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2515 int l1
= gen_new_label();
2516 int l2
= gen_new_label();
2517 int l3
= gen_new_label();
2518 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2519 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2522 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2523 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2524 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
2527 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
2532 case OPC_DDIVU_G_2E
:
2533 case OPC_DDIVU_G_2F
:
2535 int l1
= gen_new_label();
2536 int l2
= gen_new_label();
2537 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2538 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2541 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
2549 int l1
= gen_new_label();
2550 int l2
= gen_new_label();
2551 int l3
= gen_new_label();
2552 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2553 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2554 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2556 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2559 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
2564 case OPC_DMODU_G_2E
:
2565 case OPC_DMODU_G_2F
:
2567 int l1
= gen_new_label();
2568 int l2
= gen_new_label();
2569 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2570 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2573 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
2581 (void)opn
; /* avoid a compiler warning */
2582 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2588 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2589 int rs
, int rt
, int16_t imm
)
2592 TCGv t0
= tcg_temp_new();
2593 TCGv t1
= tcg_temp_new();
2596 /* Load needed operands */
2604 /* Compare two registers */
2606 gen_load_gpr(t0
, rs
);
2607 gen_load_gpr(t1
, rt
);
2617 /* Compare register to immediate */
2618 if (rs
!= 0 || imm
!= 0) {
2619 gen_load_gpr(t0
, rs
);
2620 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2627 case OPC_TEQ
: /* rs == rs */
2628 case OPC_TEQI
: /* r0 == 0 */
2629 case OPC_TGE
: /* rs >= rs */
2630 case OPC_TGEI
: /* r0 >= 0 */
2631 case OPC_TGEU
: /* rs >= rs unsigned */
2632 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2634 generate_exception(ctx
, EXCP_TRAP
);
2636 case OPC_TLT
: /* rs < rs */
2637 case OPC_TLTI
: /* r0 < 0 */
2638 case OPC_TLTU
: /* rs < rs unsigned */
2639 case OPC_TLTIU
: /* r0 < 0 unsigned */
2640 case OPC_TNE
: /* rs != rs */
2641 case OPC_TNEI
: /* r0 != 0 */
2642 /* Never trap: treat as NOP. */
2646 int l1
= gen_new_label();
2651 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2655 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2659 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2663 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2667 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2671 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2674 generate_exception(ctx
, EXCP_TRAP
);
2681 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2683 TranslationBlock
*tb
;
2685 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2686 likely(!ctx
->singlestep_enabled
)) {
2689 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
2692 if (ctx
->singlestep_enabled
) {
2693 save_cpu_state(ctx
, 0);
2694 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
2700 /* Branches (before delay slot) */
2701 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2703 int rs
, int rt
, int32_t offset
)
2705 target_ulong btgt
= -1;
2707 int bcond_compute
= 0;
2708 TCGv t0
= tcg_temp_new();
2709 TCGv t1
= tcg_temp_new();
2711 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2712 #ifdef MIPS_DEBUG_DISAS
2713 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2715 generate_exception(ctx
, EXCP_RI
);
2719 /* Load needed operands */
2725 /* Compare two registers */
2727 gen_load_gpr(t0
, rs
);
2728 gen_load_gpr(t1
, rt
);
2731 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2747 /* Compare to zero */
2749 gen_load_gpr(t0
, rs
);
2752 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2759 /* Jump to immediate */
2760 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
2766 /* Jump to register */
2767 if (offset
!= 0 && offset
!= 16) {
2768 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2769 others are reserved. */
2770 MIPS_INVAL("jump hint");
2771 generate_exception(ctx
, EXCP_RI
);
2774 gen_load_gpr(btarget
, rs
);
2777 MIPS_INVAL("branch/jump");
2778 generate_exception(ctx
, EXCP_RI
);
2781 if (bcond_compute
== 0) {
2782 /* No condition to be computed */
2784 case OPC_BEQ
: /* rx == rx */
2785 case OPC_BEQL
: /* rx == rx likely */
2786 case OPC_BGEZ
: /* 0 >= 0 */
2787 case OPC_BGEZL
: /* 0 >= 0 likely */
2788 case OPC_BLEZ
: /* 0 <= 0 */
2789 case OPC_BLEZL
: /* 0 <= 0 likely */
2791 ctx
->hflags
|= MIPS_HFLAG_B
;
2792 MIPS_DEBUG("balways");
2795 case OPC_BGEZAL
: /* 0 >= 0 */
2796 case OPC_BGEZALL
: /* 0 >= 0 likely */
2797 ctx
->hflags
|= (opc
== OPC_BGEZALS
2799 : MIPS_HFLAG_BDS32
);
2800 /* Always take and link */
2802 ctx
->hflags
|= MIPS_HFLAG_B
;
2803 MIPS_DEBUG("balways and link");
2805 case OPC_BNE
: /* rx != rx */
2806 case OPC_BGTZ
: /* 0 > 0 */
2807 case OPC_BLTZ
: /* 0 < 0 */
2809 MIPS_DEBUG("bnever (NOP)");
2812 case OPC_BLTZAL
: /* 0 < 0 */
2813 ctx
->hflags
|= (opc
== OPC_BLTZALS
2815 : MIPS_HFLAG_BDS32
);
2816 /* Handle as an unconditional branch to get correct delay
2819 btgt
= ctx
->pc
+ (opc
== OPC_BLTZALS
? 6 : 8);
2820 ctx
->hflags
|= MIPS_HFLAG_B
;
2821 MIPS_DEBUG("bnever and link");
2823 case OPC_BLTZALL
: /* 0 < 0 likely */
2824 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2825 /* Skip the instruction in the delay slot */
2826 MIPS_DEBUG("bnever, link and skip");
2829 case OPC_BNEL
: /* rx != rx likely */
2830 case OPC_BGTZL
: /* 0 > 0 likely */
2831 case OPC_BLTZL
: /* 0 < 0 likely */
2832 /* Skip the instruction in the delay slot */
2833 MIPS_DEBUG("bnever and skip");
2837 ctx
->hflags
|= MIPS_HFLAG_B
;
2838 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2842 ctx
->hflags
|= MIPS_HFLAG_BX
;
2847 ctx
->hflags
|= MIPS_HFLAG_B
;
2848 ctx
->hflags
|= ((opc
== OPC_JALS
|| opc
== OPC_JALXS
)
2850 : MIPS_HFLAG_BDS32
);
2851 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2854 ctx
->hflags
|= MIPS_HFLAG_BR
;
2855 if (insn_bytes
== 4)
2856 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
2857 MIPS_DEBUG("jr %s", regnames
[rs
]);
2863 ctx
->hflags
|= MIPS_HFLAG_BR
;
2864 ctx
->hflags
|= (opc
== OPC_JALRS
2866 : MIPS_HFLAG_BDS32
);
2867 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2870 MIPS_INVAL("branch/jump");
2871 generate_exception(ctx
, EXCP_RI
);
2877 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2878 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2879 regnames
[rs
], regnames
[rt
], btgt
);
2882 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2883 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2884 regnames
[rs
], regnames
[rt
], btgt
);
2887 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2888 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2889 regnames
[rs
], regnames
[rt
], btgt
);
2892 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2893 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2894 regnames
[rs
], regnames
[rt
], btgt
);
2897 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2898 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2901 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2902 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2906 ctx
->hflags
|= (opc
== OPC_BGEZALS
2908 : MIPS_HFLAG_BDS32
);
2909 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2910 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2914 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2916 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2919 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2920 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2923 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2924 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2927 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2928 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2931 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2932 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2935 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2936 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2939 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2940 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2944 ctx
->hflags
|= (opc
== OPC_BLTZALS
2946 : MIPS_HFLAG_BDS32
);
2947 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2949 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2951 ctx
->hflags
|= MIPS_HFLAG_BC
;
2954 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2956 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2958 ctx
->hflags
|= MIPS_HFLAG_BL
;
2961 MIPS_INVAL("conditional branch/jump");
2962 generate_exception(ctx
, EXCP_RI
);
2966 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2967 blink
, ctx
->hflags
, btgt
);
2969 ctx
->btarget
= btgt
;
2971 int post_delay
= insn_bytes
;
2972 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
2974 if (opc
!= OPC_JALRC
)
2975 post_delay
+= ((ctx
->hflags
& MIPS_HFLAG_BDS16
) ? 2 : 4);
2977 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ post_delay
+ lowbit
);
2981 if (insn_bytes
== 2)
2982 ctx
->hflags
|= MIPS_HFLAG_B16
;
2987 /* special3 bitfield operations */
2988 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2989 int rs
, int lsb
, int msb
)
2991 TCGv t0
= tcg_temp_new();
2992 TCGv t1
= tcg_temp_new();
2995 gen_load_gpr(t1
, rs
);
3000 tcg_gen_shri_tl(t0
, t1
, lsb
);
3002 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
3004 tcg_gen_ext32s_tl(t0
, t0
);
3007 #if defined(TARGET_MIPS64)
3009 tcg_gen_shri_tl(t0
, t1
, lsb
);
3011 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
3015 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
3016 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
3019 tcg_gen_shri_tl(t0
, t1
, lsb
);
3020 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
3026 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
3027 gen_load_gpr(t0
, rt
);
3028 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3029 tcg_gen_shli_tl(t1
, t1
, lsb
);
3030 tcg_gen_andi_tl(t1
, t1
, mask
);
3031 tcg_gen_or_tl(t0
, t0
, t1
);
3032 tcg_gen_ext32s_tl(t0
, t0
);
3034 #if defined(TARGET_MIPS64)
3038 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
3039 gen_load_gpr(t0
, rt
);
3040 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3041 tcg_gen_shli_tl(t1
, t1
, lsb
);
3042 tcg_gen_andi_tl(t1
, t1
, mask
);
3043 tcg_gen_or_tl(t0
, t0
, t1
);
3048 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << (lsb
+ 32);
3049 gen_load_gpr(t0
, rt
);
3050 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3051 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
3052 tcg_gen_andi_tl(t1
, t1
, mask
);
3053 tcg_gen_or_tl(t0
, t0
, t1
);
3058 gen_load_gpr(t0
, rt
);
3059 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
3060 gen_load_gpr(t0
, rt
);
3061 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3062 tcg_gen_shli_tl(t1
, t1
, lsb
);
3063 tcg_gen_andi_tl(t1
, t1
, mask
);
3064 tcg_gen_or_tl(t0
, t0
, t1
);
3069 MIPS_INVAL("bitops");
3070 generate_exception(ctx
, EXCP_RI
);
3075 gen_store_gpr(t0
, rt
);
3080 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
3085 /* If no destination, treat it as a NOP. */
3090 t0
= tcg_temp_new();
3091 gen_load_gpr(t0
, rt
);
3095 TCGv t1
= tcg_temp_new();
3097 tcg_gen_shri_tl(t1
, t0
, 8);
3098 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
3099 tcg_gen_shli_tl(t0
, t0
, 8);
3100 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
3101 tcg_gen_or_tl(t0
, t0
, t1
);
3103 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
3107 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
3110 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
3112 #if defined(TARGET_MIPS64)
3115 TCGv t1
= tcg_temp_new();
3117 tcg_gen_shri_tl(t1
, t0
, 8);
3118 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
3119 tcg_gen_shli_tl(t0
, t0
, 8);
3120 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
3121 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
3127 TCGv t1
= tcg_temp_new();
3129 tcg_gen_shri_tl(t1
, t0
, 16);
3130 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
3131 tcg_gen_shli_tl(t0
, t0
, 16);
3132 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
3133 tcg_gen_or_tl(t0
, t0
, t1
);
3134 tcg_gen_shri_tl(t1
, t0
, 32);
3135 tcg_gen_shli_tl(t0
, t0
, 32);
3136 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
3142 MIPS_INVAL("bsfhl");
3143 generate_exception(ctx
, EXCP_RI
);
3150 #ifndef CONFIG_USER_ONLY
3151 /* CP0 (MMU and control) */
3152 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
3154 TCGv_i32 t0
= tcg_temp_new_i32();
3156 tcg_gen_ld_i32(t0
, cpu_env
, off
);
3157 tcg_gen_ext_i32_tl(arg
, t0
);
3158 tcg_temp_free_i32(t0
);
3161 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
3163 tcg_gen_ld_tl(arg
, cpu_env
, off
);
3164 tcg_gen_ext32s_tl(arg
, arg
);
3167 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
3169 TCGv_i32 t0
= tcg_temp_new_i32();
3171 tcg_gen_trunc_tl_i32(t0
, arg
);
3172 tcg_gen_st_i32(t0
, cpu_env
, off
);
3173 tcg_temp_free_i32(t0
);
3176 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
3178 tcg_gen_ext32s_tl(arg
, arg
);
3179 tcg_gen_st_tl(arg
, cpu_env
, off
);
3182 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3184 const char *rn
= "invalid";
3187 check_insn(env
, ctx
, ISA_MIPS32
);
3193 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
3197 check_insn(env
, ctx
, ASE_MT
);
3198 gen_helper_mfc0_mvpcontrol(arg
);
3202 check_insn(env
, ctx
, ASE_MT
);
3203 gen_helper_mfc0_mvpconf0(arg
);
3207 check_insn(env
, ctx
, ASE_MT
);
3208 gen_helper_mfc0_mvpconf1(arg
);
3218 gen_helper_mfc0_random(arg
);
3222 check_insn(env
, ctx
, ASE_MT
);
3223 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
3227 check_insn(env
, ctx
, ASE_MT
);
3228 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
3232 check_insn(env
, ctx
, ASE_MT
);
3233 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
3237 check_insn(env
, ctx
, ASE_MT
);
3238 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
3242 check_insn(env
, ctx
, ASE_MT
);
3243 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3247 check_insn(env
, ctx
, ASE_MT
);
3248 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3249 rn
= "VPEScheFBack";
3252 check_insn(env
, ctx
, ASE_MT
);
3253 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
3263 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
3264 tcg_gen_ext32s_tl(arg
, arg
);
3268 check_insn(env
, ctx
, ASE_MT
);
3269 gen_helper_mfc0_tcstatus(arg
);
3273 check_insn(env
, ctx
, ASE_MT
);
3274 gen_helper_mfc0_tcbind(arg
);
3278 check_insn(env
, ctx
, ASE_MT
);
3279 gen_helper_mfc0_tcrestart(arg
);
3283 check_insn(env
, ctx
, ASE_MT
);
3284 gen_helper_mfc0_tchalt(arg
);
3288 check_insn(env
, ctx
, ASE_MT
);
3289 gen_helper_mfc0_tccontext(arg
);
3293 check_insn(env
, ctx
, ASE_MT
);
3294 gen_helper_mfc0_tcschedule(arg
);
3298 check_insn(env
, ctx
, ASE_MT
);
3299 gen_helper_mfc0_tcschefback(arg
);
3309 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
3310 tcg_gen_ext32s_tl(arg
, arg
);
3320 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
3321 tcg_gen_ext32s_tl(arg
, arg
);
3325 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3326 rn
= "ContextConfig";
3335 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
3339 check_insn(env
, ctx
, ISA_MIPS32R2
);
3340 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
3350 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
3354 check_insn(env
, ctx
, ISA_MIPS32R2
);
3355 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3359 check_insn(env
, ctx
, ISA_MIPS32R2
);
3360 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3364 check_insn(env
, ctx
, ISA_MIPS32R2
);
3365 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3369 check_insn(env
, ctx
, ISA_MIPS32R2
);
3370 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3374 check_insn(env
, ctx
, ISA_MIPS32R2
);
3375 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3385 check_insn(env
, ctx
, ISA_MIPS32R2
);
3386 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3396 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3397 tcg_gen_ext32s_tl(arg
, arg
);
3407 /* Mark as an IO operation because we read the time. */
3410 gen_helper_mfc0_count(arg
);
3414 /* Break the TB to be able to take timer interrupts immediately
3415 after reading count. */
3416 ctx
->bstate
= BS_STOP
;
3419 /* 6,7 are implementation dependent */
3427 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3428 tcg_gen_ext32s_tl(arg
, arg
);
3438 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3441 /* 6,7 are implementation dependent */
3449 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3453 check_insn(env
, ctx
, ISA_MIPS32R2
);
3454 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3458 check_insn(env
, ctx
, ISA_MIPS32R2
);
3459 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3463 check_insn(env
, ctx
, ISA_MIPS32R2
);
3464 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3474 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3484 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3485 tcg_gen_ext32s_tl(arg
, arg
);
3495 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3499 check_insn(env
, ctx
, ISA_MIPS32R2
);
3500 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3510 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3514 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3518 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3522 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3525 /* 4,5 are reserved */
3526 /* 6,7 are implementation dependent */
3528 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3532 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3542 gen_helper_mfc0_lladdr(arg
);
3552 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3562 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3572 #if defined(TARGET_MIPS64)
3573 check_insn(env
, ctx
, ISA_MIPS3
);
3574 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3575 tcg_gen_ext32s_tl(arg
, arg
);
3584 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3587 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3595 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3596 rn
= "'Diagnostic"; /* implementation dependent */
3601 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3605 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3606 rn
= "TraceControl";
3609 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3610 rn
= "TraceControl2";
3613 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3614 rn
= "UserTraceData";
3617 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3628 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3629 tcg_gen_ext32s_tl(arg
, arg
);
3639 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3640 rn
= "Performance0";
3643 // gen_helper_mfc0_performance1(arg);
3644 rn
= "Performance1";
3647 // gen_helper_mfc0_performance2(arg);
3648 rn
= "Performance2";
3651 // gen_helper_mfc0_performance3(arg);
3652 rn
= "Performance3";
3655 // gen_helper_mfc0_performance4(arg);
3656 rn
= "Performance4";
3659 // gen_helper_mfc0_performance5(arg);
3660 rn
= "Performance5";
3663 // gen_helper_mfc0_performance6(arg);
3664 rn
= "Performance6";
3667 // gen_helper_mfc0_performance7(arg);
3668 rn
= "Performance7";
3675 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3681 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3694 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3701 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3714 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3721 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3731 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3732 tcg_gen_ext32s_tl(arg
, arg
);
3743 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3753 (void)rn
; /* avoid a compiler warning */
3754 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3758 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3759 generate_exception(ctx
, EXCP_RI
);
3762 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3764 const char *rn
= "invalid";
3767 check_insn(env
, ctx
, ISA_MIPS32
);
3776 gen_helper_mtc0_index(arg
);
3780 check_insn(env
, ctx
, ASE_MT
);
3781 gen_helper_mtc0_mvpcontrol(arg
);
3785 check_insn(env
, ctx
, ASE_MT
);
3790 check_insn(env
, ctx
, ASE_MT
);
3805 check_insn(env
, ctx
, ASE_MT
);
3806 gen_helper_mtc0_vpecontrol(arg
);
3810 check_insn(env
, ctx
, ASE_MT
);
3811 gen_helper_mtc0_vpeconf0(arg
);
3815 check_insn(env
, ctx
, ASE_MT
);
3816 gen_helper_mtc0_vpeconf1(arg
);
3820 check_insn(env
, ctx
, ASE_MT
);
3821 gen_helper_mtc0_yqmask(arg
);
3825 check_insn(env
, ctx
, ASE_MT
);
3826 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3830 check_insn(env
, ctx
, ASE_MT
);
3831 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3832 rn
= "VPEScheFBack";
3835 check_insn(env
, ctx
, ASE_MT
);
3836 gen_helper_mtc0_vpeopt(arg
);
3846 gen_helper_mtc0_entrylo0(arg
);
3850 check_insn(env
, ctx
, ASE_MT
);
3851 gen_helper_mtc0_tcstatus(arg
);
3855 check_insn(env
, ctx
, ASE_MT
);
3856 gen_helper_mtc0_tcbind(arg
);
3860 check_insn(env
, ctx
, ASE_MT
);
3861 gen_helper_mtc0_tcrestart(arg
);
3865 check_insn(env
, ctx
, ASE_MT
);
3866 gen_helper_mtc0_tchalt(arg
);
3870 check_insn(env
, ctx
, ASE_MT
);
3871 gen_helper_mtc0_tccontext(arg
);
3875 check_insn(env
, ctx
, ASE_MT
);
3876 gen_helper_mtc0_tcschedule(arg
);
3880 check_insn(env
, ctx
, ASE_MT
);
3881 gen_helper_mtc0_tcschefback(arg
);
3891 gen_helper_mtc0_entrylo1(arg
);
3901 gen_helper_mtc0_context(arg
);
3905 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3906 rn
= "ContextConfig";
3915 gen_helper_mtc0_pagemask(arg
);
3919 check_insn(env
, ctx
, ISA_MIPS32R2
);
3920 gen_helper_mtc0_pagegrain(arg
);
3930 gen_helper_mtc0_wired(arg
);
3934 check_insn(env
, ctx
, ISA_MIPS32R2
);
3935 gen_helper_mtc0_srsconf0(arg
);
3939 check_insn(env
, ctx
, ISA_MIPS32R2
);
3940 gen_helper_mtc0_srsconf1(arg
);
3944 check_insn(env
, ctx
, ISA_MIPS32R2
);
3945 gen_helper_mtc0_srsconf2(arg
);
3949 check_insn(env
, ctx
, ISA_MIPS32R2
);
3950 gen_helper_mtc0_srsconf3(arg
);
3954 check_insn(env
, ctx
, ISA_MIPS32R2
);
3955 gen_helper_mtc0_srsconf4(arg
);
3965 check_insn(env
, ctx
, ISA_MIPS32R2
);
3966 gen_helper_mtc0_hwrena(arg
);
3980 gen_helper_mtc0_count(arg
);
3983 /* 6,7 are implementation dependent */
3991 gen_helper_mtc0_entryhi(arg
);
4001 gen_helper_mtc0_compare(arg
);
4004 /* 6,7 are implementation dependent */
4012 save_cpu_state(ctx
, 1);
4013 gen_helper_mtc0_status(arg
);
4014 /* BS_STOP isn't good enough here, hflags may have changed. */
4015 gen_save_pc(ctx
->pc
+ 4);
4016 ctx
->bstate
= BS_EXCP
;
4020 check_insn(env
, ctx
, ISA_MIPS32R2
);
4021 gen_helper_mtc0_intctl(arg
);
4022 /* Stop translation as we may have switched the execution mode */
4023 ctx
->bstate
= BS_STOP
;
4027 check_insn(env
, ctx
, ISA_MIPS32R2
);
4028 gen_helper_mtc0_srsctl(arg
);
4029 /* Stop translation as we may have switched the execution mode */
4030 ctx
->bstate
= BS_STOP
;
4034 check_insn(env
, ctx
, ISA_MIPS32R2
);
4035 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4036 /* Stop translation as we may have switched the execution mode */
4037 ctx
->bstate
= BS_STOP
;
4047 save_cpu_state(ctx
, 1);
4048 gen_helper_mtc0_cause(arg
);
4058 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
4072 check_insn(env
, ctx
, ISA_MIPS32R2
);
4073 gen_helper_mtc0_ebase(arg
);
4083 gen_helper_mtc0_config0(arg
);
4085 /* Stop translation as we may have switched the execution mode */
4086 ctx
->bstate
= BS_STOP
;
4089 /* ignored, read only */
4093 gen_helper_mtc0_config2(arg
);
4095 /* Stop translation as we may have switched the execution mode */
4096 ctx
->bstate
= BS_STOP
;
4099 /* ignored, read only */
4102 /* 4,5 are reserved */
4103 /* 6,7 are implementation dependent */
4113 rn
= "Invalid config selector";
4120 gen_helper_mtc0_lladdr(arg
);
4130 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
4140 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
4150 #if defined(TARGET_MIPS64)
4151 check_insn(env
, ctx
, ISA_MIPS3
);
4152 gen_helper_mtc0_xcontext(arg
);
4161 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4164 gen_helper_mtc0_framemask(arg
);
4173 rn
= "Diagnostic"; /* implementation dependent */
4178 gen_helper_mtc0_debug(arg
); /* EJTAG support */
4179 /* BS_STOP isn't good enough here, hflags may have changed. */
4180 gen_save_pc(ctx
->pc
+ 4);
4181 ctx
->bstate
= BS_EXCP
;
4185 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
4186 rn
= "TraceControl";
4187 /* Stop translation as we may have switched the execution mode */
4188 ctx
->bstate
= BS_STOP
;
4191 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
4192 rn
= "TraceControl2";
4193 /* Stop translation as we may have switched the execution mode */
4194 ctx
->bstate
= BS_STOP
;
4197 /* Stop translation as we may have switched the execution mode */
4198 ctx
->bstate
= BS_STOP
;
4199 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
4200 rn
= "UserTraceData";
4201 /* Stop translation as we may have switched the execution mode */
4202 ctx
->bstate
= BS_STOP
;
4205 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
4206 /* Stop translation as we may have switched the execution mode */
4207 ctx
->bstate
= BS_STOP
;
4218 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
4228 gen_helper_mtc0_performance0(arg
);
4229 rn
= "Performance0";
4232 // gen_helper_mtc0_performance1(arg);
4233 rn
= "Performance1";
4236 // gen_helper_mtc0_performance2(arg);
4237 rn
= "Performance2";
4240 // gen_helper_mtc0_performance3(arg);
4241 rn
= "Performance3";
4244 // gen_helper_mtc0_performance4(arg);
4245 rn
= "Performance4";
4248 // gen_helper_mtc0_performance5(arg);
4249 rn
= "Performance5";
4252 // gen_helper_mtc0_performance6(arg);
4253 rn
= "Performance6";
4256 // gen_helper_mtc0_performance7(arg);
4257 rn
= "Performance7";
4283 gen_helper_mtc0_taglo(arg
);
4290 gen_helper_mtc0_datalo(arg
);
4303 gen_helper_mtc0_taghi(arg
);
4310 gen_helper_mtc0_datahi(arg
);
4321 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
4332 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4338 /* Stop translation as we may have switched the execution mode */
4339 ctx
->bstate
= BS_STOP
;
4344 (void)rn
; /* avoid a compiler warning */
4345 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4346 /* For simplicity assume that all writes can cause interrupts. */
4349 ctx
->bstate
= BS_STOP
;
4354 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4355 generate_exception(ctx
, EXCP_RI
);
4358 #if defined(TARGET_MIPS64)
4359 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4361 const char *rn
= "invalid";
4364 check_insn(env
, ctx
, ISA_MIPS64
);
4370 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4374 check_insn(env
, ctx
, ASE_MT
);
4375 gen_helper_mfc0_mvpcontrol(arg
);
4379 check_insn(env
, ctx
, ASE_MT
);
4380 gen_helper_mfc0_mvpconf0(arg
);
4384 check_insn(env
, ctx
, ASE_MT
);
4385 gen_helper_mfc0_mvpconf1(arg
);
4395 gen_helper_mfc0_random(arg
);
4399 check_insn(env
, ctx
, ASE_MT
);
4400 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4404 check_insn(env
, ctx
, ASE_MT
);
4405 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4409 check_insn(env
, ctx
, ASE_MT
);
4410 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4414 check_insn(env
, ctx
, ASE_MT
);
4415 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4419 check_insn(env
, ctx
, ASE_MT
);
4420 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4424 check_insn(env
, ctx
, ASE_MT
);
4425 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4426 rn
= "VPEScheFBack";
4429 check_insn(env
, ctx
, ASE_MT
);
4430 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4440 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4444 check_insn(env
, ctx
, ASE_MT
);
4445 gen_helper_mfc0_tcstatus(arg
);
4449 check_insn(env
, ctx
, ASE_MT
);
4450 gen_helper_mfc0_tcbind(arg
);
4454 check_insn(env
, ctx
, ASE_MT
);
4455 gen_helper_dmfc0_tcrestart(arg
);
4459 check_insn(env
, ctx
, ASE_MT
);
4460 gen_helper_dmfc0_tchalt(arg
);
4464 check_insn(env
, ctx
, ASE_MT
);
4465 gen_helper_dmfc0_tccontext(arg
);
4469 check_insn(env
, ctx
, ASE_MT
);
4470 gen_helper_dmfc0_tcschedule(arg
);
4474 check_insn(env
, ctx
, ASE_MT
);
4475 gen_helper_dmfc0_tcschefback(arg
);
4485 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4495 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4499 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4500 rn
= "ContextConfig";
4509 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4513 check_insn(env
, ctx
, ISA_MIPS32R2
);
4514 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4524 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4528 check_insn(env
, ctx
, ISA_MIPS32R2
);
4529 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4533 check_insn(env
, ctx
, ISA_MIPS32R2
);
4534 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4538 check_insn(env
, ctx
, ISA_MIPS32R2
);
4539 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4543 check_insn(env
, ctx
, ISA_MIPS32R2
);
4544 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4548 check_insn(env
, ctx
, ISA_MIPS32R2
);
4549 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4559 check_insn(env
, ctx
, ISA_MIPS32R2
);
4560 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4570 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4580 /* Mark as an IO operation because we read the time. */
4583 gen_helper_mfc0_count(arg
);
4587 /* Break the TB to be able to take timer interrupts immediately
4588 after reading count. */
4589 ctx
->bstate
= BS_STOP
;
4592 /* 6,7 are implementation dependent */
4600 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4610 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4613 /* 6,7 are implementation dependent */
4621 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4625 check_insn(env
, ctx
, ISA_MIPS32R2
);
4626 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4630 check_insn(env
, ctx
, ISA_MIPS32R2
);
4631 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4635 check_insn(env
, ctx
, ISA_MIPS32R2
);
4636 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4646 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4656 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4666 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4670 check_insn(env
, ctx
, ISA_MIPS32R2
);
4671 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4681 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4685 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4689 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4693 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4696 /* 6,7 are implementation dependent */
4698 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4702 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4712 gen_helper_dmfc0_lladdr(arg
);
4722 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4732 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4742 check_insn(env
, ctx
, ISA_MIPS3
);
4743 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4751 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4754 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4762 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4763 rn
= "'Diagnostic"; /* implementation dependent */
4768 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4772 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4773 rn
= "TraceControl";
4776 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4777 rn
= "TraceControl2";
4780 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4781 rn
= "UserTraceData";
4784 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4795 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4805 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4806 rn
= "Performance0";
4809 // gen_helper_dmfc0_performance1(arg);
4810 rn
= "Performance1";
4813 // gen_helper_dmfc0_performance2(arg);
4814 rn
= "Performance2";
4817 // gen_helper_dmfc0_performance3(arg);
4818 rn
= "Performance3";
4821 // gen_helper_dmfc0_performance4(arg);
4822 rn
= "Performance4";
4825 // gen_helper_dmfc0_performance5(arg);
4826 rn
= "Performance5";
4829 // gen_helper_dmfc0_performance6(arg);
4830 rn
= "Performance6";
4833 // gen_helper_dmfc0_performance7(arg);
4834 rn
= "Performance7";
4841 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4848 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4861 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4868 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4881 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4888 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4898 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4909 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4919 (void)rn
; /* avoid a compiler warning */
4920 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4924 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4925 generate_exception(ctx
, EXCP_RI
);
4928 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4930 const char *rn
= "invalid";
4933 check_insn(env
, ctx
, ISA_MIPS64
);
4942 gen_helper_mtc0_index(arg
);
4946 check_insn(env
, ctx
, ASE_MT
);
4947 gen_helper_mtc0_mvpcontrol(arg
);
4951 check_insn(env
, ctx
, ASE_MT
);
4956 check_insn(env
, ctx
, ASE_MT
);
4971 check_insn(env
, ctx
, ASE_MT
);
4972 gen_helper_mtc0_vpecontrol(arg
);
4976 check_insn(env
, ctx
, ASE_MT
);
4977 gen_helper_mtc0_vpeconf0(arg
);
4981 check_insn(env
, ctx
, ASE_MT
);
4982 gen_helper_mtc0_vpeconf1(arg
);
4986 check_insn(env
, ctx
, ASE_MT
);
4987 gen_helper_mtc0_yqmask(arg
);
4991 check_insn(env
, ctx
, ASE_MT
);
4992 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4996 check_insn(env
, ctx
, ASE_MT
);
4997 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4998 rn
= "VPEScheFBack";
5001 check_insn(env
, ctx
, ASE_MT
);
5002 gen_helper_mtc0_vpeopt(arg
);
5012 gen_helper_mtc0_entrylo0(arg
);
5016 check_insn(env
, ctx
, ASE_MT
);
5017 gen_helper_mtc0_tcstatus(arg
);
5021 check_insn(env
, ctx
, ASE_MT
);
5022 gen_helper_mtc0_tcbind(arg
);
5026 check_insn(env
, ctx
, ASE_MT
);
5027 gen_helper_mtc0_tcrestart(arg
);
5031 check_insn(env
, ctx
, ASE_MT
);
5032 gen_helper_mtc0_tchalt(arg
);
5036 check_insn(env
, ctx
, ASE_MT
);
5037 gen_helper_mtc0_tccontext(arg
);
5041 check_insn(env
, ctx
, ASE_MT
);
5042 gen_helper_mtc0_tcschedule(arg
);
5046 check_insn(env
, ctx
, ASE_MT
);
5047 gen_helper_mtc0_tcschefback(arg
);
5057 gen_helper_mtc0_entrylo1(arg
);
5067 gen_helper_mtc0_context(arg
);
5071 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
5072 rn
= "ContextConfig";
5081 gen_helper_mtc0_pagemask(arg
);
5085 check_insn(env
, ctx
, ISA_MIPS32R2
);
5086 gen_helper_mtc0_pagegrain(arg
);
5096 gen_helper_mtc0_wired(arg
);
5100 check_insn(env
, ctx
, ISA_MIPS32R2
);
5101 gen_helper_mtc0_srsconf0(arg
);
5105 check_insn(env
, ctx
, ISA_MIPS32R2
);
5106 gen_helper_mtc0_srsconf1(arg
);
5110 check_insn(env
, ctx
, ISA_MIPS32R2
);
5111 gen_helper_mtc0_srsconf2(arg
);
5115 check_insn(env
, ctx
, ISA_MIPS32R2
);
5116 gen_helper_mtc0_srsconf3(arg
);
5120 check_insn(env
, ctx
, ISA_MIPS32R2
);
5121 gen_helper_mtc0_srsconf4(arg
);
5131 check_insn(env
, ctx
, ISA_MIPS32R2
);
5132 gen_helper_mtc0_hwrena(arg
);
5146 gen_helper_mtc0_count(arg
);
5149 /* 6,7 are implementation dependent */
5153 /* Stop translation as we may have switched the execution mode */
5154 ctx
->bstate
= BS_STOP
;
5159 gen_helper_mtc0_entryhi(arg
);
5169 gen_helper_mtc0_compare(arg
);
5172 /* 6,7 are implementation dependent */
5176 /* Stop translation as we may have switched the execution mode */
5177 ctx
->bstate
= BS_STOP
;
5182 save_cpu_state(ctx
, 1);
5183 gen_helper_mtc0_status(arg
);
5184 /* BS_STOP isn't good enough here, hflags may have changed. */
5185 gen_save_pc(ctx
->pc
+ 4);
5186 ctx
->bstate
= BS_EXCP
;
5190 check_insn(env
, ctx
, ISA_MIPS32R2
);
5191 gen_helper_mtc0_intctl(arg
);
5192 /* Stop translation as we may have switched the execution mode */
5193 ctx
->bstate
= BS_STOP
;
5197 check_insn(env
, ctx
, ISA_MIPS32R2
);
5198 gen_helper_mtc0_srsctl(arg
);
5199 /* Stop translation as we may have switched the execution mode */
5200 ctx
->bstate
= BS_STOP
;
5204 check_insn(env
, ctx
, ISA_MIPS32R2
);
5205 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
5206 /* Stop translation as we may have switched the execution mode */
5207 ctx
->bstate
= BS_STOP
;
5217 save_cpu_state(ctx
, 1);
5218 /* Mark as an IO operation because we may trigger a software
5223 gen_helper_mtc0_cause(arg
);
5227 /* Stop translation as we may have triggered an intetrupt */
5228 ctx
->bstate
= BS_STOP
;
5238 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
5252 check_insn(env
, ctx
, ISA_MIPS32R2
);
5253 gen_helper_mtc0_ebase(arg
);
5263 gen_helper_mtc0_config0(arg
);
5265 /* Stop translation as we may have switched the execution mode */
5266 ctx
->bstate
= BS_STOP
;
5269 /* ignored, read only */
5273 gen_helper_mtc0_config2(arg
);
5275 /* Stop translation as we may have switched the execution mode */
5276 ctx
->bstate
= BS_STOP
;
5282 /* 6,7 are implementation dependent */
5284 rn
= "Invalid config selector";
5291 gen_helper_mtc0_lladdr(arg
);
5301 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
5311 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
5321 check_insn(env
, ctx
, ISA_MIPS3
);
5322 gen_helper_mtc0_xcontext(arg
);
5330 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5333 gen_helper_mtc0_framemask(arg
);
5342 rn
= "Diagnostic"; /* implementation dependent */
5347 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5348 /* BS_STOP isn't good enough here, hflags may have changed. */
5349 gen_save_pc(ctx
->pc
+ 4);
5350 ctx
->bstate
= BS_EXCP
;
5354 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5355 /* Stop translation as we may have switched the execution mode */
5356 ctx
->bstate
= BS_STOP
;
5357 rn
= "TraceControl";
5360 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5361 /* Stop translation as we may have switched the execution mode */
5362 ctx
->bstate
= BS_STOP
;
5363 rn
= "TraceControl2";
5366 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5367 /* Stop translation as we may have switched the execution mode */
5368 ctx
->bstate
= BS_STOP
;
5369 rn
= "UserTraceData";
5372 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5373 /* Stop translation as we may have switched the execution mode */
5374 ctx
->bstate
= BS_STOP
;
5385 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5395 gen_helper_mtc0_performance0(arg
);
5396 rn
= "Performance0";
5399 // gen_helper_mtc0_performance1(arg);
5400 rn
= "Performance1";
5403 // gen_helper_mtc0_performance2(arg);
5404 rn
= "Performance2";
5407 // gen_helper_mtc0_performance3(arg);
5408 rn
= "Performance3";
5411 // gen_helper_mtc0_performance4(arg);
5412 rn
= "Performance4";
5415 // gen_helper_mtc0_performance5(arg);
5416 rn
= "Performance5";
5419 // gen_helper_mtc0_performance6(arg);
5420 rn
= "Performance6";
5423 // gen_helper_mtc0_performance7(arg);
5424 rn
= "Performance7";
5450 gen_helper_mtc0_taglo(arg
);
5457 gen_helper_mtc0_datalo(arg
);
5470 gen_helper_mtc0_taghi(arg
);
5477 gen_helper_mtc0_datahi(arg
);
5488 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5499 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5505 /* Stop translation as we may have switched the execution mode */
5506 ctx
->bstate
= BS_STOP
;
5511 (void)rn
; /* avoid a compiler warning */
5512 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5513 /* For simplicity assume that all writes can cause interrupts. */
5516 ctx
->bstate
= BS_STOP
;
5521 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5522 generate_exception(ctx
, EXCP_RI
);
5524 #endif /* TARGET_MIPS64 */
5526 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5527 int u
, int sel
, int h
)
5529 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5530 TCGv t0
= tcg_temp_local_new();
5532 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5533 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5534 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5535 tcg_gen_movi_tl(t0
, -1);
5536 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5537 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5538 tcg_gen_movi_tl(t0
, -1);
5544 gen_helper_mftc0_tcstatus(t0
);
5547 gen_helper_mftc0_tcbind(t0
);
5550 gen_helper_mftc0_tcrestart(t0
);
5553 gen_helper_mftc0_tchalt(t0
);
5556 gen_helper_mftc0_tccontext(t0
);
5559 gen_helper_mftc0_tcschedule(t0
);
5562 gen_helper_mftc0_tcschefback(t0
);
5565 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5572 gen_helper_mftc0_entryhi(t0
);
5575 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5581 gen_helper_mftc0_status(t0
);
5584 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5590 gen_helper_mftc0_debug(t0
);
5593 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5598 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5600 } else switch (sel
) {
5601 /* GPR registers. */
5603 gen_helper_1i(mftgpr
, t0
, rt
);
5605 /* Auxiliary CPU registers */
5609 gen_helper_1i(mftlo
, t0
, 0);
5612 gen_helper_1i(mfthi
, t0
, 0);
5615 gen_helper_1i(mftacx
, t0
, 0);
5618 gen_helper_1i(mftlo
, t0
, 1);
5621 gen_helper_1i(mfthi
, t0
, 1);
5624 gen_helper_1i(mftacx
, t0
, 1);
5627 gen_helper_1i(mftlo
, t0
, 2);
5630 gen_helper_1i(mfthi
, t0
, 2);
5633 gen_helper_1i(mftacx
, t0
, 2);
5636 gen_helper_1i(mftlo
, t0
, 3);
5639 gen_helper_1i(mfthi
, t0
, 3);
5642 gen_helper_1i(mftacx
, t0
, 3);
5645 gen_helper_mftdsp(t0
);
5651 /* Floating point (COP1). */
5653 /* XXX: For now we support only a single FPU context. */
5655 TCGv_i32 fp0
= tcg_temp_new_i32();
5657 gen_load_fpr32(fp0
, rt
);
5658 tcg_gen_ext_i32_tl(t0
, fp0
);
5659 tcg_temp_free_i32(fp0
);
5661 TCGv_i32 fp0
= tcg_temp_new_i32();
5663 gen_load_fpr32h(fp0
, rt
);
5664 tcg_gen_ext_i32_tl(t0
, fp0
);
5665 tcg_temp_free_i32(fp0
);
5669 /* XXX: For now we support only a single FPU context. */
5670 gen_helper_1i(cfc1
, t0
, rt
);
5672 /* COP2: Not implemented. */
5679 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5680 gen_store_gpr(t0
, rd
);
5686 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5687 generate_exception(ctx
, EXCP_RI
);
5690 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5691 int u
, int sel
, int h
)
5693 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5694 TCGv t0
= tcg_temp_local_new();
5696 gen_load_gpr(t0
, rt
);
5697 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5698 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5699 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5701 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5702 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5709 gen_helper_mttc0_tcstatus(t0
);
5712 gen_helper_mttc0_tcbind(t0
);
5715 gen_helper_mttc0_tcrestart(t0
);
5718 gen_helper_mttc0_tchalt(t0
);
5721 gen_helper_mttc0_tccontext(t0
);
5724 gen_helper_mttc0_tcschedule(t0
);
5727 gen_helper_mttc0_tcschefback(t0
);
5730 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5737 gen_helper_mttc0_entryhi(t0
);
5740 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5746 gen_helper_mttc0_status(t0
);
5749 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5755 gen_helper_mttc0_debug(t0
);
5758 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5763 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5765 } else switch (sel
) {
5766 /* GPR registers. */
5768 gen_helper_1i(mttgpr
, t0
, rd
);
5770 /* Auxiliary CPU registers */
5774 gen_helper_1i(mttlo
, t0
, 0);
5777 gen_helper_1i(mtthi
, t0
, 0);
5780 gen_helper_1i(mttacx
, t0
, 0);
5783 gen_helper_1i(mttlo
, t0
, 1);
5786 gen_helper_1i(mtthi
, t0
, 1);
5789 gen_helper_1i(mttacx
, t0
, 1);
5792 gen_helper_1i(mttlo
, t0
, 2);
5795 gen_helper_1i(mtthi
, t0
, 2);
5798 gen_helper_1i(mttacx
, t0
, 2);
5801 gen_helper_1i(mttlo
, t0
, 3);
5804 gen_helper_1i(mtthi
, t0
, 3);
5807 gen_helper_1i(mttacx
, t0
, 3);
5810 gen_helper_mttdsp(t0
);
5816 /* Floating point (COP1). */
5818 /* XXX: For now we support only a single FPU context. */
5820 TCGv_i32 fp0
= tcg_temp_new_i32();
5822 tcg_gen_trunc_tl_i32(fp0
, t0
);
5823 gen_store_fpr32(fp0
, rd
);
5824 tcg_temp_free_i32(fp0
);
5826 TCGv_i32 fp0
= tcg_temp_new_i32();
5828 tcg_gen_trunc_tl_i32(fp0
, t0
);
5829 gen_store_fpr32h(fp0
, rd
);
5830 tcg_temp_free_i32(fp0
);
5834 /* XXX: For now we support only a single FPU context. */
5835 gen_helper_1i(ctc1
, t0
, rd
);
5837 /* COP2: Not implemented. */
5844 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5850 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5851 generate_exception(ctx
, EXCP_RI
);
5854 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5856 const char *opn
= "ldst";
5864 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5869 TCGv t0
= tcg_temp_new();
5871 gen_load_gpr(t0
, rt
);
5872 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5877 #if defined(TARGET_MIPS64)
5879 check_insn(env
, ctx
, ISA_MIPS3
);
5884 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5888 check_insn(env
, ctx
, ISA_MIPS3
);
5890 TCGv t0
= tcg_temp_new();
5892 gen_load_gpr(t0
, rt
);
5893 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5900 check_insn(env
, ctx
, ASE_MT
);
5905 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5906 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5910 check_insn(env
, ctx
, ASE_MT
);
5911 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5912 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5917 if (!env
->tlb
->helper_tlbwi
)
5923 if (!env
->tlb
->helper_tlbwr
)
5929 if (!env
->tlb
->helper_tlbp
)
5935 if (!env
->tlb
->helper_tlbr
)
5941 check_insn(env
, ctx
, ISA_MIPS2
);
5943 ctx
->bstate
= BS_EXCP
;
5947 check_insn(env
, ctx
, ISA_MIPS32
);
5948 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5950 generate_exception(ctx
, EXCP_RI
);
5953 ctx
->bstate
= BS_EXCP
;
5958 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5959 /* If we get an exception, we want to restart at next instruction */
5961 save_cpu_state(ctx
, 1);
5964 ctx
->bstate
= BS_EXCP
;
5969 generate_exception(ctx
, EXCP_RI
);
5972 (void)opn
; /* avoid a compiler warning */
5973 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5975 #endif /* !CONFIG_USER_ONLY */
5977 /* CP1 Branches (before delay slot) */
5978 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5979 int32_t cc
, int32_t offset
)
5981 target_ulong btarget
;
5982 const char *opn
= "cp1 cond branch";
5983 TCGv_i32 t0
= tcg_temp_new_i32();
5986 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5988 btarget
= ctx
->pc
+ 4 + offset
;
5992 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5993 tcg_gen_not_i32(t0
, t0
);
5994 tcg_gen_andi_i32(t0
, t0
, 1);
5995 tcg_gen_extu_i32_tl(bcond
, t0
);
5999 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6000 tcg_gen_not_i32(t0
, t0
);
6001 tcg_gen_andi_i32(t0
, t0
, 1);
6002 tcg_gen_extu_i32_tl(bcond
, t0
);
6006 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6007 tcg_gen_andi_i32(t0
, t0
, 1);
6008 tcg_gen_extu_i32_tl(bcond
, t0
);
6012 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6013 tcg_gen_andi_i32(t0
, t0
, 1);
6014 tcg_gen_extu_i32_tl(bcond
, t0
);
6017 ctx
->hflags
|= MIPS_HFLAG_BL
;
6021 TCGv_i32 t1
= tcg_temp_new_i32();
6022 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6023 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6024 tcg_gen_nor_i32(t0
, t0
, t1
);
6025 tcg_temp_free_i32(t1
);
6026 tcg_gen_andi_i32(t0
, t0
, 1);
6027 tcg_gen_extu_i32_tl(bcond
, t0
);
6033 TCGv_i32 t1
= tcg_temp_new_i32();
6034 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6035 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6036 tcg_gen_or_i32(t0
, t0
, t1
);
6037 tcg_temp_free_i32(t1
);
6038 tcg_gen_andi_i32(t0
, t0
, 1);
6039 tcg_gen_extu_i32_tl(bcond
, t0
);
6045 TCGv_i32 t1
= tcg_temp_new_i32();
6046 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6047 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6048 tcg_gen_or_i32(t0
, t0
, t1
);
6049 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
6050 tcg_gen_or_i32(t0
, t0
, t1
);
6051 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
6052 tcg_gen_nor_i32(t0
, t0
, t1
);
6053 tcg_temp_free_i32(t1
);
6054 tcg_gen_andi_i32(t0
, t0
, 1);
6055 tcg_gen_extu_i32_tl(bcond
, t0
);
6061 TCGv_i32 t1
= tcg_temp_new_i32();
6062 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6063 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6064 tcg_gen_or_i32(t0
, t0
, t1
);
6065 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
6066 tcg_gen_or_i32(t0
, t0
, t1
);
6067 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
6068 tcg_gen_or_i32(t0
, t0
, t1
);
6069 tcg_temp_free_i32(t1
);
6070 tcg_gen_andi_i32(t0
, t0
, 1);
6071 tcg_gen_extu_i32_tl(bcond
, t0
);
6075 ctx
->hflags
|= MIPS_HFLAG_BC
;
6079 generate_exception (ctx
, EXCP_RI
);
6082 (void)opn
; /* avoid a compiler warning */
6083 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
6084 ctx
->hflags
, btarget
);
6085 ctx
->btarget
= btarget
;
6088 tcg_temp_free_i32(t0
);
6091 /* Coprocessor 1 (FPU) */
6093 #define FOP(func, fmt) (((fmt) << 21) | (func))
6096 OPC_ADD_S
= FOP(0, FMT_S
),
6097 OPC_SUB_S
= FOP(1, FMT_S
),
6098 OPC_MUL_S
= FOP(2, FMT_S
),
6099 OPC_DIV_S
= FOP(3, FMT_S
),
6100 OPC_SQRT_S
= FOP(4, FMT_S
),
6101 OPC_ABS_S
= FOP(5, FMT_S
),
6102 OPC_MOV_S
= FOP(6, FMT_S
),
6103 OPC_NEG_S
= FOP(7, FMT_S
),
6104 OPC_ROUND_L_S
= FOP(8, FMT_S
),
6105 OPC_TRUNC_L_S
= FOP(9, FMT_S
),
6106 OPC_CEIL_L_S
= FOP(10, FMT_S
),
6107 OPC_FLOOR_L_S
= FOP(11, FMT_S
),
6108 OPC_ROUND_W_S
= FOP(12, FMT_S
),
6109 OPC_TRUNC_W_S
= FOP(13, FMT_S
),
6110 OPC_CEIL_W_S
= FOP(14, FMT_S
),
6111 OPC_FLOOR_W_S
= FOP(15, FMT_S
),
6112 OPC_MOVCF_S
= FOP(17, FMT_S
),
6113 OPC_MOVZ_S
= FOP(18, FMT_S
),
6114 OPC_MOVN_S
= FOP(19, FMT_S
),
6115 OPC_RECIP_S
= FOP(21, FMT_S
),
6116 OPC_RSQRT_S
= FOP(22, FMT_S
),
6117 OPC_RECIP2_S
= FOP(28, FMT_S
),
6118 OPC_RECIP1_S
= FOP(29, FMT_S
),
6119 OPC_RSQRT1_S
= FOP(30, FMT_S
),
6120 OPC_RSQRT2_S
= FOP(31, FMT_S
),
6121 OPC_CVT_D_S
= FOP(33, FMT_S
),
6122 OPC_CVT_W_S
= FOP(36, FMT_S
),
6123 OPC_CVT_L_S
= FOP(37, FMT_S
),
6124 OPC_CVT_PS_S
= FOP(38, FMT_S
),
6125 OPC_CMP_F_S
= FOP (48, FMT_S
),
6126 OPC_CMP_UN_S
= FOP (49, FMT_S
),
6127 OPC_CMP_EQ_S
= FOP (50, FMT_S
),
6128 OPC_CMP_UEQ_S
= FOP (51, FMT_S
),
6129 OPC_CMP_OLT_S
= FOP (52, FMT_S
),
6130 OPC_CMP_ULT_S
= FOP (53, FMT_S
),
6131 OPC_CMP_OLE_S
= FOP (54, FMT_S
),
6132 OPC_CMP_ULE_S
= FOP (55, FMT_S
),
6133 OPC_CMP_SF_S
= FOP (56, FMT_S
),
6134 OPC_CMP_NGLE_S
= FOP (57, FMT_S
),
6135 OPC_CMP_SEQ_S
= FOP (58, FMT_S
),
6136 OPC_CMP_NGL_S
= FOP (59, FMT_S
),
6137 OPC_CMP_LT_S
= FOP (60, FMT_S
),
6138 OPC_CMP_NGE_S
= FOP (61, FMT_S
),
6139 OPC_CMP_LE_S
= FOP (62, FMT_S
),
6140 OPC_CMP_NGT_S
= FOP (63, FMT_S
),
6142 OPC_ADD_D
= FOP(0, FMT_D
),
6143 OPC_SUB_D
= FOP(1, FMT_D
),
6144 OPC_MUL_D
= FOP(2, FMT_D
),
6145 OPC_DIV_D
= FOP(3, FMT_D
),
6146 OPC_SQRT_D
= FOP(4, FMT_D
),
6147 OPC_ABS_D
= FOP(5, FMT_D
),
6148 OPC_MOV_D
= FOP(6, FMT_D
),
6149 OPC_NEG_D
= FOP(7, FMT_D
),
6150 OPC_ROUND_L_D
= FOP(8, FMT_D
),
6151 OPC_TRUNC_L_D
= FOP(9, FMT_D
),
6152 OPC_CEIL_L_D
= FOP(10, FMT_D
),
6153 OPC_FLOOR_L_D
= FOP(11, FMT_D
),
6154 OPC_ROUND_W_D
= FOP(12, FMT_D
),
6155 OPC_TRUNC_W_D
= FOP(13, FMT_D
),
6156 OPC_CEIL_W_D
= FOP(14, FMT_D
),
6157 OPC_FLOOR_W_D
= FOP(15, FMT_D
),
6158 OPC_MOVCF_D
= FOP(17, FMT_D
),
6159 OPC_MOVZ_D
= FOP(18, FMT_D
),
6160 OPC_MOVN_D
= FOP(19, FMT_D
),
6161 OPC_RECIP_D
= FOP(21, FMT_D
),
6162 OPC_RSQRT_D
= FOP(22, FMT_D
),
6163 OPC_RECIP2_D
= FOP(28, FMT_D
),
6164 OPC_RECIP1_D
= FOP(29, FMT_D
),
6165 OPC_RSQRT1_D
= FOP(30, FMT_D
),
6166 OPC_RSQRT2_D
= FOP(31, FMT_D
),
6167 OPC_CVT_S_D
= FOP(32, FMT_D
),
6168 OPC_CVT_W_D
= FOP(36, FMT_D
),
6169 OPC_CVT_L_D
= FOP(37, FMT_D
),
6170 OPC_CMP_F_D
= FOP (48, FMT_D
),
6171 OPC_CMP_UN_D
= FOP (49, FMT_D
),
6172 OPC_CMP_EQ_D
= FOP (50, FMT_D
),
6173 OPC_CMP_UEQ_D
= FOP (51, FMT_D
),
6174 OPC_CMP_OLT_D
= FOP (52, FMT_D
),
6175 OPC_CMP_ULT_D
= FOP (53, FMT_D
),
6176 OPC_CMP_OLE_D
= FOP (54, FMT_D
),
6177 OPC_CMP_ULE_D
= FOP (55, FMT_D
),
6178 OPC_CMP_SF_D
= FOP (56, FMT_D
),
6179 OPC_CMP_NGLE_D
= FOP (57, FMT_D
),
6180 OPC_CMP_SEQ_D
= FOP (58, FMT_D
),
6181 OPC_CMP_NGL_D
= FOP (59, FMT_D
),
6182 OPC_CMP_LT_D
= FOP (60, FMT_D
),
6183 OPC_CMP_NGE_D
= FOP (61, FMT_D
),
6184 OPC_CMP_LE_D
= FOP (62, FMT_D
),
6185 OPC_CMP_NGT_D
= FOP (63, FMT_D
),
6187 OPC_CVT_S_W
= FOP(32, FMT_W
),
6188 OPC_CVT_D_W
= FOP(33, FMT_W
),
6189 OPC_CVT_S_L
= FOP(32, FMT_L
),
6190 OPC_CVT_D_L
= FOP(33, FMT_L
),
6191 OPC_CVT_PS_PW
= FOP(38, FMT_W
),
6193 OPC_ADD_PS
= FOP(0, FMT_PS
),
6194 OPC_SUB_PS
= FOP(1, FMT_PS
),
6195 OPC_MUL_PS
= FOP(2, FMT_PS
),
6196 OPC_DIV_PS
= FOP(3, FMT_PS
),
6197 OPC_ABS_PS
= FOP(5, FMT_PS
),
6198 OPC_MOV_PS
= FOP(6, FMT_PS
),
6199 OPC_NEG_PS
= FOP(7, FMT_PS
),
6200 OPC_MOVCF_PS
= FOP(17, FMT_PS
),
6201 OPC_MOVZ_PS
= FOP(18, FMT_PS
),
6202 OPC_MOVN_PS
= FOP(19, FMT_PS
),
6203 OPC_ADDR_PS
= FOP(24, FMT_PS
),
6204 OPC_MULR_PS
= FOP(26, FMT_PS
),
6205 OPC_RECIP2_PS
= FOP(28, FMT_PS
),
6206 OPC_RECIP1_PS
= FOP(29, FMT_PS
),
6207 OPC_RSQRT1_PS
= FOP(30, FMT_PS
),
6208 OPC_RSQRT2_PS
= FOP(31, FMT_PS
),
6210 OPC_CVT_S_PU
= FOP(32, FMT_PS
),
6211 OPC_CVT_PW_PS
= FOP(36, FMT_PS
),
6212 OPC_CVT_S_PL
= FOP(40, FMT_PS
),
6213 OPC_PLL_PS
= FOP(44, FMT_PS
),
6214 OPC_PLU_PS
= FOP(45, FMT_PS
),
6215 OPC_PUL_PS
= FOP(46, FMT_PS
),
6216 OPC_PUU_PS
= FOP(47, FMT_PS
),
6217 OPC_CMP_F_PS
= FOP (48, FMT_PS
),
6218 OPC_CMP_UN_PS
= FOP (49, FMT_PS
),
6219 OPC_CMP_EQ_PS
= FOP (50, FMT_PS
),
6220 OPC_CMP_UEQ_PS
= FOP (51, FMT_PS
),
6221 OPC_CMP_OLT_PS
= FOP (52, FMT_PS
),
6222 OPC_CMP_ULT_PS
= FOP (53, FMT_PS
),
6223 OPC_CMP_OLE_PS
= FOP (54, FMT_PS
),
6224 OPC_CMP_ULE_PS
= FOP (55, FMT_PS
),
6225 OPC_CMP_SF_PS
= FOP (56, FMT_PS
),
6226 OPC_CMP_NGLE_PS
= FOP (57, FMT_PS
),
6227 OPC_CMP_SEQ_PS
= FOP (58, FMT_PS
),
6228 OPC_CMP_NGL_PS
= FOP (59, FMT_PS
),
6229 OPC_CMP_LT_PS
= FOP (60, FMT_PS
),
6230 OPC_CMP_NGE_PS
= FOP (61, FMT_PS
),
6231 OPC_CMP_LE_PS
= FOP (62, FMT_PS
),
6232 OPC_CMP_NGT_PS
= FOP (63, FMT_PS
),
6235 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
6237 const char *opn
= "cp1 move";
6238 TCGv t0
= tcg_temp_new();
6243 TCGv_i32 fp0
= tcg_temp_new_i32();
6245 gen_load_fpr32(fp0
, fs
);
6246 tcg_gen_ext_i32_tl(t0
, fp0
);
6247 tcg_temp_free_i32(fp0
);
6249 gen_store_gpr(t0
, rt
);
6253 gen_load_gpr(t0
, rt
);
6255 TCGv_i32 fp0
= tcg_temp_new_i32();
6257 tcg_gen_trunc_tl_i32(fp0
, t0
);
6258 gen_store_fpr32(fp0
, fs
);
6259 tcg_temp_free_i32(fp0
);
6264 gen_helper_1i(cfc1
, t0
, fs
);
6265 gen_store_gpr(t0
, rt
);
6269 gen_load_gpr(t0
, rt
);
6270 gen_helper_1i(ctc1
, t0
, fs
);
6273 #if defined(TARGET_MIPS64)
6275 gen_load_fpr64(ctx
, t0
, fs
);
6276 gen_store_gpr(t0
, rt
);
6280 gen_load_gpr(t0
, rt
);
6281 gen_store_fpr64(ctx
, t0
, fs
);
6287 TCGv_i32 fp0
= tcg_temp_new_i32();
6289 gen_load_fpr32h(fp0
, fs
);
6290 tcg_gen_ext_i32_tl(t0
, fp0
);
6291 tcg_temp_free_i32(fp0
);
6293 gen_store_gpr(t0
, rt
);
6297 gen_load_gpr(t0
, rt
);
6299 TCGv_i32 fp0
= tcg_temp_new_i32();
6301 tcg_gen_trunc_tl_i32(fp0
, t0
);
6302 gen_store_fpr32h(fp0
, fs
);
6303 tcg_temp_free_i32(fp0
);
6309 generate_exception (ctx
, EXCP_RI
);
6312 (void)opn
; /* avoid a compiler warning */
6313 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
6319 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
6335 l1
= gen_new_label();
6336 t0
= tcg_temp_new_i32();
6337 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6338 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6339 tcg_temp_free_i32(t0
);
6341 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
6343 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
6348 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
6351 TCGv_i32 t0
= tcg_temp_new_i32();
6352 int l1
= gen_new_label();
6359 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6360 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6361 gen_load_fpr32(t0
, fs
);
6362 gen_store_fpr32(t0
, fd
);
6364 tcg_temp_free_i32(t0
);
6367 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
6370 TCGv_i32 t0
= tcg_temp_new_i32();
6372 int l1
= gen_new_label();
6379 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6380 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6381 tcg_temp_free_i32(t0
);
6382 fp0
= tcg_temp_new_i64();
6383 gen_load_fpr64(ctx
, fp0
, fs
);
6384 gen_store_fpr64(ctx
, fp0
, fd
);
6385 tcg_temp_free_i64(fp0
);
6389 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
6392 TCGv_i32 t0
= tcg_temp_new_i32();
6393 int l1
= gen_new_label();
6394 int l2
= gen_new_label();
6401 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6402 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6403 gen_load_fpr32(t0
, fs
);
6404 gen_store_fpr32(t0
, fd
);
6407 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
6408 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
6409 gen_load_fpr32h(t0
, fs
);
6410 gen_store_fpr32h(t0
, fd
);
6411 tcg_temp_free_i32(t0
);
6416 static void gen_farith (DisasContext
*ctx
, enum fopcode op1
,
6417 int ft
, int fs
, int fd
, int cc
)
6419 const char *opn
= "farith";
6420 const char *condnames
[] = {
6438 const char *condnames_abs
[] = {
6456 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6457 uint32_t func
= ctx
->opcode
& 0x3f;
6462 TCGv_i32 fp0
= tcg_temp_new_i32();
6463 TCGv_i32 fp1
= tcg_temp_new_i32();
6465 gen_load_fpr32(fp0
, fs
);
6466 gen_load_fpr32(fp1
, ft
);
6467 gen_helper_float_add_s(fp0
, fp0
, fp1
);
6468 tcg_temp_free_i32(fp1
);
6469 gen_store_fpr32(fp0
, fd
);
6470 tcg_temp_free_i32(fp0
);
6477 TCGv_i32 fp0
= tcg_temp_new_i32();
6478 TCGv_i32 fp1
= tcg_temp_new_i32();
6480 gen_load_fpr32(fp0
, fs
);
6481 gen_load_fpr32(fp1
, ft
);
6482 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6483 tcg_temp_free_i32(fp1
);
6484 gen_store_fpr32(fp0
, fd
);
6485 tcg_temp_free_i32(fp0
);
6492 TCGv_i32 fp0
= tcg_temp_new_i32();
6493 TCGv_i32 fp1
= tcg_temp_new_i32();
6495 gen_load_fpr32(fp0
, fs
);
6496 gen_load_fpr32(fp1
, ft
);
6497 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6498 tcg_temp_free_i32(fp1
);
6499 gen_store_fpr32(fp0
, fd
);
6500 tcg_temp_free_i32(fp0
);
6507 TCGv_i32 fp0
= tcg_temp_new_i32();
6508 TCGv_i32 fp1
= tcg_temp_new_i32();
6510 gen_load_fpr32(fp0
, fs
);
6511 gen_load_fpr32(fp1
, ft
);
6512 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6513 tcg_temp_free_i32(fp1
);
6514 gen_store_fpr32(fp0
, fd
);
6515 tcg_temp_free_i32(fp0
);
6522 TCGv_i32 fp0
= tcg_temp_new_i32();
6524 gen_load_fpr32(fp0
, fs
);
6525 gen_helper_float_sqrt_s(fp0
, fp0
);
6526 gen_store_fpr32(fp0
, fd
);
6527 tcg_temp_free_i32(fp0
);
6533 TCGv_i32 fp0
= tcg_temp_new_i32();
6535 gen_load_fpr32(fp0
, fs
);
6536 gen_helper_float_abs_s(fp0
, fp0
);
6537 gen_store_fpr32(fp0
, fd
);
6538 tcg_temp_free_i32(fp0
);
6544 TCGv_i32 fp0
= tcg_temp_new_i32();
6546 gen_load_fpr32(fp0
, fs
);
6547 gen_store_fpr32(fp0
, fd
);
6548 tcg_temp_free_i32(fp0
);
6554 TCGv_i32 fp0
= tcg_temp_new_i32();
6556 gen_load_fpr32(fp0
, fs
);
6557 gen_helper_float_chs_s(fp0
, fp0
);
6558 gen_store_fpr32(fp0
, fd
);
6559 tcg_temp_free_i32(fp0
);
6564 check_cp1_64bitmode(ctx
);
6566 TCGv_i32 fp32
= tcg_temp_new_i32();
6567 TCGv_i64 fp64
= tcg_temp_new_i64();
6569 gen_load_fpr32(fp32
, fs
);
6570 gen_helper_float_roundl_s(fp64
, fp32
);
6571 tcg_temp_free_i32(fp32
);
6572 gen_store_fpr64(ctx
, fp64
, fd
);
6573 tcg_temp_free_i64(fp64
);
6578 check_cp1_64bitmode(ctx
);
6580 TCGv_i32 fp32
= tcg_temp_new_i32();
6581 TCGv_i64 fp64
= tcg_temp_new_i64();
6583 gen_load_fpr32(fp32
, fs
);
6584 gen_helper_float_truncl_s(fp64
, fp32
);
6585 tcg_temp_free_i32(fp32
);
6586 gen_store_fpr64(ctx
, fp64
, fd
);
6587 tcg_temp_free_i64(fp64
);
6592 check_cp1_64bitmode(ctx
);
6594 TCGv_i32 fp32
= tcg_temp_new_i32();
6595 TCGv_i64 fp64
= tcg_temp_new_i64();
6597 gen_load_fpr32(fp32
, fs
);
6598 gen_helper_float_ceill_s(fp64
, fp32
);
6599 tcg_temp_free_i32(fp32
);
6600 gen_store_fpr64(ctx
, fp64
, fd
);
6601 tcg_temp_free_i64(fp64
);
6606 check_cp1_64bitmode(ctx
);
6608 TCGv_i32 fp32
= tcg_temp_new_i32();
6609 TCGv_i64 fp64
= tcg_temp_new_i64();
6611 gen_load_fpr32(fp32
, fs
);
6612 gen_helper_float_floorl_s(fp64
, fp32
);
6613 tcg_temp_free_i32(fp32
);
6614 gen_store_fpr64(ctx
, fp64
, fd
);
6615 tcg_temp_free_i64(fp64
);
6621 TCGv_i32 fp0
= tcg_temp_new_i32();
6623 gen_load_fpr32(fp0
, fs
);
6624 gen_helper_float_roundw_s(fp0
, fp0
);
6625 gen_store_fpr32(fp0
, fd
);
6626 tcg_temp_free_i32(fp0
);
6632 TCGv_i32 fp0
= tcg_temp_new_i32();
6634 gen_load_fpr32(fp0
, fs
);
6635 gen_helper_float_truncw_s(fp0
, fp0
);
6636 gen_store_fpr32(fp0
, fd
);
6637 tcg_temp_free_i32(fp0
);
6643 TCGv_i32 fp0
= tcg_temp_new_i32();
6645 gen_load_fpr32(fp0
, fs
);
6646 gen_helper_float_ceilw_s(fp0
, fp0
);
6647 gen_store_fpr32(fp0
, fd
);
6648 tcg_temp_free_i32(fp0
);
6654 TCGv_i32 fp0
= tcg_temp_new_i32();
6656 gen_load_fpr32(fp0
, fs
);
6657 gen_helper_float_floorw_s(fp0
, fp0
);
6658 gen_store_fpr32(fp0
, fd
);
6659 tcg_temp_free_i32(fp0
);
6664 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6669 int l1
= gen_new_label();
6673 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6675 fp0
= tcg_temp_new_i32();
6676 gen_load_fpr32(fp0
, fs
);
6677 gen_store_fpr32(fp0
, fd
);
6678 tcg_temp_free_i32(fp0
);
6685 int l1
= gen_new_label();
6689 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6690 fp0
= tcg_temp_new_i32();
6691 gen_load_fpr32(fp0
, fs
);
6692 gen_store_fpr32(fp0
, fd
);
6693 tcg_temp_free_i32(fp0
);
6702 TCGv_i32 fp0
= tcg_temp_new_i32();
6704 gen_load_fpr32(fp0
, fs
);
6705 gen_helper_float_recip_s(fp0
, fp0
);
6706 gen_store_fpr32(fp0
, fd
);
6707 tcg_temp_free_i32(fp0
);
6714 TCGv_i32 fp0
= tcg_temp_new_i32();
6716 gen_load_fpr32(fp0
, fs
);
6717 gen_helper_float_rsqrt_s(fp0
, fp0
);
6718 gen_store_fpr32(fp0
, fd
);
6719 tcg_temp_free_i32(fp0
);
6724 check_cp1_64bitmode(ctx
);
6726 TCGv_i32 fp0
= tcg_temp_new_i32();
6727 TCGv_i32 fp1
= tcg_temp_new_i32();
6729 gen_load_fpr32(fp0
, fs
);
6730 gen_load_fpr32(fp1
, fd
);
6731 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6732 tcg_temp_free_i32(fp1
);
6733 gen_store_fpr32(fp0
, fd
);
6734 tcg_temp_free_i32(fp0
);
6739 check_cp1_64bitmode(ctx
);
6741 TCGv_i32 fp0
= tcg_temp_new_i32();
6743 gen_load_fpr32(fp0
, fs
);
6744 gen_helper_float_recip1_s(fp0
, fp0
);
6745 gen_store_fpr32(fp0
, fd
);
6746 tcg_temp_free_i32(fp0
);
6751 check_cp1_64bitmode(ctx
);
6753 TCGv_i32 fp0
= tcg_temp_new_i32();
6755 gen_load_fpr32(fp0
, fs
);
6756 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6757 gen_store_fpr32(fp0
, fd
);
6758 tcg_temp_free_i32(fp0
);
6763 check_cp1_64bitmode(ctx
);
6765 TCGv_i32 fp0
= tcg_temp_new_i32();
6766 TCGv_i32 fp1
= tcg_temp_new_i32();
6768 gen_load_fpr32(fp0
, fs
);
6769 gen_load_fpr32(fp1
, ft
);
6770 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6771 tcg_temp_free_i32(fp1
);
6772 gen_store_fpr32(fp0
, fd
);
6773 tcg_temp_free_i32(fp0
);
6778 check_cp1_registers(ctx
, fd
);
6780 TCGv_i32 fp32
= tcg_temp_new_i32();
6781 TCGv_i64 fp64
= tcg_temp_new_i64();
6783 gen_load_fpr32(fp32
, fs
);
6784 gen_helper_float_cvtd_s(fp64
, fp32
);
6785 tcg_temp_free_i32(fp32
);
6786 gen_store_fpr64(ctx
, fp64
, fd
);
6787 tcg_temp_free_i64(fp64
);
6793 TCGv_i32 fp0
= tcg_temp_new_i32();
6795 gen_load_fpr32(fp0
, fs
);
6796 gen_helper_float_cvtw_s(fp0
, fp0
);
6797 gen_store_fpr32(fp0
, fd
);
6798 tcg_temp_free_i32(fp0
);
6803 check_cp1_64bitmode(ctx
);
6805 TCGv_i32 fp32
= tcg_temp_new_i32();
6806 TCGv_i64 fp64
= tcg_temp_new_i64();
6808 gen_load_fpr32(fp32
, fs
);
6809 gen_helper_float_cvtl_s(fp64
, fp32
);
6810 tcg_temp_free_i32(fp32
);
6811 gen_store_fpr64(ctx
, fp64
, fd
);
6812 tcg_temp_free_i64(fp64
);
6817 check_cp1_64bitmode(ctx
);
6819 TCGv_i64 fp64
= tcg_temp_new_i64();
6820 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6821 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6823 gen_load_fpr32(fp32_0
, fs
);
6824 gen_load_fpr32(fp32_1
, ft
);
6825 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6826 tcg_temp_free_i32(fp32_1
);
6827 tcg_temp_free_i32(fp32_0
);
6828 gen_store_fpr64(ctx
, fp64
, fd
);
6829 tcg_temp_free_i64(fp64
);
6842 case OPC_CMP_NGLE_S
:
6849 if (ctx
->opcode
& (1 << 6)) {
6850 gen_cmpabs_s(ctx
, func
-48, ft
, fs
, cc
);
6851 opn
= condnames_abs
[func
-48];
6853 gen_cmp_s(ctx
, func
-48, ft
, fs
, cc
);
6854 opn
= condnames
[func
-48];
6858 check_cp1_registers(ctx
, fs
| ft
| fd
);
6860 TCGv_i64 fp0
= tcg_temp_new_i64();
6861 TCGv_i64 fp1
= tcg_temp_new_i64();
6863 gen_load_fpr64(ctx
, fp0
, fs
);
6864 gen_load_fpr64(ctx
, fp1
, ft
);
6865 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6866 tcg_temp_free_i64(fp1
);
6867 gen_store_fpr64(ctx
, fp0
, fd
);
6868 tcg_temp_free_i64(fp0
);
6874 check_cp1_registers(ctx
, fs
| ft
| fd
);
6876 TCGv_i64 fp0
= tcg_temp_new_i64();
6877 TCGv_i64 fp1
= tcg_temp_new_i64();
6879 gen_load_fpr64(ctx
, fp0
, fs
);
6880 gen_load_fpr64(ctx
, fp1
, ft
);
6881 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6882 tcg_temp_free_i64(fp1
);
6883 gen_store_fpr64(ctx
, fp0
, fd
);
6884 tcg_temp_free_i64(fp0
);
6890 check_cp1_registers(ctx
, fs
| ft
| fd
);
6892 TCGv_i64 fp0
= tcg_temp_new_i64();
6893 TCGv_i64 fp1
= tcg_temp_new_i64();
6895 gen_load_fpr64(ctx
, fp0
, fs
);
6896 gen_load_fpr64(ctx
, fp1
, ft
);
6897 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6898 tcg_temp_free_i64(fp1
);
6899 gen_store_fpr64(ctx
, fp0
, fd
);
6900 tcg_temp_free_i64(fp0
);
6906 check_cp1_registers(ctx
, fs
| ft
| fd
);
6908 TCGv_i64 fp0
= tcg_temp_new_i64();
6909 TCGv_i64 fp1
= tcg_temp_new_i64();
6911 gen_load_fpr64(ctx
, fp0
, fs
);
6912 gen_load_fpr64(ctx
, fp1
, ft
);
6913 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6914 tcg_temp_free_i64(fp1
);
6915 gen_store_fpr64(ctx
, fp0
, fd
);
6916 tcg_temp_free_i64(fp0
);
6922 check_cp1_registers(ctx
, fs
| fd
);
6924 TCGv_i64 fp0
= tcg_temp_new_i64();
6926 gen_load_fpr64(ctx
, fp0
, fs
);
6927 gen_helper_float_sqrt_d(fp0
, fp0
);
6928 gen_store_fpr64(ctx
, fp0
, fd
);
6929 tcg_temp_free_i64(fp0
);
6934 check_cp1_registers(ctx
, fs
| fd
);
6936 TCGv_i64 fp0
= tcg_temp_new_i64();
6938 gen_load_fpr64(ctx
, fp0
, fs
);
6939 gen_helper_float_abs_d(fp0
, fp0
);
6940 gen_store_fpr64(ctx
, fp0
, fd
);
6941 tcg_temp_free_i64(fp0
);
6946 check_cp1_registers(ctx
, fs
| fd
);
6948 TCGv_i64 fp0
= tcg_temp_new_i64();
6950 gen_load_fpr64(ctx
, fp0
, fs
);
6951 gen_store_fpr64(ctx
, fp0
, fd
);
6952 tcg_temp_free_i64(fp0
);
6957 check_cp1_registers(ctx
, fs
| fd
);
6959 TCGv_i64 fp0
= tcg_temp_new_i64();
6961 gen_load_fpr64(ctx
, fp0
, fs
);
6962 gen_helper_float_chs_d(fp0
, fp0
);
6963 gen_store_fpr64(ctx
, fp0
, fd
);
6964 tcg_temp_free_i64(fp0
);
6969 check_cp1_64bitmode(ctx
);
6971 TCGv_i64 fp0
= tcg_temp_new_i64();
6973 gen_load_fpr64(ctx
, fp0
, fs
);
6974 gen_helper_float_roundl_d(fp0
, fp0
);
6975 gen_store_fpr64(ctx
, fp0
, fd
);
6976 tcg_temp_free_i64(fp0
);
6981 check_cp1_64bitmode(ctx
);
6983 TCGv_i64 fp0
= tcg_temp_new_i64();
6985 gen_load_fpr64(ctx
, fp0
, fs
);
6986 gen_helper_float_truncl_d(fp0
, fp0
);
6987 gen_store_fpr64(ctx
, fp0
, fd
);
6988 tcg_temp_free_i64(fp0
);
6993 check_cp1_64bitmode(ctx
);
6995 TCGv_i64 fp0
= tcg_temp_new_i64();
6997 gen_load_fpr64(ctx
, fp0
, fs
);
6998 gen_helper_float_ceill_d(fp0
, fp0
);
6999 gen_store_fpr64(ctx
, fp0
, fd
);
7000 tcg_temp_free_i64(fp0
);
7005 check_cp1_64bitmode(ctx
);
7007 TCGv_i64 fp0
= tcg_temp_new_i64();
7009 gen_load_fpr64(ctx
, fp0
, fs
);
7010 gen_helper_float_floorl_d(fp0
, fp0
);
7011 gen_store_fpr64(ctx
, fp0
, fd
);
7012 tcg_temp_free_i64(fp0
);
7017 check_cp1_registers(ctx
, fs
);
7019 TCGv_i32 fp32
= tcg_temp_new_i32();
7020 TCGv_i64 fp64
= tcg_temp_new_i64();
7022 gen_load_fpr64(ctx
, fp64
, fs
);
7023 gen_helper_float_roundw_d(fp32
, fp64
);
7024 tcg_temp_free_i64(fp64
);
7025 gen_store_fpr32(fp32
, fd
);
7026 tcg_temp_free_i32(fp32
);
7031 check_cp1_registers(ctx
, fs
);
7033 TCGv_i32 fp32
= tcg_temp_new_i32();
7034 TCGv_i64 fp64
= tcg_temp_new_i64();
7036 gen_load_fpr64(ctx
, fp64
, fs
);
7037 gen_helper_float_truncw_d(fp32
, fp64
);
7038 tcg_temp_free_i64(fp64
);
7039 gen_store_fpr32(fp32
, fd
);
7040 tcg_temp_free_i32(fp32
);
7045 check_cp1_registers(ctx
, fs
);
7047 TCGv_i32 fp32
= tcg_temp_new_i32();
7048 TCGv_i64 fp64
= tcg_temp_new_i64();
7050 gen_load_fpr64(ctx
, fp64
, fs
);
7051 gen_helper_float_ceilw_d(fp32
, fp64
);
7052 tcg_temp_free_i64(fp64
);
7053 gen_store_fpr32(fp32
, fd
);
7054 tcg_temp_free_i32(fp32
);
7059 check_cp1_registers(ctx
, fs
);
7061 TCGv_i32 fp32
= tcg_temp_new_i32();
7062 TCGv_i64 fp64
= tcg_temp_new_i64();
7064 gen_load_fpr64(ctx
, fp64
, fs
);
7065 gen_helper_float_floorw_d(fp32
, fp64
);
7066 tcg_temp_free_i64(fp64
);
7067 gen_store_fpr32(fp32
, fd
);
7068 tcg_temp_free_i32(fp32
);
7073 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7078 int l1
= gen_new_label();
7082 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7084 fp0
= tcg_temp_new_i64();
7085 gen_load_fpr64(ctx
, fp0
, fs
);
7086 gen_store_fpr64(ctx
, fp0
, fd
);
7087 tcg_temp_free_i64(fp0
);
7094 int l1
= gen_new_label();
7098 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7099 fp0
= tcg_temp_new_i64();
7100 gen_load_fpr64(ctx
, fp0
, fs
);
7101 gen_store_fpr64(ctx
, fp0
, fd
);
7102 tcg_temp_free_i64(fp0
);
7109 check_cp1_64bitmode(ctx
);
7111 TCGv_i64 fp0
= tcg_temp_new_i64();
7113 gen_load_fpr64(ctx
, fp0
, fs
);
7114 gen_helper_float_recip_d(fp0
, fp0
);
7115 gen_store_fpr64(ctx
, fp0
, fd
);
7116 tcg_temp_free_i64(fp0
);
7121 check_cp1_64bitmode(ctx
);
7123 TCGv_i64 fp0
= tcg_temp_new_i64();
7125 gen_load_fpr64(ctx
, fp0
, fs
);
7126 gen_helper_float_rsqrt_d(fp0
, fp0
);
7127 gen_store_fpr64(ctx
, fp0
, fd
);
7128 tcg_temp_free_i64(fp0
);
7133 check_cp1_64bitmode(ctx
);
7135 TCGv_i64 fp0
= tcg_temp_new_i64();
7136 TCGv_i64 fp1
= tcg_temp_new_i64();
7138 gen_load_fpr64(ctx
, fp0
, fs
);
7139 gen_load_fpr64(ctx
, fp1
, ft
);
7140 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
7141 tcg_temp_free_i64(fp1
);
7142 gen_store_fpr64(ctx
, fp0
, fd
);
7143 tcg_temp_free_i64(fp0
);
7148 check_cp1_64bitmode(ctx
);
7150 TCGv_i64 fp0
= tcg_temp_new_i64();
7152 gen_load_fpr64(ctx
, fp0
, fs
);
7153 gen_helper_float_recip1_d(fp0
, fp0
);
7154 gen_store_fpr64(ctx
, fp0
, fd
);
7155 tcg_temp_free_i64(fp0
);
7160 check_cp1_64bitmode(ctx
);
7162 TCGv_i64 fp0
= tcg_temp_new_i64();
7164 gen_load_fpr64(ctx
, fp0
, fs
);
7165 gen_helper_float_rsqrt1_d(fp0
, fp0
);
7166 gen_store_fpr64(ctx
, fp0
, fd
);
7167 tcg_temp_free_i64(fp0
);
7172 check_cp1_64bitmode(ctx
);
7174 TCGv_i64 fp0
= tcg_temp_new_i64();
7175 TCGv_i64 fp1
= tcg_temp_new_i64();
7177 gen_load_fpr64(ctx
, fp0
, fs
);
7178 gen_load_fpr64(ctx
, fp1
, ft
);
7179 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
7180 tcg_temp_free_i64(fp1
);
7181 gen_store_fpr64(ctx
, fp0
, fd
);
7182 tcg_temp_free_i64(fp0
);
7195 case OPC_CMP_NGLE_D
:
7202 if (ctx
->opcode
& (1 << 6)) {
7203 gen_cmpabs_d(ctx
, func
-48, ft
, fs
, cc
);
7204 opn
= condnames_abs
[func
-48];
7206 gen_cmp_d(ctx
, func
-48, ft
, fs
, cc
);
7207 opn
= condnames
[func
-48];
7211 check_cp1_registers(ctx
, fs
);
7213 TCGv_i32 fp32
= tcg_temp_new_i32();
7214 TCGv_i64 fp64
= tcg_temp_new_i64();
7216 gen_load_fpr64(ctx
, fp64
, fs
);
7217 gen_helper_float_cvts_d(fp32
, fp64
);
7218 tcg_temp_free_i64(fp64
);
7219 gen_store_fpr32(fp32
, fd
);
7220 tcg_temp_free_i32(fp32
);
7225 check_cp1_registers(ctx
, fs
);
7227 TCGv_i32 fp32
= tcg_temp_new_i32();
7228 TCGv_i64 fp64
= tcg_temp_new_i64();
7230 gen_load_fpr64(ctx
, fp64
, fs
);
7231 gen_helper_float_cvtw_d(fp32
, fp64
);
7232 tcg_temp_free_i64(fp64
);
7233 gen_store_fpr32(fp32
, fd
);
7234 tcg_temp_free_i32(fp32
);
7239 check_cp1_64bitmode(ctx
);
7241 TCGv_i64 fp0
= tcg_temp_new_i64();
7243 gen_load_fpr64(ctx
, fp0
, fs
);
7244 gen_helper_float_cvtl_d(fp0
, fp0
);
7245 gen_store_fpr64(ctx
, fp0
, fd
);
7246 tcg_temp_free_i64(fp0
);
7252 TCGv_i32 fp0
= tcg_temp_new_i32();
7254 gen_load_fpr32(fp0
, fs
);
7255 gen_helper_float_cvts_w(fp0
, fp0
);
7256 gen_store_fpr32(fp0
, fd
);
7257 tcg_temp_free_i32(fp0
);
7262 check_cp1_registers(ctx
, fd
);
7264 TCGv_i32 fp32
= tcg_temp_new_i32();
7265 TCGv_i64 fp64
= tcg_temp_new_i64();
7267 gen_load_fpr32(fp32
, fs
);
7268 gen_helper_float_cvtd_w(fp64
, fp32
);
7269 tcg_temp_free_i32(fp32
);
7270 gen_store_fpr64(ctx
, fp64
, fd
);
7271 tcg_temp_free_i64(fp64
);
7276 check_cp1_64bitmode(ctx
);
7278 TCGv_i32 fp32
= tcg_temp_new_i32();
7279 TCGv_i64 fp64
= tcg_temp_new_i64();
7281 gen_load_fpr64(ctx
, fp64
, fs
);
7282 gen_helper_float_cvts_l(fp32
, fp64
);
7283 tcg_temp_free_i64(fp64
);
7284 gen_store_fpr32(fp32
, fd
);
7285 tcg_temp_free_i32(fp32
);
7290 check_cp1_64bitmode(ctx
);
7292 TCGv_i64 fp0
= tcg_temp_new_i64();
7294 gen_load_fpr64(ctx
, fp0
, fs
);
7295 gen_helper_float_cvtd_l(fp0
, fp0
);
7296 gen_store_fpr64(ctx
, fp0
, fd
);
7297 tcg_temp_free_i64(fp0
);
7302 check_cp1_64bitmode(ctx
);
7304 TCGv_i64 fp0
= tcg_temp_new_i64();
7306 gen_load_fpr64(ctx
, fp0
, fs
);
7307 gen_helper_float_cvtps_pw(fp0
, fp0
);
7308 gen_store_fpr64(ctx
, fp0
, fd
);
7309 tcg_temp_free_i64(fp0
);
7314 check_cp1_64bitmode(ctx
);
7316 TCGv_i64 fp0
= tcg_temp_new_i64();
7317 TCGv_i64 fp1
= tcg_temp_new_i64();
7319 gen_load_fpr64(ctx
, fp0
, fs
);
7320 gen_load_fpr64(ctx
, fp1
, ft
);
7321 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
7322 tcg_temp_free_i64(fp1
);
7323 gen_store_fpr64(ctx
, fp0
, fd
);
7324 tcg_temp_free_i64(fp0
);
7329 check_cp1_64bitmode(ctx
);
7331 TCGv_i64 fp0
= tcg_temp_new_i64();
7332 TCGv_i64 fp1
= tcg_temp_new_i64();
7334 gen_load_fpr64(ctx
, fp0
, fs
);
7335 gen_load_fpr64(ctx
, fp1
, ft
);
7336 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
7337 tcg_temp_free_i64(fp1
);
7338 gen_store_fpr64(ctx
, fp0
, fd
);
7339 tcg_temp_free_i64(fp0
);
7344 check_cp1_64bitmode(ctx
);
7346 TCGv_i64 fp0
= tcg_temp_new_i64();
7347 TCGv_i64 fp1
= tcg_temp_new_i64();
7349 gen_load_fpr64(ctx
, fp0
, fs
);
7350 gen_load_fpr64(ctx
, fp1
, ft
);
7351 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
7352 tcg_temp_free_i64(fp1
);
7353 gen_store_fpr64(ctx
, fp0
, fd
);
7354 tcg_temp_free_i64(fp0
);
7359 check_cp1_64bitmode(ctx
);
7361 TCGv_i64 fp0
= tcg_temp_new_i64();
7363 gen_load_fpr64(ctx
, fp0
, fs
);
7364 gen_helper_float_abs_ps(fp0
, fp0
);
7365 gen_store_fpr64(ctx
, fp0
, fd
);
7366 tcg_temp_free_i64(fp0
);
7371 check_cp1_64bitmode(ctx
);
7373 TCGv_i64 fp0
= tcg_temp_new_i64();
7375 gen_load_fpr64(ctx
, fp0
, fs
);
7376 gen_store_fpr64(ctx
, fp0
, fd
);
7377 tcg_temp_free_i64(fp0
);
7382 check_cp1_64bitmode(ctx
);
7384 TCGv_i64 fp0
= tcg_temp_new_i64();
7386 gen_load_fpr64(ctx
, fp0
, fs
);
7387 gen_helper_float_chs_ps(fp0
, fp0
);
7388 gen_store_fpr64(ctx
, fp0
, fd
);
7389 tcg_temp_free_i64(fp0
);
7394 check_cp1_64bitmode(ctx
);
7395 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7399 check_cp1_64bitmode(ctx
);
7401 int l1
= gen_new_label();
7405 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7406 fp0
= tcg_temp_new_i64();
7407 gen_load_fpr64(ctx
, fp0
, fs
);
7408 gen_store_fpr64(ctx
, fp0
, fd
);
7409 tcg_temp_free_i64(fp0
);
7415 check_cp1_64bitmode(ctx
);
7417 int l1
= gen_new_label();
7421 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7422 fp0
= tcg_temp_new_i64();
7423 gen_load_fpr64(ctx
, fp0
, fs
);
7424 gen_store_fpr64(ctx
, fp0
, fd
);
7425 tcg_temp_free_i64(fp0
);
7432 check_cp1_64bitmode(ctx
);
7434 TCGv_i64 fp0
= tcg_temp_new_i64();
7435 TCGv_i64 fp1
= tcg_temp_new_i64();
7437 gen_load_fpr64(ctx
, fp0
, ft
);
7438 gen_load_fpr64(ctx
, fp1
, fs
);
7439 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
7440 tcg_temp_free_i64(fp1
);
7441 gen_store_fpr64(ctx
, fp0
, fd
);
7442 tcg_temp_free_i64(fp0
);
7447 check_cp1_64bitmode(ctx
);
7449 TCGv_i64 fp0
= tcg_temp_new_i64();
7450 TCGv_i64 fp1
= tcg_temp_new_i64();
7452 gen_load_fpr64(ctx
, fp0
, ft
);
7453 gen_load_fpr64(ctx
, fp1
, fs
);
7454 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7455 tcg_temp_free_i64(fp1
);
7456 gen_store_fpr64(ctx
, fp0
, fd
);
7457 tcg_temp_free_i64(fp0
);
7462 check_cp1_64bitmode(ctx
);
7464 TCGv_i64 fp0
= tcg_temp_new_i64();
7465 TCGv_i64 fp1
= tcg_temp_new_i64();
7467 gen_load_fpr64(ctx
, fp0
, fs
);
7468 gen_load_fpr64(ctx
, fp1
, fd
);
7469 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7470 tcg_temp_free_i64(fp1
);
7471 gen_store_fpr64(ctx
, fp0
, fd
);
7472 tcg_temp_free_i64(fp0
);
7477 check_cp1_64bitmode(ctx
);
7479 TCGv_i64 fp0
= tcg_temp_new_i64();
7481 gen_load_fpr64(ctx
, fp0
, fs
);
7482 gen_helper_float_recip1_ps(fp0
, fp0
);
7483 gen_store_fpr64(ctx
, fp0
, fd
);
7484 tcg_temp_free_i64(fp0
);
7489 check_cp1_64bitmode(ctx
);
7491 TCGv_i64 fp0
= tcg_temp_new_i64();
7493 gen_load_fpr64(ctx
, fp0
, fs
);
7494 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7495 gen_store_fpr64(ctx
, fp0
, fd
);
7496 tcg_temp_free_i64(fp0
);
7501 check_cp1_64bitmode(ctx
);
7503 TCGv_i64 fp0
= tcg_temp_new_i64();
7504 TCGv_i64 fp1
= tcg_temp_new_i64();
7506 gen_load_fpr64(ctx
, fp0
, fs
);
7507 gen_load_fpr64(ctx
, fp1
, ft
);
7508 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7509 tcg_temp_free_i64(fp1
);
7510 gen_store_fpr64(ctx
, fp0
, fd
);
7511 tcg_temp_free_i64(fp0
);
7516 check_cp1_64bitmode(ctx
);
7518 TCGv_i32 fp0
= tcg_temp_new_i32();
7520 gen_load_fpr32h(fp0
, fs
);
7521 gen_helper_float_cvts_pu(fp0
, fp0
);
7522 gen_store_fpr32(fp0
, fd
);
7523 tcg_temp_free_i32(fp0
);
7528 check_cp1_64bitmode(ctx
);
7530 TCGv_i64 fp0
= tcg_temp_new_i64();
7532 gen_load_fpr64(ctx
, fp0
, fs
);
7533 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7534 gen_store_fpr64(ctx
, fp0
, fd
);
7535 tcg_temp_free_i64(fp0
);
7540 check_cp1_64bitmode(ctx
);
7542 TCGv_i32 fp0
= tcg_temp_new_i32();
7544 gen_load_fpr32(fp0
, fs
);
7545 gen_helper_float_cvts_pl(fp0
, fp0
);
7546 gen_store_fpr32(fp0
, fd
);
7547 tcg_temp_free_i32(fp0
);
7552 check_cp1_64bitmode(ctx
);
7554 TCGv_i32 fp0
= tcg_temp_new_i32();
7555 TCGv_i32 fp1
= tcg_temp_new_i32();
7557 gen_load_fpr32(fp0
, fs
);
7558 gen_load_fpr32(fp1
, ft
);
7559 gen_store_fpr32h(fp0
, fd
);
7560 gen_store_fpr32(fp1
, fd
);
7561 tcg_temp_free_i32(fp0
);
7562 tcg_temp_free_i32(fp1
);
7567 check_cp1_64bitmode(ctx
);
7569 TCGv_i32 fp0
= tcg_temp_new_i32();
7570 TCGv_i32 fp1
= tcg_temp_new_i32();
7572 gen_load_fpr32(fp0
, fs
);
7573 gen_load_fpr32h(fp1
, ft
);
7574 gen_store_fpr32(fp1
, fd
);
7575 gen_store_fpr32h(fp0
, fd
);
7576 tcg_temp_free_i32(fp0
);
7577 tcg_temp_free_i32(fp1
);
7582 check_cp1_64bitmode(ctx
);
7584 TCGv_i32 fp0
= tcg_temp_new_i32();
7585 TCGv_i32 fp1
= tcg_temp_new_i32();
7587 gen_load_fpr32h(fp0
, fs
);
7588 gen_load_fpr32(fp1
, ft
);
7589 gen_store_fpr32(fp1
, fd
);
7590 gen_store_fpr32h(fp0
, fd
);
7591 tcg_temp_free_i32(fp0
);
7592 tcg_temp_free_i32(fp1
);
7597 check_cp1_64bitmode(ctx
);
7599 TCGv_i32 fp0
= tcg_temp_new_i32();
7600 TCGv_i32 fp1
= tcg_temp_new_i32();
7602 gen_load_fpr32h(fp0
, fs
);
7603 gen_load_fpr32h(fp1
, ft
);
7604 gen_store_fpr32(fp1
, fd
);
7605 gen_store_fpr32h(fp0
, fd
);
7606 tcg_temp_free_i32(fp0
);
7607 tcg_temp_free_i32(fp1
);
7614 case OPC_CMP_UEQ_PS
:
7615 case OPC_CMP_OLT_PS
:
7616 case OPC_CMP_ULT_PS
:
7617 case OPC_CMP_OLE_PS
:
7618 case OPC_CMP_ULE_PS
:
7620 case OPC_CMP_NGLE_PS
:
7621 case OPC_CMP_SEQ_PS
:
7622 case OPC_CMP_NGL_PS
:
7624 case OPC_CMP_NGE_PS
:
7626 case OPC_CMP_NGT_PS
:
7627 if (ctx
->opcode
& (1 << 6)) {
7628 gen_cmpabs_ps(ctx
, func
-48, ft
, fs
, cc
);
7629 opn
= condnames_abs
[func
-48];
7631 gen_cmp_ps(ctx
, func
-48, ft
, fs
, cc
);
7632 opn
= condnames
[func
-48];
7637 generate_exception (ctx
, EXCP_RI
);
7640 (void)opn
; /* avoid a compiler warning */
7643 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7646 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7649 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7654 /* Coprocessor 3 (FPU) */
7655 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7656 int fd
, int fs
, int base
, int index
)
7658 const char *opn
= "extended float load/store";
7660 TCGv t0
= tcg_temp_new();
7663 gen_load_gpr(t0
, index
);
7664 } else if (index
== 0) {
7665 gen_load_gpr(t0
, base
);
7667 gen_load_gpr(t0
, index
);
7668 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7670 /* Don't do NOP if destination is zero: we must perform the actual
7672 save_cpu_state(ctx
, 0);
7677 TCGv_i32 fp0
= tcg_temp_new_i32();
7679 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7680 tcg_gen_trunc_tl_i32(fp0
, t0
);
7681 gen_store_fpr32(fp0
, fd
);
7682 tcg_temp_free_i32(fp0
);
7688 check_cp1_registers(ctx
, fd
);
7690 TCGv_i64 fp0
= tcg_temp_new_i64();
7692 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7693 gen_store_fpr64(ctx
, fp0
, fd
);
7694 tcg_temp_free_i64(fp0
);
7699 check_cp1_64bitmode(ctx
);
7700 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7702 TCGv_i64 fp0
= tcg_temp_new_i64();
7704 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7705 gen_store_fpr64(ctx
, fp0
, fd
);
7706 tcg_temp_free_i64(fp0
);
7713 TCGv_i32 fp0
= tcg_temp_new_i32();
7714 TCGv t1
= tcg_temp_new();
7716 gen_load_fpr32(fp0
, fs
);
7717 tcg_gen_extu_i32_tl(t1
, fp0
);
7718 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7719 tcg_temp_free_i32(fp0
);
7727 check_cp1_registers(ctx
, fs
);
7729 TCGv_i64 fp0
= tcg_temp_new_i64();
7731 gen_load_fpr64(ctx
, fp0
, fs
);
7732 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7733 tcg_temp_free_i64(fp0
);
7739 check_cp1_64bitmode(ctx
);
7740 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7742 TCGv_i64 fp0
= tcg_temp_new_i64();
7744 gen_load_fpr64(ctx
, fp0
, fs
);
7745 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7746 tcg_temp_free_i64(fp0
);
7753 (void)opn
; (void)store
; /* avoid compiler warnings */
7754 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7755 regnames
[index
], regnames
[base
]);
7758 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7759 int fd
, int fr
, int fs
, int ft
)
7761 const char *opn
= "flt3_arith";
7765 check_cp1_64bitmode(ctx
);
7767 TCGv t0
= tcg_temp_local_new();
7768 TCGv_i32 fp
= tcg_temp_new_i32();
7769 TCGv_i32 fph
= tcg_temp_new_i32();
7770 int l1
= gen_new_label();
7771 int l2
= gen_new_label();
7773 gen_load_gpr(t0
, fr
);
7774 tcg_gen_andi_tl(t0
, t0
, 0x7);
7776 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7777 gen_load_fpr32(fp
, fs
);
7778 gen_load_fpr32h(fph
, fs
);
7779 gen_store_fpr32(fp
, fd
);
7780 gen_store_fpr32h(fph
, fd
);
7783 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7785 #ifdef TARGET_WORDS_BIGENDIAN
7786 gen_load_fpr32(fp
, fs
);
7787 gen_load_fpr32h(fph
, ft
);
7788 gen_store_fpr32h(fp
, fd
);
7789 gen_store_fpr32(fph
, fd
);
7791 gen_load_fpr32h(fph
, fs
);
7792 gen_load_fpr32(fp
, ft
);
7793 gen_store_fpr32(fph
, fd
);
7794 gen_store_fpr32h(fp
, fd
);
7797 tcg_temp_free_i32(fp
);
7798 tcg_temp_free_i32(fph
);
7805 TCGv_i32 fp0
= tcg_temp_new_i32();
7806 TCGv_i32 fp1
= tcg_temp_new_i32();
7807 TCGv_i32 fp2
= tcg_temp_new_i32();
7809 gen_load_fpr32(fp0
, fs
);
7810 gen_load_fpr32(fp1
, ft
);
7811 gen_load_fpr32(fp2
, fr
);
7812 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7813 tcg_temp_free_i32(fp0
);
7814 tcg_temp_free_i32(fp1
);
7815 gen_store_fpr32(fp2
, fd
);
7816 tcg_temp_free_i32(fp2
);
7822 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7824 TCGv_i64 fp0
= tcg_temp_new_i64();
7825 TCGv_i64 fp1
= tcg_temp_new_i64();
7826 TCGv_i64 fp2
= tcg_temp_new_i64();
7828 gen_load_fpr64(ctx
, fp0
, fs
);
7829 gen_load_fpr64(ctx
, fp1
, ft
);
7830 gen_load_fpr64(ctx
, fp2
, fr
);
7831 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7832 tcg_temp_free_i64(fp0
);
7833 tcg_temp_free_i64(fp1
);
7834 gen_store_fpr64(ctx
, fp2
, fd
);
7835 tcg_temp_free_i64(fp2
);
7840 check_cp1_64bitmode(ctx
);
7842 TCGv_i64 fp0
= tcg_temp_new_i64();
7843 TCGv_i64 fp1
= tcg_temp_new_i64();
7844 TCGv_i64 fp2
= tcg_temp_new_i64();
7846 gen_load_fpr64(ctx
, fp0
, fs
);
7847 gen_load_fpr64(ctx
, fp1
, ft
);
7848 gen_load_fpr64(ctx
, fp2
, fr
);
7849 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7850 tcg_temp_free_i64(fp0
);
7851 tcg_temp_free_i64(fp1
);
7852 gen_store_fpr64(ctx
, fp2
, fd
);
7853 tcg_temp_free_i64(fp2
);
7860 TCGv_i32 fp0
= tcg_temp_new_i32();
7861 TCGv_i32 fp1
= tcg_temp_new_i32();
7862 TCGv_i32 fp2
= tcg_temp_new_i32();
7864 gen_load_fpr32(fp0
, fs
);
7865 gen_load_fpr32(fp1
, ft
);
7866 gen_load_fpr32(fp2
, fr
);
7867 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7868 tcg_temp_free_i32(fp0
);
7869 tcg_temp_free_i32(fp1
);
7870 gen_store_fpr32(fp2
, fd
);
7871 tcg_temp_free_i32(fp2
);
7877 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7879 TCGv_i64 fp0
= tcg_temp_new_i64();
7880 TCGv_i64 fp1
= tcg_temp_new_i64();
7881 TCGv_i64 fp2
= tcg_temp_new_i64();
7883 gen_load_fpr64(ctx
, fp0
, fs
);
7884 gen_load_fpr64(ctx
, fp1
, ft
);
7885 gen_load_fpr64(ctx
, fp2
, fr
);
7886 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7887 tcg_temp_free_i64(fp0
);
7888 tcg_temp_free_i64(fp1
);
7889 gen_store_fpr64(ctx
, fp2
, fd
);
7890 tcg_temp_free_i64(fp2
);
7895 check_cp1_64bitmode(ctx
);
7897 TCGv_i64 fp0
= tcg_temp_new_i64();
7898 TCGv_i64 fp1
= tcg_temp_new_i64();
7899 TCGv_i64 fp2
= tcg_temp_new_i64();
7901 gen_load_fpr64(ctx
, fp0
, fs
);
7902 gen_load_fpr64(ctx
, fp1
, ft
);
7903 gen_load_fpr64(ctx
, fp2
, fr
);
7904 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7905 tcg_temp_free_i64(fp0
);
7906 tcg_temp_free_i64(fp1
);
7907 gen_store_fpr64(ctx
, fp2
, fd
);
7908 tcg_temp_free_i64(fp2
);
7915 TCGv_i32 fp0
= tcg_temp_new_i32();
7916 TCGv_i32 fp1
= tcg_temp_new_i32();
7917 TCGv_i32 fp2
= tcg_temp_new_i32();
7919 gen_load_fpr32(fp0
, fs
);
7920 gen_load_fpr32(fp1
, ft
);
7921 gen_load_fpr32(fp2
, fr
);
7922 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7923 tcg_temp_free_i32(fp0
);
7924 tcg_temp_free_i32(fp1
);
7925 gen_store_fpr32(fp2
, fd
);
7926 tcg_temp_free_i32(fp2
);
7932 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7934 TCGv_i64 fp0
= tcg_temp_new_i64();
7935 TCGv_i64 fp1
= tcg_temp_new_i64();
7936 TCGv_i64 fp2
= tcg_temp_new_i64();
7938 gen_load_fpr64(ctx
, fp0
, fs
);
7939 gen_load_fpr64(ctx
, fp1
, ft
);
7940 gen_load_fpr64(ctx
, fp2
, fr
);
7941 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7942 tcg_temp_free_i64(fp0
);
7943 tcg_temp_free_i64(fp1
);
7944 gen_store_fpr64(ctx
, fp2
, fd
);
7945 tcg_temp_free_i64(fp2
);
7950 check_cp1_64bitmode(ctx
);
7952 TCGv_i64 fp0
= tcg_temp_new_i64();
7953 TCGv_i64 fp1
= tcg_temp_new_i64();
7954 TCGv_i64 fp2
= tcg_temp_new_i64();
7956 gen_load_fpr64(ctx
, fp0
, fs
);
7957 gen_load_fpr64(ctx
, fp1
, ft
);
7958 gen_load_fpr64(ctx
, fp2
, fr
);
7959 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7960 tcg_temp_free_i64(fp0
);
7961 tcg_temp_free_i64(fp1
);
7962 gen_store_fpr64(ctx
, fp2
, fd
);
7963 tcg_temp_free_i64(fp2
);
7970 TCGv_i32 fp0
= tcg_temp_new_i32();
7971 TCGv_i32 fp1
= tcg_temp_new_i32();
7972 TCGv_i32 fp2
= tcg_temp_new_i32();
7974 gen_load_fpr32(fp0
, fs
);
7975 gen_load_fpr32(fp1
, ft
);
7976 gen_load_fpr32(fp2
, fr
);
7977 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7978 tcg_temp_free_i32(fp0
);
7979 tcg_temp_free_i32(fp1
);
7980 gen_store_fpr32(fp2
, fd
);
7981 tcg_temp_free_i32(fp2
);
7987 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7989 TCGv_i64 fp0
= tcg_temp_new_i64();
7990 TCGv_i64 fp1
= tcg_temp_new_i64();
7991 TCGv_i64 fp2
= tcg_temp_new_i64();
7993 gen_load_fpr64(ctx
, fp0
, fs
);
7994 gen_load_fpr64(ctx
, fp1
, ft
);
7995 gen_load_fpr64(ctx
, fp2
, fr
);
7996 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7997 tcg_temp_free_i64(fp0
);
7998 tcg_temp_free_i64(fp1
);
7999 gen_store_fpr64(ctx
, fp2
, fd
);
8000 tcg_temp_free_i64(fp2
);
8005 check_cp1_64bitmode(ctx
);
8007 TCGv_i64 fp0
= tcg_temp_new_i64();
8008 TCGv_i64 fp1
= tcg_temp_new_i64();
8009 TCGv_i64 fp2
= tcg_temp_new_i64();
8011 gen_load_fpr64(ctx
, fp0
, fs
);
8012 gen_load_fpr64(ctx
, fp1
, ft
);
8013 gen_load_fpr64(ctx
, fp2
, fr
);
8014 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
8015 tcg_temp_free_i64(fp0
);
8016 tcg_temp_free_i64(fp1
);
8017 gen_store_fpr64(ctx
, fp2
, fd
);
8018 tcg_temp_free_i64(fp2
);
8024 generate_exception (ctx
, EXCP_RI
);
8027 (void)opn
; /* avoid a compiler warning */
8028 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
8029 fregnames
[fs
], fregnames
[ft
]);
8033 gen_rdhwr (CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
)
8037 check_insn(env
, ctx
, ISA_MIPS32R2
);
8038 t0
= tcg_temp_new();
8042 save_cpu_state(ctx
, 1);
8043 gen_helper_rdhwr_cpunum(t0
);
8044 gen_store_gpr(t0
, rt
);
8047 save_cpu_state(ctx
, 1);
8048 gen_helper_rdhwr_synci_step(t0
);
8049 gen_store_gpr(t0
, rt
);
8052 save_cpu_state(ctx
, 1);
8053 gen_helper_rdhwr_cc(t0
);
8054 gen_store_gpr(t0
, rt
);
8057 save_cpu_state(ctx
, 1);
8058 gen_helper_rdhwr_ccres(t0
);
8059 gen_store_gpr(t0
, rt
);
8062 #if defined(CONFIG_USER_ONLY)
8063 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
8064 gen_store_gpr(t0
, rt
);
8067 /* XXX: Some CPUs implement this in hardware.
8068 Not supported yet. */
8070 default: /* Invalid */
8071 MIPS_INVAL("rdhwr");
8072 generate_exception(ctx
, EXCP_RI
);
8078 static void handle_delay_slot (CPUState
*env
, DisasContext
*ctx
,
8081 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8082 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8083 /* Branches completion */
8084 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8085 ctx
->bstate
= BS_BRANCH
;
8086 save_cpu_state(ctx
, 0);
8087 /* FIXME: Need to clear can_do_io. */
8088 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
8090 /* unconditional branch */
8091 MIPS_DEBUG("unconditional branch");
8092 if (proc_hflags
& MIPS_HFLAG_BX
) {
8093 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
8095 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8098 /* blikely taken case */
8099 MIPS_DEBUG("blikely branch taken");
8100 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8103 /* Conditional branch */
8104 MIPS_DEBUG("conditional branch");
8106 int l1
= gen_new_label();
8108 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8109 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
8111 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8115 /* unconditional branch to register */
8116 MIPS_DEBUG("branch to register");
8117 if (env
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
8118 TCGv t0
= tcg_temp_new();
8119 TCGv_i32 t1
= tcg_temp_new_i32();
8121 tcg_gen_andi_tl(t0
, btarget
, 0x1);
8122 tcg_gen_trunc_tl_i32(t1
, t0
);
8124 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
8125 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
8126 tcg_gen_or_i32(hflags
, hflags
, t1
);
8127 tcg_temp_free_i32(t1
);
8129 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
8131 tcg_gen_mov_tl(cpu_PC
, btarget
);
8133 if (ctx
->singlestep_enabled
) {
8134 save_cpu_state(ctx
, 0);
8135 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8140 MIPS_DEBUG("unknown branch");
8146 /* ISA extensions (ASEs) */
8147 /* MIPS16 extension to MIPS32 */
8149 /* MIPS16 major opcodes */
8151 M16_OPC_ADDIUSP
= 0x00,
8152 M16_OPC_ADDIUPC
= 0x01,
8155 M16_OPC_BEQZ
= 0x04,
8156 M16_OPC_BNEQZ
= 0x05,
8157 M16_OPC_SHIFT
= 0x06,
8159 M16_OPC_RRIA
= 0x08,
8160 M16_OPC_ADDIU8
= 0x09,
8161 M16_OPC_SLTI
= 0x0a,
8162 M16_OPC_SLTIU
= 0x0b,
8165 M16_OPC_CMPI
= 0x0e,
8169 M16_OPC_LWSP
= 0x12,
8173 M16_OPC_LWPC
= 0x16,
8177 M16_OPC_SWSP
= 0x1a,
8181 M16_OPC_EXTEND
= 0x1e,
8185 /* I8 funct field */
8204 /* RR funct field */
8238 /* I64 funct field */
8250 /* RR ry field for CNVT */
8252 RR_RY_CNVT_ZEB
= 0x0,
8253 RR_RY_CNVT_ZEH
= 0x1,
8254 RR_RY_CNVT_ZEW
= 0x2,
8255 RR_RY_CNVT_SEB
= 0x4,
8256 RR_RY_CNVT_SEH
= 0x5,
8257 RR_RY_CNVT_SEW
= 0x6,
8260 static int xlat (int r
)
8262 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
8267 static void gen_mips16_save (DisasContext
*ctx
,
8268 int xsregs
, int aregs
,
8269 int do_ra
, int do_s0
, int do_s1
,
8272 TCGv t0
= tcg_temp_new();
8273 TCGv t1
= tcg_temp_new();
8303 generate_exception(ctx
, EXCP_RI
);
8309 gen_base_offset_addr(ctx
, t0
, 29, 12);
8310 gen_load_gpr(t1
, 7);
8311 op_st_sw(t1
, t0
, ctx
);
8314 gen_base_offset_addr(ctx
, t0
, 29, 8);
8315 gen_load_gpr(t1
, 6);
8316 op_st_sw(t1
, t0
, ctx
);
8319 gen_base_offset_addr(ctx
, t0
, 29, 4);
8320 gen_load_gpr(t1
, 5);
8321 op_st_sw(t1
, t0
, ctx
);
8324 gen_base_offset_addr(ctx
, t0
, 29, 0);
8325 gen_load_gpr(t1
, 4);
8326 op_st_sw(t1
, t0
, ctx
);
8329 gen_load_gpr(t0
, 29);
8331 #define DECR_AND_STORE(reg) do { \
8332 tcg_gen_subi_tl(t0, t0, 4); \
8333 gen_load_gpr(t1, reg); \
8334 op_st_sw(t1, t0, ctx); \
8398 generate_exception(ctx
, EXCP_RI
);
8414 #undef DECR_AND_STORE
8416 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8421 static void gen_mips16_restore (DisasContext
*ctx
,
8422 int xsregs
, int aregs
,
8423 int do_ra
, int do_s0
, int do_s1
,
8427 TCGv t0
= tcg_temp_new();
8428 TCGv t1
= tcg_temp_new();
8430 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
8432 #define DECR_AND_LOAD(reg) do { \
8433 tcg_gen_subi_tl(t0, t0, 4); \
8434 op_ld_lw(t1, t0, ctx); \
8435 gen_store_gpr(t1, reg); \
8499 generate_exception(ctx
, EXCP_RI
);
8515 #undef DECR_AND_LOAD
8517 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8522 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
8523 int is_64_bit
, int extended
)
8527 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8528 generate_exception(ctx
, EXCP_RI
);
8532 t0
= tcg_temp_new();
8534 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
8535 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
8537 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8543 #if defined(TARGET_MIPS64)
8544 static void decode_i64_mips16 (CPUState
*env
, DisasContext
*ctx
,
8545 int ry
, int funct
, int16_t offset
,
8551 offset
= extended
? offset
: offset
<< 3;
8552 gen_ld(env
, ctx
, OPC_LD
, ry
, 29, offset
);
8556 offset
= extended
? offset
: offset
<< 3;
8557 gen_st(ctx
, OPC_SD
, ry
, 29, offset
);
8561 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8562 gen_st(ctx
, OPC_SD
, 31, 29, offset
);
8566 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8567 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8570 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8571 generate_exception(ctx
, EXCP_RI
);
8573 offset
= extended
? offset
: offset
<< 3;
8574 gen_ld(env
, ctx
, OPC_LDPC
, ry
, 0, offset
);
8579 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8580 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8584 offset
= extended
? offset
: offset
<< 2;
8585 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8589 offset
= extended
? offset
: offset
<< 2;
8590 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8596 static int decode_extended_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8599 int extend
= lduw_code(ctx
->pc
+ 2);
8600 int op
, rx
, ry
, funct
, sa
;
8601 int16_t imm
, offset
;
8603 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8604 op
= (ctx
->opcode
>> 11) & 0x1f;
8605 sa
= (ctx
->opcode
>> 22) & 0x1f;
8606 funct
= (ctx
->opcode
>> 8) & 0x7;
8607 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8608 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8609 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8610 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8611 | (ctx
->opcode
& 0x1f));
8613 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8616 case M16_OPC_ADDIUSP
:
8617 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8619 case M16_OPC_ADDIUPC
:
8620 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8623 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8624 /* No delay slot, so just process as a normal instruction */
8627 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8628 /* No delay slot, so just process as a normal instruction */
8631 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8632 /* No delay slot, so just process as a normal instruction */
8635 switch (ctx
->opcode
& 0x3) {
8637 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8640 #if defined(TARGET_MIPS64)
8642 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8644 generate_exception(ctx
, EXCP_RI
);
8648 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8651 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8655 #if defined(TARGET_MIPS64)
8658 gen_ld(env
, ctx
, OPC_LD
, ry
, rx
, offset
);
8662 imm
= ctx
->opcode
& 0xf;
8663 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8664 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8665 imm
= (int16_t) (imm
<< 1) >> 1;
8666 if ((ctx
->opcode
>> 4) & 0x1) {
8667 #if defined(TARGET_MIPS64)
8669 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8671 generate_exception(ctx
, EXCP_RI
);
8674 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8677 case M16_OPC_ADDIU8
:
8678 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8681 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8684 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8689 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8692 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8695 gen_st(ctx
, OPC_SW
, 31, 29, imm
);
8698 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8702 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8703 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8704 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8705 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8706 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8707 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8708 | (ctx
->opcode
& 0xf)) << 3;
8710 if (ctx
->opcode
& (1 << 7)) {
8711 gen_mips16_save(ctx
, xsregs
, aregs
,
8712 do_ra
, do_s0
, do_s1
,
8715 gen_mips16_restore(ctx
, xsregs
, aregs
,
8716 do_ra
, do_s0
, do_s1
,
8722 generate_exception(ctx
, EXCP_RI
);
8727 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8730 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8732 #if defined(TARGET_MIPS64)
8734 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
);
8738 gen_ld(env
, ctx
, OPC_LB
, ry
, rx
, offset
);
8741 gen_ld(env
, ctx
, OPC_LH
, ry
, rx
, offset
);
8744 gen_ld(env
, ctx
, OPC_LW
, rx
, 29, offset
);
8747 gen_ld(env
, ctx
, OPC_LW
, ry
, rx
, offset
);
8750 gen_ld(env
, ctx
, OPC_LBU
, ry
, rx
, offset
);
8753 gen_ld(env
, ctx
, OPC_LHU
, ry
, rx
, offset
);
8756 gen_ld(env
, ctx
, OPC_LWPC
, rx
, 0, offset
);
8758 #if defined(TARGET_MIPS64)
8760 gen_ld(env
, ctx
, OPC_LWU
, ry
, rx
, offset
);
8764 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
8767 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
);
8770 gen_st(ctx
, OPC_SW
, rx
, 29, offset
);
8773 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
);
8775 #if defined(TARGET_MIPS64)
8777 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8781 generate_exception(ctx
, EXCP_RI
);
8788 static int decode_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8793 int op
, cnvt_op
, op1
, offset
;
8797 op
= (ctx
->opcode
>> 11) & 0x1f;
8798 sa
= (ctx
->opcode
>> 2) & 0x7;
8799 sa
= sa
== 0 ? 8 : sa
;
8800 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8801 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8802 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8803 op1
= offset
= ctx
->opcode
& 0x1f;
8808 case M16_OPC_ADDIUSP
:
8810 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8812 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8815 case M16_OPC_ADDIUPC
:
8816 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8819 offset
= (ctx
->opcode
& 0x7ff) << 1;
8820 offset
= (int16_t)(offset
<< 4) >> 4;
8821 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8822 /* No delay slot, so just process as a normal instruction */
8825 offset
= lduw_code(ctx
->pc
+ 2);
8826 offset
= (((ctx
->opcode
& 0x1f) << 21)
8827 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8829 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALXS
: OPC_JALS
;
8830 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8835 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8836 /* No delay slot, so just process as a normal instruction */
8839 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8840 /* No delay slot, so just process as a normal instruction */
8843 switch (ctx
->opcode
& 0x3) {
8845 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8848 #if defined(TARGET_MIPS64)
8850 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8852 generate_exception(ctx
, EXCP_RI
);
8856 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8859 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8863 #if defined(TARGET_MIPS64)
8866 gen_ld(env
, ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8871 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8873 if ((ctx
->opcode
>> 4) & 1) {
8874 #if defined(TARGET_MIPS64)
8876 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8878 generate_exception(ctx
, EXCP_RI
);
8881 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8885 case M16_OPC_ADDIU8
:
8887 int16_t imm
= (int8_t) ctx
->opcode
;
8889 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8894 int16_t imm
= (uint8_t) ctx
->opcode
;
8896 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8901 int16_t imm
= (uint8_t) ctx
->opcode
;
8903 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8910 funct
= (ctx
->opcode
>> 8) & 0x7;
8913 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
8914 ((int8_t)ctx
->opcode
) << 1);
8917 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
8918 ((int8_t)ctx
->opcode
) << 1);
8921 gen_st(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
8924 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
8925 ((int8_t)ctx
->opcode
) << 3);
8929 int do_ra
= ctx
->opcode
& (1 << 6);
8930 int do_s0
= ctx
->opcode
& (1 << 5);
8931 int do_s1
= ctx
->opcode
& (1 << 4);
8932 int framesize
= ctx
->opcode
& 0xf;
8934 if (framesize
== 0) {
8937 framesize
= framesize
<< 3;
8940 if (ctx
->opcode
& (1 << 7)) {
8941 gen_mips16_save(ctx
, 0, 0,
8942 do_ra
, do_s0
, do_s1
, framesize
);
8944 gen_mips16_restore(ctx
, 0, 0,
8945 do_ra
, do_s0
, do_s1
, framesize
);
8951 int rz
= xlat(ctx
->opcode
& 0x7);
8953 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
8954 ((ctx
->opcode
>> 5) & 0x7);
8955 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
8959 reg32
= ctx
->opcode
& 0x1f;
8960 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
8963 generate_exception(ctx
, EXCP_RI
);
8970 int16_t imm
= (uint8_t) ctx
->opcode
;
8972 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
8977 int16_t imm
= (uint8_t) ctx
->opcode
;
8979 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
8982 #if defined(TARGET_MIPS64)
8985 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
8989 gen_ld(env
, ctx
, OPC_LB
, ry
, rx
, offset
);
8992 gen_ld(env
, ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
8995 gen_ld(env
, ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8998 gen_ld(env
, ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
9001 gen_ld(env
, ctx
, OPC_LBU
, ry
, rx
, offset
);
9004 gen_ld(env
, ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
9007 gen_ld(env
, ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
9009 #if defined (TARGET_MIPS64)
9012 gen_ld(env
, ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
9016 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
9019 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
9022 gen_st(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
9025 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
9029 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
9032 switch (ctx
->opcode
& 0x3) {
9034 mips32_op
= OPC_ADDU
;
9037 mips32_op
= OPC_SUBU
;
9039 #if defined(TARGET_MIPS64)
9041 mips32_op
= OPC_DADDU
;
9045 mips32_op
= OPC_DSUBU
;
9050 generate_exception(ctx
, EXCP_RI
);
9054 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
9063 int nd
= (ctx
->opcode
>> 7) & 0x1;
9064 int link
= (ctx
->opcode
>> 6) & 0x1;
9065 int ra
= (ctx
->opcode
>> 5) & 0x1;
9068 op
= nd
? OPC_JALRC
: OPC_JALRS
;
9073 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
9080 /* XXX: not clear which exception should be raised
9081 * when in debug mode...
9083 check_insn(env
, ctx
, ISA_MIPS32
);
9084 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9085 generate_exception(ctx
, EXCP_DBp
);
9087 generate_exception(ctx
, EXCP_DBp
);
9091 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
9094 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
9097 generate_exception(ctx
, EXCP_BREAK
);
9100 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
9103 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
9106 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
9108 #if defined (TARGET_MIPS64)
9111 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
9115 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
9118 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
9121 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
9124 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
9127 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
9130 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
9133 gen_HILO(ctx
, OPC_MFHI
, rx
);
9137 case RR_RY_CNVT_ZEB
:
9138 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9140 case RR_RY_CNVT_ZEH
:
9141 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9143 case RR_RY_CNVT_SEB
:
9144 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9146 case RR_RY_CNVT_SEH
:
9147 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9149 #if defined (TARGET_MIPS64)
9150 case RR_RY_CNVT_ZEW
:
9152 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9154 case RR_RY_CNVT_SEW
:
9156 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9160 generate_exception(ctx
, EXCP_RI
);
9165 gen_HILO(ctx
, OPC_MFLO
, rx
);
9167 #if defined (TARGET_MIPS64)
9170 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
9174 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
9178 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
9182 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
9186 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
9189 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
9192 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
9195 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
9197 #if defined (TARGET_MIPS64)
9200 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
9204 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
9208 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
9212 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
9216 generate_exception(ctx
, EXCP_RI
);
9220 case M16_OPC_EXTEND
:
9221 decode_extended_mips16_opc(env
, ctx
, is_branch
);
9224 #if defined(TARGET_MIPS64)
9226 funct
= (ctx
->opcode
>> 8) & 0x7;
9227 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
9231 generate_exception(ctx
, EXCP_RI
);
9238 /* microMIPS extension to MIPS32 */
9240 /* microMIPS32 major opcodes */
9279 /* 0x20 is reserved */
9289 /* 0x28 and 0x29 are reserved */
9299 /* 0x30 and 0x31 are reserved */
9309 /* 0x38 and 0x39 are reserved */
9320 /* POOL32A encoding of minor opcode field */
9323 /* These opcodes are distinguished only by bits 9..6; those bits are
9324 * what are recorded below. */
9350 /* The following can be distinguished by their lower 6 bits. */
9356 /* POOL32AXF encoding of minor opcode field extension */
9370 /* bits 13..12 for 0x01 */
9376 /* bits 13..12 for 0x2a */
9382 /* bits 13..12 for 0x32 */
9386 /* bits 15..12 for 0x2c */
9402 /* bits 15..12 for 0x34 */
9410 /* bits 15..12 for 0x3c */
9412 JR
= 0x0, /* alias */
9417 /* bits 15..12 for 0x05 */
9421 /* bits 15..12 for 0x0d */
9431 /* bits 15..12 for 0x15 */
9437 /* bits 15..12 for 0x1d */
9441 /* bits 15..12 for 0x2d */
9446 /* bits 15..12 for 0x35 */
9453 /* POOL32B encoding of minor opcode field (bits 15..12) */
9469 /* POOL32C encoding of minor opcode field (bits 15..12) */
9477 /* 0xa is reserved */
9484 /* 0x6 is reserved */
9490 /* POOL32F encoding of minor opcode field (bits 5..0) */
9493 /* These are the bit 7..6 values */
9504 /* These are the bit 8..6 values */
9548 CABS_COND_FMT
= 0x1c, /* MIPS3D */
9552 /* POOL32Fxf encoding of minor opcode extension field */
9590 /* POOL32I encoding of minor opcode field (bits 25..21) */
9615 /* These overlap and are distinguished by bit16 of the instruction */
9624 /* POOL16A encoding of minor opcode field */
9631 /* POOL16B encoding of minor opcode field */
9638 /* POOL16C encoding of minor opcode field */
9658 /* POOL16D encoding of minor opcode field */
9665 /* POOL16E encoding of minor opcode field */
9672 static int mmreg (int r
)
9674 static const int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
9679 /* Used for 16-bit store instructions. */
9680 static int mmreg2 (int r
)
9682 static const int map
[] = { 0, 17, 2, 3, 4, 5, 6, 7 };
9687 #define uMIPS_RD(op) ((op >> 7) & 0x7)
9688 #define uMIPS_RS(op) ((op >> 4) & 0x7)
9689 #define uMIPS_RS2(op) uMIPS_RS(op)
9690 #define uMIPS_RS1(op) ((op >> 1) & 0x7)
9691 #define uMIPS_RD5(op) ((op >> 5) & 0x1f)
9692 #define uMIPS_RS5(op) (op & 0x1f)
9694 /* Signed immediate */
9695 #define SIMM(op, start, width) \
9696 ((int32_t)(((op >> start) & ((~0U) >> (32-width))) \
9699 /* Zero-extended immediate */
9700 #define ZIMM(op, start, width) ((op >> start) & ((~0U) >> (32-width)))
9702 static void gen_addiur1sp (CPUState
*env
, DisasContext
*ctx
)
9704 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9706 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, 29, ((ctx
->opcode
>> 1) & 0x3f) << 2);
9709 static void gen_addiur2 (CPUState
*env
, DisasContext
*ctx
)
9711 static const int decoded_imm
[] = { 1, 4, 8, 12, 16, 20, 24, -1 };
9712 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9713 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9715 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, decoded_imm
[ZIMM(ctx
->opcode
, 1, 3)]);
9718 static void gen_addiusp (CPUState
*env
, DisasContext
*ctx
)
9720 int encoded
= ZIMM(ctx
->opcode
, 1, 9);
9724 decoded
= 256 + encoded
;
9725 } else if (encoded
<= 255) {
9727 } else if (encoded
<= 509) {
9728 decoded
= encoded
- 512;
9730 decoded
= encoded
- 768;
9733 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, decoded
<< 2);
9736 static void gen_addius5 (CPUState
*env
, DisasContext
*ctx
)
9738 int imm
= SIMM(ctx
->opcode
, 1, 4);
9739 int rd
= (ctx
->opcode
>> 5) & 0x1f;
9741 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rd
, imm
);
9744 static void gen_andi16 (CPUState
*env
, DisasContext
*ctx
)
9746 static const int decoded_imm
[] = { 128, 1, 2, 3, 4, 7, 8, 15, 16,
9747 31, 32, 63, 64, 255, 32768, 65535 };
9748 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9749 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9750 int encoded
= ZIMM(ctx
->opcode
, 0, 4);
9752 gen_logic_imm(env
, OPC_ANDI
, rd
, rs
, decoded_imm
[encoded
]);
9755 static void gen_ldst_multiple (DisasContext
*ctx
, uint32_t opc
, int reglist
,
9756 int base
, int16_t offset
)
9761 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
9762 generate_exception(ctx
, EXCP_RI
);
9766 t0
= tcg_temp_new();
9768 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9770 t1
= tcg_const_tl(reglist
);
9771 t2
= tcg_const_i32(ctx
->mem_idx
);
9773 save_cpu_state(ctx
, 1);
9776 gen_helper_lwm(t0
, t1
, t2
);
9779 gen_helper_swm(t0
, t1
, t2
);
9781 #ifdef TARGET_MIPS64
9783 gen_helper_ldm(t0
, t1
, t2
);
9786 gen_helper_sdm(t0
, t1
, t2
);
9790 MIPS_DEBUG("%s, %x, %d(%s)", opn
, reglist
, offset
, regnames
[base
]);
9793 tcg_temp_free_i32(t2
);
9797 static void gen_pool16c_insn (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
9799 int rd
= mmreg((ctx
->opcode
>> 3) & 0x7);
9800 int rs
= mmreg(ctx
->opcode
& 0x7);
9803 switch (((ctx
->opcode
) >> 4) & 0x3f) {
9808 gen_logic(env
, OPC_NOR
, rd
, rs
, 0);
9814 gen_logic(env
, OPC_XOR
, rd
, rd
, rs
);
9820 gen_logic(env
, OPC_AND
, rd
, rd
, rs
);
9826 gen_logic(env
, OPC_OR
, rd
, rd
, rs
);
9833 static const int lwm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9834 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9836 gen_ldst_multiple(ctx
, LWM32
, lwm_convert
[(ctx
->opcode
>> 4) & 0x3],
9845 static const int swm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9846 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9848 gen_ldst_multiple(ctx
, SWM32
, swm_convert
[(ctx
->opcode
>> 4) & 0x3],
9855 int reg
= ctx
->opcode
& 0x1f;
9857 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9864 int reg
= ctx
->opcode
& 0x1f;
9866 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9867 /* Let normal delay slot handling in our caller take us
9868 to the branch target. */
9880 int reg
= ctx
->opcode
& 0x1f;
9882 gen_compute_branch(ctx
, opc
, 2, reg
, 31, 0);
9888 gen_HILO(ctx
, OPC_MFHI
, uMIPS_RS5(ctx
->opcode
));
9892 gen_HILO(ctx
, OPC_MFLO
, uMIPS_RS5(ctx
->opcode
));
9895 generate_exception(ctx
, EXCP_BREAK
);
9898 /* XXX: not clear which exception should be raised
9899 * when in debug mode...
9901 check_insn(env
, ctx
, ISA_MIPS32
);
9902 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9903 generate_exception(ctx
, EXCP_DBp
);
9905 generate_exception(ctx
, EXCP_DBp
);
9911 int imm
= ZIMM(ctx
->opcode
, 0, 5);
9913 gen_compute_branch(ctx
, OPC_JR
, 2, 31, 0, 0);
9914 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
<< 2);
9915 /* Let normal delay slot handling in our caller take us
9916 to the branch target. */
9920 generate_exception(ctx
, EXCP_RI
);
9925 static void gen_ldxs (DisasContext
*ctx
, int base
, int index
, int rd
)
9927 TCGv t0
= tcg_temp_new();
9928 TCGv t1
= tcg_temp_new();
9930 gen_load_gpr(t0
, base
);
9933 gen_load_gpr(t1
, index
);
9934 tcg_gen_shli_tl(t1
, t1
, 2);
9935 gen_op_addr_add(ctx
, t0
, t1
, t0
);
9938 save_cpu_state(ctx
, 0);
9939 op_ld_lw(t1
, t0
, ctx
);
9940 gen_store_gpr(t1
, rd
);
9946 static void gen_ldst_pair (DisasContext
*ctx
, uint32_t opc
, int rd
,
9947 int base
, int16_t offset
)
9949 const char *opn
= "ldst_pair";
9952 if (ctx
->hflags
& MIPS_HFLAG_BMASK
|| rd
== 31 || rd
== base
) {
9953 generate_exception(ctx
, EXCP_RI
);
9957 t0
= tcg_temp_new();
9958 t1
= tcg_temp_new();
9960 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9964 save_cpu_state(ctx
, 0);
9965 op_ld_lw(t1
, t0
, ctx
);
9966 gen_store_gpr(t1
, rd
);
9967 tcg_gen_movi_tl(t1
, 4);
9968 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9969 op_ld_lw(t1
, t0
, ctx
);
9970 gen_store_gpr(t1
, rd
+1);
9974 save_cpu_state(ctx
, 0);
9975 gen_load_gpr(t1
, rd
);
9976 op_st_sw(t1
, t0
, ctx
);
9977 tcg_gen_movi_tl(t1
, 4);
9978 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9979 gen_load_gpr(t1
, rd
+1);
9980 op_st_sw(t1
, t0
, ctx
);
9983 #ifdef TARGET_MIPS64
9985 save_cpu_state(ctx
, 0);
9986 op_ld_ld(t1
, t0
, ctx
);
9987 gen_store_gpr(t1
, rd
);
9988 tcg_gen_movi_tl(t1
, 8);
9989 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9990 op_ld_ld(t1
, t0
, ctx
);
9991 gen_store_gpr(t1
, rd
+1);
9995 save_cpu_state(ctx
, 0);
9996 gen_load_gpr(t1
, rd
);
9997 op_st_sd(t1
, t0
, ctx
);
9998 tcg_gen_movi_tl(t1
, 8);
9999 gen_op_addr_add(ctx
, t0
, t0
, t1
);
10000 gen_load_gpr(t1
, rd
+1);
10001 op_st_sd(t1
, t0
, ctx
);
10006 (void)opn
; /* avoid a compiler warning */
10007 MIPS_DEBUG("%s, %s, %d(%s)", opn
, regnames
[rd
], offset
, regnames
[base
]);
10012 static void gen_pool32axf (CPUState
*env
, DisasContext
*ctx
, int rt
, int rs
,
10015 int extension
= (ctx
->opcode
>> 6) & 0x3f;
10016 int minor
= (ctx
->opcode
>> 12) & 0xf;
10017 uint32_t mips32_op
;
10019 switch (extension
) {
10021 mips32_op
= OPC_TEQ
;
10024 mips32_op
= OPC_TGE
;
10027 mips32_op
= OPC_TGEU
;
10030 mips32_op
= OPC_TLT
;
10033 mips32_op
= OPC_TLTU
;
10036 mips32_op
= OPC_TNE
;
10038 gen_trap(ctx
, mips32_op
, rs
, rt
, -1);
10040 #ifndef CONFIG_USER_ONLY
10044 /* Treat as NOP. */
10047 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rs
, (ctx
->opcode
>> 11) & 0x7);
10052 TCGv t0
= tcg_temp_new();
10054 gen_load_gpr(t0
, rt
);
10055 gen_mtc0(env
, ctx
, t0
, rs
, (ctx
->opcode
>> 11) & 0x7);
10063 gen_bshfl(ctx
, OPC_SEB
, rs
, rt
);
10066 gen_bshfl(ctx
, OPC_SEH
, rs
, rt
);
10069 mips32_op
= OPC_CLO
;
10072 mips32_op
= OPC_CLZ
;
10074 check_insn(env
, ctx
, ISA_MIPS32
);
10075 gen_cl(ctx
, mips32_op
, rt
, rs
);
10078 gen_rdhwr(env
, ctx
, rt
, rs
);
10081 gen_bshfl(ctx
, OPC_WSBH
, rs
, rt
);
10084 mips32_op
= OPC_MULT
;
10087 mips32_op
= OPC_MULTU
;
10090 mips32_op
= OPC_DIV
;
10093 mips32_op
= OPC_DIVU
;
10096 mips32_op
= OPC_MADD
;
10099 mips32_op
= OPC_MADDU
;
10102 mips32_op
= OPC_MSUB
;
10105 mips32_op
= OPC_MSUBU
;
10107 check_insn(env
, ctx
, ISA_MIPS32
);
10108 gen_muldiv(ctx
, mips32_op
, rs
, rt
);
10111 goto pool32axf_invalid
;
10122 generate_exception_err(ctx
, EXCP_CpU
, 2);
10125 goto pool32axf_invalid
;
10132 gen_compute_branch (ctx
, OPC_JALR
, 4, rs
, rt
, 0);
10137 gen_compute_branch (ctx
, OPC_JALRS
, 4, rs
, rt
, 0);
10141 goto pool32axf_invalid
;
10147 check_insn(env
, ctx
, ISA_MIPS32R2
);
10148 gen_load_srsgpr(rt
, rs
);
10151 check_insn(env
, ctx
, ISA_MIPS32R2
);
10152 gen_store_srsgpr(rt
, rs
);
10155 goto pool32axf_invalid
;
10158 #ifndef CONFIG_USER_ONLY
10162 mips32_op
= OPC_TLBP
;
10165 mips32_op
= OPC_TLBR
;
10168 mips32_op
= OPC_TLBWI
;
10171 mips32_op
= OPC_TLBWR
;
10174 mips32_op
= OPC_WAIT
;
10177 mips32_op
= OPC_DERET
;
10180 mips32_op
= OPC_ERET
;
10182 gen_cp0(env
, ctx
, mips32_op
, rt
, rs
);
10185 goto pool32axf_invalid
;
10192 TCGv t0
= tcg_temp_new();
10194 save_cpu_state(ctx
, 1);
10196 gen_store_gpr(t0
, rs
);
10197 /* Stop translation as we may have switched the execution mode */
10198 ctx
->bstate
= BS_STOP
;
10204 TCGv t0
= tcg_temp_new();
10206 save_cpu_state(ctx
, 1);
10208 gen_store_gpr(t0
, rs
);
10209 /* Stop translation as we may have switched the execution mode */
10210 ctx
->bstate
= BS_STOP
;
10215 goto pool32axf_invalid
;
10225 generate_exception(ctx
, EXCP_SYSCALL
);
10226 ctx
->bstate
= BS_STOP
;
10229 check_insn(env
, ctx
, ISA_MIPS32
);
10230 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
10231 generate_exception(ctx
, EXCP_DBp
);
10233 generate_exception(ctx
, EXCP_DBp
);
10237 goto pool32axf_invalid
;
10243 gen_HILO(ctx
, OPC_MFHI
, rs
);
10246 gen_HILO(ctx
, OPC_MFLO
, rs
);
10249 gen_HILO(ctx
, OPC_MTHI
, rs
);
10252 gen_HILO(ctx
, OPC_MTLO
, rs
);
10255 goto pool32axf_invalid
;
10260 MIPS_INVAL("pool32axf");
10261 generate_exception(ctx
, EXCP_RI
);
10266 /* Values for microMIPS fmt field. Variable-width, depending on which
10267 formats the instruction supports. */
10286 static void gen_pool32fxf (CPUState
*env
, DisasContext
*ctx
, int rt
, int rs
)
10288 int extension
= (ctx
->opcode
>> 6) & 0x3ff;
10289 uint32_t mips32_op
;
10291 #define FLOAT_1BIT_FMT(opc, fmt) (fmt << 8) | opc
10292 #define FLOAT_2BIT_FMT(opc, fmt) (fmt << 7) | opc
10293 #define COND_FLOAT_MOV(opc, cond) (cond << 7) | opc
10295 switch (extension
) {
10296 case FLOAT_1BIT_FMT(CFC1
, 0):
10297 mips32_op
= OPC_CFC1
;
10299 case FLOAT_1BIT_FMT(CTC1
, 0):
10300 mips32_op
= OPC_CTC1
;
10302 case FLOAT_1BIT_FMT(MFC1
, 0):
10303 mips32_op
= OPC_MFC1
;
10305 case FLOAT_1BIT_FMT(MTC1
, 0):
10306 mips32_op
= OPC_MTC1
;
10308 case FLOAT_1BIT_FMT(MFHC1
, 0):
10309 mips32_op
= OPC_MFHC1
;
10311 case FLOAT_1BIT_FMT(MTHC1
, 0):
10312 mips32_op
= OPC_MTHC1
;
10314 gen_cp1(ctx
, mips32_op
, rt
, rs
);
10317 /* Reciprocal square root */
10318 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_S
):
10319 mips32_op
= OPC_RSQRT_S
;
10321 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_D
):
10322 mips32_op
= OPC_RSQRT_D
;
10326 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_S
):
10327 mips32_op
= OPC_SQRT_S
;
10329 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_D
):
10330 mips32_op
= OPC_SQRT_D
;
10334 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_S
):
10335 mips32_op
= OPC_RECIP_S
;
10337 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_D
):
10338 mips32_op
= OPC_RECIP_D
;
10342 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_S
):
10343 mips32_op
= OPC_FLOOR_L_S
;
10345 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_D
):
10346 mips32_op
= OPC_FLOOR_L_D
;
10348 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_S
):
10349 mips32_op
= OPC_FLOOR_W_S
;
10351 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_D
):
10352 mips32_op
= OPC_FLOOR_W_D
;
10356 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_S
):
10357 mips32_op
= OPC_CEIL_L_S
;
10359 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_D
):
10360 mips32_op
= OPC_CEIL_L_D
;
10362 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_S
):
10363 mips32_op
= OPC_CEIL_W_S
;
10365 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_D
):
10366 mips32_op
= OPC_CEIL_W_D
;
10370 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_S
):
10371 mips32_op
= OPC_TRUNC_L_S
;
10373 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_D
):
10374 mips32_op
= OPC_TRUNC_L_D
;
10376 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_S
):
10377 mips32_op
= OPC_TRUNC_W_S
;
10379 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_D
):
10380 mips32_op
= OPC_TRUNC_W_D
;
10384 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_S
):
10385 mips32_op
= OPC_ROUND_L_S
;
10387 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_D
):
10388 mips32_op
= OPC_ROUND_L_D
;
10390 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_S
):
10391 mips32_op
= OPC_ROUND_W_S
;
10393 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_D
):
10394 mips32_op
= OPC_ROUND_W_D
;
10397 /* Integer to floating-point conversion */
10398 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_S
):
10399 mips32_op
= OPC_CVT_L_S
;
10401 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_D
):
10402 mips32_op
= OPC_CVT_L_D
;
10404 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_S
):
10405 mips32_op
= OPC_CVT_W_S
;
10407 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_D
):
10408 mips32_op
= OPC_CVT_W_D
;
10411 /* Paired-foo conversions */
10412 case FLOAT_1BIT_FMT(CVT_S_PL
, 0):
10413 mips32_op
= OPC_CVT_S_PL
;
10415 case FLOAT_1BIT_FMT(CVT_S_PU
, 0):
10416 mips32_op
= OPC_CVT_S_PU
;
10418 case FLOAT_1BIT_FMT(CVT_PW_PS
, 0):
10419 mips32_op
= OPC_CVT_PW_PS
;
10421 case FLOAT_1BIT_FMT(CVT_PS_PW
, 0):
10422 mips32_op
= OPC_CVT_PS_PW
;
10425 /* Floating-point moves */
10426 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_S
):
10427 mips32_op
= OPC_MOV_S
;
10429 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_D
):
10430 mips32_op
= OPC_MOV_D
;
10432 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_PS
):
10433 mips32_op
= OPC_MOV_PS
;
10436 /* Absolute value */
10437 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_S
):
10438 mips32_op
= OPC_ABS_S
;
10440 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_D
):
10441 mips32_op
= OPC_ABS_D
;
10443 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_PS
):
10444 mips32_op
= OPC_ABS_PS
;
10448 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_S
):
10449 mips32_op
= OPC_NEG_S
;
10451 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_D
):
10452 mips32_op
= OPC_NEG_D
;
10454 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_PS
):
10455 mips32_op
= OPC_NEG_PS
;
10458 /* Reciprocal square root step */
10459 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_S
):
10460 mips32_op
= OPC_RSQRT1_S
;
10462 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_D
):
10463 mips32_op
= OPC_RSQRT1_D
;
10465 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_PS
):
10466 mips32_op
= OPC_RSQRT1_PS
;
10469 /* Reciprocal step */
10470 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_S
):
10471 mips32_op
= OPC_RECIP1_S
;
10473 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_D
):
10474 mips32_op
= OPC_RECIP1_S
;
10476 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_PS
):
10477 mips32_op
= OPC_RECIP1_PS
;
10480 /* Conversions from double */
10481 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_S
):
10482 mips32_op
= OPC_CVT_D_S
;
10484 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_W
):
10485 mips32_op
= OPC_CVT_D_W
;
10487 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_L
):
10488 mips32_op
= OPC_CVT_D_L
;
10491 /* Conversions from single */
10492 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_D
):
10493 mips32_op
= OPC_CVT_S_D
;
10495 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_W
):
10496 mips32_op
= OPC_CVT_S_W
;
10498 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_L
):
10499 mips32_op
= OPC_CVT_S_L
;
10501 gen_farith(ctx
, mips32_op
, -1, rs
, rt
, 0);
10504 /* Conditional moves on floating-point codes */
10505 case COND_FLOAT_MOV(MOVT
, 0):
10506 case COND_FLOAT_MOV(MOVT
, 1):
10507 case COND_FLOAT_MOV(MOVT
, 2):
10508 case COND_FLOAT_MOV(MOVT
, 3):
10509 case COND_FLOAT_MOV(MOVT
, 4):
10510 case COND_FLOAT_MOV(MOVT
, 5):
10511 case COND_FLOAT_MOV(MOVT
, 6):
10512 case COND_FLOAT_MOV(MOVT
, 7):
10513 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 1);
10515 case COND_FLOAT_MOV(MOVF
, 0):
10516 case COND_FLOAT_MOV(MOVF
, 1):
10517 case COND_FLOAT_MOV(MOVF
, 2):
10518 case COND_FLOAT_MOV(MOVF
, 3):
10519 case COND_FLOAT_MOV(MOVF
, 4):
10520 case COND_FLOAT_MOV(MOVF
, 5):
10521 case COND_FLOAT_MOV(MOVF
, 6):
10522 case COND_FLOAT_MOV(MOVF
, 7):
10523 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 0);
10526 MIPS_INVAL("pool32fxf");
10527 generate_exception(ctx
, EXCP_RI
);
10532 static void decode_micromips32_opc (CPUState
*env
, DisasContext
*ctx
,
10533 uint16_t insn_hw1
, int *is_branch
)
10537 int rt
, rs
, rd
, rr
;
10539 uint32_t op
, minor
, mips32_op
;
10540 uint32_t cond
, fmt
, cc
;
10542 insn
= lduw_code(ctx
->pc
+ 2);
10543 ctx
->opcode
= (ctx
->opcode
<< 16) | insn
;
10545 rt
= (ctx
->opcode
>> 21) & 0x1f;
10546 rs
= (ctx
->opcode
>> 16) & 0x1f;
10547 rd
= (ctx
->opcode
>> 11) & 0x1f;
10548 rr
= (ctx
->opcode
>> 6) & 0x1f;
10549 imm
= (int16_t) ctx
->opcode
;
10551 op
= (ctx
->opcode
>> 26) & 0x3f;
10554 minor
= ctx
->opcode
& 0x3f;
10557 minor
= (ctx
->opcode
>> 6) & 0xf;
10560 mips32_op
= OPC_SLL
;
10563 mips32_op
= OPC_SRA
;
10566 mips32_op
= OPC_SRL
;
10569 mips32_op
= OPC_ROTR
;
10571 gen_shift_imm(env
, ctx
, mips32_op
, rt
, rs
, rd
);
10574 goto pool32a_invalid
;
10578 minor
= (ctx
->opcode
>> 6) & 0xf;
10582 mips32_op
= OPC_ADD
;
10585 mips32_op
= OPC_ADDU
;
10588 mips32_op
= OPC_SUB
;
10591 mips32_op
= OPC_SUBU
;
10594 mips32_op
= OPC_MUL
;
10596 gen_arith(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10600 mips32_op
= OPC_SLLV
;
10603 mips32_op
= OPC_SRLV
;
10606 mips32_op
= OPC_SRAV
;
10609 mips32_op
= OPC_ROTRV
;
10611 gen_shift(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10613 /* Logical operations */
10615 mips32_op
= OPC_AND
;
10618 mips32_op
= OPC_OR
;
10621 mips32_op
= OPC_NOR
;
10624 mips32_op
= OPC_XOR
;
10626 gen_logic(env
, mips32_op
, rd
, rs
, rt
);
10628 /* Set less than */
10630 mips32_op
= OPC_SLT
;
10633 mips32_op
= OPC_SLTU
;
10635 gen_slt(env
, mips32_op
, rd
, rs
, rt
);
10638 goto pool32a_invalid
;
10642 minor
= (ctx
->opcode
>> 6) & 0xf;
10644 /* Conditional moves */
10646 mips32_op
= OPC_MOVN
;
10649 mips32_op
= OPC_MOVZ
;
10651 gen_cond_move(env
, mips32_op
, rd
, rs
, rt
);
10654 gen_ldxs(ctx
, rs
, rt
, rd
);
10657 goto pool32a_invalid
;
10661 gen_bitops(ctx
, OPC_INS
, rt
, rs
, rr
, rd
);
10664 gen_bitops(ctx
, OPC_EXT
, rt
, rs
, rr
, rd
);
10667 gen_pool32axf(env
, ctx
, rt
, rs
, is_branch
);
10670 generate_exception(ctx
, EXCP_BREAK
);
10674 MIPS_INVAL("pool32a");
10675 generate_exception(ctx
, EXCP_RI
);
10680 minor
= (ctx
->opcode
>> 12) & 0xf;
10683 /* Treat as no-op. */
10687 /* COP2: Not implemented. */
10688 generate_exception_err(ctx
, EXCP_CpU
, 2);
10692 #ifdef TARGET_MIPS64
10696 gen_ldst_pair(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10700 #ifdef TARGET_MIPS64
10704 gen_ldst_multiple(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10707 MIPS_INVAL("pool32b");
10708 generate_exception(ctx
, EXCP_RI
);
10713 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
10714 minor
= ctx
->opcode
& 0x3f;
10715 check_cp1_enabled(ctx
);
10718 mips32_op
= OPC_ALNV_PS
;
10721 mips32_op
= OPC_MADD_S
;
10724 mips32_op
= OPC_MADD_D
;
10727 mips32_op
= OPC_MADD_PS
;
10730 mips32_op
= OPC_MSUB_S
;
10733 mips32_op
= OPC_MSUB_D
;
10736 mips32_op
= OPC_MSUB_PS
;
10739 mips32_op
= OPC_NMADD_S
;
10742 mips32_op
= OPC_NMADD_D
;
10745 mips32_op
= OPC_NMADD_PS
;
10748 mips32_op
= OPC_NMSUB_S
;
10751 mips32_op
= OPC_NMSUB_D
;
10754 mips32_op
= OPC_NMSUB_PS
;
10756 gen_flt3_arith(ctx
, mips32_op
, rd
, rr
, rs
, rt
);
10758 case CABS_COND_FMT
:
10759 cond
= (ctx
->opcode
>> 6) & 0xf;
10760 cc
= (ctx
->opcode
>> 13) & 0x7;
10761 fmt
= (ctx
->opcode
>> 10) & 0x3;
10764 gen_cmpabs_s(ctx
, cond
, rt
, rs
, cc
);
10767 gen_cmpabs_d(ctx
, cond
, rt
, rs
, cc
);
10770 gen_cmpabs_ps(ctx
, cond
, rt
, rs
, cc
);
10773 goto pool32f_invalid
;
10777 cond
= (ctx
->opcode
>> 6) & 0xf;
10778 cc
= (ctx
->opcode
>> 13) & 0x7;
10779 fmt
= (ctx
->opcode
>> 10) & 0x3;
10782 gen_cmp_s(ctx
, cond
, rt
, rs
, cc
);
10785 gen_cmp_d(ctx
, cond
, rt
, rs
, cc
);
10788 gen_cmp_ps(ctx
, cond
, rt
, rs
, cc
);
10791 goto pool32f_invalid
;
10795 gen_pool32fxf(env
, ctx
, rt
, rs
);
10799 switch ((ctx
->opcode
>> 6) & 0x7) {
10801 mips32_op
= OPC_PLL_PS
;
10804 mips32_op
= OPC_PLU_PS
;
10807 mips32_op
= OPC_PUL_PS
;
10810 mips32_op
= OPC_PUU_PS
;
10813 mips32_op
= OPC_CVT_PS_S
;
10815 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10818 goto pool32f_invalid
;
10823 switch ((ctx
->opcode
>> 6) & 0x7) {
10825 mips32_op
= OPC_LWXC1
;
10828 mips32_op
= OPC_SWXC1
;
10831 mips32_op
= OPC_LDXC1
;
10834 mips32_op
= OPC_SDXC1
;
10837 mips32_op
= OPC_LUXC1
;
10840 mips32_op
= OPC_SUXC1
;
10842 gen_flt3_ldst(ctx
, mips32_op
, rd
, rd
, rt
, rs
);
10845 goto pool32f_invalid
;
10850 fmt
= (ctx
->opcode
>> 9) & 0x3;
10851 switch ((ctx
->opcode
>> 6) & 0x7) {
10855 mips32_op
= OPC_RSQRT2_S
;
10858 mips32_op
= OPC_RSQRT2_D
;
10861 mips32_op
= OPC_RSQRT2_PS
;
10864 goto pool32f_invalid
;
10870 mips32_op
= OPC_RECIP2_S
;
10873 mips32_op
= OPC_RECIP2_D
;
10876 mips32_op
= OPC_RECIP2_PS
;
10879 goto pool32f_invalid
;
10883 mips32_op
= OPC_ADDR_PS
;
10886 mips32_op
= OPC_MULR_PS
;
10888 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10891 goto pool32f_invalid
;
10895 /* MOV[FT].fmt and PREFX */
10896 cc
= (ctx
->opcode
>> 13) & 0x7;
10897 fmt
= (ctx
->opcode
>> 9) & 0x3;
10898 switch ((ctx
->opcode
>> 6) & 0x7) {
10902 gen_movcf_s(rs
, rt
, cc
, 0);
10905 gen_movcf_d(ctx
, rs
, rt
, cc
, 0);
10908 gen_movcf_ps(rs
, rt
, cc
, 0);
10911 goto pool32f_invalid
;
10917 gen_movcf_s(rs
, rt
, cc
, 1);
10920 gen_movcf_d(ctx
, rs
, rt
, cc
, 1);
10923 gen_movcf_ps(rs
, rt
, cc
, 1);
10926 goto pool32f_invalid
;
10932 goto pool32f_invalid
;
10935 #define FINSN_3ARG_SDPS(prfx) \
10936 switch ((ctx->opcode >> 8) & 0x3) { \
10938 mips32_op = OPC_##prfx##_S; \
10941 mips32_op = OPC_##prfx##_D; \
10943 case FMT_SDPS_PS: \
10944 mips32_op = OPC_##prfx##_PS; \
10947 goto pool32f_invalid; \
10950 /* regular FP ops */
10951 switch ((ctx
->opcode
>> 6) & 0x3) {
10953 FINSN_3ARG_SDPS(ADD
);
10956 FINSN_3ARG_SDPS(SUB
);
10959 FINSN_3ARG_SDPS(MUL
);
10962 fmt
= (ctx
->opcode
>> 8) & 0x3;
10964 mips32_op
= OPC_DIV_D
;
10965 } else if (fmt
== 0) {
10966 mips32_op
= OPC_DIV_S
;
10968 goto pool32f_invalid
;
10972 goto pool32f_invalid
;
10977 switch ((ctx
->opcode
>> 6) & 0x3) {
10979 FINSN_3ARG_SDPS(MOVN
);
10982 FINSN_3ARG_SDPS(MOVZ
);
10985 goto pool32f_invalid
;
10989 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10993 MIPS_INVAL("pool32f");
10994 generate_exception(ctx
, EXCP_RI
);
10998 generate_exception_err(ctx
, EXCP_CpU
, 1);
11002 minor
= (ctx
->opcode
>> 21) & 0x1f;
11005 mips32_op
= OPC_BLTZ
;
11008 mips32_op
= OPC_BLTZAL
;
11011 mips32_op
= OPC_BLTZALS
;
11014 mips32_op
= OPC_BGEZ
;
11017 mips32_op
= OPC_BGEZAL
;
11020 mips32_op
= OPC_BGEZALS
;
11023 mips32_op
= OPC_BLEZ
;
11026 mips32_op
= OPC_BGTZ
;
11028 gen_compute_branch(ctx
, mips32_op
, 4, rs
, -1, imm
<< 1);
11034 mips32_op
= OPC_TLTI
;
11037 mips32_op
= OPC_TGEI
;
11040 mips32_op
= OPC_TLTIU
;
11043 mips32_op
= OPC_TGEIU
;
11046 mips32_op
= OPC_TNEI
;
11049 mips32_op
= OPC_TEQI
;
11051 gen_trap(ctx
, mips32_op
, rs
, -1, imm
);
11056 gen_compute_branch(ctx
, minor
== BNEZC
? OPC_BNE
: OPC_BEQ
,
11057 4, rs
, 0, imm
<< 1);
11058 /* Compact branches don't have a delay slot, so just let
11059 the normal delay slot handling take us to the branch
11063 gen_logic_imm(env
, OPC_LUI
, rs
, -1, imm
);
11069 /* COP2: Not implemented. */
11070 generate_exception_err(ctx
, EXCP_CpU
, 2);
11073 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1FANY2
: OPC_BC1F
;
11076 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1TANY2
: OPC_BC1T
;
11079 mips32_op
= OPC_BC1FANY4
;
11082 mips32_op
= OPC_BC1TANY4
;
11085 check_insn(env
, ctx
, ASE_MIPS3D
);
11088 gen_compute_branch1(env
, ctx
, mips32_op
,
11089 (ctx
->opcode
>> 18) & 0x7, imm
<< 1);
11094 /* MIPS DSP: not implemented */
11097 MIPS_INVAL("pool32i");
11098 generate_exception(ctx
, EXCP_RI
);
11103 minor
= (ctx
->opcode
>> 12) & 0xf;
11106 mips32_op
= OPC_LWL
;
11109 mips32_op
= OPC_SWL
;
11112 mips32_op
= OPC_LWR
;
11115 mips32_op
= OPC_SWR
;
11117 #if defined(TARGET_MIPS64)
11119 mips32_op
= OPC_LDL
;
11122 mips32_op
= OPC_SDL
;
11125 mips32_op
= OPC_LDR
;
11128 mips32_op
= OPC_SDR
;
11131 mips32_op
= OPC_LWU
;
11134 mips32_op
= OPC_LLD
;
11138 mips32_op
= OPC_LL
;
11141 gen_ld(env
, ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11144 gen_st(ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11147 gen_st_cond(ctx
, OPC_SC
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11149 #if defined(TARGET_MIPS64)
11151 gen_st_cond(ctx
, OPC_SCD
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11155 /* Treat as no-op */
11158 MIPS_INVAL("pool32c");
11159 generate_exception(ctx
, EXCP_RI
);
11164 mips32_op
= OPC_ADDI
;
11167 mips32_op
= OPC_ADDIU
;
11169 gen_arith_imm(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11172 /* Logical operations */
11174 mips32_op
= OPC_ORI
;
11177 mips32_op
= OPC_XORI
;
11180 mips32_op
= OPC_ANDI
;
11182 gen_logic_imm(env
, mips32_op
, rt
, rs
, imm
);
11185 /* Set less than immediate */
11187 mips32_op
= OPC_SLTI
;
11190 mips32_op
= OPC_SLTIU
;
11192 gen_slt_imm(env
, mips32_op
, rt
, rs
, imm
);
11195 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
11196 gen_compute_branch(ctx
, OPC_JALX
, 4, rt
, rs
, offset
);
11200 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1;
11201 gen_compute_branch(ctx
, OPC_JALS
, 4, rt
, rs
, offset
);
11205 gen_compute_branch(ctx
, OPC_BEQ
, 4, rt
, rs
, imm
<< 1);
11209 gen_compute_branch(ctx
, OPC_BNE
, 4, rt
, rs
, imm
<< 1);
11213 gen_compute_branch(ctx
, OPC_J
, 4, rt
, rs
,
11214 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
11218 gen_compute_branch(ctx
, OPC_JAL
, 4, rt
, rs
,
11219 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
11222 /* Floating point (COP1) */
11224 mips32_op
= OPC_LWC1
;
11227 mips32_op
= OPC_LDC1
;
11230 mips32_op
= OPC_SWC1
;
11233 mips32_op
= OPC_SDC1
;
11235 gen_cop1_ldst(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11239 int reg
= mmreg(ZIMM(ctx
->opcode
, 23, 3));
11240 int offset
= SIMM(ctx
->opcode
, 0, 23) << 2;
11242 gen_addiupc(ctx
, reg
, offset
, 0, 0);
11245 /* Loads and stores */
11247 mips32_op
= OPC_LB
;
11250 mips32_op
= OPC_LBU
;
11253 mips32_op
= OPC_LH
;
11256 mips32_op
= OPC_LHU
;
11259 mips32_op
= OPC_LW
;
11261 #ifdef TARGET_MIPS64
11263 mips32_op
= OPC_LD
;
11266 mips32_op
= OPC_SD
;
11270 mips32_op
= OPC_SB
;
11273 mips32_op
= OPC_SH
;
11276 mips32_op
= OPC_SW
;
11279 gen_ld(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11282 gen_st(ctx
, mips32_op
, rt
, rs
, imm
);
11285 generate_exception(ctx
, EXCP_RI
);
11290 static int decode_micromips_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
11294 /* make sure instructions are on a halfword boundary */
11295 if (ctx
->pc
& 0x1) {
11296 env
->CP0_BadVAddr
= ctx
->pc
;
11297 generate_exception(ctx
, EXCP_AdEL
);
11298 ctx
->bstate
= BS_STOP
;
11302 op
= (ctx
->opcode
>> 10) & 0x3f;
11303 /* Enforce properly-sized instructions in a delay slot */
11304 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
11305 int bits
= ctx
->hflags
& MIPS_HFLAG_BMASK_EXT
;
11339 case POOL48A
: /* ??? */
11344 if (bits
& MIPS_HFLAG_BDS16
) {
11345 generate_exception(ctx
, EXCP_RI
);
11346 /* Just stop translation; the user is confused. */
11347 ctx
->bstate
= BS_STOP
;
11372 if (bits
& MIPS_HFLAG_BDS32
) {
11373 generate_exception(ctx
, EXCP_RI
);
11374 /* Just stop translation; the user is confused. */
11375 ctx
->bstate
= BS_STOP
;
11386 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11387 int rs1
= mmreg(uMIPS_RS1(ctx
->opcode
));
11388 int rs2
= mmreg(uMIPS_RS2(ctx
->opcode
));
11391 switch (ctx
->opcode
& 0x1) {
11400 gen_arith(env
, ctx
, opc
, rd
, rs1
, rs2
);
11405 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11406 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
11407 int amount
= (ctx
->opcode
>> 1) & 0x7;
11409 amount
= amount
== 0 ? 8 : amount
;
11411 switch (ctx
->opcode
& 0x1) {
11420 gen_shift_imm(env
, ctx
, opc
, rd
, rs
, amount
);
11424 gen_pool16c_insn(env
, ctx
, is_branch
);
11428 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11429 int rb
= 28; /* GP */
11430 int16_t offset
= SIMM(ctx
->opcode
, 0, 7) << 2;
11432 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11436 if (ctx
->opcode
& 1) {
11437 generate_exception(ctx
, EXCP_RI
);
11440 int enc_dest
= uMIPS_RD(ctx
->opcode
);
11441 int enc_rt
= uMIPS_RS2(ctx
->opcode
);
11442 int enc_rs
= uMIPS_RS1(ctx
->opcode
);
11443 int rd
, rs
, re
, rt
;
11444 static const int rd_enc
[] = { 5, 5, 6, 4, 4, 4, 4, 4 };
11445 static const int re_enc
[] = { 6, 7, 7, 21, 22, 5, 6, 7 };
11446 static const int rs_rt_enc
[] = { 0, 17, 2, 3, 16, 18, 19, 20 };
11448 rd
= rd_enc
[enc_dest
];
11449 re
= re_enc
[enc_dest
];
11450 rs
= rs_rt_enc
[enc_rs
];
11451 rt
= rs_rt_enc
[enc_rt
];
11453 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11454 gen_arith_imm(env
, ctx
, OPC_ADDIU
, re
, rt
, 0);
11459 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11460 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11461 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11462 offset
= (offset
== 0xf ? -1 : offset
);
11464 gen_ld(env
, ctx
, OPC_LBU
, rd
, rb
, offset
);
11469 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11470 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11471 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11473 gen_ld(env
, ctx
, OPC_LHU
, rd
, rb
, offset
);
11478 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11479 int rb
= 29; /* SP */
11480 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11482 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11487 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11488 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11489 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11491 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11496 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11497 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11498 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11500 gen_st(ctx
, OPC_SB
, rd
, rb
, offset
);
11505 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11506 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11507 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11509 gen_st(ctx
, OPC_SH
, rd
, rb
, offset
);
11514 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11515 int rb
= 29; /* SP */
11516 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11518 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11523 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11524 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11525 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11527 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11532 int rd
= uMIPS_RD5(ctx
->opcode
);
11533 int rs
= uMIPS_RS5(ctx
->opcode
);
11535 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11539 gen_andi16(env
, ctx
);
11542 switch (ctx
->opcode
& 0x1) {
11544 gen_addius5(env
, ctx
);
11547 gen_addiusp(env
, ctx
);
11552 switch (ctx
->opcode
& 0x1) {
11554 gen_addiur2(env
, ctx
);
11557 gen_addiur1sp(env
, ctx
);
11562 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0,
11563 SIMM(ctx
->opcode
, 0, 10) << 1);
11568 gen_compute_branch(ctx
, op
== BNEZ16
? OPC_BNE
: OPC_BEQ
, 2,
11569 mmreg(uMIPS_RD(ctx
->opcode
)),
11570 0, SIMM(ctx
->opcode
, 0, 7) << 1);
11575 int reg
= mmreg(uMIPS_RD(ctx
->opcode
));
11576 int imm
= ZIMM(ctx
->opcode
, 0, 7);
11578 imm
= (imm
== 0x7f ? -1 : imm
);
11579 tcg_gen_movi_tl(cpu_gpr
[reg
], imm
);
11589 generate_exception(ctx
, EXCP_RI
);
11592 decode_micromips32_opc (env
, ctx
, op
, is_branch
);
11599 /* SmartMIPS extension to MIPS32 */
11601 #if defined(TARGET_MIPS64)
11603 /* MDMX extension to MIPS64 */
11607 static void decode_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
11610 int rs
, rt
, rd
, sa
;
11611 uint32_t op
, op1
, op2
;
11614 /* make sure instructions are on a word boundary */
11615 if (ctx
->pc
& 0x3) {
11616 env
->CP0_BadVAddr
= ctx
->pc
;
11617 generate_exception(ctx
, EXCP_AdEL
);
11621 /* Handle blikely not taken case */
11622 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
11623 int l1
= gen_new_label();
11625 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
11626 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
11627 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
11628 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
11632 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
11633 tcg_gen_debug_insn_start(ctx
->pc
);
11635 op
= MASK_OP_MAJOR(ctx
->opcode
);
11636 rs
= (ctx
->opcode
>> 21) & 0x1f;
11637 rt
= (ctx
->opcode
>> 16) & 0x1f;
11638 rd
= (ctx
->opcode
>> 11) & 0x1f;
11639 sa
= (ctx
->opcode
>> 6) & 0x1f;
11640 imm
= (int16_t)ctx
->opcode
;
11643 op1
= MASK_SPECIAL(ctx
->opcode
);
11645 case OPC_SLL
: /* Shift with immediate */
11647 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11650 switch ((ctx
->opcode
>> 21) & 0x1f) {
11652 /* rotr is decoded as srl on non-R2 CPUs */
11653 if (env
->insn_flags
& ISA_MIPS32R2
) {
11658 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11661 generate_exception(ctx
, EXCP_RI
);
11665 case OPC_MOVN
: /* Conditional move */
11667 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
|
11668 INSN_LOONGSON2E
| INSN_LOONGSON2F
);
11669 gen_cond_move(env
, op1
, rd
, rs
, rt
);
11671 case OPC_ADD
... OPC_SUBU
:
11672 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11674 case OPC_SLLV
: /* Shifts */
11676 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11679 switch ((ctx
->opcode
>> 6) & 0x1f) {
11681 /* rotrv is decoded as srlv on non-R2 CPUs */
11682 if (env
->insn_flags
& ISA_MIPS32R2
) {
11687 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11690 generate_exception(ctx
, EXCP_RI
);
11694 case OPC_SLT
: /* Set on less than */
11696 gen_slt(env
, op1
, rd
, rs
, rt
);
11698 case OPC_AND
: /* Logic*/
11702 gen_logic(env
, op1
, rd
, rs
, rt
);
11704 case OPC_MULT
... OPC_DIVU
:
11706 check_insn(env
, ctx
, INSN_VR54XX
);
11707 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
11708 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
11710 gen_muldiv(ctx
, op1
, rs
, rt
);
11712 case OPC_JR
... OPC_JALR
:
11713 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
11716 case OPC_TGE
... OPC_TEQ
: /* Traps */
11718 gen_trap(ctx
, op1
, rs
, rt
, -1);
11720 case OPC_MFHI
: /* Move from HI/LO */
11722 gen_HILO(ctx
, op1
, rd
);
11725 case OPC_MTLO
: /* Move to HI/LO */
11726 gen_HILO(ctx
, op1
, rs
);
11728 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
11729 #ifdef MIPS_STRICT_STANDARD
11730 MIPS_INVAL("PMON / selsl");
11731 generate_exception(ctx
, EXCP_RI
);
11733 gen_helper_0i(pmon
, sa
);
11737 generate_exception(ctx
, EXCP_SYSCALL
);
11738 ctx
->bstate
= BS_STOP
;
11741 generate_exception(ctx
, EXCP_BREAK
);
11744 #ifdef MIPS_STRICT_STANDARD
11745 MIPS_INVAL("SPIM");
11746 generate_exception(ctx
, EXCP_RI
);
11748 /* Implemented as RI exception for now. */
11749 MIPS_INVAL("spim (unofficial)");
11750 generate_exception(ctx
, EXCP_RI
);
11754 /* Treat as NOP. */
11758 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
11759 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
11760 check_cp1_enabled(ctx
);
11761 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
11762 (ctx
->opcode
>> 16) & 1);
11764 generate_exception_err(ctx
, EXCP_CpU
, 1);
11768 #if defined(TARGET_MIPS64)
11769 /* MIPS64 specific opcodes */
11774 check_insn(env
, ctx
, ISA_MIPS3
);
11775 check_mips_64(ctx
);
11776 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11779 switch ((ctx
->opcode
>> 21) & 0x1f) {
11781 /* drotr is decoded as dsrl on non-R2 CPUs */
11782 if (env
->insn_flags
& ISA_MIPS32R2
) {
11787 check_insn(env
, ctx
, ISA_MIPS3
);
11788 check_mips_64(ctx
);
11789 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11792 generate_exception(ctx
, EXCP_RI
);
11797 switch ((ctx
->opcode
>> 21) & 0x1f) {
11799 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
11800 if (env
->insn_flags
& ISA_MIPS32R2
) {
11805 check_insn(env
, ctx
, ISA_MIPS3
);
11806 check_mips_64(ctx
);
11807 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11810 generate_exception(ctx
, EXCP_RI
);
11814 case OPC_DADD
... OPC_DSUBU
:
11815 check_insn(env
, ctx
, ISA_MIPS3
);
11816 check_mips_64(ctx
);
11817 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11821 check_insn(env
, ctx
, ISA_MIPS3
);
11822 check_mips_64(ctx
);
11823 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11826 switch ((ctx
->opcode
>> 6) & 0x1f) {
11828 /* drotrv is decoded as dsrlv on non-R2 CPUs */
11829 if (env
->insn_flags
& ISA_MIPS32R2
) {
11834 check_insn(env
, ctx
, ISA_MIPS3
);
11835 check_mips_64(ctx
);
11836 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11839 generate_exception(ctx
, EXCP_RI
);
11843 case OPC_DMULT
... OPC_DDIVU
:
11844 check_insn(env
, ctx
, ISA_MIPS3
);
11845 check_mips_64(ctx
);
11846 gen_muldiv(ctx
, op1
, rs
, rt
);
11849 default: /* Invalid */
11850 MIPS_INVAL("special");
11851 generate_exception(ctx
, EXCP_RI
);
11856 op1
= MASK_SPECIAL2(ctx
->opcode
);
11858 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
11859 case OPC_MSUB
... OPC_MSUBU
:
11860 check_insn(env
, ctx
, ISA_MIPS32
);
11861 gen_muldiv(ctx
, op1
, rs
, rt
);
11864 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11868 check_insn(env
, ctx
, ISA_MIPS32
);
11869 gen_cl(ctx
, op1
, rd
, rs
);
11872 /* XXX: not clear which exception should be raised
11873 * when in debug mode...
11875 check_insn(env
, ctx
, ISA_MIPS32
);
11876 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
11877 generate_exception(ctx
, EXCP_DBp
);
11879 generate_exception(ctx
, EXCP_DBp
);
11881 /* Treat as NOP. */
11884 case OPC_DIVU_G_2F
:
11885 case OPC_MULT_G_2F
:
11886 case OPC_MULTU_G_2F
:
11888 case OPC_MODU_G_2F
:
11889 check_insn(env
, ctx
, INSN_LOONGSON2F
);
11890 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11892 #if defined(TARGET_MIPS64)
11895 check_insn(env
, ctx
, ISA_MIPS64
);
11896 check_mips_64(ctx
);
11897 gen_cl(ctx
, op1
, rd
, rs
);
11899 case OPC_DMULT_G_2F
:
11900 case OPC_DMULTU_G_2F
:
11901 case OPC_DDIV_G_2F
:
11902 case OPC_DDIVU_G_2F
:
11903 case OPC_DMOD_G_2F
:
11904 case OPC_DMODU_G_2F
:
11905 check_insn(env
, ctx
, INSN_LOONGSON2F
);
11906 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11909 default: /* Invalid */
11910 MIPS_INVAL("special2");
11911 generate_exception(ctx
, EXCP_RI
);
11916 op1
= MASK_SPECIAL3(ctx
->opcode
);
11920 check_insn(env
, ctx
, ISA_MIPS32R2
);
11921 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
11924 check_insn(env
, ctx
, ISA_MIPS32R2
);
11925 op2
= MASK_BSHFL(ctx
->opcode
);
11926 gen_bshfl(ctx
, op2
, rt
, rd
);
11929 gen_rdhwr(env
, ctx
, rt
, rd
);
11932 check_insn(env
, ctx
, ASE_MT
);
11934 TCGv t0
= tcg_temp_new();
11935 TCGv t1
= tcg_temp_new();
11937 gen_load_gpr(t0
, rt
);
11938 gen_load_gpr(t1
, rs
);
11939 gen_helper_fork(t0
, t1
);
11945 check_insn(env
, ctx
, ASE_MT
);
11947 TCGv t0
= tcg_temp_new();
11949 save_cpu_state(ctx
, 1);
11950 gen_load_gpr(t0
, rs
);
11951 gen_helper_yield(t0
, t0
);
11952 gen_store_gpr(t0
, rd
);
11956 case OPC_DIV_G_2E
... OPC_DIVU_G_2E
:
11957 case OPC_MULT_G_2E
... OPC_MULTU_G_2E
:
11958 case OPC_MOD_G_2E
... OPC_MODU_G_2E
:
11959 check_insn(env
, ctx
, INSN_LOONGSON2E
);
11960 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11962 #if defined(TARGET_MIPS64)
11963 case OPC_DEXTM
... OPC_DEXT
:
11964 case OPC_DINSM
... OPC_DINS
:
11965 check_insn(env
, ctx
, ISA_MIPS64R2
);
11966 check_mips_64(ctx
);
11967 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
11970 check_insn(env
, ctx
, ISA_MIPS64R2
);
11971 check_mips_64(ctx
);
11972 op2
= MASK_DBSHFL(ctx
->opcode
);
11973 gen_bshfl(ctx
, op2
, rt
, rd
);
11975 case OPC_DDIV_G_2E
... OPC_DDIVU_G_2E
:
11976 case OPC_DMULT_G_2E
... OPC_DMULTU_G_2E
:
11977 case OPC_DMOD_G_2E
... OPC_DMODU_G_2E
:
11978 check_insn(env
, ctx
, INSN_LOONGSON2E
);
11979 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11982 default: /* Invalid */
11983 MIPS_INVAL("special3");
11984 generate_exception(ctx
, EXCP_RI
);
11989 op1
= MASK_REGIMM(ctx
->opcode
);
11991 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
11992 case OPC_BLTZAL
... OPC_BGEZALL
:
11993 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
11996 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
11998 gen_trap(ctx
, op1
, rs
, -1, imm
);
12001 check_insn(env
, ctx
, ISA_MIPS32R2
);
12002 /* Treat as NOP. */
12004 default: /* Invalid */
12005 MIPS_INVAL("regimm");
12006 generate_exception(ctx
, EXCP_RI
);
12011 check_cp0_enabled(ctx
);
12012 op1
= MASK_CP0(ctx
->opcode
);
12018 #if defined(TARGET_MIPS64)
12022 #ifndef CONFIG_USER_ONLY
12023 gen_cp0(env
, ctx
, op1
, rt
, rd
);
12024 #endif /* !CONFIG_USER_ONLY */
12026 case OPC_C0_FIRST
... OPC_C0_LAST
:
12027 #ifndef CONFIG_USER_ONLY
12028 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
12029 #endif /* !CONFIG_USER_ONLY */
12032 #ifndef CONFIG_USER_ONLY
12034 TCGv t0
= tcg_temp_new();
12036 op2
= MASK_MFMC0(ctx
->opcode
);
12039 check_insn(env
, ctx
, ASE_MT
);
12040 gen_helper_dmt(t0
);
12041 gen_store_gpr(t0
, rt
);
12044 check_insn(env
, ctx
, ASE_MT
);
12045 gen_helper_emt(t0
);
12046 gen_store_gpr(t0
, rt
);
12049 check_insn(env
, ctx
, ASE_MT
);
12050 gen_helper_dvpe(t0
);
12051 gen_store_gpr(t0
, rt
);
12054 check_insn(env
, ctx
, ASE_MT
);
12055 gen_helper_evpe(t0
);
12056 gen_store_gpr(t0
, rt
);
12059 check_insn(env
, ctx
, ISA_MIPS32R2
);
12060 save_cpu_state(ctx
, 1);
12062 gen_store_gpr(t0
, rt
);
12063 /* Stop translation as we may have switched the execution mode */
12064 ctx
->bstate
= BS_STOP
;
12067 check_insn(env
, ctx
, ISA_MIPS32R2
);
12068 save_cpu_state(ctx
, 1);
12070 gen_store_gpr(t0
, rt
);
12071 /* Stop translation as we may have switched the execution mode */
12072 ctx
->bstate
= BS_STOP
;
12074 default: /* Invalid */
12075 MIPS_INVAL("mfmc0");
12076 generate_exception(ctx
, EXCP_RI
);
12081 #endif /* !CONFIG_USER_ONLY */
12084 check_insn(env
, ctx
, ISA_MIPS32R2
);
12085 gen_load_srsgpr(rt
, rd
);
12088 check_insn(env
, ctx
, ISA_MIPS32R2
);
12089 gen_store_srsgpr(rt
, rd
);
12093 generate_exception(ctx
, EXCP_RI
);
12097 case OPC_ADDI
: /* Arithmetic with immediate opcode */
12099 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
12101 case OPC_SLTI
: /* Set on less than with immediate opcode */
12103 gen_slt_imm(env
, op
, rt
, rs
, imm
);
12105 case OPC_ANDI
: /* Arithmetic with immediate opcode */
12109 gen_logic_imm(env
, op
, rt
, rs
, imm
);
12111 case OPC_J
... OPC_JAL
: /* Jump */
12112 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
12113 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
12116 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
12117 case OPC_BEQL
... OPC_BGTZL
:
12118 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
12121 case OPC_LB
... OPC_LWR
: /* Load and stores */
12123 gen_ld(env
, ctx
, op
, rt
, rs
, imm
);
12125 case OPC_SB
... OPC_SW
:
12127 gen_st(ctx
, op
, rt
, rs
, imm
);
12130 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
12133 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
12134 /* Treat as NOP. */
12137 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
12138 /* Treat as NOP. */
12141 /* Floating point (COP1). */
12146 gen_cop1_ldst(env
, ctx
, op
, rt
, rs
, imm
);
12150 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12151 check_cp1_enabled(ctx
);
12152 op1
= MASK_CP1(ctx
->opcode
);
12156 check_insn(env
, ctx
, ISA_MIPS32R2
);
12161 gen_cp1(ctx
, op1
, rt
, rd
);
12163 #if defined(TARGET_MIPS64)
12166 check_insn(env
, ctx
, ISA_MIPS3
);
12167 gen_cp1(ctx
, op1
, rt
, rd
);
12173 check_insn(env
, ctx
, ASE_MIPS3D
);
12176 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
12177 (rt
>> 2) & 0x7, imm
<< 2);
12185 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
12190 generate_exception (ctx
, EXCP_RI
);
12194 generate_exception_err(ctx
, EXCP_CpU
, 1);
12204 /* COP2: Not implemented. */
12205 generate_exception_err(ctx
, EXCP_CpU
, 2);
12209 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12210 check_cp1_enabled(ctx
);
12211 op1
= MASK_CP3(ctx
->opcode
);
12219 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
12222 /* Treat as NOP. */
12237 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
12241 generate_exception (ctx
, EXCP_RI
);
12245 generate_exception_err(ctx
, EXCP_CpU
, 1);
12249 #if defined(TARGET_MIPS64)
12250 /* MIPS64 opcodes */
12252 case OPC_LDL
... OPC_LDR
:
12255 check_insn(env
, ctx
, ISA_MIPS3
);
12256 check_mips_64(ctx
);
12257 gen_ld(env
, ctx
, op
, rt
, rs
, imm
);
12259 case OPC_SDL
... OPC_SDR
:
12261 check_insn(env
, ctx
, ISA_MIPS3
);
12262 check_mips_64(ctx
);
12263 gen_st(ctx
, op
, rt
, rs
, imm
);
12266 check_insn(env
, ctx
, ISA_MIPS3
);
12267 check_mips_64(ctx
);
12268 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
12272 check_insn(env
, ctx
, ISA_MIPS3
);
12273 check_mips_64(ctx
);
12274 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
12278 check_insn(env
, ctx
, ASE_MIPS16
| ASE_MICROMIPS
);
12279 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
12280 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
12284 check_insn(env
, ctx
, ASE_MDMX
);
12285 /* MDMX: Not implemented. */
12286 default: /* Invalid */
12287 MIPS_INVAL("major opcode");
12288 generate_exception(ctx
, EXCP_RI
);
12294 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
12298 target_ulong pc_start
;
12299 uint16_t *gen_opc_end
;
12308 qemu_log("search pc %d\n", search_pc
);
12311 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
12314 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
12316 ctx
.bstate
= BS_NONE
;
12317 /* Restore delay slot state from the tb context. */
12318 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
12319 restore_cpu_state(env
, &ctx
);
12320 #ifdef CONFIG_USER_ONLY
12321 ctx
.mem_idx
= MIPS_HFLAG_UM
;
12323 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
12326 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
12327 if (max_insns
== 0)
12328 max_insns
= CF_COUNT_MASK
;
12329 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
12330 gen_icount_start();
12331 while (ctx
.bstate
== BS_NONE
) {
12332 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
12333 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
12334 if (bp
->pc
== ctx
.pc
) {
12335 save_cpu_state(&ctx
, 1);
12336 ctx
.bstate
= BS_BRANCH
;
12337 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
12338 /* Include the breakpoint location or the tb won't
12339 * be flushed when it must be. */
12341 goto done_generating
;
12347 j
= gen_opc_ptr
- gen_opc_buf
;
12351 gen_opc_instr_start
[lj
++] = 0;
12353 gen_opc_pc
[lj
] = ctx
.pc
;
12354 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
12355 gen_opc_instr_start
[lj
] = 1;
12356 gen_opc_icount
[lj
] = num_insns
;
12358 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
12362 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
12363 ctx
.opcode
= ldl_code(ctx
.pc
);
12365 decode_opc(env
, &ctx
, &is_branch
);
12366 } else if (env
->insn_flags
& ASE_MICROMIPS
) {
12367 ctx
.opcode
= lduw_code(ctx
.pc
);
12368 insn_bytes
= decode_micromips_opc(env
, &ctx
, &is_branch
);
12369 } else if (env
->insn_flags
& ASE_MIPS16
) {
12370 ctx
.opcode
= lduw_code(ctx
.pc
);
12371 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
12373 generate_exception(&ctx
, EXCP_RI
);
12374 ctx
.bstate
= BS_STOP
;
12378 handle_delay_slot(env
, &ctx
, insn_bytes
);
12380 ctx
.pc
+= insn_bytes
;
12384 /* Execute a branch and its delay slot as a single instruction.
12385 This is what GDB expects and is consistent with what the
12386 hardware does (e.g. if a delay slot instruction faults, the
12387 reported PC is the PC of the branch). */
12388 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
12391 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
12394 if (gen_opc_ptr
>= gen_opc_end
)
12397 if (num_insns
>= max_insns
)
12403 if (tb
->cflags
& CF_LAST_IO
)
12405 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
12406 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
12407 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
12409 switch (ctx
.bstate
) {
12411 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12414 save_cpu_state(&ctx
, 0);
12415 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12418 tcg_gen_exit_tb(0);
12426 gen_icount_end(tb
, num_insns
);
12427 *gen_opc_ptr
= INDEX_op_end
;
12429 j
= gen_opc_ptr
- gen_opc_buf
;
12432 gen_opc_instr_start
[lj
++] = 0;
12434 tb
->size
= ctx
.pc
- pc_start
;
12435 tb
->icount
= num_insns
;
12439 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
12440 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
12441 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
12447 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
12449 gen_intermediate_code_internal(env
, tb
, 0);
12452 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
12454 gen_intermediate_code_internal(env
, tb
, 1);
12457 static void fpu_dump_state(CPUState
*env
, FILE *f
, fprintf_function fpu_fprintf
,
12461 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
12463 #define printfpr(fp) \
12466 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12467 " fd:%13g fs:%13g psu: %13g\n", \
12468 (fp)->w[FP_ENDIAN_IDX], (fp)->d, \
12469 (double)(fp)->fd, \
12470 (double)(fp)->fs[FP_ENDIAN_IDX], \
12471 (double)(fp)->fs[!FP_ENDIAN_IDX]); \
12474 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
12475 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
12476 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12477 " fd:%13g fs:%13g psu:%13g\n", \
12478 tmp.w[FP_ENDIAN_IDX], tmp.d, \
12480 (double)tmp.fs[FP_ENDIAN_IDX], \
12481 (double)tmp.fs[!FP_ENDIAN_IDX]); \
12486 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%02x\n",
12487 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
,
12488 get_float_exception_flags(&env
->active_fpu
.fp_status
));
12489 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
12490 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
12491 printfpr(&env
->active_fpu
.fpr
[i
]);
12497 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12498 /* Debug help: The architecture requires 32bit code to maintain proper
12499 sign-extended values on 64bit machines. */
12501 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
12504 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
12505 fprintf_function cpu_fprintf
,
12510 if (!SIGN_EXT_P(env
->active_tc
.PC
))
12511 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
12512 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
12513 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
12514 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
12515 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
12516 if (!SIGN_EXT_P(env
->btarget
))
12517 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
12519 for (i
= 0; i
< 32; i
++) {
12520 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
12521 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
12524 if (!SIGN_EXT_P(env
->CP0_EPC
))
12525 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
12526 if (!SIGN_EXT_P(env
->lladdr
))
12527 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
12531 void cpu_dump_state (CPUState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
12536 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
12537 " LO=0x" TARGET_FMT_lx
" ds %04x "
12538 TARGET_FMT_lx
" " TARGET_FMT_ld
"\n",
12539 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
12540 env
->hflags
, env
->btarget
, env
->bcond
);
12541 for (i
= 0; i
< 32; i
++) {
12543 cpu_fprintf(f
, "GPR%02d:", i
);
12544 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
12546 cpu_fprintf(f
, "\n");
12549 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
12550 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
12551 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
12552 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
12553 if (env
->hflags
& MIPS_HFLAG_FPU
)
12554 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
12555 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12556 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
12560 static void mips_tcg_init(void)
12565 /* Initialize various static tables. */
12569 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
12570 TCGV_UNUSED(cpu_gpr
[0]);
12571 for (i
= 1; i
< 32; i
++)
12572 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
12573 offsetof(CPUState
, active_tc
.gpr
[i
]),
12575 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
12576 offsetof(CPUState
, active_tc
.PC
), "PC");
12577 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
12578 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
12579 offsetof(CPUState
, active_tc
.HI
[i
]),
12581 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
12582 offsetof(CPUState
, active_tc
.LO
[i
]),
12584 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
12585 offsetof(CPUState
, active_tc
.ACX
[i
]),
12588 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
12589 offsetof(CPUState
, active_tc
.DSPControl
),
12591 bcond
= tcg_global_mem_new(TCG_AREG0
,
12592 offsetof(CPUState
, bcond
), "bcond");
12593 btarget
= tcg_global_mem_new(TCG_AREG0
,
12594 offsetof(CPUState
, btarget
), "btarget");
12595 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
12596 offsetof(CPUState
, hflags
), "hflags");
12598 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
12599 offsetof(CPUState
, active_fpu
.fcr0
),
12601 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
12602 offsetof(CPUState
, active_fpu
.fcr31
),
12605 /* register helpers */
12606 #define GEN_HELPER 2
12607 #include "helper.h"
12612 #include "translate_init.c"
12614 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
12617 const mips_def_t
*def
;
12619 def
= cpu_mips_find_by_name(cpu_model
);
12622 env
= qemu_mallocz(sizeof(CPUMIPSState
));
12623 env
->cpu_model
= def
;
12624 env
->cpu_model_str
= cpu_model
;
12626 cpu_exec_init(env
);
12627 #ifndef CONFIG_USER_ONLY
12628 mmu_init(env
, def
);
12630 fpu_init(env
, def
);
12631 mvp_init(env
, def
);
12634 qemu_init_vcpu(env
);
12638 void cpu_reset (CPUMIPSState
*env
)
12640 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
12641 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
12642 log_cpu_state(env
, 0);
12645 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
12648 /* Reset registers to their default values */
12649 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
12650 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
12651 #ifdef TARGET_WORDS_BIGENDIAN
12652 env
->CP0_Config0
|= (1 << CP0C0_BE
);
12654 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
12655 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
12656 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
12657 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
12658 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
12659 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
12660 << env
->cpu_model
->CP0_LLAddr_shift
;
12661 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
12662 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
12663 env
->CCRes
= env
->cpu_model
->CCRes
;
12664 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
12665 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
12666 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
12667 env
->current_tc
= 0;
12668 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
12669 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
12670 #if defined(TARGET_MIPS64)
12671 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12672 env
->SEGMask
|= 3ULL << 62;
12675 env
->PABITS
= env
->cpu_model
->PABITS
;
12676 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
12677 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
12678 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
12679 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
12680 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
12681 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
12682 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
12683 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
12684 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
12685 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
12686 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
12687 env
->insn_flags
= env
->cpu_model
->insn_flags
;
12689 #if defined(CONFIG_USER_ONLY)
12690 env
->hflags
= MIPS_HFLAG_UM
;
12691 /* Enable access to the SYNCI_Step register. */
12692 env
->CP0_HWREna
|= (1 << 1);
12693 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12694 env
->hflags
|= MIPS_HFLAG_FPU
;
12696 #ifdef TARGET_MIPS64
12697 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
12698 env
->hflags
|= MIPS_HFLAG_F64
;
12702 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
12703 /* If the exception was raised from a delay slot,
12704 come back to the jump. */
12705 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
12707 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
12709 env
->active_tc
.PC
= (int32_t)0xBFC00000;
12710 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
12711 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
12712 env
->CP0_Wired
= 0;
12713 env
->CP0_EBase
= 0x80000000 | (env
->cpu_index
& 0x3FF);
12714 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
12715 /* vectored interrupts not implemented, timer on int 7,
12716 no performance counters. */
12717 env
->CP0_IntCtl
= 0xe0000000;
12721 for (i
= 0; i
< 7; i
++) {
12722 env
->CP0_WatchLo
[i
] = 0;
12723 env
->CP0_WatchHi
[i
] = 0x80000000;
12725 env
->CP0_WatchLo
[7] = 0;
12726 env
->CP0_WatchHi
[7] = 0;
12728 /* Count register increments in debug mode, EJTAG version 1 */
12729 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
12730 env
->hflags
= MIPS_HFLAG_CP0
;
12732 #if defined(TARGET_MIPS64)
12733 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12734 env
->hflags
|= MIPS_HFLAG_64
;
12737 env
->exception_index
= EXCP_NONE
;
12740 void restore_state_to_opc(CPUState
*env
, TranslationBlock
*tb
, int pc_pos
)
12742 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
12743 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
12744 env
->hflags
|= gen_opc_hflags
[pc_pos
];