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
, 0);
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
, 1);
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
, 1);
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 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1162 static void gen_st (DisasContext
*ctx
, uint32_t opc
, int rt
,
1163 int base
, int16_t offset
)
1165 const char *opn
= "st";
1166 TCGv t0
= tcg_temp_new();
1167 TCGv t1
= tcg_temp_new();
1169 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1170 gen_load_gpr(t1
, rt
);
1172 #if defined(TARGET_MIPS64)
1174 save_cpu_state(ctx
, 0);
1175 op_st_sd(t1
, t0
, ctx
);
1179 save_cpu_state(ctx
, 1);
1180 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1184 save_cpu_state(ctx
, 1);
1185 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1190 save_cpu_state(ctx
, 0);
1191 op_st_sw(t1
, t0
, ctx
);
1195 save_cpu_state(ctx
, 0);
1196 op_st_sh(t1
, t0
, ctx
);
1200 save_cpu_state(ctx
, 0);
1201 op_st_sb(t1
, t0
, ctx
);
1205 save_cpu_state(ctx
, 1);
1206 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1210 save_cpu_state(ctx
, 1);
1211 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1215 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1221 /* Store conditional */
1222 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1223 int base
, int16_t offset
)
1225 const char *opn
= "st_cond";
1228 t0
= tcg_temp_local_new();
1230 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1231 /* Don't do NOP if destination is zero: we must perform the actual
1234 t1
= tcg_temp_local_new();
1235 gen_load_gpr(t1
, rt
);
1237 #if defined(TARGET_MIPS64)
1239 save_cpu_state(ctx
, 0);
1240 op_st_scd(t1
, t0
, rt
, ctx
);
1245 save_cpu_state(ctx
, 1);
1246 op_st_sc(t1
, t0
, rt
, ctx
);
1250 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1255 /* Load and store */
1256 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1257 int base
, int16_t offset
)
1259 const char *opn
= "flt_ldst";
1260 TCGv t0
= tcg_temp_new();
1262 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1263 /* Don't do NOP if destination is zero: we must perform the actual
1268 TCGv_i32 fp0
= tcg_temp_new_i32();
1270 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1271 tcg_gen_trunc_tl_i32(fp0
, t0
);
1272 gen_store_fpr32(fp0
, ft
);
1273 tcg_temp_free_i32(fp0
);
1279 TCGv_i32 fp0
= tcg_temp_new_i32();
1280 TCGv t1
= tcg_temp_new();
1282 gen_load_fpr32(fp0
, ft
);
1283 tcg_gen_extu_i32_tl(t1
, fp0
);
1284 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1286 tcg_temp_free_i32(fp0
);
1292 TCGv_i64 fp0
= tcg_temp_new_i64();
1294 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1295 gen_store_fpr64(ctx
, fp0
, ft
);
1296 tcg_temp_free_i64(fp0
);
1302 TCGv_i64 fp0
= tcg_temp_new_i64();
1304 gen_load_fpr64(ctx
, fp0
, ft
);
1305 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1306 tcg_temp_free_i64(fp0
);
1312 generate_exception(ctx
, EXCP_RI
);
1315 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1320 static void gen_cop1_ldst(CPUState
*env
, DisasContext
*ctx
,
1321 uint32_t op
, int rt
, int rs
, int16_t imm
)
1323 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
1324 check_cp1_enabled(ctx
);
1325 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
1327 generate_exception_err(ctx
, EXCP_CpU
, 1);
1331 /* Arithmetic with immediate operand */
1332 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1333 int rt
, int rs
, int16_t imm
)
1335 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1336 const char *opn
= "imm arith";
1338 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1339 /* If no destination, treat it as a NOP.
1340 For addi, we must generate the overflow exception when needed. */
1347 TCGv t0
= tcg_temp_local_new();
1348 TCGv t1
= tcg_temp_new();
1349 TCGv t2
= tcg_temp_new();
1350 int l1
= gen_new_label();
1352 gen_load_gpr(t1
, rs
);
1353 tcg_gen_addi_tl(t0
, t1
, uimm
);
1354 tcg_gen_ext32s_tl(t0
, t0
);
1356 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1357 tcg_gen_xori_tl(t2
, t0
, uimm
);
1358 tcg_gen_and_tl(t1
, t1
, t2
);
1360 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1362 /* operands of same sign, result different sign */
1363 generate_exception(ctx
, EXCP_OVERFLOW
);
1365 tcg_gen_ext32s_tl(t0
, t0
);
1366 gen_store_gpr(t0
, rt
);
1373 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1374 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1376 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1380 #if defined(TARGET_MIPS64)
1383 TCGv t0
= tcg_temp_local_new();
1384 TCGv t1
= tcg_temp_new();
1385 TCGv t2
= tcg_temp_new();
1386 int l1
= gen_new_label();
1388 gen_load_gpr(t1
, rs
);
1389 tcg_gen_addi_tl(t0
, t1
, uimm
);
1391 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1392 tcg_gen_xori_tl(t2
, t0
, uimm
);
1393 tcg_gen_and_tl(t1
, t1
, t2
);
1395 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1397 /* operands of same sign, result different sign */
1398 generate_exception(ctx
, EXCP_OVERFLOW
);
1400 gen_store_gpr(t0
, rt
);
1407 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1409 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1415 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1418 /* Logic with immediate operand */
1419 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1422 const char *opn
= "imm logic";
1425 /* If no destination, treat it as a NOP. */
1429 uimm
= (uint16_t)imm
;
1432 if (likely(rs
!= 0))
1433 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1435 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1440 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1442 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1446 if (likely(rs
!= 0))
1447 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1449 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1453 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1457 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1460 /* Set on less than with immediate operand */
1461 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1463 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1464 const char *opn
= "imm arith";
1468 /* If no destination, treat it as a NOP. */
1472 t0
= tcg_temp_new();
1473 gen_load_gpr(t0
, rs
);
1476 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
1480 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
1484 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1488 /* Shifts with immediate operand */
1489 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1490 int rt
, int rs
, int16_t imm
)
1492 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1493 const char *opn
= "imm shift";
1497 /* If no destination, treat it as a NOP. */
1502 t0
= tcg_temp_new();
1503 gen_load_gpr(t0
, rs
);
1506 tcg_gen_shli_tl(t0
, t0
, uimm
);
1507 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1511 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1516 tcg_gen_ext32u_tl(t0
, t0
);
1517 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1519 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1525 TCGv_i32 t1
= tcg_temp_new_i32();
1527 tcg_gen_trunc_tl_i32(t1
, t0
);
1528 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1529 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1530 tcg_temp_free_i32(t1
);
1532 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1536 #if defined(TARGET_MIPS64)
1538 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1542 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1546 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1551 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1553 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
1558 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1562 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1566 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1570 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1575 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1580 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1581 int rd
, int rs
, int rt
)
1583 const char *opn
= "arith";
1585 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1586 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1587 /* If no destination, treat it as a NOP.
1588 For add & sub, we must generate the overflow exception when needed. */
1596 TCGv t0
= tcg_temp_local_new();
1597 TCGv t1
= tcg_temp_new();
1598 TCGv t2
= tcg_temp_new();
1599 int l1
= gen_new_label();
1601 gen_load_gpr(t1
, rs
);
1602 gen_load_gpr(t2
, rt
);
1603 tcg_gen_add_tl(t0
, t1
, t2
);
1604 tcg_gen_ext32s_tl(t0
, t0
);
1605 tcg_gen_xor_tl(t1
, t1
, t2
);
1606 tcg_gen_xor_tl(t2
, t0
, t2
);
1607 tcg_gen_andc_tl(t1
, t2
, t1
);
1609 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1611 /* operands of same sign, result different sign */
1612 generate_exception(ctx
, EXCP_OVERFLOW
);
1614 gen_store_gpr(t0
, rd
);
1620 if (rs
!= 0 && rt
!= 0) {
1621 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1622 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1623 } else if (rs
== 0 && rt
!= 0) {
1624 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1625 } else if (rs
!= 0 && rt
== 0) {
1626 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1628 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1634 TCGv t0
= tcg_temp_local_new();
1635 TCGv t1
= tcg_temp_new();
1636 TCGv t2
= tcg_temp_new();
1637 int l1
= gen_new_label();
1639 gen_load_gpr(t1
, rs
);
1640 gen_load_gpr(t2
, rt
);
1641 tcg_gen_sub_tl(t0
, t1
, t2
);
1642 tcg_gen_ext32s_tl(t0
, t0
);
1643 tcg_gen_xor_tl(t2
, t1
, t2
);
1644 tcg_gen_xor_tl(t1
, t0
, t1
);
1645 tcg_gen_and_tl(t1
, t1
, t2
);
1647 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1649 /* operands of different sign, first operand and result different sign */
1650 generate_exception(ctx
, EXCP_OVERFLOW
);
1652 gen_store_gpr(t0
, rd
);
1658 if (rs
!= 0 && rt
!= 0) {
1659 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1660 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1661 } else if (rs
== 0 && rt
!= 0) {
1662 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1663 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1664 } else if (rs
!= 0 && rt
== 0) {
1665 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1667 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1671 #if defined(TARGET_MIPS64)
1674 TCGv t0
= tcg_temp_local_new();
1675 TCGv t1
= tcg_temp_new();
1676 TCGv t2
= tcg_temp_new();
1677 int l1
= gen_new_label();
1679 gen_load_gpr(t1
, rs
);
1680 gen_load_gpr(t2
, rt
);
1681 tcg_gen_add_tl(t0
, t1
, t2
);
1682 tcg_gen_xor_tl(t1
, t1
, t2
);
1683 tcg_gen_xor_tl(t2
, t0
, t2
);
1684 tcg_gen_andc_tl(t1
, t2
, t1
);
1686 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1688 /* operands of same sign, result different sign */
1689 generate_exception(ctx
, EXCP_OVERFLOW
);
1691 gen_store_gpr(t0
, rd
);
1697 if (rs
!= 0 && rt
!= 0) {
1698 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1699 } else if (rs
== 0 && rt
!= 0) {
1700 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1701 } else if (rs
!= 0 && rt
== 0) {
1702 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1704 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1710 TCGv t0
= tcg_temp_local_new();
1711 TCGv t1
= tcg_temp_new();
1712 TCGv t2
= tcg_temp_new();
1713 int l1
= gen_new_label();
1715 gen_load_gpr(t1
, rs
);
1716 gen_load_gpr(t2
, rt
);
1717 tcg_gen_sub_tl(t0
, t1
, t2
);
1718 tcg_gen_xor_tl(t2
, t1
, t2
);
1719 tcg_gen_xor_tl(t1
, t0
, t1
);
1720 tcg_gen_and_tl(t1
, t1
, t2
);
1722 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1724 /* operands of different sign, first operand and result different sign */
1725 generate_exception(ctx
, EXCP_OVERFLOW
);
1727 gen_store_gpr(t0
, rd
);
1733 if (rs
!= 0 && rt
!= 0) {
1734 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1735 } else if (rs
== 0 && rt
!= 0) {
1736 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1737 } else if (rs
!= 0 && rt
== 0) {
1738 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1740 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1746 if (likely(rs
!= 0 && rt
!= 0)) {
1747 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1748 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1750 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1755 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1758 /* Conditional move */
1759 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1761 const char *opn
= "cond move";
1765 /* If no destination, treat it as a NOP.
1766 For add & sub, we must generate the overflow exception when needed. */
1771 l1
= gen_new_label();
1774 if (likely(rt
!= 0))
1775 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1781 if (likely(rt
!= 0))
1782 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1787 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1789 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1792 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1796 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1798 const char *opn
= "logic";
1801 /* If no destination, treat it as a NOP. */
1808 if (likely(rs
!= 0 && rt
!= 0)) {
1809 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1811 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1816 if (rs
!= 0 && rt
!= 0) {
1817 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1818 } else if (rs
== 0 && rt
!= 0) {
1819 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1820 } else if (rs
!= 0 && rt
== 0) {
1821 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1823 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1828 if (likely(rs
!= 0 && rt
!= 0)) {
1829 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1830 } else if (rs
== 0 && rt
!= 0) {
1831 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1832 } else if (rs
!= 0 && rt
== 0) {
1833 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1835 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1840 if (likely(rs
!= 0 && rt
!= 0)) {
1841 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1842 } else if (rs
== 0 && rt
!= 0) {
1843 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1844 } else if (rs
!= 0 && rt
== 0) {
1845 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1847 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1852 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1855 /* Set on lower than */
1856 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1858 const char *opn
= "slt";
1862 /* If no destination, treat it as a NOP. */
1867 t0
= tcg_temp_new();
1868 t1
= tcg_temp_new();
1869 gen_load_gpr(t0
, rs
);
1870 gen_load_gpr(t1
, rt
);
1873 tcg_gen_setcond_tl(TCG_COND_LT
, cpu_gpr
[rd
], t0
, t1
);
1877 tcg_gen_setcond_tl(TCG_COND_LTU
, cpu_gpr
[rd
], t0
, t1
);
1881 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1887 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1888 int rd
, int rs
, int rt
)
1890 const char *opn
= "shifts";
1894 /* If no destination, treat it as a NOP.
1895 For add & sub, we must generate the overflow exception when needed. */
1900 t0
= tcg_temp_new();
1901 t1
= tcg_temp_new();
1902 gen_load_gpr(t0
, rs
);
1903 gen_load_gpr(t1
, rt
);
1906 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1907 tcg_gen_shl_tl(t0
, t1
, t0
);
1908 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1912 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1913 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1917 tcg_gen_ext32u_tl(t1
, t1
);
1918 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1919 tcg_gen_shr_tl(t0
, t1
, t0
);
1920 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1925 TCGv_i32 t2
= tcg_temp_new_i32();
1926 TCGv_i32 t3
= tcg_temp_new_i32();
1928 tcg_gen_trunc_tl_i32(t2
, t0
);
1929 tcg_gen_trunc_tl_i32(t3
, t1
);
1930 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1931 tcg_gen_rotr_i32(t2
, t3
, t2
);
1932 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1933 tcg_temp_free_i32(t2
);
1934 tcg_temp_free_i32(t3
);
1938 #if defined(TARGET_MIPS64)
1940 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1941 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1945 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1946 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1950 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1951 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1955 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1956 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1961 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1966 /* Arithmetic on HI/LO registers */
1967 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1969 const char *opn
= "hilo";
1971 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1978 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1982 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1987 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1989 tcg_gen_movi_tl(cpu_HI
[0], 0);
1994 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
1996 tcg_gen_movi_tl(cpu_LO
[0], 0);
2000 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
2003 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
2006 const char *opn
= "mul/div";
2012 #if defined(TARGET_MIPS64)
2016 t0
= tcg_temp_local_new();
2017 t1
= tcg_temp_local_new();
2020 t0
= tcg_temp_new();
2021 t1
= tcg_temp_new();
2025 gen_load_gpr(t0
, rs
);
2026 gen_load_gpr(t1
, rt
);
2030 int l1
= gen_new_label();
2031 int l2
= gen_new_label();
2033 tcg_gen_ext32s_tl(t0
, t0
);
2034 tcg_gen_ext32s_tl(t1
, t1
);
2035 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2036 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2037 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2039 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2040 tcg_gen_movi_tl(cpu_HI
[0], 0);
2043 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
2044 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
2045 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2046 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2053 int l1
= gen_new_label();
2055 tcg_gen_ext32u_tl(t0
, t0
);
2056 tcg_gen_ext32u_tl(t1
, t1
);
2057 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2058 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2059 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2060 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2061 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2068 TCGv_i64 t2
= tcg_temp_new_i64();
2069 TCGv_i64 t3
= tcg_temp_new_i64();
2071 tcg_gen_ext_tl_i64(t2
, t0
);
2072 tcg_gen_ext_tl_i64(t3
, t1
);
2073 tcg_gen_mul_i64(t2
, t2
, t3
);
2074 tcg_temp_free_i64(t3
);
2075 tcg_gen_trunc_i64_tl(t0
, t2
);
2076 tcg_gen_shri_i64(t2
, t2
, 32);
2077 tcg_gen_trunc_i64_tl(t1
, t2
);
2078 tcg_temp_free_i64(t2
);
2079 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2080 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2086 TCGv_i64 t2
= tcg_temp_new_i64();
2087 TCGv_i64 t3
= tcg_temp_new_i64();
2089 tcg_gen_ext32u_tl(t0
, t0
);
2090 tcg_gen_ext32u_tl(t1
, t1
);
2091 tcg_gen_extu_tl_i64(t2
, t0
);
2092 tcg_gen_extu_tl_i64(t3
, t1
);
2093 tcg_gen_mul_i64(t2
, t2
, t3
);
2094 tcg_temp_free_i64(t3
);
2095 tcg_gen_trunc_i64_tl(t0
, t2
);
2096 tcg_gen_shri_i64(t2
, t2
, 32);
2097 tcg_gen_trunc_i64_tl(t1
, t2
);
2098 tcg_temp_free_i64(t2
);
2099 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2100 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2104 #if defined(TARGET_MIPS64)
2107 int l1
= gen_new_label();
2108 int l2
= gen_new_label();
2110 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2111 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2112 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2113 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2114 tcg_gen_movi_tl(cpu_HI
[0], 0);
2117 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2118 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2125 int l1
= gen_new_label();
2127 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2128 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2129 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2135 gen_helper_dmult(t0
, t1
);
2139 gen_helper_dmultu(t0
, t1
);
2145 TCGv_i64 t2
= tcg_temp_new_i64();
2146 TCGv_i64 t3
= tcg_temp_new_i64();
2148 tcg_gen_ext_tl_i64(t2
, t0
);
2149 tcg_gen_ext_tl_i64(t3
, t1
);
2150 tcg_gen_mul_i64(t2
, t2
, t3
);
2151 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2152 tcg_gen_add_i64(t2
, t2
, t3
);
2153 tcg_temp_free_i64(t3
);
2154 tcg_gen_trunc_i64_tl(t0
, t2
);
2155 tcg_gen_shri_i64(t2
, t2
, 32);
2156 tcg_gen_trunc_i64_tl(t1
, t2
);
2157 tcg_temp_free_i64(t2
);
2158 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2159 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2165 TCGv_i64 t2
= tcg_temp_new_i64();
2166 TCGv_i64 t3
= tcg_temp_new_i64();
2168 tcg_gen_ext32u_tl(t0
, t0
);
2169 tcg_gen_ext32u_tl(t1
, t1
);
2170 tcg_gen_extu_tl_i64(t2
, t0
);
2171 tcg_gen_extu_tl_i64(t3
, t1
);
2172 tcg_gen_mul_i64(t2
, t2
, t3
);
2173 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2174 tcg_gen_add_i64(t2
, t2
, t3
);
2175 tcg_temp_free_i64(t3
);
2176 tcg_gen_trunc_i64_tl(t0
, t2
);
2177 tcg_gen_shri_i64(t2
, t2
, 32);
2178 tcg_gen_trunc_i64_tl(t1
, t2
);
2179 tcg_temp_free_i64(t2
);
2180 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2181 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2187 TCGv_i64 t2
= tcg_temp_new_i64();
2188 TCGv_i64 t3
= tcg_temp_new_i64();
2190 tcg_gen_ext_tl_i64(t2
, t0
);
2191 tcg_gen_ext_tl_i64(t3
, t1
);
2192 tcg_gen_mul_i64(t2
, t2
, t3
);
2193 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2194 tcg_gen_sub_i64(t2
, t3
, t2
);
2195 tcg_temp_free_i64(t3
);
2196 tcg_gen_trunc_i64_tl(t0
, t2
);
2197 tcg_gen_shri_i64(t2
, t2
, 32);
2198 tcg_gen_trunc_i64_tl(t1
, t2
);
2199 tcg_temp_free_i64(t2
);
2200 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2201 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2207 TCGv_i64 t2
= tcg_temp_new_i64();
2208 TCGv_i64 t3
= tcg_temp_new_i64();
2210 tcg_gen_ext32u_tl(t0
, t0
);
2211 tcg_gen_ext32u_tl(t1
, t1
);
2212 tcg_gen_extu_tl_i64(t2
, t0
);
2213 tcg_gen_extu_tl_i64(t3
, t1
);
2214 tcg_gen_mul_i64(t2
, t2
, t3
);
2215 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2216 tcg_gen_sub_i64(t2
, t3
, t2
);
2217 tcg_temp_free_i64(t3
);
2218 tcg_gen_trunc_i64_tl(t0
, t2
);
2219 tcg_gen_shri_i64(t2
, t2
, 32);
2220 tcg_gen_trunc_i64_tl(t1
, t2
);
2221 tcg_temp_free_i64(t2
);
2222 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2223 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2229 generate_exception(ctx
, EXCP_RI
);
2232 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2238 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2239 int rd
, int rs
, int rt
)
2241 const char *opn
= "mul vr54xx";
2242 TCGv t0
= tcg_temp_new();
2243 TCGv t1
= tcg_temp_new();
2245 gen_load_gpr(t0
, rs
);
2246 gen_load_gpr(t1
, rt
);
2249 case OPC_VR54XX_MULS
:
2250 gen_helper_muls(t0
, t0
, t1
);
2253 case OPC_VR54XX_MULSU
:
2254 gen_helper_mulsu(t0
, t0
, t1
);
2257 case OPC_VR54XX_MACC
:
2258 gen_helper_macc(t0
, t0
, t1
);
2261 case OPC_VR54XX_MACCU
:
2262 gen_helper_maccu(t0
, t0
, t1
);
2265 case OPC_VR54XX_MSAC
:
2266 gen_helper_msac(t0
, t0
, t1
);
2269 case OPC_VR54XX_MSACU
:
2270 gen_helper_msacu(t0
, t0
, t1
);
2273 case OPC_VR54XX_MULHI
:
2274 gen_helper_mulhi(t0
, t0
, t1
);
2277 case OPC_VR54XX_MULHIU
:
2278 gen_helper_mulhiu(t0
, t0
, t1
);
2281 case OPC_VR54XX_MULSHI
:
2282 gen_helper_mulshi(t0
, t0
, t1
);
2285 case OPC_VR54XX_MULSHIU
:
2286 gen_helper_mulshiu(t0
, t0
, t1
);
2289 case OPC_VR54XX_MACCHI
:
2290 gen_helper_macchi(t0
, t0
, t1
);
2293 case OPC_VR54XX_MACCHIU
:
2294 gen_helper_macchiu(t0
, t0
, t1
);
2297 case OPC_VR54XX_MSACHI
:
2298 gen_helper_msachi(t0
, t0
, t1
);
2301 case OPC_VR54XX_MSACHIU
:
2302 gen_helper_msachiu(t0
, t0
, t1
);
2306 MIPS_INVAL("mul vr54xx");
2307 generate_exception(ctx
, EXCP_RI
);
2310 gen_store_gpr(t0
, rd
);
2311 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2318 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2321 const char *opn
= "CLx";
2329 t0
= tcg_temp_new();
2330 gen_load_gpr(t0
, rs
);
2333 gen_helper_clo(cpu_gpr
[rd
], t0
);
2337 gen_helper_clz(cpu_gpr
[rd
], t0
);
2340 #if defined(TARGET_MIPS64)
2342 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2346 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2351 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2355 /* Godson integer instructions */
2356 static void gen_loongson_integer (DisasContext
*ctx
, uint32_t opc
,
2357 int rd
, int rs
, int rt
)
2359 const char *opn
= "loongson";
2371 case OPC_MULTU_G_2E
:
2372 case OPC_MULTU_G_2F
:
2373 #if defined(TARGET_MIPS64)
2374 case OPC_DMULT_G_2E
:
2375 case OPC_DMULT_G_2F
:
2376 case OPC_DMULTU_G_2E
:
2377 case OPC_DMULTU_G_2F
:
2379 t0
= tcg_temp_new();
2380 t1
= tcg_temp_new();
2383 t0
= tcg_temp_local_new();
2384 t1
= tcg_temp_local_new();
2388 gen_load_gpr(t0
, rs
);
2389 gen_load_gpr(t1
, rt
);
2394 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2395 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2398 case OPC_MULTU_G_2E
:
2399 case OPC_MULTU_G_2F
:
2400 tcg_gen_ext32u_tl(t0
, t0
);
2401 tcg_gen_ext32u_tl(t1
, t1
);
2402 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2403 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2409 int l1
= gen_new_label();
2410 int l2
= gen_new_label();
2411 int l3
= gen_new_label();
2412 tcg_gen_ext32s_tl(t0
, t0
);
2413 tcg_gen_ext32s_tl(t1
, t1
);
2414 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2415 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2418 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2419 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2420 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
2423 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
2424 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2432 int l1
= gen_new_label();
2433 int l2
= gen_new_label();
2434 tcg_gen_ext32u_tl(t0
, t0
);
2435 tcg_gen_ext32u_tl(t1
, t1
);
2436 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2437 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2440 tcg_gen_divu_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 int l3
= gen_new_label();
2452 tcg_gen_ext32u_tl(t0
, t0
);
2453 tcg_gen_ext32u_tl(t1
, t1
);
2454 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2455 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2456 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2458 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2461 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
2462 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2470 int l1
= gen_new_label();
2471 int l2
= gen_new_label();
2472 tcg_gen_ext32u_tl(t0
, t0
);
2473 tcg_gen_ext32u_tl(t1
, t1
);
2474 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2475 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2478 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
2479 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2484 #if defined(TARGET_MIPS64)
2485 case OPC_DMULT_G_2E
:
2486 case OPC_DMULT_G_2F
:
2487 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2490 case OPC_DMULTU_G_2E
:
2491 case OPC_DMULTU_G_2F
:
2492 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2498 int l1
= gen_new_label();
2499 int l2
= gen_new_label();
2500 int l3
= gen_new_label();
2501 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2502 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2505 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2506 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2507 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
2510 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
2515 case OPC_DDIVU_G_2E
:
2516 case OPC_DDIVU_G_2F
:
2518 int l1
= gen_new_label();
2519 int l2
= gen_new_label();
2520 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2521 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2524 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
2532 int l1
= gen_new_label();
2533 int l2
= gen_new_label();
2534 int l3
= gen_new_label();
2535 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2536 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2537 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2539 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2542 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
2547 case OPC_DMODU_G_2E
:
2548 case OPC_DMODU_G_2F
:
2550 int l1
= gen_new_label();
2551 int l2
= gen_new_label();
2552 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2553 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2556 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
2564 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2570 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2571 int rs
, int rt
, int16_t imm
)
2574 TCGv t0
= tcg_temp_new();
2575 TCGv t1
= tcg_temp_new();
2578 /* Load needed operands */
2586 /* Compare two registers */
2588 gen_load_gpr(t0
, rs
);
2589 gen_load_gpr(t1
, rt
);
2599 /* Compare register to immediate */
2600 if (rs
!= 0 || imm
!= 0) {
2601 gen_load_gpr(t0
, rs
);
2602 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2609 case OPC_TEQ
: /* rs == rs */
2610 case OPC_TEQI
: /* r0 == 0 */
2611 case OPC_TGE
: /* rs >= rs */
2612 case OPC_TGEI
: /* r0 >= 0 */
2613 case OPC_TGEU
: /* rs >= rs unsigned */
2614 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2616 generate_exception(ctx
, EXCP_TRAP
);
2618 case OPC_TLT
: /* rs < rs */
2619 case OPC_TLTI
: /* r0 < 0 */
2620 case OPC_TLTU
: /* rs < rs unsigned */
2621 case OPC_TLTIU
: /* r0 < 0 unsigned */
2622 case OPC_TNE
: /* rs != rs */
2623 case OPC_TNEI
: /* r0 != 0 */
2624 /* Never trap: treat as NOP. */
2628 int l1
= gen_new_label();
2633 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2637 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2641 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2645 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2649 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2653 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2656 generate_exception(ctx
, EXCP_TRAP
);
2663 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2665 TranslationBlock
*tb
;
2667 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2668 likely(!ctx
->singlestep_enabled
)) {
2671 tcg_gen_exit_tb((long)tb
+ n
);
2674 if (ctx
->singlestep_enabled
) {
2675 save_cpu_state(ctx
, 0);
2676 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
2682 /* Branches (before delay slot) */
2683 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2685 int rs
, int rt
, int32_t offset
)
2687 target_ulong btgt
= -1;
2689 int bcond_compute
= 0;
2690 TCGv t0
= tcg_temp_new();
2691 TCGv t1
= tcg_temp_new();
2693 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2694 #ifdef MIPS_DEBUG_DISAS
2695 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2697 generate_exception(ctx
, EXCP_RI
);
2701 /* Load needed operands */
2707 /* Compare two registers */
2709 gen_load_gpr(t0
, rs
);
2710 gen_load_gpr(t1
, rt
);
2713 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2729 /* Compare to zero */
2731 gen_load_gpr(t0
, rs
);
2734 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2741 /* Jump to immediate */
2742 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
2748 /* Jump to register */
2749 if (offset
!= 0 && offset
!= 16) {
2750 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2751 others are reserved. */
2752 MIPS_INVAL("jump hint");
2753 generate_exception(ctx
, EXCP_RI
);
2756 gen_load_gpr(btarget
, rs
);
2759 MIPS_INVAL("branch/jump");
2760 generate_exception(ctx
, EXCP_RI
);
2763 if (bcond_compute
== 0) {
2764 /* No condition to be computed */
2766 case OPC_BEQ
: /* rx == rx */
2767 case OPC_BEQL
: /* rx == rx likely */
2768 case OPC_BGEZ
: /* 0 >= 0 */
2769 case OPC_BGEZL
: /* 0 >= 0 likely */
2770 case OPC_BLEZ
: /* 0 <= 0 */
2771 case OPC_BLEZL
: /* 0 <= 0 likely */
2773 ctx
->hflags
|= MIPS_HFLAG_B
;
2774 MIPS_DEBUG("balways");
2777 case OPC_BGEZAL
: /* 0 >= 0 */
2778 case OPC_BGEZALL
: /* 0 >= 0 likely */
2779 ctx
->hflags
|= (opc
== OPC_BGEZALS
2781 : MIPS_HFLAG_BDS32
);
2782 /* Always take and link */
2784 ctx
->hflags
|= MIPS_HFLAG_B
;
2785 MIPS_DEBUG("balways and link");
2787 case OPC_BNE
: /* rx != rx */
2788 case OPC_BGTZ
: /* 0 > 0 */
2789 case OPC_BLTZ
: /* 0 < 0 */
2791 MIPS_DEBUG("bnever (NOP)");
2794 case OPC_BLTZAL
: /* 0 < 0 */
2795 ctx
->hflags
|= (opc
== OPC_BLTZALS
2797 : MIPS_HFLAG_BDS32
);
2798 /* Handle as an unconditional branch to get correct delay
2801 btgt
= ctx
->pc
+ (opc
== OPC_BLTZALS
? 6 : 8);
2802 ctx
->hflags
|= MIPS_HFLAG_B
;
2803 MIPS_DEBUG("bnever and link");
2805 case OPC_BLTZALL
: /* 0 < 0 likely */
2806 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2807 /* Skip the instruction in the delay slot */
2808 MIPS_DEBUG("bnever, link and skip");
2811 case OPC_BNEL
: /* rx != rx likely */
2812 case OPC_BGTZL
: /* 0 > 0 likely */
2813 case OPC_BLTZL
: /* 0 < 0 likely */
2814 /* Skip the instruction in the delay slot */
2815 MIPS_DEBUG("bnever and skip");
2819 ctx
->hflags
|= MIPS_HFLAG_B
;
2820 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2824 ctx
->hflags
|= MIPS_HFLAG_BX
;
2829 ctx
->hflags
|= MIPS_HFLAG_B
;
2830 ctx
->hflags
|= ((opc
== OPC_JALS
|| opc
== OPC_JALXS
)
2832 : MIPS_HFLAG_BDS32
);
2833 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2836 ctx
->hflags
|= MIPS_HFLAG_BR
;
2837 if (insn_bytes
== 4)
2838 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
2839 MIPS_DEBUG("jr %s", regnames
[rs
]);
2845 ctx
->hflags
|= MIPS_HFLAG_BR
;
2846 ctx
->hflags
|= (opc
== OPC_JALRS
2848 : MIPS_HFLAG_BDS32
);
2849 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2852 MIPS_INVAL("branch/jump");
2853 generate_exception(ctx
, EXCP_RI
);
2859 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2860 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2861 regnames
[rs
], regnames
[rt
], btgt
);
2864 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2865 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2866 regnames
[rs
], regnames
[rt
], btgt
);
2869 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2870 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2871 regnames
[rs
], regnames
[rt
], btgt
);
2874 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2875 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2876 regnames
[rs
], regnames
[rt
], btgt
);
2879 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2880 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2883 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2884 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2888 ctx
->hflags
|= (opc
== OPC_BGEZALS
2890 : MIPS_HFLAG_BDS32
);
2891 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2892 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2896 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2898 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2901 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2902 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2905 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2906 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2909 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2910 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2913 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2914 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2917 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2918 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2921 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2922 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2926 ctx
->hflags
|= (opc
== OPC_BLTZALS
2928 : MIPS_HFLAG_BDS32
);
2929 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2931 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2933 ctx
->hflags
|= MIPS_HFLAG_BC
;
2936 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2938 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2940 ctx
->hflags
|= MIPS_HFLAG_BL
;
2943 MIPS_INVAL("conditional branch/jump");
2944 generate_exception(ctx
, EXCP_RI
);
2948 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2949 blink
, ctx
->hflags
, btgt
);
2951 ctx
->btarget
= btgt
;
2953 int post_delay
= insn_bytes
;
2954 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
2956 if (opc
!= OPC_JALRC
)
2957 post_delay
+= ((ctx
->hflags
& MIPS_HFLAG_BDS16
) ? 2 : 4);
2959 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ post_delay
+ lowbit
);
2963 if (insn_bytes
== 2)
2964 ctx
->hflags
|= MIPS_HFLAG_B16
;
2969 /* special3 bitfield operations */
2970 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2971 int rs
, int lsb
, int msb
)
2973 TCGv t0
= tcg_temp_new();
2974 TCGv t1
= tcg_temp_new();
2977 gen_load_gpr(t1
, rs
);
2982 tcg_gen_shri_tl(t0
, t1
, lsb
);
2984 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2986 tcg_gen_ext32s_tl(t0
, t0
);
2989 #if defined(TARGET_MIPS64)
2991 tcg_gen_shri_tl(t0
, t1
, lsb
);
2993 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2997 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2998 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
3001 tcg_gen_shri_tl(t0
, t1
, lsb
);
3002 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
3008 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
3009 gen_load_gpr(t0
, rt
);
3010 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3011 tcg_gen_shli_tl(t1
, t1
, lsb
);
3012 tcg_gen_andi_tl(t1
, t1
, mask
);
3013 tcg_gen_or_tl(t0
, t0
, t1
);
3014 tcg_gen_ext32s_tl(t0
, t0
);
3016 #if defined(TARGET_MIPS64)
3020 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
3021 gen_load_gpr(t0
, rt
);
3022 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3023 tcg_gen_shli_tl(t1
, t1
, lsb
);
3024 tcg_gen_andi_tl(t1
, t1
, mask
);
3025 tcg_gen_or_tl(t0
, t0
, t1
);
3030 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << (lsb
+ 32);
3031 gen_load_gpr(t0
, rt
);
3032 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3033 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
3034 tcg_gen_andi_tl(t1
, t1
, mask
);
3035 tcg_gen_or_tl(t0
, t0
, t1
);
3040 gen_load_gpr(t0
, rt
);
3041 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
3042 gen_load_gpr(t0
, rt
);
3043 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3044 tcg_gen_shli_tl(t1
, t1
, lsb
);
3045 tcg_gen_andi_tl(t1
, t1
, mask
);
3046 tcg_gen_or_tl(t0
, t0
, t1
);
3051 MIPS_INVAL("bitops");
3052 generate_exception(ctx
, EXCP_RI
);
3057 gen_store_gpr(t0
, rt
);
3062 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
3067 /* If no destination, treat it as a NOP. */
3072 t0
= tcg_temp_new();
3073 gen_load_gpr(t0
, rt
);
3077 TCGv t1
= tcg_temp_new();
3079 tcg_gen_shri_tl(t1
, t0
, 8);
3080 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
3081 tcg_gen_shli_tl(t0
, t0
, 8);
3082 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
3083 tcg_gen_or_tl(t0
, t0
, t1
);
3085 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
3089 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
3092 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
3094 #if defined(TARGET_MIPS64)
3097 TCGv t1
= tcg_temp_new();
3099 tcg_gen_shri_tl(t1
, t0
, 8);
3100 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
3101 tcg_gen_shli_tl(t0
, t0
, 8);
3102 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
3103 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
3109 TCGv t1
= tcg_temp_new();
3111 tcg_gen_shri_tl(t1
, t0
, 16);
3112 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
3113 tcg_gen_shli_tl(t0
, t0
, 16);
3114 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
3115 tcg_gen_or_tl(t0
, t0
, t1
);
3116 tcg_gen_shri_tl(t1
, t0
, 32);
3117 tcg_gen_shli_tl(t0
, t0
, 32);
3118 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
3124 MIPS_INVAL("bsfhl");
3125 generate_exception(ctx
, EXCP_RI
);
3132 #ifndef CONFIG_USER_ONLY
3133 /* CP0 (MMU and control) */
3134 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
3136 TCGv_i32 t0
= tcg_temp_new_i32();
3138 tcg_gen_ld_i32(t0
, cpu_env
, off
);
3139 tcg_gen_ext_i32_tl(arg
, t0
);
3140 tcg_temp_free_i32(t0
);
3143 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
3145 tcg_gen_ld_tl(arg
, cpu_env
, off
);
3146 tcg_gen_ext32s_tl(arg
, arg
);
3149 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
3151 TCGv_i32 t0
= tcg_temp_new_i32();
3153 tcg_gen_trunc_tl_i32(t0
, arg
);
3154 tcg_gen_st_i32(t0
, cpu_env
, off
);
3155 tcg_temp_free_i32(t0
);
3158 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
3160 tcg_gen_ext32s_tl(arg
, arg
);
3161 tcg_gen_st_tl(arg
, cpu_env
, off
);
3164 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3166 const char *rn
= "invalid";
3169 check_insn(env
, ctx
, ISA_MIPS32
);
3175 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
3179 check_insn(env
, ctx
, ASE_MT
);
3180 gen_helper_mfc0_mvpcontrol(arg
);
3184 check_insn(env
, ctx
, ASE_MT
);
3185 gen_helper_mfc0_mvpconf0(arg
);
3189 check_insn(env
, ctx
, ASE_MT
);
3190 gen_helper_mfc0_mvpconf1(arg
);
3200 gen_helper_mfc0_random(arg
);
3204 check_insn(env
, ctx
, ASE_MT
);
3205 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
3209 check_insn(env
, ctx
, ASE_MT
);
3210 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
3214 check_insn(env
, ctx
, ASE_MT
);
3215 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
3219 check_insn(env
, ctx
, ASE_MT
);
3220 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
3224 check_insn(env
, ctx
, ASE_MT
);
3225 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3229 check_insn(env
, ctx
, ASE_MT
);
3230 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3231 rn
= "VPEScheFBack";
3234 check_insn(env
, ctx
, ASE_MT
);
3235 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
3245 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
3246 tcg_gen_ext32s_tl(arg
, arg
);
3250 check_insn(env
, ctx
, ASE_MT
);
3251 gen_helper_mfc0_tcstatus(arg
);
3255 check_insn(env
, ctx
, ASE_MT
);
3256 gen_helper_mfc0_tcbind(arg
);
3260 check_insn(env
, ctx
, ASE_MT
);
3261 gen_helper_mfc0_tcrestart(arg
);
3265 check_insn(env
, ctx
, ASE_MT
);
3266 gen_helper_mfc0_tchalt(arg
);
3270 check_insn(env
, ctx
, ASE_MT
);
3271 gen_helper_mfc0_tccontext(arg
);
3275 check_insn(env
, ctx
, ASE_MT
);
3276 gen_helper_mfc0_tcschedule(arg
);
3280 check_insn(env
, ctx
, ASE_MT
);
3281 gen_helper_mfc0_tcschefback(arg
);
3291 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
3292 tcg_gen_ext32s_tl(arg
, arg
);
3302 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
3303 tcg_gen_ext32s_tl(arg
, arg
);
3307 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3308 rn
= "ContextConfig";
3317 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
3321 check_insn(env
, ctx
, ISA_MIPS32R2
);
3322 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
3332 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
3336 check_insn(env
, ctx
, ISA_MIPS32R2
);
3337 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3341 check_insn(env
, ctx
, ISA_MIPS32R2
);
3342 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3346 check_insn(env
, ctx
, ISA_MIPS32R2
);
3347 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3351 check_insn(env
, ctx
, ISA_MIPS32R2
);
3352 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3356 check_insn(env
, ctx
, ISA_MIPS32R2
);
3357 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3367 check_insn(env
, ctx
, ISA_MIPS32R2
);
3368 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3378 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3379 tcg_gen_ext32s_tl(arg
, arg
);
3389 /* Mark as an IO operation because we read the time. */
3392 gen_helper_mfc0_count(arg
);
3395 ctx
->bstate
= BS_STOP
;
3399 /* 6,7 are implementation dependent */
3407 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3408 tcg_gen_ext32s_tl(arg
, arg
);
3418 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3421 /* 6,7 are implementation dependent */
3429 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3433 check_insn(env
, ctx
, ISA_MIPS32R2
);
3434 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3438 check_insn(env
, ctx
, ISA_MIPS32R2
);
3439 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3443 check_insn(env
, ctx
, ISA_MIPS32R2
);
3444 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3454 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3464 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3465 tcg_gen_ext32s_tl(arg
, arg
);
3475 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3479 check_insn(env
, ctx
, ISA_MIPS32R2
);
3480 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3490 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3494 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3498 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3502 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3505 /* 4,5 are reserved */
3506 /* 6,7 are implementation dependent */
3508 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3512 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3522 gen_helper_mfc0_lladdr(arg
);
3532 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3542 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3552 #if defined(TARGET_MIPS64)
3553 check_insn(env
, ctx
, ISA_MIPS3
);
3554 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3555 tcg_gen_ext32s_tl(arg
, arg
);
3564 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3567 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3575 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3576 rn
= "'Diagnostic"; /* implementation dependent */
3581 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3585 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3586 rn
= "TraceControl";
3589 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3590 rn
= "TraceControl2";
3593 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3594 rn
= "UserTraceData";
3597 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3608 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3609 tcg_gen_ext32s_tl(arg
, arg
);
3619 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3620 rn
= "Performance0";
3623 // gen_helper_mfc0_performance1(arg);
3624 rn
= "Performance1";
3627 // gen_helper_mfc0_performance2(arg);
3628 rn
= "Performance2";
3631 // gen_helper_mfc0_performance3(arg);
3632 rn
= "Performance3";
3635 // gen_helper_mfc0_performance4(arg);
3636 rn
= "Performance4";
3639 // gen_helper_mfc0_performance5(arg);
3640 rn
= "Performance5";
3643 // gen_helper_mfc0_performance6(arg);
3644 rn
= "Performance6";
3647 // gen_helper_mfc0_performance7(arg);
3648 rn
= "Performance7";
3655 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3661 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3674 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3681 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3694 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3701 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3711 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3712 tcg_gen_ext32s_tl(arg
, arg
);
3723 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3733 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3737 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3738 generate_exception(ctx
, EXCP_RI
);
3741 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3743 const char *rn
= "invalid";
3746 check_insn(env
, ctx
, ISA_MIPS32
);
3755 gen_helper_mtc0_index(arg
);
3759 check_insn(env
, ctx
, ASE_MT
);
3760 gen_helper_mtc0_mvpcontrol(arg
);
3764 check_insn(env
, ctx
, ASE_MT
);
3769 check_insn(env
, ctx
, ASE_MT
);
3784 check_insn(env
, ctx
, ASE_MT
);
3785 gen_helper_mtc0_vpecontrol(arg
);
3789 check_insn(env
, ctx
, ASE_MT
);
3790 gen_helper_mtc0_vpeconf0(arg
);
3794 check_insn(env
, ctx
, ASE_MT
);
3795 gen_helper_mtc0_vpeconf1(arg
);
3799 check_insn(env
, ctx
, ASE_MT
);
3800 gen_helper_mtc0_yqmask(arg
);
3804 check_insn(env
, ctx
, ASE_MT
);
3805 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3809 check_insn(env
, ctx
, ASE_MT
);
3810 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3811 rn
= "VPEScheFBack";
3814 check_insn(env
, ctx
, ASE_MT
);
3815 gen_helper_mtc0_vpeopt(arg
);
3825 gen_helper_mtc0_entrylo0(arg
);
3829 check_insn(env
, ctx
, ASE_MT
);
3830 gen_helper_mtc0_tcstatus(arg
);
3834 check_insn(env
, ctx
, ASE_MT
);
3835 gen_helper_mtc0_tcbind(arg
);
3839 check_insn(env
, ctx
, ASE_MT
);
3840 gen_helper_mtc0_tcrestart(arg
);
3844 check_insn(env
, ctx
, ASE_MT
);
3845 gen_helper_mtc0_tchalt(arg
);
3849 check_insn(env
, ctx
, ASE_MT
);
3850 gen_helper_mtc0_tccontext(arg
);
3854 check_insn(env
, ctx
, ASE_MT
);
3855 gen_helper_mtc0_tcschedule(arg
);
3859 check_insn(env
, ctx
, ASE_MT
);
3860 gen_helper_mtc0_tcschefback(arg
);
3870 gen_helper_mtc0_entrylo1(arg
);
3880 gen_helper_mtc0_context(arg
);
3884 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3885 rn
= "ContextConfig";
3894 gen_helper_mtc0_pagemask(arg
);
3898 check_insn(env
, ctx
, ISA_MIPS32R2
);
3899 gen_helper_mtc0_pagegrain(arg
);
3909 gen_helper_mtc0_wired(arg
);
3913 check_insn(env
, ctx
, ISA_MIPS32R2
);
3914 gen_helper_mtc0_srsconf0(arg
);
3918 check_insn(env
, ctx
, ISA_MIPS32R2
);
3919 gen_helper_mtc0_srsconf1(arg
);
3923 check_insn(env
, ctx
, ISA_MIPS32R2
);
3924 gen_helper_mtc0_srsconf2(arg
);
3928 check_insn(env
, ctx
, ISA_MIPS32R2
);
3929 gen_helper_mtc0_srsconf3(arg
);
3933 check_insn(env
, ctx
, ISA_MIPS32R2
);
3934 gen_helper_mtc0_srsconf4(arg
);
3944 check_insn(env
, ctx
, ISA_MIPS32R2
);
3945 gen_helper_mtc0_hwrena(arg
);
3959 gen_helper_mtc0_count(arg
);
3962 /* 6,7 are implementation dependent */
3970 gen_helper_mtc0_entryhi(arg
);
3980 gen_helper_mtc0_compare(arg
);
3983 /* 6,7 are implementation dependent */
3991 save_cpu_state(ctx
, 1);
3992 gen_helper_mtc0_status(arg
);
3993 /* BS_STOP isn't good enough here, hflags may have changed. */
3994 gen_save_pc(ctx
->pc
+ 4);
3995 ctx
->bstate
= BS_EXCP
;
3999 check_insn(env
, ctx
, ISA_MIPS32R2
);
4000 gen_helper_mtc0_intctl(arg
);
4001 /* Stop translation as we may have switched the execution mode */
4002 ctx
->bstate
= BS_STOP
;
4006 check_insn(env
, ctx
, ISA_MIPS32R2
);
4007 gen_helper_mtc0_srsctl(arg
);
4008 /* Stop translation as we may have switched the execution mode */
4009 ctx
->bstate
= BS_STOP
;
4013 check_insn(env
, ctx
, ISA_MIPS32R2
);
4014 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4015 /* Stop translation as we may have switched the execution mode */
4016 ctx
->bstate
= BS_STOP
;
4026 save_cpu_state(ctx
, 1);
4027 gen_helper_mtc0_cause(arg
);
4037 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
4051 check_insn(env
, ctx
, ISA_MIPS32R2
);
4052 gen_helper_mtc0_ebase(arg
);
4062 gen_helper_mtc0_config0(arg
);
4064 /* Stop translation as we may have switched the execution mode */
4065 ctx
->bstate
= BS_STOP
;
4068 /* ignored, read only */
4072 gen_helper_mtc0_config2(arg
);
4074 /* Stop translation as we may have switched the execution mode */
4075 ctx
->bstate
= BS_STOP
;
4078 /* ignored, read only */
4081 /* 4,5 are reserved */
4082 /* 6,7 are implementation dependent */
4092 rn
= "Invalid config selector";
4099 gen_helper_mtc0_lladdr(arg
);
4109 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
4119 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
4129 #if defined(TARGET_MIPS64)
4130 check_insn(env
, ctx
, ISA_MIPS3
);
4131 gen_helper_mtc0_xcontext(arg
);
4140 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4143 gen_helper_mtc0_framemask(arg
);
4152 rn
= "Diagnostic"; /* implementation dependent */
4157 gen_helper_mtc0_debug(arg
); /* EJTAG support */
4158 /* BS_STOP isn't good enough here, hflags may have changed. */
4159 gen_save_pc(ctx
->pc
+ 4);
4160 ctx
->bstate
= BS_EXCP
;
4164 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
4165 rn
= "TraceControl";
4166 /* Stop translation as we may have switched the execution mode */
4167 ctx
->bstate
= BS_STOP
;
4170 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
4171 rn
= "TraceControl2";
4172 /* Stop translation as we may have switched the execution mode */
4173 ctx
->bstate
= BS_STOP
;
4176 /* Stop translation as we may have switched the execution mode */
4177 ctx
->bstate
= BS_STOP
;
4178 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
4179 rn
= "UserTraceData";
4180 /* Stop translation as we may have switched the execution mode */
4181 ctx
->bstate
= BS_STOP
;
4184 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
4185 /* Stop translation as we may have switched the execution mode */
4186 ctx
->bstate
= BS_STOP
;
4197 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
4207 gen_helper_mtc0_performance0(arg
);
4208 rn
= "Performance0";
4211 // gen_helper_mtc0_performance1(arg);
4212 rn
= "Performance1";
4215 // gen_helper_mtc0_performance2(arg);
4216 rn
= "Performance2";
4219 // gen_helper_mtc0_performance3(arg);
4220 rn
= "Performance3";
4223 // gen_helper_mtc0_performance4(arg);
4224 rn
= "Performance4";
4227 // gen_helper_mtc0_performance5(arg);
4228 rn
= "Performance5";
4231 // gen_helper_mtc0_performance6(arg);
4232 rn
= "Performance6";
4235 // gen_helper_mtc0_performance7(arg);
4236 rn
= "Performance7";
4262 gen_helper_mtc0_taglo(arg
);
4269 gen_helper_mtc0_datalo(arg
);
4282 gen_helper_mtc0_taghi(arg
);
4289 gen_helper_mtc0_datahi(arg
);
4300 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
4311 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4317 /* Stop translation as we may have switched the execution mode */
4318 ctx
->bstate
= BS_STOP
;
4323 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4324 /* For simplicity assume that all writes can cause interrupts. */
4327 ctx
->bstate
= BS_STOP
;
4332 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4333 generate_exception(ctx
, EXCP_RI
);
4336 #if defined(TARGET_MIPS64)
4337 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4339 const char *rn
= "invalid";
4342 check_insn(env
, ctx
, ISA_MIPS64
);
4348 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4352 check_insn(env
, ctx
, ASE_MT
);
4353 gen_helper_mfc0_mvpcontrol(arg
);
4357 check_insn(env
, ctx
, ASE_MT
);
4358 gen_helper_mfc0_mvpconf0(arg
);
4362 check_insn(env
, ctx
, ASE_MT
);
4363 gen_helper_mfc0_mvpconf1(arg
);
4373 gen_helper_mfc0_random(arg
);
4377 check_insn(env
, ctx
, ASE_MT
);
4378 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4382 check_insn(env
, ctx
, ASE_MT
);
4383 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4387 check_insn(env
, ctx
, ASE_MT
);
4388 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4392 check_insn(env
, ctx
, ASE_MT
);
4393 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4397 check_insn(env
, ctx
, ASE_MT
);
4398 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4402 check_insn(env
, ctx
, ASE_MT
);
4403 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4404 rn
= "VPEScheFBack";
4407 check_insn(env
, ctx
, ASE_MT
);
4408 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4418 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4422 check_insn(env
, ctx
, ASE_MT
);
4423 gen_helper_mfc0_tcstatus(arg
);
4427 check_insn(env
, ctx
, ASE_MT
);
4428 gen_helper_mfc0_tcbind(arg
);
4432 check_insn(env
, ctx
, ASE_MT
);
4433 gen_helper_dmfc0_tcrestart(arg
);
4437 check_insn(env
, ctx
, ASE_MT
);
4438 gen_helper_dmfc0_tchalt(arg
);
4442 check_insn(env
, ctx
, ASE_MT
);
4443 gen_helper_dmfc0_tccontext(arg
);
4447 check_insn(env
, ctx
, ASE_MT
);
4448 gen_helper_dmfc0_tcschedule(arg
);
4452 check_insn(env
, ctx
, ASE_MT
);
4453 gen_helper_dmfc0_tcschefback(arg
);
4463 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4473 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4477 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4478 rn
= "ContextConfig";
4487 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4491 check_insn(env
, ctx
, ISA_MIPS32R2
);
4492 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4502 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4506 check_insn(env
, ctx
, ISA_MIPS32R2
);
4507 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4511 check_insn(env
, ctx
, ISA_MIPS32R2
);
4512 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4516 check_insn(env
, ctx
, ISA_MIPS32R2
);
4517 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4521 check_insn(env
, ctx
, ISA_MIPS32R2
);
4522 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4526 check_insn(env
, ctx
, ISA_MIPS32R2
);
4527 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4537 check_insn(env
, ctx
, ISA_MIPS32R2
);
4538 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4548 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4558 /* Mark as an IO operation because we read the time. */
4561 gen_helper_mfc0_count(arg
);
4564 ctx
->bstate
= BS_STOP
;
4568 /* 6,7 are implementation dependent */
4576 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4586 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4589 /* 6,7 are implementation dependent */
4597 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4601 check_insn(env
, ctx
, ISA_MIPS32R2
);
4602 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4606 check_insn(env
, ctx
, ISA_MIPS32R2
);
4607 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4611 check_insn(env
, ctx
, ISA_MIPS32R2
);
4612 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4622 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4632 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4642 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4646 check_insn(env
, ctx
, ISA_MIPS32R2
);
4647 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4657 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4661 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4665 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4669 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4672 /* 6,7 are implementation dependent */
4674 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4678 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4688 gen_helper_dmfc0_lladdr(arg
);
4698 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4708 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4718 check_insn(env
, ctx
, ISA_MIPS3
);
4719 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4727 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4730 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4738 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4739 rn
= "'Diagnostic"; /* implementation dependent */
4744 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4748 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4749 rn
= "TraceControl";
4752 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4753 rn
= "TraceControl2";
4756 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4757 rn
= "UserTraceData";
4760 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4771 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4781 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4782 rn
= "Performance0";
4785 // gen_helper_dmfc0_performance1(arg);
4786 rn
= "Performance1";
4789 // gen_helper_dmfc0_performance2(arg);
4790 rn
= "Performance2";
4793 // gen_helper_dmfc0_performance3(arg);
4794 rn
= "Performance3";
4797 // gen_helper_dmfc0_performance4(arg);
4798 rn
= "Performance4";
4801 // gen_helper_dmfc0_performance5(arg);
4802 rn
= "Performance5";
4805 // gen_helper_dmfc0_performance6(arg);
4806 rn
= "Performance6";
4809 // gen_helper_dmfc0_performance7(arg);
4810 rn
= "Performance7";
4817 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4824 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4837 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4844 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4857 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4864 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4874 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4885 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4895 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4899 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4900 generate_exception(ctx
, EXCP_RI
);
4903 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4905 const char *rn
= "invalid";
4908 check_insn(env
, ctx
, ISA_MIPS64
);
4917 gen_helper_mtc0_index(arg
);
4921 check_insn(env
, ctx
, ASE_MT
);
4922 gen_helper_mtc0_mvpcontrol(arg
);
4926 check_insn(env
, ctx
, ASE_MT
);
4931 check_insn(env
, ctx
, ASE_MT
);
4946 check_insn(env
, ctx
, ASE_MT
);
4947 gen_helper_mtc0_vpecontrol(arg
);
4951 check_insn(env
, ctx
, ASE_MT
);
4952 gen_helper_mtc0_vpeconf0(arg
);
4956 check_insn(env
, ctx
, ASE_MT
);
4957 gen_helper_mtc0_vpeconf1(arg
);
4961 check_insn(env
, ctx
, ASE_MT
);
4962 gen_helper_mtc0_yqmask(arg
);
4966 check_insn(env
, ctx
, ASE_MT
);
4967 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4971 check_insn(env
, ctx
, ASE_MT
);
4972 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4973 rn
= "VPEScheFBack";
4976 check_insn(env
, ctx
, ASE_MT
);
4977 gen_helper_mtc0_vpeopt(arg
);
4987 gen_helper_mtc0_entrylo0(arg
);
4991 check_insn(env
, ctx
, ASE_MT
);
4992 gen_helper_mtc0_tcstatus(arg
);
4996 check_insn(env
, ctx
, ASE_MT
);
4997 gen_helper_mtc0_tcbind(arg
);
5001 check_insn(env
, ctx
, ASE_MT
);
5002 gen_helper_mtc0_tcrestart(arg
);
5006 check_insn(env
, ctx
, ASE_MT
);
5007 gen_helper_mtc0_tchalt(arg
);
5011 check_insn(env
, ctx
, ASE_MT
);
5012 gen_helper_mtc0_tccontext(arg
);
5016 check_insn(env
, ctx
, ASE_MT
);
5017 gen_helper_mtc0_tcschedule(arg
);
5021 check_insn(env
, ctx
, ASE_MT
);
5022 gen_helper_mtc0_tcschefback(arg
);
5032 gen_helper_mtc0_entrylo1(arg
);
5042 gen_helper_mtc0_context(arg
);
5046 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
5047 rn
= "ContextConfig";
5056 gen_helper_mtc0_pagemask(arg
);
5060 check_insn(env
, ctx
, ISA_MIPS32R2
);
5061 gen_helper_mtc0_pagegrain(arg
);
5071 gen_helper_mtc0_wired(arg
);
5075 check_insn(env
, ctx
, ISA_MIPS32R2
);
5076 gen_helper_mtc0_srsconf0(arg
);
5080 check_insn(env
, ctx
, ISA_MIPS32R2
);
5081 gen_helper_mtc0_srsconf1(arg
);
5085 check_insn(env
, ctx
, ISA_MIPS32R2
);
5086 gen_helper_mtc0_srsconf2(arg
);
5090 check_insn(env
, ctx
, ISA_MIPS32R2
);
5091 gen_helper_mtc0_srsconf3(arg
);
5095 check_insn(env
, ctx
, ISA_MIPS32R2
);
5096 gen_helper_mtc0_srsconf4(arg
);
5106 check_insn(env
, ctx
, ISA_MIPS32R2
);
5107 gen_helper_mtc0_hwrena(arg
);
5121 gen_helper_mtc0_count(arg
);
5124 /* 6,7 are implementation dependent */
5128 /* Stop translation as we may have switched the execution mode */
5129 ctx
->bstate
= BS_STOP
;
5134 gen_helper_mtc0_entryhi(arg
);
5144 gen_helper_mtc0_compare(arg
);
5147 /* 6,7 are implementation dependent */
5151 /* Stop translation as we may have switched the execution mode */
5152 ctx
->bstate
= BS_STOP
;
5157 save_cpu_state(ctx
, 1);
5158 gen_helper_mtc0_status(arg
);
5159 /* BS_STOP isn't good enough here, hflags may have changed. */
5160 gen_save_pc(ctx
->pc
+ 4);
5161 ctx
->bstate
= BS_EXCP
;
5165 check_insn(env
, ctx
, ISA_MIPS32R2
);
5166 gen_helper_mtc0_intctl(arg
);
5167 /* Stop translation as we may have switched the execution mode */
5168 ctx
->bstate
= BS_STOP
;
5172 check_insn(env
, ctx
, ISA_MIPS32R2
);
5173 gen_helper_mtc0_srsctl(arg
);
5174 /* Stop translation as we may have switched the execution mode */
5175 ctx
->bstate
= BS_STOP
;
5179 check_insn(env
, ctx
, ISA_MIPS32R2
);
5180 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
5181 /* Stop translation as we may have switched the execution mode */
5182 ctx
->bstate
= BS_STOP
;
5192 save_cpu_state(ctx
, 1);
5193 /* Mark as an IO operation because we may trigger a software
5198 gen_helper_mtc0_cause(arg
);
5202 /* Stop translation as we may have triggered an intetrupt */
5203 ctx
->bstate
= BS_STOP
;
5213 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
5227 check_insn(env
, ctx
, ISA_MIPS32R2
);
5228 gen_helper_mtc0_ebase(arg
);
5238 gen_helper_mtc0_config0(arg
);
5240 /* Stop translation as we may have switched the execution mode */
5241 ctx
->bstate
= BS_STOP
;
5244 /* ignored, read only */
5248 gen_helper_mtc0_config2(arg
);
5250 /* Stop translation as we may have switched the execution mode */
5251 ctx
->bstate
= BS_STOP
;
5257 /* 6,7 are implementation dependent */
5259 rn
= "Invalid config selector";
5266 gen_helper_mtc0_lladdr(arg
);
5276 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
5286 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
5296 check_insn(env
, ctx
, ISA_MIPS3
);
5297 gen_helper_mtc0_xcontext(arg
);
5305 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5308 gen_helper_mtc0_framemask(arg
);
5317 rn
= "Diagnostic"; /* implementation dependent */
5322 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5323 /* BS_STOP isn't good enough here, hflags may have changed. */
5324 gen_save_pc(ctx
->pc
+ 4);
5325 ctx
->bstate
= BS_EXCP
;
5329 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5330 /* Stop translation as we may have switched the execution mode */
5331 ctx
->bstate
= BS_STOP
;
5332 rn
= "TraceControl";
5335 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5336 /* Stop translation as we may have switched the execution mode */
5337 ctx
->bstate
= BS_STOP
;
5338 rn
= "TraceControl2";
5341 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5342 /* Stop translation as we may have switched the execution mode */
5343 ctx
->bstate
= BS_STOP
;
5344 rn
= "UserTraceData";
5347 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5348 /* Stop translation as we may have switched the execution mode */
5349 ctx
->bstate
= BS_STOP
;
5360 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5370 gen_helper_mtc0_performance0(arg
);
5371 rn
= "Performance0";
5374 // gen_helper_mtc0_performance1(arg);
5375 rn
= "Performance1";
5378 // gen_helper_mtc0_performance2(arg);
5379 rn
= "Performance2";
5382 // gen_helper_mtc0_performance3(arg);
5383 rn
= "Performance3";
5386 // gen_helper_mtc0_performance4(arg);
5387 rn
= "Performance4";
5390 // gen_helper_mtc0_performance5(arg);
5391 rn
= "Performance5";
5394 // gen_helper_mtc0_performance6(arg);
5395 rn
= "Performance6";
5398 // gen_helper_mtc0_performance7(arg);
5399 rn
= "Performance7";
5425 gen_helper_mtc0_taglo(arg
);
5432 gen_helper_mtc0_datalo(arg
);
5445 gen_helper_mtc0_taghi(arg
);
5452 gen_helper_mtc0_datahi(arg
);
5463 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5474 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5480 /* Stop translation as we may have switched the execution mode */
5481 ctx
->bstate
= BS_STOP
;
5486 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5487 /* For simplicity assume that all writes can cause interrupts. */
5490 ctx
->bstate
= BS_STOP
;
5495 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5496 generate_exception(ctx
, EXCP_RI
);
5498 #endif /* TARGET_MIPS64 */
5500 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5501 int u
, int sel
, int h
)
5503 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5504 TCGv t0
= tcg_temp_local_new();
5506 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5507 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5508 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5509 tcg_gen_movi_tl(t0
, -1);
5510 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5511 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5512 tcg_gen_movi_tl(t0
, -1);
5518 gen_helper_mftc0_tcstatus(t0
);
5521 gen_helper_mftc0_tcbind(t0
);
5524 gen_helper_mftc0_tcrestart(t0
);
5527 gen_helper_mftc0_tchalt(t0
);
5530 gen_helper_mftc0_tccontext(t0
);
5533 gen_helper_mftc0_tcschedule(t0
);
5536 gen_helper_mftc0_tcschefback(t0
);
5539 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5546 gen_helper_mftc0_entryhi(t0
);
5549 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5555 gen_helper_mftc0_status(t0
);
5558 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5564 gen_helper_mftc0_debug(t0
);
5567 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5572 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5574 } else switch (sel
) {
5575 /* GPR registers. */
5577 gen_helper_1i(mftgpr
, t0
, rt
);
5579 /* Auxiliary CPU registers */
5583 gen_helper_1i(mftlo
, t0
, 0);
5586 gen_helper_1i(mfthi
, t0
, 0);
5589 gen_helper_1i(mftacx
, t0
, 0);
5592 gen_helper_1i(mftlo
, t0
, 1);
5595 gen_helper_1i(mfthi
, t0
, 1);
5598 gen_helper_1i(mftacx
, t0
, 1);
5601 gen_helper_1i(mftlo
, t0
, 2);
5604 gen_helper_1i(mfthi
, t0
, 2);
5607 gen_helper_1i(mftacx
, t0
, 2);
5610 gen_helper_1i(mftlo
, t0
, 3);
5613 gen_helper_1i(mfthi
, t0
, 3);
5616 gen_helper_1i(mftacx
, t0
, 3);
5619 gen_helper_mftdsp(t0
);
5625 /* Floating point (COP1). */
5627 /* XXX: For now we support only a single FPU context. */
5629 TCGv_i32 fp0
= tcg_temp_new_i32();
5631 gen_load_fpr32(fp0
, rt
);
5632 tcg_gen_ext_i32_tl(t0
, fp0
);
5633 tcg_temp_free_i32(fp0
);
5635 TCGv_i32 fp0
= tcg_temp_new_i32();
5637 gen_load_fpr32h(fp0
, rt
);
5638 tcg_gen_ext_i32_tl(t0
, fp0
);
5639 tcg_temp_free_i32(fp0
);
5643 /* XXX: For now we support only a single FPU context. */
5644 gen_helper_1i(cfc1
, t0
, rt
);
5646 /* COP2: Not implemented. */
5653 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5654 gen_store_gpr(t0
, rd
);
5660 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5661 generate_exception(ctx
, EXCP_RI
);
5664 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5665 int u
, int sel
, int h
)
5667 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5668 TCGv t0
= tcg_temp_local_new();
5670 gen_load_gpr(t0
, rt
);
5671 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5672 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5673 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5675 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5676 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5683 gen_helper_mttc0_tcstatus(t0
);
5686 gen_helper_mttc0_tcbind(t0
);
5689 gen_helper_mttc0_tcrestart(t0
);
5692 gen_helper_mttc0_tchalt(t0
);
5695 gen_helper_mttc0_tccontext(t0
);
5698 gen_helper_mttc0_tcschedule(t0
);
5701 gen_helper_mttc0_tcschefback(t0
);
5704 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5711 gen_helper_mttc0_entryhi(t0
);
5714 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5720 gen_helper_mttc0_status(t0
);
5723 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5729 gen_helper_mttc0_debug(t0
);
5732 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5737 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5739 } else switch (sel
) {
5740 /* GPR registers. */
5742 gen_helper_1i(mttgpr
, t0
, rd
);
5744 /* Auxiliary CPU registers */
5748 gen_helper_1i(mttlo
, t0
, 0);
5751 gen_helper_1i(mtthi
, t0
, 0);
5754 gen_helper_1i(mttacx
, t0
, 0);
5757 gen_helper_1i(mttlo
, t0
, 1);
5760 gen_helper_1i(mtthi
, t0
, 1);
5763 gen_helper_1i(mttacx
, t0
, 1);
5766 gen_helper_1i(mttlo
, t0
, 2);
5769 gen_helper_1i(mtthi
, t0
, 2);
5772 gen_helper_1i(mttacx
, t0
, 2);
5775 gen_helper_1i(mttlo
, t0
, 3);
5778 gen_helper_1i(mtthi
, t0
, 3);
5781 gen_helper_1i(mttacx
, t0
, 3);
5784 gen_helper_mttdsp(t0
);
5790 /* Floating point (COP1). */
5792 /* XXX: For now we support only a single FPU context. */
5794 TCGv_i32 fp0
= tcg_temp_new_i32();
5796 tcg_gen_trunc_tl_i32(fp0
, t0
);
5797 gen_store_fpr32(fp0
, rd
);
5798 tcg_temp_free_i32(fp0
);
5800 TCGv_i32 fp0
= tcg_temp_new_i32();
5802 tcg_gen_trunc_tl_i32(fp0
, t0
);
5803 gen_store_fpr32h(fp0
, rd
);
5804 tcg_temp_free_i32(fp0
);
5808 /* XXX: For now we support only a single FPU context. */
5809 gen_helper_1i(ctc1
, t0
, rd
);
5811 /* COP2: Not implemented. */
5818 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5824 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5825 generate_exception(ctx
, EXCP_RI
);
5828 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5830 const char *opn
= "ldst";
5838 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5843 TCGv t0
= tcg_temp_new();
5845 gen_load_gpr(t0
, rt
);
5846 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5851 #if defined(TARGET_MIPS64)
5853 check_insn(env
, ctx
, ISA_MIPS3
);
5858 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5862 check_insn(env
, ctx
, ISA_MIPS3
);
5864 TCGv t0
= tcg_temp_new();
5866 gen_load_gpr(t0
, rt
);
5867 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5874 check_insn(env
, ctx
, ASE_MT
);
5879 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5880 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5884 check_insn(env
, ctx
, ASE_MT
);
5885 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5886 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5891 if (!env
->tlb
->helper_tlbwi
)
5897 if (!env
->tlb
->helper_tlbwr
)
5903 if (!env
->tlb
->helper_tlbp
)
5909 if (!env
->tlb
->helper_tlbr
)
5915 check_insn(env
, ctx
, ISA_MIPS2
);
5917 ctx
->bstate
= BS_EXCP
;
5921 check_insn(env
, ctx
, ISA_MIPS32
);
5922 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5924 generate_exception(ctx
, EXCP_RI
);
5927 ctx
->bstate
= BS_EXCP
;
5932 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5933 /* If we get an exception, we want to restart at next instruction */
5935 save_cpu_state(ctx
, 1);
5938 ctx
->bstate
= BS_EXCP
;
5943 generate_exception(ctx
, EXCP_RI
);
5946 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5948 #endif /* !CONFIG_USER_ONLY */
5950 /* CP1 Branches (before delay slot) */
5951 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5952 int32_t cc
, int32_t offset
)
5954 target_ulong btarget
;
5955 const char *opn
= "cp1 cond branch";
5956 TCGv_i32 t0
= tcg_temp_new_i32();
5959 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5961 btarget
= ctx
->pc
+ 4 + offset
;
5965 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5966 tcg_gen_not_i32(t0
, t0
);
5967 tcg_gen_andi_i32(t0
, t0
, 1);
5968 tcg_gen_extu_i32_tl(bcond
, t0
);
5972 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5973 tcg_gen_not_i32(t0
, t0
);
5974 tcg_gen_andi_i32(t0
, t0
, 1);
5975 tcg_gen_extu_i32_tl(bcond
, t0
);
5979 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5980 tcg_gen_andi_i32(t0
, t0
, 1);
5981 tcg_gen_extu_i32_tl(bcond
, t0
);
5985 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5986 tcg_gen_andi_i32(t0
, t0
, 1);
5987 tcg_gen_extu_i32_tl(bcond
, t0
);
5990 ctx
->hflags
|= MIPS_HFLAG_BL
;
5994 TCGv_i32 t1
= tcg_temp_new_i32();
5995 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5996 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5997 tcg_gen_nor_i32(t0
, t0
, t1
);
5998 tcg_temp_free_i32(t1
);
5999 tcg_gen_andi_i32(t0
, t0
, 1);
6000 tcg_gen_extu_i32_tl(bcond
, t0
);
6006 TCGv_i32 t1
= tcg_temp_new_i32();
6007 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6008 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6009 tcg_gen_or_i32(t0
, t0
, t1
);
6010 tcg_temp_free_i32(t1
);
6011 tcg_gen_andi_i32(t0
, t0
, 1);
6012 tcg_gen_extu_i32_tl(bcond
, t0
);
6018 TCGv_i32 t1
= tcg_temp_new_i32();
6019 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6020 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6021 tcg_gen_or_i32(t0
, t0
, t1
);
6022 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
6023 tcg_gen_or_i32(t0
, t0
, t1
);
6024 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
6025 tcg_gen_nor_i32(t0
, t0
, t1
);
6026 tcg_temp_free_i32(t1
);
6027 tcg_gen_andi_i32(t0
, t0
, 1);
6028 tcg_gen_extu_i32_tl(bcond
, t0
);
6034 TCGv_i32 t1
= tcg_temp_new_i32();
6035 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6036 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6037 tcg_gen_or_i32(t0
, t0
, t1
);
6038 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
6039 tcg_gen_or_i32(t0
, t0
, t1
);
6040 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
6041 tcg_gen_or_i32(t0
, t0
, t1
);
6042 tcg_temp_free_i32(t1
);
6043 tcg_gen_andi_i32(t0
, t0
, 1);
6044 tcg_gen_extu_i32_tl(bcond
, t0
);
6048 ctx
->hflags
|= MIPS_HFLAG_BC
;
6052 generate_exception (ctx
, EXCP_RI
);
6055 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
6056 ctx
->hflags
, btarget
);
6057 ctx
->btarget
= btarget
;
6060 tcg_temp_free_i32(t0
);
6063 /* Coprocessor 1 (FPU) */
6065 #define FOP(func, fmt) (((fmt) << 21) | (func))
6068 OPC_ADD_S
= FOP(0, FMT_S
),
6069 OPC_SUB_S
= FOP(1, FMT_S
),
6070 OPC_MUL_S
= FOP(2, FMT_S
),
6071 OPC_DIV_S
= FOP(3, FMT_S
),
6072 OPC_SQRT_S
= FOP(4, FMT_S
),
6073 OPC_ABS_S
= FOP(5, FMT_S
),
6074 OPC_MOV_S
= FOP(6, FMT_S
),
6075 OPC_NEG_S
= FOP(7, FMT_S
),
6076 OPC_ROUND_L_S
= FOP(8, FMT_S
),
6077 OPC_TRUNC_L_S
= FOP(9, FMT_S
),
6078 OPC_CEIL_L_S
= FOP(10, FMT_S
),
6079 OPC_FLOOR_L_S
= FOP(11, FMT_S
),
6080 OPC_ROUND_W_S
= FOP(12, FMT_S
),
6081 OPC_TRUNC_W_S
= FOP(13, FMT_S
),
6082 OPC_CEIL_W_S
= FOP(14, FMT_S
),
6083 OPC_FLOOR_W_S
= FOP(15, FMT_S
),
6084 OPC_MOVCF_S
= FOP(17, FMT_S
),
6085 OPC_MOVZ_S
= FOP(18, FMT_S
),
6086 OPC_MOVN_S
= FOP(19, FMT_S
),
6087 OPC_RECIP_S
= FOP(21, FMT_S
),
6088 OPC_RSQRT_S
= FOP(22, FMT_S
),
6089 OPC_RECIP2_S
= FOP(28, FMT_S
),
6090 OPC_RECIP1_S
= FOP(29, FMT_S
),
6091 OPC_RSQRT1_S
= FOP(30, FMT_S
),
6092 OPC_RSQRT2_S
= FOP(31, FMT_S
),
6093 OPC_CVT_D_S
= FOP(33, FMT_S
),
6094 OPC_CVT_W_S
= FOP(36, FMT_S
),
6095 OPC_CVT_L_S
= FOP(37, FMT_S
),
6096 OPC_CVT_PS_S
= FOP(38, FMT_S
),
6097 OPC_CMP_F_S
= FOP (48, FMT_S
),
6098 OPC_CMP_UN_S
= FOP (49, FMT_S
),
6099 OPC_CMP_EQ_S
= FOP (50, FMT_S
),
6100 OPC_CMP_UEQ_S
= FOP (51, FMT_S
),
6101 OPC_CMP_OLT_S
= FOP (52, FMT_S
),
6102 OPC_CMP_ULT_S
= FOP (53, FMT_S
),
6103 OPC_CMP_OLE_S
= FOP (54, FMT_S
),
6104 OPC_CMP_ULE_S
= FOP (55, FMT_S
),
6105 OPC_CMP_SF_S
= FOP (56, FMT_S
),
6106 OPC_CMP_NGLE_S
= FOP (57, FMT_S
),
6107 OPC_CMP_SEQ_S
= FOP (58, FMT_S
),
6108 OPC_CMP_NGL_S
= FOP (59, FMT_S
),
6109 OPC_CMP_LT_S
= FOP (60, FMT_S
),
6110 OPC_CMP_NGE_S
= FOP (61, FMT_S
),
6111 OPC_CMP_LE_S
= FOP (62, FMT_S
),
6112 OPC_CMP_NGT_S
= FOP (63, FMT_S
),
6114 OPC_ADD_D
= FOP(0, FMT_D
),
6115 OPC_SUB_D
= FOP(1, FMT_D
),
6116 OPC_MUL_D
= FOP(2, FMT_D
),
6117 OPC_DIV_D
= FOP(3, FMT_D
),
6118 OPC_SQRT_D
= FOP(4, FMT_D
),
6119 OPC_ABS_D
= FOP(5, FMT_D
),
6120 OPC_MOV_D
= FOP(6, FMT_D
),
6121 OPC_NEG_D
= FOP(7, FMT_D
),
6122 OPC_ROUND_L_D
= FOP(8, FMT_D
),
6123 OPC_TRUNC_L_D
= FOP(9, FMT_D
),
6124 OPC_CEIL_L_D
= FOP(10, FMT_D
),
6125 OPC_FLOOR_L_D
= FOP(11, FMT_D
),
6126 OPC_ROUND_W_D
= FOP(12, FMT_D
),
6127 OPC_TRUNC_W_D
= FOP(13, FMT_D
),
6128 OPC_CEIL_W_D
= FOP(14, FMT_D
),
6129 OPC_FLOOR_W_D
= FOP(15, FMT_D
),
6130 OPC_MOVCF_D
= FOP(17, FMT_D
),
6131 OPC_MOVZ_D
= FOP(18, FMT_D
),
6132 OPC_MOVN_D
= FOP(19, FMT_D
),
6133 OPC_RECIP_D
= FOP(21, FMT_D
),
6134 OPC_RSQRT_D
= FOP(22, FMT_D
),
6135 OPC_RECIP2_D
= FOP(28, FMT_D
),
6136 OPC_RECIP1_D
= FOP(29, FMT_D
),
6137 OPC_RSQRT1_D
= FOP(30, FMT_D
),
6138 OPC_RSQRT2_D
= FOP(31, FMT_D
),
6139 OPC_CVT_S_D
= FOP(32, FMT_D
),
6140 OPC_CVT_W_D
= FOP(36, FMT_D
),
6141 OPC_CVT_L_D
= FOP(37, FMT_D
),
6142 OPC_CMP_F_D
= FOP (48, FMT_D
),
6143 OPC_CMP_UN_D
= FOP (49, FMT_D
),
6144 OPC_CMP_EQ_D
= FOP (50, FMT_D
),
6145 OPC_CMP_UEQ_D
= FOP (51, FMT_D
),
6146 OPC_CMP_OLT_D
= FOP (52, FMT_D
),
6147 OPC_CMP_ULT_D
= FOP (53, FMT_D
),
6148 OPC_CMP_OLE_D
= FOP (54, FMT_D
),
6149 OPC_CMP_ULE_D
= FOP (55, FMT_D
),
6150 OPC_CMP_SF_D
= FOP (56, FMT_D
),
6151 OPC_CMP_NGLE_D
= FOP (57, FMT_D
),
6152 OPC_CMP_SEQ_D
= FOP (58, FMT_D
),
6153 OPC_CMP_NGL_D
= FOP (59, FMT_D
),
6154 OPC_CMP_LT_D
= FOP (60, FMT_D
),
6155 OPC_CMP_NGE_D
= FOP (61, FMT_D
),
6156 OPC_CMP_LE_D
= FOP (62, FMT_D
),
6157 OPC_CMP_NGT_D
= FOP (63, FMT_D
),
6159 OPC_CVT_S_W
= FOP(32, FMT_W
),
6160 OPC_CVT_D_W
= FOP(33, FMT_W
),
6161 OPC_CVT_S_L
= FOP(32, FMT_L
),
6162 OPC_CVT_D_L
= FOP(33, FMT_L
),
6163 OPC_CVT_PS_PW
= FOP(38, FMT_W
),
6165 OPC_ADD_PS
= FOP(0, FMT_PS
),
6166 OPC_SUB_PS
= FOP(1, FMT_PS
),
6167 OPC_MUL_PS
= FOP(2, FMT_PS
),
6168 OPC_DIV_PS
= FOP(3, FMT_PS
),
6169 OPC_ABS_PS
= FOP(5, FMT_PS
),
6170 OPC_MOV_PS
= FOP(6, FMT_PS
),
6171 OPC_NEG_PS
= FOP(7, FMT_PS
),
6172 OPC_MOVCF_PS
= FOP(17, FMT_PS
),
6173 OPC_MOVZ_PS
= FOP(18, FMT_PS
),
6174 OPC_MOVN_PS
= FOP(19, FMT_PS
),
6175 OPC_ADDR_PS
= FOP(24, FMT_PS
),
6176 OPC_MULR_PS
= FOP(26, FMT_PS
),
6177 OPC_RECIP2_PS
= FOP(28, FMT_PS
),
6178 OPC_RECIP1_PS
= FOP(29, FMT_PS
),
6179 OPC_RSQRT1_PS
= FOP(30, FMT_PS
),
6180 OPC_RSQRT2_PS
= FOP(31, FMT_PS
),
6182 OPC_CVT_S_PU
= FOP(32, FMT_PS
),
6183 OPC_CVT_PW_PS
= FOP(36, FMT_PS
),
6184 OPC_CVT_S_PL
= FOP(40, FMT_PS
),
6185 OPC_PLL_PS
= FOP(44, FMT_PS
),
6186 OPC_PLU_PS
= FOP(45, FMT_PS
),
6187 OPC_PUL_PS
= FOP(46, FMT_PS
),
6188 OPC_PUU_PS
= FOP(47, FMT_PS
),
6189 OPC_CMP_F_PS
= FOP (48, FMT_PS
),
6190 OPC_CMP_UN_PS
= FOP (49, FMT_PS
),
6191 OPC_CMP_EQ_PS
= FOP (50, FMT_PS
),
6192 OPC_CMP_UEQ_PS
= FOP (51, FMT_PS
),
6193 OPC_CMP_OLT_PS
= FOP (52, FMT_PS
),
6194 OPC_CMP_ULT_PS
= FOP (53, FMT_PS
),
6195 OPC_CMP_OLE_PS
= FOP (54, FMT_PS
),
6196 OPC_CMP_ULE_PS
= FOP (55, FMT_PS
),
6197 OPC_CMP_SF_PS
= FOP (56, FMT_PS
),
6198 OPC_CMP_NGLE_PS
= FOP (57, FMT_PS
),
6199 OPC_CMP_SEQ_PS
= FOP (58, FMT_PS
),
6200 OPC_CMP_NGL_PS
= FOP (59, FMT_PS
),
6201 OPC_CMP_LT_PS
= FOP (60, FMT_PS
),
6202 OPC_CMP_NGE_PS
= FOP (61, FMT_PS
),
6203 OPC_CMP_LE_PS
= FOP (62, FMT_PS
),
6204 OPC_CMP_NGT_PS
= FOP (63, FMT_PS
),
6207 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
6209 const char *opn
= "cp1 move";
6210 TCGv t0
= tcg_temp_new();
6215 TCGv_i32 fp0
= tcg_temp_new_i32();
6217 gen_load_fpr32(fp0
, fs
);
6218 tcg_gen_ext_i32_tl(t0
, fp0
);
6219 tcg_temp_free_i32(fp0
);
6221 gen_store_gpr(t0
, rt
);
6225 gen_load_gpr(t0
, rt
);
6227 TCGv_i32 fp0
= tcg_temp_new_i32();
6229 tcg_gen_trunc_tl_i32(fp0
, t0
);
6230 gen_store_fpr32(fp0
, fs
);
6231 tcg_temp_free_i32(fp0
);
6236 gen_helper_1i(cfc1
, t0
, fs
);
6237 gen_store_gpr(t0
, rt
);
6241 gen_load_gpr(t0
, rt
);
6242 gen_helper_1i(ctc1
, t0
, fs
);
6245 #if defined(TARGET_MIPS64)
6247 gen_load_fpr64(ctx
, t0
, fs
);
6248 gen_store_gpr(t0
, rt
);
6252 gen_load_gpr(t0
, rt
);
6253 gen_store_fpr64(ctx
, t0
, fs
);
6259 TCGv_i32 fp0
= tcg_temp_new_i32();
6261 gen_load_fpr32h(fp0
, fs
);
6262 tcg_gen_ext_i32_tl(t0
, fp0
);
6263 tcg_temp_free_i32(fp0
);
6265 gen_store_gpr(t0
, rt
);
6269 gen_load_gpr(t0
, rt
);
6271 TCGv_i32 fp0
= tcg_temp_new_i32();
6273 tcg_gen_trunc_tl_i32(fp0
, t0
);
6274 gen_store_fpr32h(fp0
, fs
);
6275 tcg_temp_free_i32(fp0
);
6281 generate_exception (ctx
, EXCP_RI
);
6284 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
6290 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
6306 l1
= gen_new_label();
6307 t0
= tcg_temp_new_i32();
6308 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6309 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6310 tcg_temp_free_i32(t0
);
6312 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
6314 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
6319 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
6322 TCGv_i32 t0
= tcg_temp_new_i32();
6323 int l1
= gen_new_label();
6330 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6331 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6332 gen_load_fpr32(t0
, fs
);
6333 gen_store_fpr32(t0
, fd
);
6335 tcg_temp_free_i32(t0
);
6338 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
6341 TCGv_i32 t0
= tcg_temp_new_i32();
6343 int l1
= gen_new_label();
6350 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6351 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6352 tcg_temp_free_i32(t0
);
6353 fp0
= tcg_temp_new_i64();
6354 gen_load_fpr64(ctx
, fp0
, fs
);
6355 gen_store_fpr64(ctx
, fp0
, fd
);
6356 tcg_temp_free_i64(fp0
);
6360 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
6363 TCGv_i32 t0
= tcg_temp_new_i32();
6364 int l1
= gen_new_label();
6365 int l2
= gen_new_label();
6372 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6373 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6374 gen_load_fpr32(t0
, fs
);
6375 gen_store_fpr32(t0
, fd
);
6378 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
6379 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
6380 gen_load_fpr32h(t0
, fs
);
6381 gen_store_fpr32h(t0
, fd
);
6382 tcg_temp_free_i32(t0
);
6387 static void gen_farith (DisasContext
*ctx
, enum fopcode op1
,
6388 int ft
, int fs
, int fd
, int cc
)
6390 const char *opn
= "farith";
6391 const char *condnames
[] = {
6409 const char *condnames_abs
[] = {
6427 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6428 uint32_t func
= ctx
->opcode
& 0x3f;
6433 TCGv_i32 fp0
= tcg_temp_new_i32();
6434 TCGv_i32 fp1
= tcg_temp_new_i32();
6436 gen_load_fpr32(fp0
, fs
);
6437 gen_load_fpr32(fp1
, ft
);
6438 gen_helper_float_add_s(fp0
, fp0
, fp1
);
6439 tcg_temp_free_i32(fp1
);
6440 gen_store_fpr32(fp0
, fd
);
6441 tcg_temp_free_i32(fp0
);
6448 TCGv_i32 fp0
= tcg_temp_new_i32();
6449 TCGv_i32 fp1
= tcg_temp_new_i32();
6451 gen_load_fpr32(fp0
, fs
);
6452 gen_load_fpr32(fp1
, ft
);
6453 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6454 tcg_temp_free_i32(fp1
);
6455 gen_store_fpr32(fp0
, fd
);
6456 tcg_temp_free_i32(fp0
);
6463 TCGv_i32 fp0
= tcg_temp_new_i32();
6464 TCGv_i32 fp1
= tcg_temp_new_i32();
6466 gen_load_fpr32(fp0
, fs
);
6467 gen_load_fpr32(fp1
, ft
);
6468 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6469 tcg_temp_free_i32(fp1
);
6470 gen_store_fpr32(fp0
, fd
);
6471 tcg_temp_free_i32(fp0
);
6478 TCGv_i32 fp0
= tcg_temp_new_i32();
6479 TCGv_i32 fp1
= tcg_temp_new_i32();
6481 gen_load_fpr32(fp0
, fs
);
6482 gen_load_fpr32(fp1
, ft
);
6483 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6484 tcg_temp_free_i32(fp1
);
6485 gen_store_fpr32(fp0
, fd
);
6486 tcg_temp_free_i32(fp0
);
6493 TCGv_i32 fp0
= tcg_temp_new_i32();
6495 gen_load_fpr32(fp0
, fs
);
6496 gen_helper_float_sqrt_s(fp0
, fp0
);
6497 gen_store_fpr32(fp0
, fd
);
6498 tcg_temp_free_i32(fp0
);
6504 TCGv_i32 fp0
= tcg_temp_new_i32();
6506 gen_load_fpr32(fp0
, fs
);
6507 gen_helper_float_abs_s(fp0
, fp0
);
6508 gen_store_fpr32(fp0
, fd
);
6509 tcg_temp_free_i32(fp0
);
6515 TCGv_i32 fp0
= tcg_temp_new_i32();
6517 gen_load_fpr32(fp0
, fs
);
6518 gen_store_fpr32(fp0
, fd
);
6519 tcg_temp_free_i32(fp0
);
6525 TCGv_i32 fp0
= tcg_temp_new_i32();
6527 gen_load_fpr32(fp0
, fs
);
6528 gen_helper_float_chs_s(fp0
, fp0
);
6529 gen_store_fpr32(fp0
, fd
);
6530 tcg_temp_free_i32(fp0
);
6535 check_cp1_64bitmode(ctx
);
6537 TCGv_i32 fp32
= tcg_temp_new_i32();
6538 TCGv_i64 fp64
= tcg_temp_new_i64();
6540 gen_load_fpr32(fp32
, fs
);
6541 gen_helper_float_roundl_s(fp64
, fp32
);
6542 tcg_temp_free_i32(fp32
);
6543 gen_store_fpr64(ctx
, fp64
, fd
);
6544 tcg_temp_free_i64(fp64
);
6549 check_cp1_64bitmode(ctx
);
6551 TCGv_i32 fp32
= tcg_temp_new_i32();
6552 TCGv_i64 fp64
= tcg_temp_new_i64();
6554 gen_load_fpr32(fp32
, fs
);
6555 gen_helper_float_truncl_s(fp64
, fp32
);
6556 tcg_temp_free_i32(fp32
);
6557 gen_store_fpr64(ctx
, fp64
, fd
);
6558 tcg_temp_free_i64(fp64
);
6563 check_cp1_64bitmode(ctx
);
6565 TCGv_i32 fp32
= tcg_temp_new_i32();
6566 TCGv_i64 fp64
= tcg_temp_new_i64();
6568 gen_load_fpr32(fp32
, fs
);
6569 gen_helper_float_ceill_s(fp64
, fp32
);
6570 tcg_temp_free_i32(fp32
);
6571 gen_store_fpr64(ctx
, fp64
, fd
);
6572 tcg_temp_free_i64(fp64
);
6577 check_cp1_64bitmode(ctx
);
6579 TCGv_i32 fp32
= tcg_temp_new_i32();
6580 TCGv_i64 fp64
= tcg_temp_new_i64();
6582 gen_load_fpr32(fp32
, fs
);
6583 gen_helper_float_floorl_s(fp64
, fp32
);
6584 tcg_temp_free_i32(fp32
);
6585 gen_store_fpr64(ctx
, fp64
, fd
);
6586 tcg_temp_free_i64(fp64
);
6592 TCGv_i32 fp0
= tcg_temp_new_i32();
6594 gen_load_fpr32(fp0
, fs
);
6595 gen_helper_float_roundw_s(fp0
, fp0
);
6596 gen_store_fpr32(fp0
, fd
);
6597 tcg_temp_free_i32(fp0
);
6603 TCGv_i32 fp0
= tcg_temp_new_i32();
6605 gen_load_fpr32(fp0
, fs
);
6606 gen_helper_float_truncw_s(fp0
, fp0
);
6607 gen_store_fpr32(fp0
, fd
);
6608 tcg_temp_free_i32(fp0
);
6614 TCGv_i32 fp0
= tcg_temp_new_i32();
6616 gen_load_fpr32(fp0
, fs
);
6617 gen_helper_float_ceilw_s(fp0
, fp0
);
6618 gen_store_fpr32(fp0
, fd
);
6619 tcg_temp_free_i32(fp0
);
6625 TCGv_i32 fp0
= tcg_temp_new_i32();
6627 gen_load_fpr32(fp0
, fs
);
6628 gen_helper_float_floorw_s(fp0
, fp0
);
6629 gen_store_fpr32(fp0
, fd
);
6630 tcg_temp_free_i32(fp0
);
6635 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6640 int l1
= gen_new_label();
6644 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6646 fp0
= tcg_temp_new_i32();
6647 gen_load_fpr32(fp0
, fs
);
6648 gen_store_fpr32(fp0
, fd
);
6649 tcg_temp_free_i32(fp0
);
6656 int l1
= gen_new_label();
6660 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6661 fp0
= tcg_temp_new_i32();
6662 gen_load_fpr32(fp0
, fs
);
6663 gen_store_fpr32(fp0
, fd
);
6664 tcg_temp_free_i32(fp0
);
6673 TCGv_i32 fp0
= tcg_temp_new_i32();
6675 gen_load_fpr32(fp0
, fs
);
6676 gen_helper_float_recip_s(fp0
, fp0
);
6677 gen_store_fpr32(fp0
, fd
);
6678 tcg_temp_free_i32(fp0
);
6685 TCGv_i32 fp0
= tcg_temp_new_i32();
6687 gen_load_fpr32(fp0
, fs
);
6688 gen_helper_float_rsqrt_s(fp0
, fp0
);
6689 gen_store_fpr32(fp0
, fd
);
6690 tcg_temp_free_i32(fp0
);
6695 check_cp1_64bitmode(ctx
);
6697 TCGv_i32 fp0
= tcg_temp_new_i32();
6698 TCGv_i32 fp1
= tcg_temp_new_i32();
6700 gen_load_fpr32(fp0
, fs
);
6701 gen_load_fpr32(fp1
, fd
);
6702 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6703 tcg_temp_free_i32(fp1
);
6704 gen_store_fpr32(fp0
, fd
);
6705 tcg_temp_free_i32(fp0
);
6710 check_cp1_64bitmode(ctx
);
6712 TCGv_i32 fp0
= tcg_temp_new_i32();
6714 gen_load_fpr32(fp0
, fs
);
6715 gen_helper_float_recip1_s(fp0
, fp0
);
6716 gen_store_fpr32(fp0
, fd
);
6717 tcg_temp_free_i32(fp0
);
6722 check_cp1_64bitmode(ctx
);
6724 TCGv_i32 fp0
= tcg_temp_new_i32();
6726 gen_load_fpr32(fp0
, fs
);
6727 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6728 gen_store_fpr32(fp0
, fd
);
6729 tcg_temp_free_i32(fp0
);
6734 check_cp1_64bitmode(ctx
);
6736 TCGv_i32 fp0
= tcg_temp_new_i32();
6737 TCGv_i32 fp1
= tcg_temp_new_i32();
6739 gen_load_fpr32(fp0
, fs
);
6740 gen_load_fpr32(fp1
, ft
);
6741 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6742 tcg_temp_free_i32(fp1
);
6743 gen_store_fpr32(fp0
, fd
);
6744 tcg_temp_free_i32(fp0
);
6749 check_cp1_registers(ctx
, fd
);
6751 TCGv_i32 fp32
= tcg_temp_new_i32();
6752 TCGv_i64 fp64
= tcg_temp_new_i64();
6754 gen_load_fpr32(fp32
, fs
);
6755 gen_helper_float_cvtd_s(fp64
, fp32
);
6756 tcg_temp_free_i32(fp32
);
6757 gen_store_fpr64(ctx
, fp64
, fd
);
6758 tcg_temp_free_i64(fp64
);
6764 TCGv_i32 fp0
= tcg_temp_new_i32();
6766 gen_load_fpr32(fp0
, fs
);
6767 gen_helper_float_cvtw_s(fp0
, fp0
);
6768 gen_store_fpr32(fp0
, fd
);
6769 tcg_temp_free_i32(fp0
);
6774 check_cp1_64bitmode(ctx
);
6776 TCGv_i32 fp32
= tcg_temp_new_i32();
6777 TCGv_i64 fp64
= tcg_temp_new_i64();
6779 gen_load_fpr32(fp32
, fs
);
6780 gen_helper_float_cvtl_s(fp64
, fp32
);
6781 tcg_temp_free_i32(fp32
);
6782 gen_store_fpr64(ctx
, fp64
, fd
);
6783 tcg_temp_free_i64(fp64
);
6788 check_cp1_64bitmode(ctx
);
6790 TCGv_i64 fp64
= tcg_temp_new_i64();
6791 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6792 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6794 gen_load_fpr32(fp32_0
, fs
);
6795 gen_load_fpr32(fp32_1
, ft
);
6796 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6797 tcg_temp_free_i32(fp32_1
);
6798 tcg_temp_free_i32(fp32_0
);
6799 gen_store_fpr64(ctx
, fp64
, fd
);
6800 tcg_temp_free_i64(fp64
);
6813 case OPC_CMP_NGLE_S
:
6820 if (ctx
->opcode
& (1 << 6)) {
6821 gen_cmpabs_s(ctx
, func
-48, ft
, fs
, cc
);
6822 opn
= condnames_abs
[func
-48];
6824 gen_cmp_s(ctx
, func
-48, ft
, fs
, cc
);
6825 opn
= condnames
[func
-48];
6829 check_cp1_registers(ctx
, fs
| ft
| fd
);
6831 TCGv_i64 fp0
= tcg_temp_new_i64();
6832 TCGv_i64 fp1
= tcg_temp_new_i64();
6834 gen_load_fpr64(ctx
, fp0
, fs
);
6835 gen_load_fpr64(ctx
, fp1
, ft
);
6836 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6837 tcg_temp_free_i64(fp1
);
6838 gen_store_fpr64(ctx
, fp0
, fd
);
6839 tcg_temp_free_i64(fp0
);
6845 check_cp1_registers(ctx
, fs
| ft
| fd
);
6847 TCGv_i64 fp0
= tcg_temp_new_i64();
6848 TCGv_i64 fp1
= tcg_temp_new_i64();
6850 gen_load_fpr64(ctx
, fp0
, fs
);
6851 gen_load_fpr64(ctx
, fp1
, ft
);
6852 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6853 tcg_temp_free_i64(fp1
);
6854 gen_store_fpr64(ctx
, fp0
, fd
);
6855 tcg_temp_free_i64(fp0
);
6861 check_cp1_registers(ctx
, fs
| ft
| fd
);
6863 TCGv_i64 fp0
= tcg_temp_new_i64();
6864 TCGv_i64 fp1
= tcg_temp_new_i64();
6866 gen_load_fpr64(ctx
, fp0
, fs
);
6867 gen_load_fpr64(ctx
, fp1
, ft
);
6868 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6869 tcg_temp_free_i64(fp1
);
6870 gen_store_fpr64(ctx
, fp0
, fd
);
6871 tcg_temp_free_i64(fp0
);
6877 check_cp1_registers(ctx
, fs
| ft
| fd
);
6879 TCGv_i64 fp0
= tcg_temp_new_i64();
6880 TCGv_i64 fp1
= tcg_temp_new_i64();
6882 gen_load_fpr64(ctx
, fp0
, fs
);
6883 gen_load_fpr64(ctx
, fp1
, ft
);
6884 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6885 tcg_temp_free_i64(fp1
);
6886 gen_store_fpr64(ctx
, fp0
, fd
);
6887 tcg_temp_free_i64(fp0
);
6893 check_cp1_registers(ctx
, fs
| fd
);
6895 TCGv_i64 fp0
= tcg_temp_new_i64();
6897 gen_load_fpr64(ctx
, fp0
, fs
);
6898 gen_helper_float_sqrt_d(fp0
, fp0
);
6899 gen_store_fpr64(ctx
, fp0
, fd
);
6900 tcg_temp_free_i64(fp0
);
6905 check_cp1_registers(ctx
, fs
| fd
);
6907 TCGv_i64 fp0
= tcg_temp_new_i64();
6909 gen_load_fpr64(ctx
, fp0
, fs
);
6910 gen_helper_float_abs_d(fp0
, fp0
);
6911 gen_store_fpr64(ctx
, fp0
, fd
);
6912 tcg_temp_free_i64(fp0
);
6917 check_cp1_registers(ctx
, fs
| fd
);
6919 TCGv_i64 fp0
= tcg_temp_new_i64();
6921 gen_load_fpr64(ctx
, fp0
, fs
);
6922 gen_store_fpr64(ctx
, fp0
, fd
);
6923 tcg_temp_free_i64(fp0
);
6928 check_cp1_registers(ctx
, fs
| fd
);
6930 TCGv_i64 fp0
= tcg_temp_new_i64();
6932 gen_load_fpr64(ctx
, fp0
, fs
);
6933 gen_helper_float_chs_d(fp0
, fp0
);
6934 gen_store_fpr64(ctx
, fp0
, fd
);
6935 tcg_temp_free_i64(fp0
);
6940 check_cp1_64bitmode(ctx
);
6942 TCGv_i64 fp0
= tcg_temp_new_i64();
6944 gen_load_fpr64(ctx
, fp0
, fs
);
6945 gen_helper_float_roundl_d(fp0
, fp0
);
6946 gen_store_fpr64(ctx
, fp0
, fd
);
6947 tcg_temp_free_i64(fp0
);
6952 check_cp1_64bitmode(ctx
);
6954 TCGv_i64 fp0
= tcg_temp_new_i64();
6956 gen_load_fpr64(ctx
, fp0
, fs
);
6957 gen_helper_float_truncl_d(fp0
, fp0
);
6958 gen_store_fpr64(ctx
, fp0
, fd
);
6959 tcg_temp_free_i64(fp0
);
6964 check_cp1_64bitmode(ctx
);
6966 TCGv_i64 fp0
= tcg_temp_new_i64();
6968 gen_load_fpr64(ctx
, fp0
, fs
);
6969 gen_helper_float_ceill_d(fp0
, fp0
);
6970 gen_store_fpr64(ctx
, fp0
, fd
);
6971 tcg_temp_free_i64(fp0
);
6976 check_cp1_64bitmode(ctx
);
6978 TCGv_i64 fp0
= tcg_temp_new_i64();
6980 gen_load_fpr64(ctx
, fp0
, fs
);
6981 gen_helper_float_floorl_d(fp0
, fp0
);
6982 gen_store_fpr64(ctx
, fp0
, fd
);
6983 tcg_temp_free_i64(fp0
);
6988 check_cp1_registers(ctx
, fs
);
6990 TCGv_i32 fp32
= tcg_temp_new_i32();
6991 TCGv_i64 fp64
= tcg_temp_new_i64();
6993 gen_load_fpr64(ctx
, fp64
, fs
);
6994 gen_helper_float_roundw_d(fp32
, fp64
);
6995 tcg_temp_free_i64(fp64
);
6996 gen_store_fpr32(fp32
, fd
);
6997 tcg_temp_free_i32(fp32
);
7002 check_cp1_registers(ctx
, fs
);
7004 TCGv_i32 fp32
= tcg_temp_new_i32();
7005 TCGv_i64 fp64
= tcg_temp_new_i64();
7007 gen_load_fpr64(ctx
, fp64
, fs
);
7008 gen_helper_float_truncw_d(fp32
, fp64
);
7009 tcg_temp_free_i64(fp64
);
7010 gen_store_fpr32(fp32
, fd
);
7011 tcg_temp_free_i32(fp32
);
7016 check_cp1_registers(ctx
, fs
);
7018 TCGv_i32 fp32
= tcg_temp_new_i32();
7019 TCGv_i64 fp64
= tcg_temp_new_i64();
7021 gen_load_fpr64(ctx
, fp64
, fs
);
7022 gen_helper_float_ceilw_d(fp32
, fp64
);
7023 tcg_temp_free_i64(fp64
);
7024 gen_store_fpr32(fp32
, fd
);
7025 tcg_temp_free_i32(fp32
);
7030 check_cp1_registers(ctx
, fs
);
7032 TCGv_i32 fp32
= tcg_temp_new_i32();
7033 TCGv_i64 fp64
= tcg_temp_new_i64();
7035 gen_load_fpr64(ctx
, fp64
, fs
);
7036 gen_helper_float_floorw_d(fp32
, fp64
);
7037 tcg_temp_free_i64(fp64
);
7038 gen_store_fpr32(fp32
, fd
);
7039 tcg_temp_free_i32(fp32
);
7044 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7049 int l1
= gen_new_label();
7053 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7055 fp0
= tcg_temp_new_i64();
7056 gen_load_fpr64(ctx
, fp0
, fs
);
7057 gen_store_fpr64(ctx
, fp0
, fd
);
7058 tcg_temp_free_i64(fp0
);
7065 int l1
= gen_new_label();
7069 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7070 fp0
= tcg_temp_new_i64();
7071 gen_load_fpr64(ctx
, fp0
, fs
);
7072 gen_store_fpr64(ctx
, fp0
, fd
);
7073 tcg_temp_free_i64(fp0
);
7080 check_cp1_64bitmode(ctx
);
7082 TCGv_i64 fp0
= tcg_temp_new_i64();
7084 gen_load_fpr64(ctx
, fp0
, fs
);
7085 gen_helper_float_recip_d(fp0
, fp0
);
7086 gen_store_fpr64(ctx
, fp0
, fd
);
7087 tcg_temp_free_i64(fp0
);
7092 check_cp1_64bitmode(ctx
);
7094 TCGv_i64 fp0
= tcg_temp_new_i64();
7096 gen_load_fpr64(ctx
, fp0
, fs
);
7097 gen_helper_float_rsqrt_d(fp0
, fp0
);
7098 gen_store_fpr64(ctx
, fp0
, fd
);
7099 tcg_temp_free_i64(fp0
);
7104 check_cp1_64bitmode(ctx
);
7106 TCGv_i64 fp0
= tcg_temp_new_i64();
7107 TCGv_i64 fp1
= tcg_temp_new_i64();
7109 gen_load_fpr64(ctx
, fp0
, fs
);
7110 gen_load_fpr64(ctx
, fp1
, ft
);
7111 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
7112 tcg_temp_free_i64(fp1
);
7113 gen_store_fpr64(ctx
, fp0
, fd
);
7114 tcg_temp_free_i64(fp0
);
7119 check_cp1_64bitmode(ctx
);
7121 TCGv_i64 fp0
= tcg_temp_new_i64();
7123 gen_load_fpr64(ctx
, fp0
, fs
);
7124 gen_helper_float_recip1_d(fp0
, fp0
);
7125 gen_store_fpr64(ctx
, fp0
, fd
);
7126 tcg_temp_free_i64(fp0
);
7131 check_cp1_64bitmode(ctx
);
7133 TCGv_i64 fp0
= tcg_temp_new_i64();
7135 gen_load_fpr64(ctx
, fp0
, fs
);
7136 gen_helper_float_rsqrt1_d(fp0
, fp0
);
7137 gen_store_fpr64(ctx
, fp0
, fd
);
7138 tcg_temp_free_i64(fp0
);
7143 check_cp1_64bitmode(ctx
);
7145 TCGv_i64 fp0
= tcg_temp_new_i64();
7146 TCGv_i64 fp1
= tcg_temp_new_i64();
7148 gen_load_fpr64(ctx
, fp0
, fs
);
7149 gen_load_fpr64(ctx
, fp1
, ft
);
7150 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
7151 tcg_temp_free_i64(fp1
);
7152 gen_store_fpr64(ctx
, fp0
, fd
);
7153 tcg_temp_free_i64(fp0
);
7166 case OPC_CMP_NGLE_D
:
7173 if (ctx
->opcode
& (1 << 6)) {
7174 gen_cmpabs_d(ctx
, func
-48, ft
, fs
, cc
);
7175 opn
= condnames_abs
[func
-48];
7177 gen_cmp_d(ctx
, func
-48, ft
, fs
, cc
);
7178 opn
= condnames
[func
-48];
7182 check_cp1_registers(ctx
, fs
);
7184 TCGv_i32 fp32
= tcg_temp_new_i32();
7185 TCGv_i64 fp64
= tcg_temp_new_i64();
7187 gen_load_fpr64(ctx
, fp64
, fs
);
7188 gen_helper_float_cvts_d(fp32
, fp64
);
7189 tcg_temp_free_i64(fp64
);
7190 gen_store_fpr32(fp32
, fd
);
7191 tcg_temp_free_i32(fp32
);
7196 check_cp1_registers(ctx
, fs
);
7198 TCGv_i32 fp32
= tcg_temp_new_i32();
7199 TCGv_i64 fp64
= tcg_temp_new_i64();
7201 gen_load_fpr64(ctx
, fp64
, fs
);
7202 gen_helper_float_cvtw_d(fp32
, fp64
);
7203 tcg_temp_free_i64(fp64
);
7204 gen_store_fpr32(fp32
, fd
);
7205 tcg_temp_free_i32(fp32
);
7210 check_cp1_64bitmode(ctx
);
7212 TCGv_i64 fp0
= tcg_temp_new_i64();
7214 gen_load_fpr64(ctx
, fp0
, fs
);
7215 gen_helper_float_cvtl_d(fp0
, fp0
);
7216 gen_store_fpr64(ctx
, fp0
, fd
);
7217 tcg_temp_free_i64(fp0
);
7223 TCGv_i32 fp0
= tcg_temp_new_i32();
7225 gen_load_fpr32(fp0
, fs
);
7226 gen_helper_float_cvts_w(fp0
, fp0
);
7227 gen_store_fpr32(fp0
, fd
);
7228 tcg_temp_free_i32(fp0
);
7233 check_cp1_registers(ctx
, fd
);
7235 TCGv_i32 fp32
= tcg_temp_new_i32();
7236 TCGv_i64 fp64
= tcg_temp_new_i64();
7238 gen_load_fpr32(fp32
, fs
);
7239 gen_helper_float_cvtd_w(fp64
, fp32
);
7240 tcg_temp_free_i32(fp32
);
7241 gen_store_fpr64(ctx
, fp64
, fd
);
7242 tcg_temp_free_i64(fp64
);
7247 check_cp1_64bitmode(ctx
);
7249 TCGv_i32 fp32
= tcg_temp_new_i32();
7250 TCGv_i64 fp64
= tcg_temp_new_i64();
7252 gen_load_fpr64(ctx
, fp64
, fs
);
7253 gen_helper_float_cvts_l(fp32
, fp64
);
7254 tcg_temp_free_i64(fp64
);
7255 gen_store_fpr32(fp32
, fd
);
7256 tcg_temp_free_i32(fp32
);
7261 check_cp1_64bitmode(ctx
);
7263 TCGv_i64 fp0
= tcg_temp_new_i64();
7265 gen_load_fpr64(ctx
, fp0
, fs
);
7266 gen_helper_float_cvtd_l(fp0
, fp0
);
7267 gen_store_fpr64(ctx
, fp0
, fd
);
7268 tcg_temp_free_i64(fp0
);
7273 check_cp1_64bitmode(ctx
);
7275 TCGv_i64 fp0
= tcg_temp_new_i64();
7277 gen_load_fpr64(ctx
, fp0
, fs
);
7278 gen_helper_float_cvtps_pw(fp0
, fp0
);
7279 gen_store_fpr64(ctx
, fp0
, fd
);
7280 tcg_temp_free_i64(fp0
);
7285 check_cp1_64bitmode(ctx
);
7287 TCGv_i64 fp0
= tcg_temp_new_i64();
7288 TCGv_i64 fp1
= tcg_temp_new_i64();
7290 gen_load_fpr64(ctx
, fp0
, fs
);
7291 gen_load_fpr64(ctx
, fp1
, ft
);
7292 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
7293 tcg_temp_free_i64(fp1
);
7294 gen_store_fpr64(ctx
, fp0
, fd
);
7295 tcg_temp_free_i64(fp0
);
7300 check_cp1_64bitmode(ctx
);
7302 TCGv_i64 fp0
= tcg_temp_new_i64();
7303 TCGv_i64 fp1
= tcg_temp_new_i64();
7305 gen_load_fpr64(ctx
, fp0
, fs
);
7306 gen_load_fpr64(ctx
, fp1
, ft
);
7307 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
7308 tcg_temp_free_i64(fp1
);
7309 gen_store_fpr64(ctx
, fp0
, fd
);
7310 tcg_temp_free_i64(fp0
);
7315 check_cp1_64bitmode(ctx
);
7317 TCGv_i64 fp0
= tcg_temp_new_i64();
7318 TCGv_i64 fp1
= tcg_temp_new_i64();
7320 gen_load_fpr64(ctx
, fp0
, fs
);
7321 gen_load_fpr64(ctx
, fp1
, ft
);
7322 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
7323 tcg_temp_free_i64(fp1
);
7324 gen_store_fpr64(ctx
, fp0
, fd
);
7325 tcg_temp_free_i64(fp0
);
7330 check_cp1_64bitmode(ctx
);
7332 TCGv_i64 fp0
= tcg_temp_new_i64();
7334 gen_load_fpr64(ctx
, fp0
, fs
);
7335 gen_helper_float_abs_ps(fp0
, fp0
);
7336 gen_store_fpr64(ctx
, fp0
, fd
);
7337 tcg_temp_free_i64(fp0
);
7342 check_cp1_64bitmode(ctx
);
7344 TCGv_i64 fp0
= tcg_temp_new_i64();
7346 gen_load_fpr64(ctx
, fp0
, fs
);
7347 gen_store_fpr64(ctx
, fp0
, fd
);
7348 tcg_temp_free_i64(fp0
);
7353 check_cp1_64bitmode(ctx
);
7355 TCGv_i64 fp0
= tcg_temp_new_i64();
7357 gen_load_fpr64(ctx
, fp0
, fs
);
7358 gen_helper_float_chs_ps(fp0
, fp0
);
7359 gen_store_fpr64(ctx
, fp0
, fd
);
7360 tcg_temp_free_i64(fp0
);
7365 check_cp1_64bitmode(ctx
);
7366 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7370 check_cp1_64bitmode(ctx
);
7372 int l1
= gen_new_label();
7376 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7377 fp0
= tcg_temp_new_i64();
7378 gen_load_fpr64(ctx
, fp0
, fs
);
7379 gen_store_fpr64(ctx
, fp0
, fd
);
7380 tcg_temp_free_i64(fp0
);
7386 check_cp1_64bitmode(ctx
);
7388 int l1
= gen_new_label();
7392 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7393 fp0
= tcg_temp_new_i64();
7394 gen_load_fpr64(ctx
, fp0
, fs
);
7395 gen_store_fpr64(ctx
, fp0
, fd
);
7396 tcg_temp_free_i64(fp0
);
7403 check_cp1_64bitmode(ctx
);
7405 TCGv_i64 fp0
= tcg_temp_new_i64();
7406 TCGv_i64 fp1
= tcg_temp_new_i64();
7408 gen_load_fpr64(ctx
, fp0
, ft
);
7409 gen_load_fpr64(ctx
, fp1
, fs
);
7410 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
7411 tcg_temp_free_i64(fp1
);
7412 gen_store_fpr64(ctx
, fp0
, fd
);
7413 tcg_temp_free_i64(fp0
);
7418 check_cp1_64bitmode(ctx
);
7420 TCGv_i64 fp0
= tcg_temp_new_i64();
7421 TCGv_i64 fp1
= tcg_temp_new_i64();
7423 gen_load_fpr64(ctx
, fp0
, ft
);
7424 gen_load_fpr64(ctx
, fp1
, fs
);
7425 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7426 tcg_temp_free_i64(fp1
);
7427 gen_store_fpr64(ctx
, fp0
, fd
);
7428 tcg_temp_free_i64(fp0
);
7433 check_cp1_64bitmode(ctx
);
7435 TCGv_i64 fp0
= tcg_temp_new_i64();
7436 TCGv_i64 fp1
= tcg_temp_new_i64();
7438 gen_load_fpr64(ctx
, fp0
, fs
);
7439 gen_load_fpr64(ctx
, fp1
, fd
);
7440 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7441 tcg_temp_free_i64(fp1
);
7442 gen_store_fpr64(ctx
, fp0
, fd
);
7443 tcg_temp_free_i64(fp0
);
7448 check_cp1_64bitmode(ctx
);
7450 TCGv_i64 fp0
= tcg_temp_new_i64();
7452 gen_load_fpr64(ctx
, fp0
, fs
);
7453 gen_helper_float_recip1_ps(fp0
, fp0
);
7454 gen_store_fpr64(ctx
, fp0
, fd
);
7455 tcg_temp_free_i64(fp0
);
7460 check_cp1_64bitmode(ctx
);
7462 TCGv_i64 fp0
= tcg_temp_new_i64();
7464 gen_load_fpr64(ctx
, fp0
, fs
);
7465 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7466 gen_store_fpr64(ctx
, fp0
, fd
);
7467 tcg_temp_free_i64(fp0
);
7472 check_cp1_64bitmode(ctx
);
7474 TCGv_i64 fp0
= tcg_temp_new_i64();
7475 TCGv_i64 fp1
= tcg_temp_new_i64();
7477 gen_load_fpr64(ctx
, fp0
, fs
);
7478 gen_load_fpr64(ctx
, fp1
, ft
);
7479 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7480 tcg_temp_free_i64(fp1
);
7481 gen_store_fpr64(ctx
, fp0
, fd
);
7482 tcg_temp_free_i64(fp0
);
7487 check_cp1_64bitmode(ctx
);
7489 TCGv_i32 fp0
= tcg_temp_new_i32();
7491 gen_load_fpr32h(fp0
, fs
);
7492 gen_helper_float_cvts_pu(fp0
, fp0
);
7493 gen_store_fpr32(fp0
, fd
);
7494 tcg_temp_free_i32(fp0
);
7499 check_cp1_64bitmode(ctx
);
7501 TCGv_i64 fp0
= tcg_temp_new_i64();
7503 gen_load_fpr64(ctx
, fp0
, fs
);
7504 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7505 gen_store_fpr64(ctx
, fp0
, fd
);
7506 tcg_temp_free_i64(fp0
);
7511 check_cp1_64bitmode(ctx
);
7513 TCGv_i32 fp0
= tcg_temp_new_i32();
7515 gen_load_fpr32(fp0
, fs
);
7516 gen_helper_float_cvts_pl(fp0
, fp0
);
7517 gen_store_fpr32(fp0
, fd
);
7518 tcg_temp_free_i32(fp0
);
7523 check_cp1_64bitmode(ctx
);
7525 TCGv_i32 fp0
= tcg_temp_new_i32();
7526 TCGv_i32 fp1
= tcg_temp_new_i32();
7528 gen_load_fpr32(fp0
, fs
);
7529 gen_load_fpr32(fp1
, ft
);
7530 gen_store_fpr32h(fp0
, fd
);
7531 gen_store_fpr32(fp1
, fd
);
7532 tcg_temp_free_i32(fp0
);
7533 tcg_temp_free_i32(fp1
);
7538 check_cp1_64bitmode(ctx
);
7540 TCGv_i32 fp0
= tcg_temp_new_i32();
7541 TCGv_i32 fp1
= tcg_temp_new_i32();
7543 gen_load_fpr32(fp0
, fs
);
7544 gen_load_fpr32h(fp1
, ft
);
7545 gen_store_fpr32(fp1
, fd
);
7546 gen_store_fpr32h(fp0
, fd
);
7547 tcg_temp_free_i32(fp0
);
7548 tcg_temp_free_i32(fp1
);
7553 check_cp1_64bitmode(ctx
);
7555 TCGv_i32 fp0
= tcg_temp_new_i32();
7556 TCGv_i32 fp1
= tcg_temp_new_i32();
7558 gen_load_fpr32h(fp0
, fs
);
7559 gen_load_fpr32(fp1
, ft
);
7560 gen_store_fpr32(fp1
, fd
);
7561 gen_store_fpr32h(fp0
, fd
);
7562 tcg_temp_free_i32(fp0
);
7563 tcg_temp_free_i32(fp1
);
7568 check_cp1_64bitmode(ctx
);
7570 TCGv_i32 fp0
= tcg_temp_new_i32();
7571 TCGv_i32 fp1
= tcg_temp_new_i32();
7573 gen_load_fpr32h(fp0
, fs
);
7574 gen_load_fpr32h(fp1
, ft
);
7575 gen_store_fpr32(fp1
, fd
);
7576 gen_store_fpr32h(fp0
, fd
);
7577 tcg_temp_free_i32(fp0
);
7578 tcg_temp_free_i32(fp1
);
7585 case OPC_CMP_UEQ_PS
:
7586 case OPC_CMP_OLT_PS
:
7587 case OPC_CMP_ULT_PS
:
7588 case OPC_CMP_OLE_PS
:
7589 case OPC_CMP_ULE_PS
:
7591 case OPC_CMP_NGLE_PS
:
7592 case OPC_CMP_SEQ_PS
:
7593 case OPC_CMP_NGL_PS
:
7595 case OPC_CMP_NGE_PS
:
7597 case OPC_CMP_NGT_PS
:
7598 if (ctx
->opcode
& (1 << 6)) {
7599 gen_cmpabs_ps(ctx
, func
-48, ft
, fs
, cc
);
7600 opn
= condnames_abs
[func
-48];
7602 gen_cmp_ps(ctx
, func
-48, ft
, fs
, cc
);
7603 opn
= condnames
[func
-48];
7608 generate_exception (ctx
, EXCP_RI
);
7613 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7616 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7619 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7624 /* Coprocessor 3 (FPU) */
7625 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7626 int fd
, int fs
, int base
, int index
)
7628 const char *opn
= "extended float load/store";
7630 TCGv t0
= tcg_temp_new();
7633 gen_load_gpr(t0
, index
);
7634 } else if (index
== 0) {
7635 gen_load_gpr(t0
, base
);
7637 gen_load_gpr(t0
, index
);
7638 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7640 /* Don't do NOP if destination is zero: we must perform the actual
7642 save_cpu_state(ctx
, 0);
7647 TCGv_i32 fp0
= tcg_temp_new_i32();
7649 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7650 tcg_gen_trunc_tl_i32(fp0
, t0
);
7651 gen_store_fpr32(fp0
, fd
);
7652 tcg_temp_free_i32(fp0
);
7658 check_cp1_registers(ctx
, fd
);
7660 TCGv_i64 fp0
= tcg_temp_new_i64();
7662 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7663 gen_store_fpr64(ctx
, fp0
, fd
);
7664 tcg_temp_free_i64(fp0
);
7669 check_cp1_64bitmode(ctx
);
7670 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7672 TCGv_i64 fp0
= tcg_temp_new_i64();
7674 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7675 gen_store_fpr64(ctx
, fp0
, fd
);
7676 tcg_temp_free_i64(fp0
);
7683 TCGv_i32 fp0
= tcg_temp_new_i32();
7684 TCGv t1
= tcg_temp_new();
7686 gen_load_fpr32(fp0
, fs
);
7687 tcg_gen_extu_i32_tl(t1
, fp0
);
7688 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7689 tcg_temp_free_i32(fp0
);
7697 check_cp1_registers(ctx
, fs
);
7699 TCGv_i64 fp0
= tcg_temp_new_i64();
7701 gen_load_fpr64(ctx
, fp0
, fs
);
7702 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7703 tcg_temp_free_i64(fp0
);
7709 check_cp1_64bitmode(ctx
);
7710 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7712 TCGv_i64 fp0
= tcg_temp_new_i64();
7714 gen_load_fpr64(ctx
, fp0
, fs
);
7715 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7716 tcg_temp_free_i64(fp0
);
7723 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7724 regnames
[index
], regnames
[base
]);
7727 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7728 int fd
, int fr
, int fs
, int ft
)
7730 const char *opn
= "flt3_arith";
7734 check_cp1_64bitmode(ctx
);
7736 TCGv t0
= tcg_temp_local_new();
7737 TCGv_i32 fp
= tcg_temp_new_i32();
7738 TCGv_i32 fph
= tcg_temp_new_i32();
7739 int l1
= gen_new_label();
7740 int l2
= gen_new_label();
7742 gen_load_gpr(t0
, fr
);
7743 tcg_gen_andi_tl(t0
, t0
, 0x7);
7745 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7746 gen_load_fpr32(fp
, fs
);
7747 gen_load_fpr32h(fph
, fs
);
7748 gen_store_fpr32(fp
, fd
);
7749 gen_store_fpr32h(fph
, fd
);
7752 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7754 #ifdef TARGET_WORDS_BIGENDIAN
7755 gen_load_fpr32(fp
, fs
);
7756 gen_load_fpr32h(fph
, ft
);
7757 gen_store_fpr32h(fp
, fd
);
7758 gen_store_fpr32(fph
, fd
);
7760 gen_load_fpr32h(fph
, fs
);
7761 gen_load_fpr32(fp
, ft
);
7762 gen_store_fpr32(fph
, fd
);
7763 gen_store_fpr32h(fp
, fd
);
7766 tcg_temp_free_i32(fp
);
7767 tcg_temp_free_i32(fph
);
7774 TCGv_i32 fp0
= tcg_temp_new_i32();
7775 TCGv_i32 fp1
= tcg_temp_new_i32();
7776 TCGv_i32 fp2
= tcg_temp_new_i32();
7778 gen_load_fpr32(fp0
, fs
);
7779 gen_load_fpr32(fp1
, ft
);
7780 gen_load_fpr32(fp2
, fr
);
7781 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7782 tcg_temp_free_i32(fp0
);
7783 tcg_temp_free_i32(fp1
);
7784 gen_store_fpr32(fp2
, fd
);
7785 tcg_temp_free_i32(fp2
);
7791 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7793 TCGv_i64 fp0
= tcg_temp_new_i64();
7794 TCGv_i64 fp1
= tcg_temp_new_i64();
7795 TCGv_i64 fp2
= tcg_temp_new_i64();
7797 gen_load_fpr64(ctx
, fp0
, fs
);
7798 gen_load_fpr64(ctx
, fp1
, ft
);
7799 gen_load_fpr64(ctx
, fp2
, fr
);
7800 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7801 tcg_temp_free_i64(fp0
);
7802 tcg_temp_free_i64(fp1
);
7803 gen_store_fpr64(ctx
, fp2
, fd
);
7804 tcg_temp_free_i64(fp2
);
7809 check_cp1_64bitmode(ctx
);
7811 TCGv_i64 fp0
= tcg_temp_new_i64();
7812 TCGv_i64 fp1
= tcg_temp_new_i64();
7813 TCGv_i64 fp2
= tcg_temp_new_i64();
7815 gen_load_fpr64(ctx
, fp0
, fs
);
7816 gen_load_fpr64(ctx
, fp1
, ft
);
7817 gen_load_fpr64(ctx
, fp2
, fr
);
7818 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7819 tcg_temp_free_i64(fp0
);
7820 tcg_temp_free_i64(fp1
);
7821 gen_store_fpr64(ctx
, fp2
, fd
);
7822 tcg_temp_free_i64(fp2
);
7829 TCGv_i32 fp0
= tcg_temp_new_i32();
7830 TCGv_i32 fp1
= tcg_temp_new_i32();
7831 TCGv_i32 fp2
= tcg_temp_new_i32();
7833 gen_load_fpr32(fp0
, fs
);
7834 gen_load_fpr32(fp1
, ft
);
7835 gen_load_fpr32(fp2
, fr
);
7836 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7837 tcg_temp_free_i32(fp0
);
7838 tcg_temp_free_i32(fp1
);
7839 gen_store_fpr32(fp2
, fd
);
7840 tcg_temp_free_i32(fp2
);
7846 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7848 TCGv_i64 fp0
= tcg_temp_new_i64();
7849 TCGv_i64 fp1
= tcg_temp_new_i64();
7850 TCGv_i64 fp2
= tcg_temp_new_i64();
7852 gen_load_fpr64(ctx
, fp0
, fs
);
7853 gen_load_fpr64(ctx
, fp1
, ft
);
7854 gen_load_fpr64(ctx
, fp2
, fr
);
7855 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7856 tcg_temp_free_i64(fp0
);
7857 tcg_temp_free_i64(fp1
);
7858 gen_store_fpr64(ctx
, fp2
, fd
);
7859 tcg_temp_free_i64(fp2
);
7864 check_cp1_64bitmode(ctx
);
7866 TCGv_i64 fp0
= tcg_temp_new_i64();
7867 TCGv_i64 fp1
= tcg_temp_new_i64();
7868 TCGv_i64 fp2
= tcg_temp_new_i64();
7870 gen_load_fpr64(ctx
, fp0
, fs
);
7871 gen_load_fpr64(ctx
, fp1
, ft
);
7872 gen_load_fpr64(ctx
, fp2
, fr
);
7873 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7874 tcg_temp_free_i64(fp0
);
7875 tcg_temp_free_i64(fp1
);
7876 gen_store_fpr64(ctx
, fp2
, fd
);
7877 tcg_temp_free_i64(fp2
);
7884 TCGv_i32 fp0
= tcg_temp_new_i32();
7885 TCGv_i32 fp1
= tcg_temp_new_i32();
7886 TCGv_i32 fp2
= tcg_temp_new_i32();
7888 gen_load_fpr32(fp0
, fs
);
7889 gen_load_fpr32(fp1
, ft
);
7890 gen_load_fpr32(fp2
, fr
);
7891 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7892 tcg_temp_free_i32(fp0
);
7893 tcg_temp_free_i32(fp1
);
7894 gen_store_fpr32(fp2
, fd
);
7895 tcg_temp_free_i32(fp2
);
7901 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7903 TCGv_i64 fp0
= tcg_temp_new_i64();
7904 TCGv_i64 fp1
= tcg_temp_new_i64();
7905 TCGv_i64 fp2
= tcg_temp_new_i64();
7907 gen_load_fpr64(ctx
, fp0
, fs
);
7908 gen_load_fpr64(ctx
, fp1
, ft
);
7909 gen_load_fpr64(ctx
, fp2
, fr
);
7910 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7911 tcg_temp_free_i64(fp0
);
7912 tcg_temp_free_i64(fp1
);
7913 gen_store_fpr64(ctx
, fp2
, fd
);
7914 tcg_temp_free_i64(fp2
);
7919 check_cp1_64bitmode(ctx
);
7921 TCGv_i64 fp0
= tcg_temp_new_i64();
7922 TCGv_i64 fp1
= tcg_temp_new_i64();
7923 TCGv_i64 fp2
= tcg_temp_new_i64();
7925 gen_load_fpr64(ctx
, fp0
, fs
);
7926 gen_load_fpr64(ctx
, fp1
, ft
);
7927 gen_load_fpr64(ctx
, fp2
, fr
);
7928 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7929 tcg_temp_free_i64(fp0
);
7930 tcg_temp_free_i64(fp1
);
7931 gen_store_fpr64(ctx
, fp2
, fd
);
7932 tcg_temp_free_i64(fp2
);
7939 TCGv_i32 fp0
= tcg_temp_new_i32();
7940 TCGv_i32 fp1
= tcg_temp_new_i32();
7941 TCGv_i32 fp2
= tcg_temp_new_i32();
7943 gen_load_fpr32(fp0
, fs
);
7944 gen_load_fpr32(fp1
, ft
);
7945 gen_load_fpr32(fp2
, fr
);
7946 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7947 tcg_temp_free_i32(fp0
);
7948 tcg_temp_free_i32(fp1
);
7949 gen_store_fpr32(fp2
, fd
);
7950 tcg_temp_free_i32(fp2
);
7956 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7958 TCGv_i64 fp0
= tcg_temp_new_i64();
7959 TCGv_i64 fp1
= tcg_temp_new_i64();
7960 TCGv_i64 fp2
= tcg_temp_new_i64();
7962 gen_load_fpr64(ctx
, fp0
, fs
);
7963 gen_load_fpr64(ctx
, fp1
, ft
);
7964 gen_load_fpr64(ctx
, fp2
, fr
);
7965 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7966 tcg_temp_free_i64(fp0
);
7967 tcg_temp_free_i64(fp1
);
7968 gen_store_fpr64(ctx
, fp2
, fd
);
7969 tcg_temp_free_i64(fp2
);
7974 check_cp1_64bitmode(ctx
);
7976 TCGv_i64 fp0
= tcg_temp_new_i64();
7977 TCGv_i64 fp1
= tcg_temp_new_i64();
7978 TCGv_i64 fp2
= tcg_temp_new_i64();
7980 gen_load_fpr64(ctx
, fp0
, fs
);
7981 gen_load_fpr64(ctx
, fp1
, ft
);
7982 gen_load_fpr64(ctx
, fp2
, fr
);
7983 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7984 tcg_temp_free_i64(fp0
);
7985 tcg_temp_free_i64(fp1
);
7986 gen_store_fpr64(ctx
, fp2
, fd
);
7987 tcg_temp_free_i64(fp2
);
7993 generate_exception (ctx
, EXCP_RI
);
7996 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7997 fregnames
[fs
], fregnames
[ft
]);
8001 gen_rdhwr (CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
)
8005 check_insn(env
, ctx
, ISA_MIPS32R2
);
8006 t0
= tcg_temp_new();
8010 save_cpu_state(ctx
, 1);
8011 gen_helper_rdhwr_cpunum(t0
);
8012 gen_store_gpr(t0
, rt
);
8015 save_cpu_state(ctx
, 1);
8016 gen_helper_rdhwr_synci_step(t0
);
8017 gen_store_gpr(t0
, rt
);
8020 save_cpu_state(ctx
, 1);
8021 gen_helper_rdhwr_cc(t0
);
8022 gen_store_gpr(t0
, rt
);
8025 save_cpu_state(ctx
, 1);
8026 gen_helper_rdhwr_ccres(t0
);
8027 gen_store_gpr(t0
, rt
);
8030 #if defined(CONFIG_USER_ONLY)
8031 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
8032 gen_store_gpr(t0
, rt
);
8035 /* XXX: Some CPUs implement this in hardware.
8036 Not supported yet. */
8038 default: /* Invalid */
8039 MIPS_INVAL("rdhwr");
8040 generate_exception(ctx
, EXCP_RI
);
8046 static void handle_delay_slot (CPUState
*env
, DisasContext
*ctx
,
8049 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8050 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8051 /* Branches completion */
8052 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8053 ctx
->bstate
= BS_BRANCH
;
8054 save_cpu_state(ctx
, 0);
8055 /* FIXME: Need to clear can_do_io. */
8056 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
8058 /* unconditional branch */
8059 MIPS_DEBUG("unconditional branch");
8060 if (proc_hflags
& MIPS_HFLAG_BX
) {
8061 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
8063 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8066 /* blikely taken case */
8067 MIPS_DEBUG("blikely branch taken");
8068 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8071 /* Conditional branch */
8072 MIPS_DEBUG("conditional branch");
8074 int l1
= gen_new_label();
8076 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8077 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
8079 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8083 /* unconditional branch to register */
8084 MIPS_DEBUG("branch to register");
8085 if (env
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
8086 TCGv t0
= tcg_temp_new();
8087 TCGv_i32 t1
= tcg_temp_new_i32();
8089 tcg_gen_andi_tl(t0
, btarget
, 0x1);
8090 tcg_gen_trunc_tl_i32(t1
, t0
);
8092 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
8093 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
8094 tcg_gen_or_i32(hflags
, hflags
, t1
);
8095 tcg_temp_free_i32(t1
);
8097 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
8099 tcg_gen_mov_tl(cpu_PC
, btarget
);
8101 if (ctx
->singlestep_enabled
) {
8102 save_cpu_state(ctx
, 0);
8103 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8108 MIPS_DEBUG("unknown branch");
8114 /* ISA extensions (ASEs) */
8115 /* MIPS16 extension to MIPS32 */
8117 /* MIPS16 major opcodes */
8119 M16_OPC_ADDIUSP
= 0x00,
8120 M16_OPC_ADDIUPC
= 0x01,
8123 M16_OPC_BEQZ
= 0x04,
8124 M16_OPC_BNEQZ
= 0x05,
8125 M16_OPC_SHIFT
= 0x06,
8127 M16_OPC_RRIA
= 0x08,
8128 M16_OPC_ADDIU8
= 0x09,
8129 M16_OPC_SLTI
= 0x0a,
8130 M16_OPC_SLTIU
= 0x0b,
8133 M16_OPC_CMPI
= 0x0e,
8137 M16_OPC_LWSP
= 0x12,
8141 M16_OPC_LWPC
= 0x16,
8145 M16_OPC_SWSP
= 0x1a,
8149 M16_OPC_EXTEND
= 0x1e,
8153 /* I8 funct field */
8172 /* RR funct field */
8206 /* I64 funct field */
8218 /* RR ry field for CNVT */
8220 RR_RY_CNVT_ZEB
= 0x0,
8221 RR_RY_CNVT_ZEH
= 0x1,
8222 RR_RY_CNVT_ZEW
= 0x2,
8223 RR_RY_CNVT_SEB
= 0x4,
8224 RR_RY_CNVT_SEH
= 0x5,
8225 RR_RY_CNVT_SEW
= 0x6,
8228 static int xlat (int r
)
8230 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
8235 static void gen_mips16_save (DisasContext
*ctx
,
8236 int xsregs
, int aregs
,
8237 int do_ra
, int do_s0
, int do_s1
,
8240 TCGv t0
= tcg_temp_new();
8241 TCGv t1
= tcg_temp_new();
8271 generate_exception(ctx
, EXCP_RI
);
8277 gen_base_offset_addr(ctx
, t0
, 29, 12);
8278 gen_load_gpr(t1
, 7);
8279 op_st_sw(t1
, t0
, ctx
);
8282 gen_base_offset_addr(ctx
, t0
, 29, 8);
8283 gen_load_gpr(t1
, 6);
8284 op_st_sw(t1
, t0
, ctx
);
8287 gen_base_offset_addr(ctx
, t0
, 29, 4);
8288 gen_load_gpr(t1
, 5);
8289 op_st_sw(t1
, t0
, ctx
);
8292 gen_base_offset_addr(ctx
, t0
, 29, 0);
8293 gen_load_gpr(t1
, 4);
8294 op_st_sw(t1
, t0
, ctx
);
8297 gen_load_gpr(t0
, 29);
8299 #define DECR_AND_STORE(reg) do { \
8300 tcg_gen_subi_tl(t0, t0, 4); \
8301 gen_load_gpr(t1, reg); \
8302 op_st_sw(t1, t0, ctx); \
8366 generate_exception(ctx
, EXCP_RI
);
8382 #undef DECR_AND_STORE
8384 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8389 static void gen_mips16_restore (DisasContext
*ctx
,
8390 int xsregs
, int aregs
,
8391 int do_ra
, int do_s0
, int do_s1
,
8395 TCGv t0
= tcg_temp_new();
8396 TCGv t1
= tcg_temp_new();
8398 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
8400 #define DECR_AND_LOAD(reg) do { \
8401 tcg_gen_subi_tl(t0, t0, 4); \
8402 op_ld_lw(t1, t0, ctx); \
8403 gen_store_gpr(t1, reg); \
8467 generate_exception(ctx
, EXCP_RI
);
8483 #undef DECR_AND_LOAD
8485 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8490 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
8491 int is_64_bit
, int extended
)
8495 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8496 generate_exception(ctx
, EXCP_RI
);
8500 t0
= tcg_temp_new();
8502 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
8503 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
8505 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8511 #if defined(TARGET_MIPS64)
8512 static void decode_i64_mips16 (CPUState
*env
, DisasContext
*ctx
,
8513 int ry
, int funct
, int16_t offset
,
8519 offset
= extended
? offset
: offset
<< 3;
8520 gen_ld(env
, ctx
, OPC_LD
, ry
, 29, offset
);
8524 offset
= extended
? offset
: offset
<< 3;
8525 gen_st(ctx
, OPC_SD
, ry
, 29, offset
);
8529 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8530 gen_st(ctx
, OPC_SD
, 31, 29, offset
);
8534 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8535 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8538 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8539 generate_exception(ctx
, EXCP_RI
);
8541 offset
= extended
? offset
: offset
<< 3;
8542 gen_ld(env
, ctx
, OPC_LDPC
, ry
, 0, offset
);
8547 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8548 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8552 offset
= extended
? offset
: offset
<< 2;
8553 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8557 offset
= extended
? offset
: offset
<< 2;
8558 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8564 static int decode_extended_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8567 int extend
= lduw_code(ctx
->pc
+ 2);
8568 int op
, rx
, ry
, funct
, sa
;
8569 int16_t imm
, offset
;
8571 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8572 op
= (ctx
->opcode
>> 11) & 0x1f;
8573 sa
= (ctx
->opcode
>> 22) & 0x1f;
8574 funct
= (ctx
->opcode
>> 8) & 0x7;
8575 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8576 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8577 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8578 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8579 | (ctx
->opcode
& 0x1f));
8581 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8584 case M16_OPC_ADDIUSP
:
8585 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8587 case M16_OPC_ADDIUPC
:
8588 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8591 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8592 /* No delay slot, so just process as a normal instruction */
8595 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8596 /* No delay slot, so just process as a normal instruction */
8599 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8600 /* No delay slot, so just process as a normal instruction */
8603 switch (ctx
->opcode
& 0x3) {
8605 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8608 #if defined(TARGET_MIPS64)
8610 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8612 generate_exception(ctx
, EXCP_RI
);
8616 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8619 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8623 #if defined(TARGET_MIPS64)
8626 gen_ld(env
, ctx
, OPC_LD
, ry
, rx
, offset
);
8630 imm
= ctx
->opcode
& 0xf;
8631 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8632 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8633 imm
= (int16_t) (imm
<< 1) >> 1;
8634 if ((ctx
->opcode
>> 4) & 0x1) {
8635 #if defined(TARGET_MIPS64)
8637 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8639 generate_exception(ctx
, EXCP_RI
);
8642 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8645 case M16_OPC_ADDIU8
:
8646 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8649 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8652 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8657 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8660 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8663 gen_st(ctx
, OPC_SW
, 31, 29, imm
);
8666 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8670 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8671 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8672 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8673 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8674 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8675 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8676 | (ctx
->opcode
& 0xf)) << 3;
8678 if (ctx
->opcode
& (1 << 7)) {
8679 gen_mips16_save(ctx
, xsregs
, aregs
,
8680 do_ra
, do_s0
, do_s1
,
8683 gen_mips16_restore(ctx
, xsregs
, aregs
,
8684 do_ra
, do_s0
, do_s1
,
8690 generate_exception(ctx
, EXCP_RI
);
8695 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8698 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8700 #if defined(TARGET_MIPS64)
8702 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
);
8706 gen_ld(env
, ctx
, OPC_LB
, ry
, rx
, offset
);
8709 gen_ld(env
, ctx
, OPC_LH
, ry
, rx
, offset
);
8712 gen_ld(env
, ctx
, OPC_LW
, rx
, 29, offset
);
8715 gen_ld(env
, ctx
, OPC_LW
, ry
, rx
, offset
);
8718 gen_ld(env
, ctx
, OPC_LBU
, ry
, rx
, offset
);
8721 gen_ld(env
, ctx
, OPC_LHU
, ry
, rx
, offset
);
8724 gen_ld(env
, ctx
, OPC_LWPC
, rx
, 0, offset
);
8726 #if defined(TARGET_MIPS64)
8728 gen_ld(env
, ctx
, OPC_LWU
, ry
, rx
, offset
);
8732 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
8735 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
);
8738 gen_st(ctx
, OPC_SW
, rx
, 29, offset
);
8741 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
);
8743 #if defined(TARGET_MIPS64)
8745 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8749 generate_exception(ctx
, EXCP_RI
);
8756 static int decode_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8761 int op
, cnvt_op
, op1
, offset
;
8765 op
= (ctx
->opcode
>> 11) & 0x1f;
8766 sa
= (ctx
->opcode
>> 2) & 0x7;
8767 sa
= sa
== 0 ? 8 : sa
;
8768 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8769 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8770 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8771 op1
= offset
= ctx
->opcode
& 0x1f;
8776 case M16_OPC_ADDIUSP
:
8778 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8780 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8783 case M16_OPC_ADDIUPC
:
8784 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8787 offset
= (ctx
->opcode
& 0x7ff) << 1;
8788 offset
= (int16_t)(offset
<< 4) >> 4;
8789 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8790 /* No delay slot, so just process as a normal instruction */
8793 offset
= lduw_code(ctx
->pc
+ 2);
8794 offset
= (((ctx
->opcode
& 0x1f) << 21)
8795 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8797 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALXS
: OPC_JALS
;
8798 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8803 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8804 /* No delay slot, so just process as a normal instruction */
8807 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8808 /* No delay slot, so just process as a normal instruction */
8811 switch (ctx
->opcode
& 0x3) {
8813 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8816 #if defined(TARGET_MIPS64)
8818 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8820 generate_exception(ctx
, EXCP_RI
);
8824 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8827 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8831 #if defined(TARGET_MIPS64)
8834 gen_ld(env
, ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8839 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8841 if ((ctx
->opcode
>> 4) & 1) {
8842 #if defined(TARGET_MIPS64)
8844 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8846 generate_exception(ctx
, EXCP_RI
);
8849 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8853 case M16_OPC_ADDIU8
:
8855 int16_t imm
= (int8_t) ctx
->opcode
;
8857 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8862 int16_t imm
= (uint8_t) ctx
->opcode
;
8864 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8869 int16_t imm
= (uint8_t) ctx
->opcode
;
8871 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8878 funct
= (ctx
->opcode
>> 8) & 0x7;
8881 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
8882 ((int8_t)ctx
->opcode
) << 1);
8885 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
8886 ((int8_t)ctx
->opcode
) << 1);
8889 gen_st(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
8892 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
8893 ((int8_t)ctx
->opcode
) << 3);
8897 int do_ra
= ctx
->opcode
& (1 << 6);
8898 int do_s0
= ctx
->opcode
& (1 << 5);
8899 int do_s1
= ctx
->opcode
& (1 << 4);
8900 int framesize
= ctx
->opcode
& 0xf;
8902 if (framesize
== 0) {
8905 framesize
= framesize
<< 3;
8908 if (ctx
->opcode
& (1 << 7)) {
8909 gen_mips16_save(ctx
, 0, 0,
8910 do_ra
, do_s0
, do_s1
, framesize
);
8912 gen_mips16_restore(ctx
, 0, 0,
8913 do_ra
, do_s0
, do_s1
, framesize
);
8919 int rz
= xlat(ctx
->opcode
& 0x7);
8921 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
8922 ((ctx
->opcode
>> 5) & 0x7);
8923 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
8927 reg32
= ctx
->opcode
& 0x1f;
8928 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
8931 generate_exception(ctx
, EXCP_RI
);
8938 int16_t imm
= (uint8_t) ctx
->opcode
;
8940 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
8945 int16_t imm
= (uint8_t) ctx
->opcode
;
8947 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
8950 #if defined(TARGET_MIPS64)
8953 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
8957 gen_ld(env
, ctx
, OPC_LB
, ry
, rx
, offset
);
8960 gen_ld(env
, ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
8963 gen_ld(env
, ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8966 gen_ld(env
, ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
8969 gen_ld(env
, ctx
, OPC_LBU
, ry
, rx
, offset
);
8972 gen_ld(env
, ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
8975 gen_ld(env
, ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
8977 #if defined (TARGET_MIPS64)
8980 gen_ld(env
, ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
8984 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
8987 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
8990 gen_st(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8993 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
8997 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
9000 switch (ctx
->opcode
& 0x3) {
9002 mips32_op
= OPC_ADDU
;
9005 mips32_op
= OPC_SUBU
;
9007 #if defined(TARGET_MIPS64)
9009 mips32_op
= OPC_DADDU
;
9013 mips32_op
= OPC_DSUBU
;
9018 generate_exception(ctx
, EXCP_RI
);
9022 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
9031 int nd
= (ctx
->opcode
>> 7) & 0x1;
9032 int link
= (ctx
->opcode
>> 6) & 0x1;
9033 int ra
= (ctx
->opcode
>> 5) & 0x1;
9036 op
= nd
? OPC_JALRC
: OPC_JALRS
;
9041 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
9048 /* XXX: not clear which exception should be raised
9049 * when in debug mode...
9051 check_insn(env
, ctx
, ISA_MIPS32
);
9052 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9053 generate_exception(ctx
, EXCP_DBp
);
9055 generate_exception(ctx
, EXCP_DBp
);
9059 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
9062 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
9065 generate_exception(ctx
, EXCP_BREAK
);
9068 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
9071 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
9074 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
9076 #if defined (TARGET_MIPS64)
9079 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
9083 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
9086 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
9089 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
9092 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
9095 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
9098 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
9101 gen_HILO(ctx
, OPC_MFHI
, rx
);
9105 case RR_RY_CNVT_ZEB
:
9106 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9108 case RR_RY_CNVT_ZEH
:
9109 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9111 case RR_RY_CNVT_SEB
:
9112 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9114 case RR_RY_CNVT_SEH
:
9115 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9117 #if defined (TARGET_MIPS64)
9118 case RR_RY_CNVT_ZEW
:
9120 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9122 case RR_RY_CNVT_SEW
:
9124 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9128 generate_exception(ctx
, EXCP_RI
);
9133 gen_HILO(ctx
, OPC_MFLO
, rx
);
9135 #if defined (TARGET_MIPS64)
9138 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
9142 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
9146 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
9150 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
9154 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
9157 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
9160 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
9163 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
9165 #if defined (TARGET_MIPS64)
9168 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
9172 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
9176 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
9180 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
9184 generate_exception(ctx
, EXCP_RI
);
9188 case M16_OPC_EXTEND
:
9189 decode_extended_mips16_opc(env
, ctx
, is_branch
);
9192 #if defined(TARGET_MIPS64)
9194 funct
= (ctx
->opcode
>> 8) & 0x7;
9195 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
9199 generate_exception(ctx
, EXCP_RI
);
9206 /* microMIPS extension to MIPS32 */
9208 /* microMIPS32 major opcodes */
9247 /* 0x20 is reserved */
9257 /* 0x28 and 0x29 are reserved */
9267 /* 0x30 and 0x31 are reserved */
9277 /* 0x38 and 0x39 are reserved */
9288 /* POOL32A encoding of minor opcode field */
9291 /* These opcodes are distinguished only by bits 9..6; those bits are
9292 * what are recorded below. */
9318 /* The following can be distinguished by their lower 6 bits. */
9324 /* POOL32AXF encoding of minor opcode field extension */
9338 /* bits 13..12 for 0x01 */
9344 /* bits 13..12 for 0x2a */
9350 /* bits 13..12 for 0x32 */
9354 /* bits 15..12 for 0x2c */
9370 /* bits 15..12 for 0x34 */
9378 /* bits 15..12 for 0x3c */
9380 JR
= 0x0, /* alias */
9385 /* bits 15..12 for 0x05 */
9389 /* bits 15..12 for 0x0d */
9399 /* bits 15..12 for 0x15 */
9405 /* bits 15..12 for 0x1d */
9409 /* bits 15..12 for 0x2d */
9414 /* bits 15..12 for 0x35 */
9421 /* POOL32B encoding of minor opcode field (bits 15..12) */
9437 /* POOL32C encoding of minor opcode field (bits 15..12) */
9445 /* 0xa is reserved */
9452 /* 0x6 is reserved */
9458 /* POOL32F encoding of minor opcode field (bits 5..0) */
9461 /* These are the bit 7..6 values */
9472 /* These are the bit 8..6 values */
9516 CABS_COND_FMT
= 0x1c, /* MIPS3D */
9520 /* POOL32Fxf encoding of minor opcode extension field */
9558 /* POOL32I encoding of minor opcode field (bits 25..21) */
9583 /* These overlap and are distinguished by bit16 of the instruction */
9592 /* POOL16A encoding of minor opcode field */
9599 /* POOL16B encoding of minor opcode field */
9606 /* POOL16C encoding of minor opcode field */
9626 /* POOL16D encoding of minor opcode field */
9633 /* POOL16E encoding of minor opcode field */
9640 static int mmreg (int r
)
9642 static const int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
9647 /* Used for 16-bit store instructions. */
9648 static int mmreg2 (int r
)
9650 static const int map
[] = { 0, 17, 2, 3, 4, 5, 6, 7 };
9655 #define uMIPS_RD(op) ((op >> 7) & 0x7)
9656 #define uMIPS_RS(op) ((op >> 4) & 0x7)
9657 #define uMIPS_RS2(op) uMIPS_RS(op)
9658 #define uMIPS_RS1(op) ((op >> 1) & 0x7)
9659 #define uMIPS_RD5(op) ((op >> 5) & 0x1f)
9660 #define uMIPS_RS5(op) (op & 0x1f)
9662 /* Signed immediate */
9663 #define SIMM(op, start, width) \
9664 ((int32_t)(((op >> start) & ((~0U) >> (32-width))) \
9667 /* Zero-extended immediate */
9668 #define ZIMM(op, start, width) ((op >> start) & ((~0U) >> (32-width)))
9670 static void gen_addiur1sp (CPUState
*env
, DisasContext
*ctx
)
9672 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9674 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, 29, ((ctx
->opcode
>> 1) & 0x3f) << 2);
9677 static void gen_addiur2 (CPUState
*env
, DisasContext
*ctx
)
9679 static const int decoded_imm
[] = { 1, 4, 8, 12, 16, 20, 24, -1 };
9680 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9681 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9683 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, decoded_imm
[ZIMM(ctx
->opcode
, 1, 3)]);
9686 static void gen_addiusp (CPUState
*env
, DisasContext
*ctx
)
9688 int encoded
= ZIMM(ctx
->opcode
, 1, 9);
9692 decoded
= 256 + encoded
;
9693 } else if (encoded
<= 255) {
9695 } else if (encoded
<= 509) {
9696 decoded
= encoded
- 512;
9698 decoded
= encoded
- 768;
9701 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, decoded
<< 2);
9704 static void gen_addius5 (CPUState
*env
, DisasContext
*ctx
)
9706 int imm
= SIMM(ctx
->opcode
, 1, 4);
9707 int rd
= (ctx
->opcode
>> 5) & 0x1f;
9709 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rd
, imm
);
9712 static void gen_andi16 (CPUState
*env
, DisasContext
*ctx
)
9714 static const int decoded_imm
[] = { 128, 1, 2, 3, 4, 7, 8, 15, 16,
9715 31, 32, 63, 64, 255, 32768, 65535 };
9716 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9717 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9718 int encoded
= ZIMM(ctx
->opcode
, 0, 4);
9720 gen_logic_imm(env
, OPC_ANDI
, rd
, rs
, decoded_imm
[encoded
]);
9723 static void gen_ldst_multiple (DisasContext
*ctx
, uint32_t opc
, int reglist
,
9724 int base
, int16_t offset
)
9729 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
9730 generate_exception(ctx
, EXCP_RI
);
9734 t0
= tcg_temp_new();
9736 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9738 t1
= tcg_const_tl(reglist
);
9739 t2
= tcg_const_i32(ctx
->mem_idx
);
9741 save_cpu_state(ctx
, 1);
9744 gen_helper_lwm(t0
, t1
, t2
);
9747 gen_helper_swm(t0
, t1
, t2
);
9749 #ifdef TARGET_MIPS64
9751 gen_helper_ldm(t0
, t1
, t2
);
9754 gen_helper_sdm(t0
, t1
, t2
);
9758 MIPS_DEBUG("%s, %x, %d(%s)", opn
, reglist
, offset
, regnames
[base
]);
9761 tcg_temp_free_i32(t2
);
9765 static void gen_pool16c_insn (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
9767 int rd
= mmreg((ctx
->opcode
>> 3) & 0x7);
9768 int rs
= mmreg(ctx
->opcode
& 0x7);
9771 switch (((ctx
->opcode
) >> 4) & 0x3f) {
9776 gen_logic(env
, OPC_NOR
, rd
, rs
, 0);
9782 gen_logic(env
, OPC_XOR
, rd
, rd
, rs
);
9788 gen_logic(env
, OPC_AND
, rd
, rd
, rs
);
9794 gen_logic(env
, OPC_OR
, rd
, rd
, rs
);
9801 static const int lwm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9802 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9804 gen_ldst_multiple(ctx
, LWM32
, lwm_convert
[(ctx
->opcode
>> 4) & 0x3],
9813 static const int swm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9814 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9816 gen_ldst_multiple(ctx
, SWM32
, swm_convert
[(ctx
->opcode
>> 4) & 0x3],
9823 int reg
= ctx
->opcode
& 0x1f;
9825 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9832 int reg
= ctx
->opcode
& 0x1f;
9834 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9835 /* Let normal delay slot handling in our caller take us
9836 to the branch target. */
9848 int reg
= ctx
->opcode
& 0x1f;
9850 gen_compute_branch(ctx
, opc
, 2, reg
, 31, 0);
9856 gen_HILO(ctx
, OPC_MFHI
, uMIPS_RS5(ctx
->opcode
));
9860 gen_HILO(ctx
, OPC_MFLO
, uMIPS_RS5(ctx
->opcode
));
9863 generate_exception(ctx
, EXCP_BREAK
);
9866 /* XXX: not clear which exception should be raised
9867 * when in debug mode...
9869 check_insn(env
, ctx
, ISA_MIPS32
);
9870 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9871 generate_exception(ctx
, EXCP_DBp
);
9873 generate_exception(ctx
, EXCP_DBp
);
9879 int imm
= ZIMM(ctx
->opcode
, 0, 5);
9881 gen_compute_branch(ctx
, OPC_JR
, 2, 31, 0, 0);
9882 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
<< 2);
9883 /* Let normal delay slot handling in our caller take us
9884 to the branch target. */
9888 generate_exception(ctx
, EXCP_RI
);
9893 static void gen_ldxs (DisasContext
*ctx
, int base
, int index
, int rd
)
9895 TCGv t0
= tcg_temp_new();
9896 TCGv t1
= tcg_temp_new();
9898 gen_load_gpr(t0
, base
);
9901 gen_load_gpr(t1
, index
);
9902 tcg_gen_shli_tl(t1
, t1
, 2);
9903 gen_op_addr_add(ctx
, t0
, t1
, t0
);
9906 save_cpu_state(ctx
, 0);
9907 op_ld_lw(t1
, t0
, ctx
);
9908 gen_store_gpr(t1
, rd
);
9914 static void gen_ldst_pair (DisasContext
*ctx
, uint32_t opc
, int rd
,
9915 int base
, int16_t offset
)
9917 const char *opn
= "ldst_pair";
9920 if (ctx
->hflags
& MIPS_HFLAG_BMASK
|| rd
== 31 || rd
== base
) {
9921 generate_exception(ctx
, EXCP_RI
);
9925 t0
= tcg_temp_new();
9926 t1
= tcg_temp_new();
9928 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9932 save_cpu_state(ctx
, 0);
9933 op_ld_lw(t1
, t0
, ctx
);
9934 gen_store_gpr(t1
, rd
);
9935 tcg_gen_movi_tl(t1
, 4);
9936 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9937 op_ld_lw(t1
, t0
, ctx
);
9938 gen_store_gpr(t1
, rd
+1);
9942 save_cpu_state(ctx
, 1);
9943 gen_load_gpr(t1
, rd
);
9944 op_st_sw(t1
, t0
, ctx
);
9945 tcg_gen_movi_tl(t1
, 4);
9946 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9947 gen_load_gpr(t1
, rd
+1);
9948 op_st_sw(t1
, t0
, ctx
);
9951 #ifdef TARGET_MIPS64
9953 save_cpu_state(ctx
, 0);
9954 op_ld_ld(t1
, t0
, ctx
);
9955 gen_store_gpr(t1
, rd
);
9956 tcg_gen_movi_tl(t1
, 8);
9957 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9958 op_ld_ld(t1
, t0
, ctx
);
9959 gen_store_gpr(t1
, rd
+1);
9963 save_cpu_state(ctx
, 1);
9964 gen_load_gpr(t1
, rd
);
9965 op_st_sd(t1
, t0
, ctx
);
9966 tcg_gen_movi_tl(t1
, 8);
9967 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9968 gen_load_gpr(t1
, rd
+1);
9969 op_st_sd(t1
, t0
, ctx
);
9974 MIPS_DEBUG("%s, %s, %d(%s)", opn
, regnames
[rd
], offset
, regnames
[base
]);
9979 static void gen_pool32axf (CPUState
*env
, DisasContext
*ctx
, int rt
, int rs
,
9982 int extension
= (ctx
->opcode
>> 6) & 0x3f;
9983 int minor
= (ctx
->opcode
>> 12) & 0xf;
9986 switch (extension
) {
9988 mips32_op
= OPC_TEQ
;
9991 mips32_op
= OPC_TGE
;
9994 mips32_op
= OPC_TGEU
;
9997 mips32_op
= OPC_TLT
;
10000 mips32_op
= OPC_TLTU
;
10003 mips32_op
= OPC_TNE
;
10005 gen_trap(ctx
, mips32_op
, rs
, rt
, -1);
10007 #ifndef CONFIG_USER_ONLY
10011 /* Treat as NOP. */
10014 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rs
, (ctx
->opcode
>> 11) & 0x7);
10019 TCGv t0
= tcg_temp_new();
10021 gen_load_gpr(t0
, rt
);
10022 gen_mtc0(env
, ctx
, t0
, rs
, (ctx
->opcode
>> 11) & 0x7);
10030 gen_bshfl(ctx
, OPC_SEB
, rs
, rt
);
10033 gen_bshfl(ctx
, OPC_SEH
, rs
, rt
);
10036 mips32_op
= OPC_CLO
;
10039 mips32_op
= OPC_CLZ
;
10041 check_insn(env
, ctx
, ISA_MIPS32
);
10042 gen_cl(ctx
, mips32_op
, rt
, rs
);
10045 gen_rdhwr(env
, ctx
, rt
, rs
);
10048 gen_bshfl(ctx
, OPC_WSBH
, rs
, rt
);
10051 mips32_op
= OPC_MULT
;
10054 mips32_op
= OPC_MULTU
;
10057 mips32_op
= OPC_DIV
;
10060 mips32_op
= OPC_DIVU
;
10063 mips32_op
= OPC_MADD
;
10066 mips32_op
= OPC_MADDU
;
10069 mips32_op
= OPC_MSUB
;
10072 mips32_op
= OPC_MSUBU
;
10074 check_insn(env
, ctx
, ISA_MIPS32
);
10075 gen_muldiv(ctx
, mips32_op
, rs
, rt
);
10078 goto pool32axf_invalid
;
10089 generate_exception_err(ctx
, EXCP_CpU
, 2);
10092 goto pool32axf_invalid
;
10099 gen_compute_branch (ctx
, OPC_JALR
, 4, rs
, rt
, 0);
10104 gen_compute_branch (ctx
, OPC_JALRS
, 4, rs
, rt
, 0);
10108 goto pool32axf_invalid
;
10114 check_insn(env
, ctx
, ISA_MIPS32R2
);
10115 gen_load_srsgpr(rt
, rs
);
10118 check_insn(env
, ctx
, ISA_MIPS32R2
);
10119 gen_store_srsgpr(rt
, rs
);
10122 goto pool32axf_invalid
;
10125 #ifndef CONFIG_USER_ONLY
10129 mips32_op
= OPC_TLBP
;
10132 mips32_op
= OPC_TLBR
;
10135 mips32_op
= OPC_TLBWI
;
10138 mips32_op
= OPC_TLBWR
;
10141 mips32_op
= OPC_WAIT
;
10144 mips32_op
= OPC_DERET
;
10147 mips32_op
= OPC_ERET
;
10149 gen_cp0(env
, ctx
, mips32_op
, rt
, rs
);
10152 goto pool32axf_invalid
;
10159 TCGv t0
= tcg_temp_new();
10161 save_cpu_state(ctx
, 1);
10163 gen_store_gpr(t0
, rs
);
10164 /* Stop translation as we may have switched the execution mode */
10165 ctx
->bstate
= BS_STOP
;
10171 TCGv t0
= tcg_temp_new();
10173 save_cpu_state(ctx
, 1);
10175 gen_store_gpr(t0
, rs
);
10176 /* Stop translation as we may have switched the execution mode */
10177 ctx
->bstate
= BS_STOP
;
10182 goto pool32axf_invalid
;
10192 generate_exception(ctx
, EXCP_SYSCALL
);
10193 ctx
->bstate
= BS_STOP
;
10196 check_insn(env
, ctx
, ISA_MIPS32
);
10197 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
10198 generate_exception(ctx
, EXCP_DBp
);
10200 generate_exception(ctx
, EXCP_DBp
);
10204 goto pool32axf_invalid
;
10210 gen_HILO(ctx
, OPC_MFHI
, rs
);
10213 gen_HILO(ctx
, OPC_MFLO
, rs
);
10216 gen_HILO(ctx
, OPC_MTHI
, rs
);
10219 gen_HILO(ctx
, OPC_MTLO
, rs
);
10222 goto pool32axf_invalid
;
10227 MIPS_INVAL("pool32axf");
10228 generate_exception(ctx
, EXCP_RI
);
10233 /* Values for microMIPS fmt field. Variable-width, depending on which
10234 formats the instruction supports. */
10253 static void gen_pool32fxf (CPUState
*env
, DisasContext
*ctx
, int rt
, int rs
)
10255 int extension
= (ctx
->opcode
>> 6) & 0x3ff;
10256 uint32_t mips32_op
;
10258 #define FLOAT_1BIT_FMT(opc, fmt) (fmt << 8) | opc
10259 #define FLOAT_2BIT_FMT(opc, fmt) (fmt << 7) | opc
10260 #define COND_FLOAT_MOV(opc, cond) (cond << 7) | opc
10262 switch (extension
) {
10263 case FLOAT_1BIT_FMT(CFC1
, 0):
10264 mips32_op
= OPC_CFC1
;
10266 case FLOAT_1BIT_FMT(CTC1
, 0):
10267 mips32_op
= OPC_CTC1
;
10269 case FLOAT_1BIT_FMT(MFC1
, 0):
10270 mips32_op
= OPC_MFC1
;
10272 case FLOAT_1BIT_FMT(MTC1
, 0):
10273 mips32_op
= OPC_MTC1
;
10275 case FLOAT_1BIT_FMT(MFHC1
, 0):
10276 mips32_op
= OPC_MFHC1
;
10278 case FLOAT_1BIT_FMT(MTHC1
, 0):
10279 mips32_op
= OPC_MTHC1
;
10281 gen_cp1(ctx
, mips32_op
, rt
, rs
);
10284 /* Reciprocal square root */
10285 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_S
):
10286 mips32_op
= OPC_RSQRT_S
;
10288 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_D
):
10289 mips32_op
= OPC_RSQRT_D
;
10293 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_S
):
10294 mips32_op
= OPC_SQRT_S
;
10296 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_D
):
10297 mips32_op
= OPC_SQRT_D
;
10301 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_S
):
10302 mips32_op
= OPC_RECIP_S
;
10304 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_D
):
10305 mips32_op
= OPC_RECIP_D
;
10309 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_S
):
10310 mips32_op
= OPC_FLOOR_L_S
;
10312 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_D
):
10313 mips32_op
= OPC_FLOOR_L_D
;
10315 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_S
):
10316 mips32_op
= OPC_FLOOR_W_S
;
10318 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_D
):
10319 mips32_op
= OPC_FLOOR_W_D
;
10323 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_S
):
10324 mips32_op
= OPC_CEIL_L_S
;
10326 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_D
):
10327 mips32_op
= OPC_CEIL_L_D
;
10329 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_S
):
10330 mips32_op
= OPC_CEIL_W_S
;
10332 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_D
):
10333 mips32_op
= OPC_CEIL_W_D
;
10337 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_S
):
10338 mips32_op
= OPC_TRUNC_L_S
;
10340 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_D
):
10341 mips32_op
= OPC_TRUNC_L_D
;
10343 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_S
):
10344 mips32_op
= OPC_TRUNC_W_S
;
10346 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_D
):
10347 mips32_op
= OPC_TRUNC_W_D
;
10351 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_S
):
10352 mips32_op
= OPC_ROUND_L_S
;
10354 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_D
):
10355 mips32_op
= OPC_ROUND_L_D
;
10357 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_S
):
10358 mips32_op
= OPC_ROUND_W_S
;
10360 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_D
):
10361 mips32_op
= OPC_ROUND_W_D
;
10364 /* Integer to floating-point conversion */
10365 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_S
):
10366 mips32_op
= OPC_CVT_L_S
;
10368 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_D
):
10369 mips32_op
= OPC_CVT_L_D
;
10371 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_S
):
10372 mips32_op
= OPC_CVT_W_S
;
10374 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_D
):
10375 mips32_op
= OPC_CVT_W_D
;
10378 /* Paired-foo conversions */
10379 case FLOAT_1BIT_FMT(CVT_S_PL
, 0):
10380 mips32_op
= OPC_CVT_S_PL
;
10382 case FLOAT_1BIT_FMT(CVT_S_PU
, 0):
10383 mips32_op
= OPC_CVT_S_PU
;
10385 case FLOAT_1BIT_FMT(CVT_PW_PS
, 0):
10386 mips32_op
= OPC_CVT_PW_PS
;
10388 case FLOAT_1BIT_FMT(CVT_PS_PW
, 0):
10389 mips32_op
= OPC_CVT_PS_PW
;
10392 /* Floating-point moves */
10393 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_S
):
10394 mips32_op
= OPC_MOV_S
;
10396 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_D
):
10397 mips32_op
= OPC_MOV_D
;
10399 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_PS
):
10400 mips32_op
= OPC_MOV_PS
;
10403 /* Absolute value */
10404 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_S
):
10405 mips32_op
= OPC_ABS_S
;
10407 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_D
):
10408 mips32_op
= OPC_ABS_D
;
10410 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_PS
):
10411 mips32_op
= OPC_ABS_PS
;
10415 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_S
):
10416 mips32_op
= OPC_NEG_S
;
10418 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_D
):
10419 mips32_op
= OPC_NEG_D
;
10421 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_PS
):
10422 mips32_op
= OPC_NEG_PS
;
10425 /* Reciprocal square root step */
10426 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_S
):
10427 mips32_op
= OPC_RSQRT1_S
;
10429 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_D
):
10430 mips32_op
= OPC_RSQRT1_D
;
10432 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_PS
):
10433 mips32_op
= OPC_RSQRT1_PS
;
10436 /* Reciprocal step */
10437 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_S
):
10438 mips32_op
= OPC_RECIP1_S
;
10440 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_D
):
10441 mips32_op
= OPC_RECIP1_S
;
10443 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_PS
):
10444 mips32_op
= OPC_RECIP1_PS
;
10447 /* Conversions from double */
10448 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_S
):
10449 mips32_op
= OPC_CVT_D_S
;
10451 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_W
):
10452 mips32_op
= OPC_CVT_D_W
;
10454 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_L
):
10455 mips32_op
= OPC_CVT_D_L
;
10458 /* Conversions from single */
10459 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_D
):
10460 mips32_op
= OPC_CVT_S_D
;
10462 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_W
):
10463 mips32_op
= OPC_CVT_S_W
;
10465 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_L
):
10466 mips32_op
= OPC_CVT_S_L
;
10468 gen_farith(ctx
, mips32_op
, -1, rs
, rt
, 0);
10471 /* Conditional moves on floating-point codes */
10472 case COND_FLOAT_MOV(MOVT
, 0):
10473 case COND_FLOAT_MOV(MOVT
, 1):
10474 case COND_FLOAT_MOV(MOVT
, 2):
10475 case COND_FLOAT_MOV(MOVT
, 3):
10476 case COND_FLOAT_MOV(MOVT
, 4):
10477 case COND_FLOAT_MOV(MOVT
, 5):
10478 case COND_FLOAT_MOV(MOVT
, 6):
10479 case COND_FLOAT_MOV(MOVT
, 7):
10480 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 1);
10482 case COND_FLOAT_MOV(MOVF
, 0):
10483 case COND_FLOAT_MOV(MOVF
, 1):
10484 case COND_FLOAT_MOV(MOVF
, 2):
10485 case COND_FLOAT_MOV(MOVF
, 3):
10486 case COND_FLOAT_MOV(MOVF
, 4):
10487 case COND_FLOAT_MOV(MOVF
, 5):
10488 case COND_FLOAT_MOV(MOVF
, 6):
10489 case COND_FLOAT_MOV(MOVF
, 7):
10490 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 0);
10493 MIPS_INVAL("pool32fxf");
10494 generate_exception(ctx
, EXCP_RI
);
10499 static void decode_micromips32_opc (CPUState
*env
, DisasContext
*ctx
,
10500 uint16_t insn_hw1
, int *is_branch
)
10504 int rt
, rs
, rd
, rr
;
10506 uint32_t op
, minor
, mips32_op
;
10507 uint32_t cond
, fmt
, cc
;
10509 insn
= lduw_code(ctx
->pc
+ 2);
10510 ctx
->opcode
= (ctx
->opcode
<< 16) | insn
;
10512 rt
= (ctx
->opcode
>> 21) & 0x1f;
10513 rs
= (ctx
->opcode
>> 16) & 0x1f;
10514 rd
= (ctx
->opcode
>> 11) & 0x1f;
10515 rr
= (ctx
->opcode
>> 6) & 0x1f;
10516 imm
= (int16_t) ctx
->opcode
;
10518 op
= (ctx
->opcode
>> 26) & 0x3f;
10521 minor
= ctx
->opcode
& 0x3f;
10524 minor
= (ctx
->opcode
>> 6) & 0xf;
10527 mips32_op
= OPC_SLL
;
10530 mips32_op
= OPC_SRA
;
10533 mips32_op
= OPC_SRL
;
10536 mips32_op
= OPC_ROTR
;
10538 gen_shift_imm(env
, ctx
, mips32_op
, rt
, rs
, rd
);
10541 goto pool32a_invalid
;
10545 minor
= (ctx
->opcode
>> 6) & 0xf;
10549 mips32_op
= OPC_ADD
;
10552 mips32_op
= OPC_ADDU
;
10555 mips32_op
= OPC_SUB
;
10558 mips32_op
= OPC_SUBU
;
10561 mips32_op
= OPC_MUL
;
10563 gen_arith(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10567 mips32_op
= OPC_SLLV
;
10570 mips32_op
= OPC_SRLV
;
10573 mips32_op
= OPC_SRAV
;
10576 mips32_op
= OPC_ROTRV
;
10578 gen_shift(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10580 /* Logical operations */
10582 mips32_op
= OPC_AND
;
10585 mips32_op
= OPC_OR
;
10588 mips32_op
= OPC_NOR
;
10591 mips32_op
= OPC_XOR
;
10593 gen_logic(env
, mips32_op
, rd
, rs
, rt
);
10595 /* Set less than */
10597 mips32_op
= OPC_SLT
;
10600 mips32_op
= OPC_SLTU
;
10602 gen_slt(env
, mips32_op
, rd
, rs
, rt
);
10605 goto pool32a_invalid
;
10609 minor
= (ctx
->opcode
>> 6) & 0xf;
10611 /* Conditional moves */
10613 mips32_op
= OPC_MOVN
;
10616 mips32_op
= OPC_MOVZ
;
10618 gen_cond_move(env
, mips32_op
, rd
, rs
, rt
);
10621 gen_ldxs(ctx
, rs
, rt
, rd
);
10624 goto pool32a_invalid
;
10628 gen_bitops(ctx
, OPC_INS
, rt
, rs
, rr
, rd
);
10631 gen_bitops(ctx
, OPC_EXT
, rt
, rs
, rr
, rd
);
10634 gen_pool32axf(env
, ctx
, rt
, rs
, is_branch
);
10637 generate_exception(ctx
, EXCP_BREAK
);
10641 MIPS_INVAL("pool32a");
10642 generate_exception(ctx
, EXCP_RI
);
10647 minor
= (ctx
->opcode
>> 12) & 0xf;
10650 /* Treat as no-op. */
10654 /* COP2: Not implemented. */
10655 generate_exception_err(ctx
, EXCP_CpU
, 2);
10659 #ifdef TARGET_MIPS64
10663 gen_ldst_pair(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10667 #ifdef TARGET_MIPS64
10671 gen_ldst_multiple(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10674 MIPS_INVAL("pool32b");
10675 generate_exception(ctx
, EXCP_RI
);
10680 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
10681 minor
= ctx
->opcode
& 0x3f;
10682 check_cp1_enabled(ctx
);
10685 mips32_op
= OPC_ALNV_PS
;
10688 mips32_op
= OPC_MADD_S
;
10691 mips32_op
= OPC_MADD_D
;
10694 mips32_op
= OPC_MADD_PS
;
10697 mips32_op
= OPC_MSUB_S
;
10700 mips32_op
= OPC_MSUB_D
;
10703 mips32_op
= OPC_MSUB_PS
;
10706 mips32_op
= OPC_NMADD_S
;
10709 mips32_op
= OPC_NMADD_D
;
10712 mips32_op
= OPC_NMADD_PS
;
10715 mips32_op
= OPC_NMSUB_S
;
10718 mips32_op
= OPC_NMSUB_D
;
10721 mips32_op
= OPC_NMSUB_PS
;
10723 gen_flt3_arith(ctx
, mips32_op
, rd
, rr
, rs
, rt
);
10725 case CABS_COND_FMT
:
10726 cond
= (ctx
->opcode
>> 6) & 0xf;
10727 cc
= (ctx
->opcode
>> 13) & 0x7;
10728 fmt
= (ctx
->opcode
>> 10) & 0x3;
10731 gen_cmpabs_s(ctx
, cond
, rt
, rs
, cc
);
10734 gen_cmpabs_d(ctx
, cond
, rt
, rs
, cc
);
10737 gen_cmpabs_ps(ctx
, cond
, rt
, rs
, cc
);
10740 goto pool32f_invalid
;
10744 cond
= (ctx
->opcode
>> 6) & 0xf;
10745 cc
= (ctx
->opcode
>> 13) & 0x7;
10746 fmt
= (ctx
->opcode
>> 10) & 0x3;
10749 gen_cmp_s(ctx
, cond
, rt
, rs
, cc
);
10752 gen_cmp_d(ctx
, cond
, rt
, rs
, cc
);
10755 gen_cmp_ps(ctx
, cond
, rt
, rs
, cc
);
10758 goto pool32f_invalid
;
10762 gen_pool32fxf(env
, ctx
, rt
, rs
);
10766 switch ((ctx
->opcode
>> 6) & 0x7) {
10768 mips32_op
= OPC_PLL_PS
;
10771 mips32_op
= OPC_PLU_PS
;
10774 mips32_op
= OPC_PUL_PS
;
10777 mips32_op
= OPC_PUU_PS
;
10780 mips32_op
= OPC_CVT_PS_S
;
10782 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10785 goto pool32f_invalid
;
10790 switch ((ctx
->opcode
>> 6) & 0x7) {
10792 mips32_op
= OPC_LWXC1
;
10795 mips32_op
= OPC_SWXC1
;
10798 mips32_op
= OPC_LDXC1
;
10801 mips32_op
= OPC_SDXC1
;
10804 mips32_op
= OPC_LUXC1
;
10807 mips32_op
= OPC_SUXC1
;
10809 gen_flt3_ldst(ctx
, mips32_op
, rd
, rd
, rt
, rs
);
10812 goto pool32f_invalid
;
10817 fmt
= (ctx
->opcode
>> 9) & 0x3;
10818 switch ((ctx
->opcode
>> 6) & 0x7) {
10822 mips32_op
= OPC_RSQRT2_S
;
10825 mips32_op
= OPC_RSQRT2_D
;
10828 mips32_op
= OPC_RSQRT2_PS
;
10831 goto pool32f_invalid
;
10837 mips32_op
= OPC_RECIP2_S
;
10840 mips32_op
= OPC_RECIP2_D
;
10843 mips32_op
= OPC_RECIP2_PS
;
10846 goto pool32f_invalid
;
10850 mips32_op
= OPC_ADDR_PS
;
10853 mips32_op
= OPC_MULR_PS
;
10855 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10858 goto pool32f_invalid
;
10862 /* MOV[FT].fmt and PREFX */
10863 cc
= (ctx
->opcode
>> 13) & 0x7;
10864 fmt
= (ctx
->opcode
>> 9) & 0x3;
10865 switch ((ctx
->opcode
>> 6) & 0x7) {
10869 gen_movcf_s(rs
, rt
, cc
, 0);
10872 gen_movcf_d(ctx
, rs
, rt
, cc
, 0);
10875 gen_movcf_ps(rs
, rt
, cc
, 0);
10878 goto pool32f_invalid
;
10884 gen_movcf_s(rs
, rt
, cc
, 1);
10887 gen_movcf_d(ctx
, rs
, rt
, cc
, 1);
10890 gen_movcf_ps(rs
, rt
, cc
, 1);
10893 goto pool32f_invalid
;
10899 goto pool32f_invalid
;
10902 #define FINSN_3ARG_SDPS(prfx) \
10903 switch ((ctx->opcode >> 8) & 0x3) { \
10905 mips32_op = OPC_##prfx##_S; \
10908 mips32_op = OPC_##prfx##_D; \
10910 case FMT_SDPS_PS: \
10911 mips32_op = OPC_##prfx##_PS; \
10914 goto pool32f_invalid; \
10917 /* regular FP ops */
10918 switch ((ctx
->opcode
>> 6) & 0x3) {
10920 FINSN_3ARG_SDPS(ADD
);
10923 FINSN_3ARG_SDPS(SUB
);
10926 FINSN_3ARG_SDPS(MUL
);
10929 fmt
= (ctx
->opcode
>> 8) & 0x3;
10931 mips32_op
= OPC_DIV_D
;
10932 } else if (fmt
== 0) {
10933 mips32_op
= OPC_DIV_S
;
10935 goto pool32f_invalid
;
10939 goto pool32f_invalid
;
10944 switch ((ctx
->opcode
>> 6) & 0x3) {
10946 FINSN_3ARG_SDPS(MOVN
);
10949 FINSN_3ARG_SDPS(MOVZ
);
10952 goto pool32f_invalid
;
10956 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10960 MIPS_INVAL("pool32f");
10961 generate_exception(ctx
, EXCP_RI
);
10965 generate_exception_err(ctx
, EXCP_CpU
, 1);
10969 minor
= (ctx
->opcode
>> 21) & 0x1f;
10972 mips32_op
= OPC_BLTZ
;
10975 mips32_op
= OPC_BLTZAL
;
10978 mips32_op
= OPC_BLTZALS
;
10981 mips32_op
= OPC_BGEZ
;
10984 mips32_op
= OPC_BGEZAL
;
10987 mips32_op
= OPC_BGEZALS
;
10990 mips32_op
= OPC_BLEZ
;
10993 mips32_op
= OPC_BGTZ
;
10995 gen_compute_branch(ctx
, mips32_op
, 4, rs
, -1, imm
<< 1);
11001 mips32_op
= OPC_TLTI
;
11004 mips32_op
= OPC_TGEI
;
11007 mips32_op
= OPC_TLTIU
;
11010 mips32_op
= OPC_TGEIU
;
11013 mips32_op
= OPC_TNEI
;
11016 mips32_op
= OPC_TEQI
;
11018 gen_trap(ctx
, mips32_op
, rs
, -1, imm
);
11023 gen_compute_branch(ctx
, minor
== BNEZC
? OPC_BNE
: OPC_BEQ
,
11024 4, rs
, 0, imm
<< 1);
11025 /* Compact branches don't have a delay slot, so just let
11026 the normal delay slot handling take us to the branch
11030 gen_logic_imm(env
, OPC_LUI
, rs
, -1, imm
);
11036 /* COP2: Not implemented. */
11037 generate_exception_err(ctx
, EXCP_CpU
, 2);
11040 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1FANY2
: OPC_BC1F
;
11043 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1TANY2
: OPC_BC1T
;
11046 mips32_op
= OPC_BC1FANY4
;
11049 mips32_op
= OPC_BC1TANY4
;
11052 check_insn(env
, ctx
, ASE_MIPS3D
);
11055 gen_compute_branch1(env
, ctx
, mips32_op
,
11056 (ctx
->opcode
>> 18) & 0x7, imm
<< 1);
11061 /* MIPS DSP: not implemented */
11064 MIPS_INVAL("pool32i");
11065 generate_exception(ctx
, EXCP_RI
);
11070 minor
= (ctx
->opcode
>> 12) & 0xf;
11073 mips32_op
= OPC_LWL
;
11076 mips32_op
= OPC_SWL
;
11079 mips32_op
= OPC_LWR
;
11082 mips32_op
= OPC_SWR
;
11084 #if defined(TARGET_MIPS64)
11086 mips32_op
= OPC_LDL
;
11089 mips32_op
= OPC_SDL
;
11092 mips32_op
= OPC_LDR
;
11095 mips32_op
= OPC_SDR
;
11098 mips32_op
= OPC_LWU
;
11101 mips32_op
= OPC_LLD
;
11105 mips32_op
= OPC_LL
;
11108 gen_ld(env
, ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11111 gen_st(ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11114 gen_st_cond(ctx
, OPC_SC
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11116 #if defined(TARGET_MIPS64)
11118 gen_st_cond(ctx
, OPC_SCD
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11122 /* Treat as no-op */
11125 MIPS_INVAL("pool32c");
11126 generate_exception(ctx
, EXCP_RI
);
11131 mips32_op
= OPC_ADDI
;
11134 mips32_op
= OPC_ADDIU
;
11136 gen_arith_imm(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11139 /* Logical operations */
11141 mips32_op
= OPC_ORI
;
11144 mips32_op
= OPC_XORI
;
11147 mips32_op
= OPC_ANDI
;
11149 gen_logic_imm(env
, mips32_op
, rt
, rs
, imm
);
11152 /* Set less than immediate */
11154 mips32_op
= OPC_SLTI
;
11157 mips32_op
= OPC_SLTIU
;
11159 gen_slt_imm(env
, mips32_op
, rt
, rs
, imm
);
11162 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
11163 gen_compute_branch(ctx
, OPC_JALX
, 4, rt
, rs
, offset
);
11167 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1;
11168 gen_compute_branch(ctx
, OPC_JALS
, 4, rt
, rs
, offset
);
11172 gen_compute_branch(ctx
, OPC_BEQ
, 4, rt
, rs
, imm
<< 1);
11176 gen_compute_branch(ctx
, OPC_BNE
, 4, rt
, rs
, imm
<< 1);
11180 gen_compute_branch(ctx
, OPC_J
, 4, rt
, rs
,
11181 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
11185 gen_compute_branch(ctx
, OPC_JAL
, 4, rt
, rs
,
11186 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
11189 /* Floating point (COP1) */
11191 mips32_op
= OPC_LWC1
;
11194 mips32_op
= OPC_LDC1
;
11197 mips32_op
= OPC_SWC1
;
11200 mips32_op
= OPC_SDC1
;
11202 gen_cop1_ldst(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11206 int reg
= mmreg(ZIMM(ctx
->opcode
, 23, 3));
11207 int offset
= SIMM(ctx
->opcode
, 0, 23) << 2;
11209 gen_addiupc(ctx
, reg
, offset
, 0, 0);
11212 /* Loads and stores */
11214 mips32_op
= OPC_LB
;
11217 mips32_op
= OPC_LBU
;
11220 mips32_op
= OPC_LH
;
11223 mips32_op
= OPC_LHU
;
11226 mips32_op
= OPC_LW
;
11228 #ifdef TARGET_MIPS64
11230 mips32_op
= OPC_LD
;
11233 mips32_op
= OPC_SD
;
11237 mips32_op
= OPC_SB
;
11240 mips32_op
= OPC_SH
;
11243 mips32_op
= OPC_SW
;
11246 gen_ld(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11249 gen_st(ctx
, mips32_op
, rt
, rs
, imm
);
11252 generate_exception(ctx
, EXCP_RI
);
11257 static int decode_micromips_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
11261 /* make sure instructions are on a halfword boundary */
11262 if (ctx
->pc
& 0x1) {
11263 env
->CP0_BadVAddr
= ctx
->pc
;
11264 generate_exception(ctx
, EXCP_AdEL
);
11265 ctx
->bstate
= BS_STOP
;
11269 op
= (ctx
->opcode
>> 10) & 0x3f;
11270 /* Enforce properly-sized instructions in a delay slot */
11271 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
11272 int bits
= ctx
->hflags
& MIPS_HFLAG_BMASK_EXT
;
11306 case POOL48A
: /* ??? */
11311 if (bits
& MIPS_HFLAG_BDS16
) {
11312 generate_exception(ctx
, EXCP_RI
);
11313 /* Just stop translation; the user is confused. */
11314 ctx
->bstate
= BS_STOP
;
11339 if (bits
& MIPS_HFLAG_BDS32
) {
11340 generate_exception(ctx
, EXCP_RI
);
11341 /* Just stop translation; the user is confused. */
11342 ctx
->bstate
= BS_STOP
;
11353 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11354 int rs1
= mmreg(uMIPS_RS1(ctx
->opcode
));
11355 int rs2
= mmreg(uMIPS_RS2(ctx
->opcode
));
11358 switch (ctx
->opcode
& 0x1) {
11367 gen_arith(env
, ctx
, opc
, rd
, rs1
, rs2
);
11372 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11373 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
11374 int amount
= (ctx
->opcode
>> 1) & 0x7;
11376 amount
= amount
== 0 ? 8 : amount
;
11378 switch (ctx
->opcode
& 0x1) {
11387 gen_shift_imm(env
, ctx
, opc
, rd
, rs
, amount
);
11391 gen_pool16c_insn(env
, ctx
, is_branch
);
11395 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11396 int rb
= 28; /* GP */
11397 int16_t offset
= SIMM(ctx
->opcode
, 0, 7) << 2;
11399 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11403 if (ctx
->opcode
& 1) {
11404 generate_exception(ctx
, EXCP_RI
);
11407 int enc_dest
= uMIPS_RD(ctx
->opcode
);
11408 int enc_rt
= uMIPS_RS2(ctx
->opcode
);
11409 int enc_rs
= uMIPS_RS1(ctx
->opcode
);
11410 int rd
, rs
, re
, rt
;
11411 static const int rd_enc
[] = { 5, 5, 6, 4, 4, 4, 4, 4 };
11412 static const int re_enc
[] = { 6, 7, 7, 21, 22, 5, 6, 7 };
11413 static const int rs_rt_enc
[] = { 0, 17, 2, 3, 16, 18, 19, 20 };
11415 rd
= rd_enc
[enc_dest
];
11416 re
= re_enc
[enc_dest
];
11417 rs
= rs_rt_enc
[enc_rs
];
11418 rt
= rs_rt_enc
[enc_rt
];
11420 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11421 gen_arith_imm(env
, ctx
, OPC_ADDIU
, re
, rt
, 0);
11426 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11427 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11428 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11429 offset
= (offset
== 0xf ? -1 : offset
);
11431 gen_ld(env
, ctx
, OPC_LBU
, rd
, rb
, offset
);
11436 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11437 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11438 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11440 gen_ld(env
, ctx
, OPC_LHU
, rd
, rb
, offset
);
11445 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11446 int rb
= 29; /* SP */
11447 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11449 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11454 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11455 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11456 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11458 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11463 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11464 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11465 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11467 gen_st(ctx
, OPC_SB
, rd
, rb
, offset
);
11472 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11473 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11474 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11476 gen_st(ctx
, OPC_SH
, rd
, rb
, offset
);
11481 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11482 int rb
= 29; /* SP */
11483 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11485 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11490 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11491 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11492 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11494 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11499 int rd
= uMIPS_RD5(ctx
->opcode
);
11500 int rs
= uMIPS_RS5(ctx
->opcode
);
11502 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11506 gen_andi16(env
, ctx
);
11509 switch (ctx
->opcode
& 0x1) {
11511 gen_addius5(env
, ctx
);
11514 gen_addiusp(env
, ctx
);
11519 switch (ctx
->opcode
& 0x1) {
11521 gen_addiur2(env
, ctx
);
11524 gen_addiur1sp(env
, ctx
);
11529 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0,
11530 SIMM(ctx
->opcode
, 0, 10) << 1);
11535 gen_compute_branch(ctx
, op
== BNEZ16
? OPC_BNE
: OPC_BEQ
, 2,
11536 mmreg(uMIPS_RD(ctx
->opcode
)),
11537 0, SIMM(ctx
->opcode
, 0, 7) << 1);
11542 int reg
= mmreg(uMIPS_RD(ctx
->opcode
));
11543 int imm
= ZIMM(ctx
->opcode
, 0, 7);
11545 imm
= (imm
== 0x7f ? -1 : imm
);
11546 tcg_gen_movi_tl(cpu_gpr
[reg
], imm
);
11556 generate_exception(ctx
, EXCP_RI
);
11559 decode_micromips32_opc (env
, ctx
, op
, is_branch
);
11566 /* SmartMIPS extension to MIPS32 */
11568 #if defined(TARGET_MIPS64)
11570 /* MDMX extension to MIPS64 */
11574 static void decode_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
11577 int rs
, rt
, rd
, sa
;
11578 uint32_t op
, op1
, op2
;
11581 /* make sure instructions are on a word boundary */
11582 if (ctx
->pc
& 0x3) {
11583 env
->CP0_BadVAddr
= ctx
->pc
;
11584 generate_exception(ctx
, EXCP_AdEL
);
11588 /* Handle blikely not taken case */
11589 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
11590 int l1
= gen_new_label();
11592 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
11593 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
11594 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
11595 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
11599 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
11600 tcg_gen_debug_insn_start(ctx
->pc
);
11602 op
= MASK_OP_MAJOR(ctx
->opcode
);
11603 rs
= (ctx
->opcode
>> 21) & 0x1f;
11604 rt
= (ctx
->opcode
>> 16) & 0x1f;
11605 rd
= (ctx
->opcode
>> 11) & 0x1f;
11606 sa
= (ctx
->opcode
>> 6) & 0x1f;
11607 imm
= (int16_t)ctx
->opcode
;
11610 op1
= MASK_SPECIAL(ctx
->opcode
);
11612 case OPC_SLL
: /* Shift with immediate */
11614 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11617 switch ((ctx
->opcode
>> 21) & 0x1f) {
11619 /* rotr is decoded as srl on non-R2 CPUs */
11620 if (env
->insn_flags
& ISA_MIPS32R2
) {
11625 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11628 generate_exception(ctx
, EXCP_RI
);
11632 case OPC_MOVN
: /* Conditional move */
11634 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
|
11635 INSN_LOONGSON2E
| INSN_LOONGSON2F
);
11636 gen_cond_move(env
, op1
, rd
, rs
, rt
);
11638 case OPC_ADD
... OPC_SUBU
:
11639 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11641 case OPC_SLLV
: /* Shifts */
11643 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11646 switch ((ctx
->opcode
>> 6) & 0x1f) {
11648 /* rotrv is decoded as srlv on non-R2 CPUs */
11649 if (env
->insn_flags
& ISA_MIPS32R2
) {
11654 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11657 generate_exception(ctx
, EXCP_RI
);
11661 case OPC_SLT
: /* Set on less than */
11663 gen_slt(env
, op1
, rd
, rs
, rt
);
11665 case OPC_AND
: /* Logic*/
11669 gen_logic(env
, op1
, rd
, rs
, rt
);
11671 case OPC_MULT
... OPC_DIVU
:
11673 check_insn(env
, ctx
, INSN_VR54XX
);
11674 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
11675 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
11677 gen_muldiv(ctx
, op1
, rs
, rt
);
11679 case OPC_JR
... OPC_JALR
:
11680 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
11683 case OPC_TGE
... OPC_TEQ
: /* Traps */
11685 gen_trap(ctx
, op1
, rs
, rt
, -1);
11687 case OPC_MFHI
: /* Move from HI/LO */
11689 gen_HILO(ctx
, op1
, rd
);
11692 case OPC_MTLO
: /* Move to HI/LO */
11693 gen_HILO(ctx
, op1
, rs
);
11695 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
11696 #ifdef MIPS_STRICT_STANDARD
11697 MIPS_INVAL("PMON / selsl");
11698 generate_exception(ctx
, EXCP_RI
);
11700 gen_helper_0i(pmon
, sa
);
11704 generate_exception(ctx
, EXCP_SYSCALL
);
11705 ctx
->bstate
= BS_STOP
;
11708 generate_exception(ctx
, EXCP_BREAK
);
11711 #ifdef MIPS_STRICT_STANDARD
11712 MIPS_INVAL("SPIM");
11713 generate_exception(ctx
, EXCP_RI
);
11715 /* Implemented as RI exception for now. */
11716 MIPS_INVAL("spim (unofficial)");
11717 generate_exception(ctx
, EXCP_RI
);
11721 /* Treat as NOP. */
11725 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
11726 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
11727 check_cp1_enabled(ctx
);
11728 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
11729 (ctx
->opcode
>> 16) & 1);
11731 generate_exception_err(ctx
, EXCP_CpU
, 1);
11735 #if defined(TARGET_MIPS64)
11736 /* MIPS64 specific opcodes */
11741 check_insn(env
, ctx
, ISA_MIPS3
);
11742 check_mips_64(ctx
);
11743 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11746 switch ((ctx
->opcode
>> 21) & 0x1f) {
11748 /* drotr is decoded as dsrl on non-R2 CPUs */
11749 if (env
->insn_flags
& ISA_MIPS32R2
) {
11754 check_insn(env
, ctx
, ISA_MIPS3
);
11755 check_mips_64(ctx
);
11756 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11759 generate_exception(ctx
, EXCP_RI
);
11764 switch ((ctx
->opcode
>> 21) & 0x1f) {
11766 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
11767 if (env
->insn_flags
& ISA_MIPS32R2
) {
11772 check_insn(env
, ctx
, ISA_MIPS3
);
11773 check_mips_64(ctx
);
11774 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11777 generate_exception(ctx
, EXCP_RI
);
11781 case OPC_DADD
... OPC_DSUBU
:
11782 check_insn(env
, ctx
, ISA_MIPS3
);
11783 check_mips_64(ctx
);
11784 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11788 check_insn(env
, ctx
, ISA_MIPS3
);
11789 check_mips_64(ctx
);
11790 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11793 switch ((ctx
->opcode
>> 6) & 0x1f) {
11795 /* drotrv is decoded as dsrlv on non-R2 CPUs */
11796 if (env
->insn_flags
& ISA_MIPS32R2
) {
11801 check_insn(env
, ctx
, ISA_MIPS3
);
11802 check_mips_64(ctx
);
11803 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11806 generate_exception(ctx
, EXCP_RI
);
11810 case OPC_DMULT
... OPC_DDIVU
:
11811 check_insn(env
, ctx
, ISA_MIPS3
);
11812 check_mips_64(ctx
);
11813 gen_muldiv(ctx
, op1
, rs
, rt
);
11816 default: /* Invalid */
11817 MIPS_INVAL("special");
11818 generate_exception(ctx
, EXCP_RI
);
11823 op1
= MASK_SPECIAL2(ctx
->opcode
);
11825 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
11826 case OPC_MSUB
... OPC_MSUBU
:
11827 check_insn(env
, ctx
, ISA_MIPS32
);
11828 gen_muldiv(ctx
, op1
, rs
, rt
);
11831 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11835 check_insn(env
, ctx
, ISA_MIPS32
);
11836 gen_cl(ctx
, op1
, rd
, rs
);
11839 /* XXX: not clear which exception should be raised
11840 * when in debug mode...
11842 check_insn(env
, ctx
, ISA_MIPS32
);
11843 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
11844 generate_exception(ctx
, EXCP_DBp
);
11846 generate_exception(ctx
, EXCP_DBp
);
11848 /* Treat as NOP. */
11851 case OPC_DIVU_G_2F
:
11852 case OPC_MULT_G_2F
:
11853 case OPC_MULTU_G_2F
:
11855 case OPC_MODU_G_2F
:
11856 check_insn(env
, ctx
, INSN_LOONGSON2F
);
11857 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11859 #if defined(TARGET_MIPS64)
11862 check_insn(env
, ctx
, ISA_MIPS64
);
11863 check_mips_64(ctx
);
11864 gen_cl(ctx
, op1
, rd
, rs
);
11866 case OPC_DMULT_G_2F
:
11867 case OPC_DMULTU_G_2F
:
11868 case OPC_DDIV_G_2F
:
11869 case OPC_DDIVU_G_2F
:
11870 case OPC_DMOD_G_2F
:
11871 case OPC_DMODU_G_2F
:
11872 check_insn(env
, ctx
, INSN_LOONGSON2F
);
11873 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11876 default: /* Invalid */
11877 MIPS_INVAL("special2");
11878 generate_exception(ctx
, EXCP_RI
);
11883 op1
= MASK_SPECIAL3(ctx
->opcode
);
11887 check_insn(env
, ctx
, ISA_MIPS32R2
);
11888 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
11891 check_insn(env
, ctx
, ISA_MIPS32R2
);
11892 op2
= MASK_BSHFL(ctx
->opcode
);
11893 gen_bshfl(ctx
, op2
, rt
, rd
);
11896 gen_rdhwr(env
, ctx
, rt
, rd
);
11899 check_insn(env
, ctx
, ASE_MT
);
11901 TCGv t0
= tcg_temp_new();
11902 TCGv t1
= tcg_temp_new();
11904 gen_load_gpr(t0
, rt
);
11905 gen_load_gpr(t1
, rs
);
11906 gen_helper_fork(t0
, t1
);
11912 check_insn(env
, ctx
, ASE_MT
);
11914 TCGv t0
= tcg_temp_new();
11916 save_cpu_state(ctx
, 1);
11917 gen_load_gpr(t0
, rs
);
11918 gen_helper_yield(t0
, t0
);
11919 gen_store_gpr(t0
, rd
);
11923 case OPC_DIV_G_2E
... OPC_DIVU_G_2E
:
11924 case OPC_MULT_G_2E
... OPC_MULTU_G_2E
:
11925 case OPC_MOD_G_2E
... OPC_MODU_G_2E
:
11926 check_insn(env
, ctx
, INSN_LOONGSON2E
);
11927 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11929 #if defined(TARGET_MIPS64)
11930 case OPC_DEXTM
... OPC_DEXT
:
11931 case OPC_DINSM
... OPC_DINS
:
11932 check_insn(env
, ctx
, ISA_MIPS64R2
);
11933 check_mips_64(ctx
);
11934 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
11937 check_insn(env
, ctx
, ISA_MIPS64R2
);
11938 check_mips_64(ctx
);
11939 op2
= MASK_DBSHFL(ctx
->opcode
);
11940 gen_bshfl(ctx
, op2
, rt
, rd
);
11942 case OPC_DDIV_G_2E
... OPC_DDIVU_G_2E
:
11943 case OPC_DMULT_G_2E
... OPC_DMULTU_G_2E
:
11944 case OPC_DMOD_G_2E
... OPC_DMODU_G_2E
:
11945 check_insn(env
, ctx
, INSN_LOONGSON2E
);
11946 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11949 default: /* Invalid */
11950 MIPS_INVAL("special3");
11951 generate_exception(ctx
, EXCP_RI
);
11956 op1
= MASK_REGIMM(ctx
->opcode
);
11958 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
11959 case OPC_BLTZAL
... OPC_BGEZALL
:
11960 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
11963 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
11965 gen_trap(ctx
, op1
, rs
, -1, imm
);
11968 check_insn(env
, ctx
, ISA_MIPS32R2
);
11969 /* Treat as NOP. */
11971 default: /* Invalid */
11972 MIPS_INVAL("regimm");
11973 generate_exception(ctx
, EXCP_RI
);
11978 check_cp0_enabled(ctx
);
11979 op1
= MASK_CP0(ctx
->opcode
);
11985 #if defined(TARGET_MIPS64)
11989 #ifndef CONFIG_USER_ONLY
11990 gen_cp0(env
, ctx
, op1
, rt
, rd
);
11991 #endif /* !CONFIG_USER_ONLY */
11993 case OPC_C0_FIRST
... OPC_C0_LAST
:
11994 #ifndef CONFIG_USER_ONLY
11995 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
11996 #endif /* !CONFIG_USER_ONLY */
11999 #ifndef CONFIG_USER_ONLY
12001 TCGv t0
= tcg_temp_new();
12003 op2
= MASK_MFMC0(ctx
->opcode
);
12006 check_insn(env
, ctx
, ASE_MT
);
12007 gen_helper_dmt(t0
, t0
);
12008 gen_store_gpr(t0
, rt
);
12011 check_insn(env
, ctx
, ASE_MT
);
12012 gen_helper_emt(t0
, t0
);
12013 gen_store_gpr(t0
, rt
);
12016 check_insn(env
, ctx
, ASE_MT
);
12017 gen_helper_dvpe(t0
, t0
);
12018 gen_store_gpr(t0
, rt
);
12021 check_insn(env
, ctx
, ASE_MT
);
12022 gen_helper_evpe(t0
, t0
);
12023 gen_store_gpr(t0
, rt
);
12026 check_insn(env
, ctx
, ISA_MIPS32R2
);
12027 save_cpu_state(ctx
, 1);
12029 gen_store_gpr(t0
, rt
);
12030 /* Stop translation as we may have switched the execution mode */
12031 ctx
->bstate
= BS_STOP
;
12034 check_insn(env
, ctx
, ISA_MIPS32R2
);
12035 save_cpu_state(ctx
, 1);
12037 gen_store_gpr(t0
, rt
);
12038 /* Stop translation as we may have switched the execution mode */
12039 ctx
->bstate
= BS_STOP
;
12041 default: /* Invalid */
12042 MIPS_INVAL("mfmc0");
12043 generate_exception(ctx
, EXCP_RI
);
12048 #endif /* !CONFIG_USER_ONLY */
12051 check_insn(env
, ctx
, ISA_MIPS32R2
);
12052 gen_load_srsgpr(rt
, rd
);
12055 check_insn(env
, ctx
, ISA_MIPS32R2
);
12056 gen_store_srsgpr(rt
, rd
);
12060 generate_exception(ctx
, EXCP_RI
);
12064 case OPC_ADDI
: /* Arithmetic with immediate opcode */
12066 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
12068 case OPC_SLTI
: /* Set on less than with immediate opcode */
12070 gen_slt_imm(env
, op
, rt
, rs
, imm
);
12072 case OPC_ANDI
: /* Arithmetic with immediate opcode */
12076 gen_logic_imm(env
, op
, rt
, rs
, imm
);
12078 case OPC_J
... OPC_JAL
: /* Jump */
12079 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
12080 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
12083 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
12084 case OPC_BEQL
... OPC_BGTZL
:
12085 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
12088 case OPC_LB
... OPC_LWR
: /* Load and stores */
12090 gen_ld(env
, ctx
, op
, rt
, rs
, imm
);
12092 case OPC_SB
... OPC_SW
:
12094 gen_st(ctx
, op
, rt
, rs
, imm
);
12097 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
12100 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
12101 /* Treat as NOP. */
12104 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
12105 /* Treat as NOP. */
12108 /* Floating point (COP1). */
12113 gen_cop1_ldst(env
, ctx
, op
, rt
, rs
, imm
);
12117 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12118 check_cp1_enabled(ctx
);
12119 op1
= MASK_CP1(ctx
->opcode
);
12123 check_insn(env
, ctx
, ISA_MIPS32R2
);
12128 gen_cp1(ctx
, op1
, rt
, rd
);
12130 #if defined(TARGET_MIPS64)
12133 check_insn(env
, ctx
, ISA_MIPS3
);
12134 gen_cp1(ctx
, op1
, rt
, rd
);
12140 check_insn(env
, ctx
, ASE_MIPS3D
);
12143 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
12144 (rt
>> 2) & 0x7, imm
<< 2);
12152 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
12157 generate_exception (ctx
, EXCP_RI
);
12161 generate_exception_err(ctx
, EXCP_CpU
, 1);
12171 /* COP2: Not implemented. */
12172 generate_exception_err(ctx
, EXCP_CpU
, 2);
12176 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12177 check_cp1_enabled(ctx
);
12178 op1
= MASK_CP3(ctx
->opcode
);
12186 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
12189 /* Treat as NOP. */
12204 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
12208 generate_exception (ctx
, EXCP_RI
);
12212 generate_exception_err(ctx
, EXCP_CpU
, 1);
12216 #if defined(TARGET_MIPS64)
12217 /* MIPS64 opcodes */
12219 case OPC_LDL
... OPC_LDR
:
12222 check_insn(env
, ctx
, ISA_MIPS3
);
12223 check_mips_64(ctx
);
12224 gen_ld(env
, ctx
, op
, rt
, rs
, imm
);
12226 case OPC_SDL
... OPC_SDR
:
12228 check_insn(env
, ctx
, ISA_MIPS3
);
12229 check_mips_64(ctx
);
12230 gen_st(ctx
, op
, rt
, rs
, imm
);
12233 check_insn(env
, ctx
, ISA_MIPS3
);
12234 check_mips_64(ctx
);
12235 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
12239 check_insn(env
, ctx
, ISA_MIPS3
);
12240 check_mips_64(ctx
);
12241 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
12245 check_insn(env
, ctx
, ASE_MIPS16
| ASE_MICROMIPS
);
12246 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
12247 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
12251 check_insn(env
, ctx
, ASE_MDMX
);
12252 /* MDMX: Not implemented. */
12253 default: /* Invalid */
12254 MIPS_INVAL("major opcode");
12255 generate_exception(ctx
, EXCP_RI
);
12261 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
12265 target_ulong pc_start
;
12266 uint16_t *gen_opc_end
;
12275 qemu_log("search pc %d\n", search_pc
);
12278 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
12281 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
12283 ctx
.bstate
= BS_NONE
;
12284 /* Restore delay slot state from the tb context. */
12285 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
12286 restore_cpu_state(env
, &ctx
);
12287 #ifdef CONFIG_USER_ONLY
12288 ctx
.mem_idx
= MIPS_HFLAG_UM
;
12290 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
12293 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
12294 if (max_insns
== 0)
12295 max_insns
= CF_COUNT_MASK
;
12296 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
12297 gen_icount_start();
12298 while (ctx
.bstate
== BS_NONE
) {
12299 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
12300 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
12301 if (bp
->pc
== ctx
.pc
) {
12302 save_cpu_state(&ctx
, 1);
12303 ctx
.bstate
= BS_BRANCH
;
12304 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
12305 /* Include the breakpoint location or the tb won't
12306 * be flushed when it must be. */
12308 goto done_generating
;
12314 j
= gen_opc_ptr
- gen_opc_buf
;
12318 gen_opc_instr_start
[lj
++] = 0;
12320 gen_opc_pc
[lj
] = ctx
.pc
;
12321 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
12322 gen_opc_instr_start
[lj
] = 1;
12323 gen_opc_icount
[lj
] = num_insns
;
12325 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
12329 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
12330 ctx
.opcode
= ldl_code(ctx
.pc
);
12332 decode_opc(env
, &ctx
, &is_branch
);
12333 } else if (env
->insn_flags
& ASE_MICROMIPS
) {
12334 ctx
.opcode
= lduw_code(ctx
.pc
);
12335 insn_bytes
= decode_micromips_opc(env
, &ctx
, &is_branch
);
12336 } else if (env
->insn_flags
& ASE_MIPS16
) {
12337 ctx
.opcode
= lduw_code(ctx
.pc
);
12338 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
12340 generate_exception(&ctx
, EXCP_RI
);
12341 ctx
.bstate
= BS_STOP
;
12345 handle_delay_slot(env
, &ctx
, insn_bytes
);
12347 ctx
.pc
+= insn_bytes
;
12351 /* Execute a branch and its delay slot as a single instruction.
12352 This is what GDB expects and is consistent with what the
12353 hardware does (e.g. if a delay slot instruction faults, the
12354 reported PC is the PC of the branch). */
12355 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
12358 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
12361 if (gen_opc_ptr
>= gen_opc_end
)
12364 if (num_insns
>= max_insns
)
12370 if (tb
->cflags
& CF_LAST_IO
)
12372 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
12373 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
12374 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
12376 switch (ctx
.bstate
) {
12378 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12381 save_cpu_state(&ctx
, 0);
12382 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12385 tcg_gen_exit_tb(0);
12393 gen_icount_end(tb
, num_insns
);
12394 *gen_opc_ptr
= INDEX_op_end
;
12396 j
= gen_opc_ptr
- gen_opc_buf
;
12399 gen_opc_instr_start
[lj
++] = 0;
12401 tb
->size
= ctx
.pc
- pc_start
;
12402 tb
->icount
= num_insns
;
12406 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
12407 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
12408 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
12414 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
12416 gen_intermediate_code_internal(env
, tb
, 0);
12419 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
12421 gen_intermediate_code_internal(env
, tb
, 1);
12424 static void fpu_dump_state(CPUState
*env
, FILE *f
,
12425 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12429 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
12431 #define printfpr(fp) \
12434 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12435 " fd:%13g fs:%13g psu: %13g\n", \
12436 (fp)->w[FP_ENDIAN_IDX], (fp)->d, \
12437 (double)(fp)->fd, \
12438 (double)(fp)->fs[FP_ENDIAN_IDX], \
12439 (double)(fp)->fs[!FP_ENDIAN_IDX]); \
12442 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
12443 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
12444 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12445 " fd:%13g fs:%13g psu:%13g\n", \
12446 tmp.w[FP_ENDIAN_IDX], tmp.d, \
12448 (double)tmp.fs[FP_ENDIAN_IDX], \
12449 (double)tmp.fs[!FP_ENDIAN_IDX]); \
12454 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
12455 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
12456 get_float_exception_flags(&env
->active_fpu
.fp_status
));
12457 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
12458 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
12459 printfpr(&env
->active_fpu
.fpr
[i
]);
12465 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12466 /* Debug help: The architecture requires 32bit code to maintain proper
12467 sign-extended values on 64bit machines. */
12469 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
12472 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
12473 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12478 if (!SIGN_EXT_P(env
->active_tc
.PC
))
12479 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
12480 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
12481 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
12482 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
12483 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
12484 if (!SIGN_EXT_P(env
->btarget
))
12485 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
12487 for (i
= 0; i
< 32; i
++) {
12488 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
12489 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
12492 if (!SIGN_EXT_P(env
->CP0_EPC
))
12493 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
12494 if (!SIGN_EXT_P(env
->lladdr
))
12495 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
12499 void cpu_dump_state (CPUState
*env
, FILE *f
,
12500 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12505 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
12506 " LO=0x" TARGET_FMT_lx
" ds %04x "
12507 TARGET_FMT_lx
" " TARGET_FMT_ld
"\n",
12508 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
12509 env
->hflags
, env
->btarget
, env
->bcond
);
12510 for (i
= 0; i
< 32; i
++) {
12512 cpu_fprintf(f
, "GPR%02d:", i
);
12513 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
12515 cpu_fprintf(f
, "\n");
12518 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
12519 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
12520 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
12521 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
12522 if (env
->hflags
& MIPS_HFLAG_FPU
)
12523 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
12524 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12525 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
12529 static void mips_tcg_init(void)
12534 /* Initialize various static tables. */
12538 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
12539 TCGV_UNUSED(cpu_gpr
[0]);
12540 for (i
= 1; i
< 32; i
++)
12541 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
12542 offsetof(CPUState
, active_tc
.gpr
[i
]),
12544 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
12545 offsetof(CPUState
, active_tc
.PC
), "PC");
12546 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
12547 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
12548 offsetof(CPUState
, active_tc
.HI
[i
]),
12550 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
12551 offsetof(CPUState
, active_tc
.LO
[i
]),
12553 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
12554 offsetof(CPUState
, active_tc
.ACX
[i
]),
12557 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
12558 offsetof(CPUState
, active_tc
.DSPControl
),
12560 bcond
= tcg_global_mem_new(TCG_AREG0
,
12561 offsetof(CPUState
, bcond
), "bcond");
12562 btarget
= tcg_global_mem_new(TCG_AREG0
,
12563 offsetof(CPUState
, btarget
), "btarget");
12564 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
12565 offsetof(CPUState
, hflags
), "hflags");
12567 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
12568 offsetof(CPUState
, active_fpu
.fcr0
),
12570 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
12571 offsetof(CPUState
, active_fpu
.fcr31
),
12574 /* register helpers */
12575 #define GEN_HELPER 2
12576 #include "helper.h"
12581 #include "translate_init.c"
12583 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
12586 const mips_def_t
*def
;
12588 def
= cpu_mips_find_by_name(cpu_model
);
12591 env
= qemu_mallocz(sizeof(CPUMIPSState
));
12592 env
->cpu_model
= def
;
12593 env
->cpu_model_str
= cpu_model
;
12595 cpu_exec_init(env
);
12596 #ifndef CONFIG_USER_ONLY
12597 mmu_init(env
, def
);
12599 fpu_init(env
, def
);
12600 mvp_init(env
, def
);
12603 qemu_init_vcpu(env
);
12607 void cpu_reset (CPUMIPSState
*env
)
12609 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
12610 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
12611 log_cpu_state(env
, 0);
12614 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
12617 /* Reset registers to their default values */
12618 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
12619 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
12620 #ifdef TARGET_WORDS_BIGENDIAN
12621 env
->CP0_Config0
|= (1 << CP0C0_BE
);
12623 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
12624 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
12625 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
12626 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
12627 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
12628 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
12629 << env
->cpu_model
->CP0_LLAddr_shift
;
12630 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
12631 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
12632 env
->CCRes
= env
->cpu_model
->CCRes
;
12633 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
12634 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
12635 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
12636 env
->current_tc
= 0;
12637 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
12638 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
12639 #if defined(TARGET_MIPS64)
12640 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12641 env
->SEGMask
|= 3ULL << 62;
12644 env
->PABITS
= env
->cpu_model
->PABITS
;
12645 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
12646 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
12647 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
12648 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
12649 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
12650 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
12651 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
12652 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
12653 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
12654 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
12655 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
12656 env
->insn_flags
= env
->cpu_model
->insn_flags
;
12658 #if defined(CONFIG_USER_ONLY)
12659 env
->hflags
= MIPS_HFLAG_UM
;
12660 /* Enable access to the SYNCI_Step register. */
12661 env
->CP0_HWREna
|= (1 << 1);
12662 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12663 env
->hflags
|= MIPS_HFLAG_FPU
;
12665 #ifdef TARGET_MIPS64
12666 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
12667 env
->hflags
|= MIPS_HFLAG_F64
;
12671 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
12672 /* If the exception was raised from a delay slot,
12673 come back to the jump. */
12674 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
12676 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
12678 env
->active_tc
.PC
= (int32_t)0xBFC00000;
12679 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
12680 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
12681 env
->CP0_Wired
= 0;
12682 env
->CP0_EBase
= 0x80000000 | (env
->cpu_index
& 0x3FF);
12683 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
12684 /* vectored interrupts not implemented, timer on int 7,
12685 no performance counters. */
12686 env
->CP0_IntCtl
= 0xe0000000;
12690 for (i
= 0; i
< 7; i
++) {
12691 env
->CP0_WatchLo
[i
] = 0;
12692 env
->CP0_WatchHi
[i
] = 0x80000000;
12694 env
->CP0_WatchLo
[7] = 0;
12695 env
->CP0_WatchHi
[7] = 0;
12697 /* Count register increments in debug mode, EJTAG version 1 */
12698 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
12699 env
->hflags
= MIPS_HFLAG_CP0
;
12701 #if defined(TARGET_MIPS64)
12702 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12703 env
->hflags
|= MIPS_HFLAG_64
;
12706 env
->exception_index
= EXCP_NONE
;
12709 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
12710 unsigned long searched_pc
, int pc_pos
, void *puc
)
12712 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
12713 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
12714 env
->hflags
|= gen_opc_hflags
[pc_pos
];