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 gen_helper_mtc0_cause(arg
);
5203 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
5217 check_insn(env
, ctx
, ISA_MIPS32R2
);
5218 gen_helper_mtc0_ebase(arg
);
5228 gen_helper_mtc0_config0(arg
);
5230 /* Stop translation as we may have switched the execution mode */
5231 ctx
->bstate
= BS_STOP
;
5234 /* ignored, read only */
5238 gen_helper_mtc0_config2(arg
);
5240 /* Stop translation as we may have switched the execution mode */
5241 ctx
->bstate
= BS_STOP
;
5247 /* 6,7 are implementation dependent */
5249 rn
= "Invalid config selector";
5256 gen_helper_mtc0_lladdr(arg
);
5266 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
5276 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
5286 check_insn(env
, ctx
, ISA_MIPS3
);
5287 gen_helper_mtc0_xcontext(arg
);
5295 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5298 gen_helper_mtc0_framemask(arg
);
5307 rn
= "Diagnostic"; /* implementation dependent */
5312 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5313 /* BS_STOP isn't good enough here, hflags may have changed. */
5314 gen_save_pc(ctx
->pc
+ 4);
5315 ctx
->bstate
= BS_EXCP
;
5319 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5320 /* Stop translation as we may have switched the execution mode */
5321 ctx
->bstate
= BS_STOP
;
5322 rn
= "TraceControl";
5325 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5326 /* Stop translation as we may have switched the execution mode */
5327 ctx
->bstate
= BS_STOP
;
5328 rn
= "TraceControl2";
5331 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5332 /* Stop translation as we may have switched the execution mode */
5333 ctx
->bstate
= BS_STOP
;
5334 rn
= "UserTraceData";
5337 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5338 /* Stop translation as we may have switched the execution mode */
5339 ctx
->bstate
= BS_STOP
;
5350 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5360 gen_helper_mtc0_performance0(arg
);
5361 rn
= "Performance0";
5364 // gen_helper_mtc0_performance1(arg);
5365 rn
= "Performance1";
5368 // gen_helper_mtc0_performance2(arg);
5369 rn
= "Performance2";
5372 // gen_helper_mtc0_performance3(arg);
5373 rn
= "Performance3";
5376 // gen_helper_mtc0_performance4(arg);
5377 rn
= "Performance4";
5380 // gen_helper_mtc0_performance5(arg);
5381 rn
= "Performance5";
5384 // gen_helper_mtc0_performance6(arg);
5385 rn
= "Performance6";
5388 // gen_helper_mtc0_performance7(arg);
5389 rn
= "Performance7";
5415 gen_helper_mtc0_taglo(arg
);
5422 gen_helper_mtc0_datalo(arg
);
5435 gen_helper_mtc0_taghi(arg
);
5442 gen_helper_mtc0_datahi(arg
);
5453 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5464 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5470 /* Stop translation as we may have switched the execution mode */
5471 ctx
->bstate
= BS_STOP
;
5476 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5477 /* For simplicity assume that all writes can cause interrupts. */
5480 ctx
->bstate
= BS_STOP
;
5485 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5486 generate_exception(ctx
, EXCP_RI
);
5488 #endif /* TARGET_MIPS64 */
5490 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5491 int u
, int sel
, int h
)
5493 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5494 TCGv t0
= tcg_temp_local_new();
5496 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5497 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5498 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5499 tcg_gen_movi_tl(t0
, -1);
5500 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5501 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5502 tcg_gen_movi_tl(t0
, -1);
5508 gen_helper_mftc0_tcstatus(t0
);
5511 gen_helper_mftc0_tcbind(t0
);
5514 gen_helper_mftc0_tcrestart(t0
);
5517 gen_helper_mftc0_tchalt(t0
);
5520 gen_helper_mftc0_tccontext(t0
);
5523 gen_helper_mftc0_tcschedule(t0
);
5526 gen_helper_mftc0_tcschefback(t0
);
5529 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5536 gen_helper_mftc0_entryhi(t0
);
5539 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5545 gen_helper_mftc0_status(t0
);
5548 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5554 gen_helper_mftc0_debug(t0
);
5557 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5562 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5564 } else switch (sel
) {
5565 /* GPR registers. */
5567 gen_helper_1i(mftgpr
, t0
, rt
);
5569 /* Auxiliary CPU registers */
5573 gen_helper_1i(mftlo
, t0
, 0);
5576 gen_helper_1i(mfthi
, t0
, 0);
5579 gen_helper_1i(mftacx
, t0
, 0);
5582 gen_helper_1i(mftlo
, t0
, 1);
5585 gen_helper_1i(mfthi
, t0
, 1);
5588 gen_helper_1i(mftacx
, t0
, 1);
5591 gen_helper_1i(mftlo
, t0
, 2);
5594 gen_helper_1i(mfthi
, t0
, 2);
5597 gen_helper_1i(mftacx
, t0
, 2);
5600 gen_helper_1i(mftlo
, t0
, 3);
5603 gen_helper_1i(mfthi
, t0
, 3);
5606 gen_helper_1i(mftacx
, t0
, 3);
5609 gen_helper_mftdsp(t0
);
5615 /* Floating point (COP1). */
5617 /* XXX: For now we support only a single FPU context. */
5619 TCGv_i32 fp0
= tcg_temp_new_i32();
5621 gen_load_fpr32(fp0
, rt
);
5622 tcg_gen_ext_i32_tl(t0
, fp0
);
5623 tcg_temp_free_i32(fp0
);
5625 TCGv_i32 fp0
= tcg_temp_new_i32();
5627 gen_load_fpr32h(fp0
, rt
);
5628 tcg_gen_ext_i32_tl(t0
, fp0
);
5629 tcg_temp_free_i32(fp0
);
5633 /* XXX: For now we support only a single FPU context. */
5634 gen_helper_1i(cfc1
, t0
, rt
);
5636 /* COP2: Not implemented. */
5643 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5644 gen_store_gpr(t0
, rd
);
5650 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5651 generate_exception(ctx
, EXCP_RI
);
5654 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5655 int u
, int sel
, int h
)
5657 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5658 TCGv t0
= tcg_temp_local_new();
5660 gen_load_gpr(t0
, rt
);
5661 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5662 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5663 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5665 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5666 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5673 gen_helper_mttc0_tcstatus(t0
);
5676 gen_helper_mttc0_tcbind(t0
);
5679 gen_helper_mttc0_tcrestart(t0
);
5682 gen_helper_mttc0_tchalt(t0
);
5685 gen_helper_mttc0_tccontext(t0
);
5688 gen_helper_mttc0_tcschedule(t0
);
5691 gen_helper_mttc0_tcschefback(t0
);
5694 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5701 gen_helper_mttc0_entryhi(t0
);
5704 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5710 gen_helper_mttc0_status(t0
);
5713 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5719 gen_helper_mttc0_debug(t0
);
5722 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5727 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5729 } else switch (sel
) {
5730 /* GPR registers. */
5732 gen_helper_1i(mttgpr
, t0
, rd
);
5734 /* Auxiliary CPU registers */
5738 gen_helper_1i(mttlo
, t0
, 0);
5741 gen_helper_1i(mtthi
, t0
, 0);
5744 gen_helper_1i(mttacx
, t0
, 0);
5747 gen_helper_1i(mttlo
, t0
, 1);
5750 gen_helper_1i(mtthi
, t0
, 1);
5753 gen_helper_1i(mttacx
, t0
, 1);
5756 gen_helper_1i(mttlo
, t0
, 2);
5759 gen_helper_1i(mtthi
, t0
, 2);
5762 gen_helper_1i(mttacx
, t0
, 2);
5765 gen_helper_1i(mttlo
, t0
, 3);
5768 gen_helper_1i(mtthi
, t0
, 3);
5771 gen_helper_1i(mttacx
, t0
, 3);
5774 gen_helper_mttdsp(t0
);
5780 /* Floating point (COP1). */
5782 /* XXX: For now we support only a single FPU context. */
5784 TCGv_i32 fp0
= tcg_temp_new_i32();
5786 tcg_gen_trunc_tl_i32(fp0
, t0
);
5787 gen_store_fpr32(fp0
, rd
);
5788 tcg_temp_free_i32(fp0
);
5790 TCGv_i32 fp0
= tcg_temp_new_i32();
5792 tcg_gen_trunc_tl_i32(fp0
, t0
);
5793 gen_store_fpr32h(fp0
, rd
);
5794 tcg_temp_free_i32(fp0
);
5798 /* XXX: For now we support only a single FPU context. */
5799 gen_helper_1i(ctc1
, t0
, rd
);
5801 /* COP2: Not implemented. */
5808 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5814 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5815 generate_exception(ctx
, EXCP_RI
);
5818 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5820 const char *opn
= "ldst";
5828 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5833 TCGv t0
= tcg_temp_new();
5835 gen_load_gpr(t0
, rt
);
5836 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5841 #if defined(TARGET_MIPS64)
5843 check_insn(env
, ctx
, ISA_MIPS3
);
5848 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5852 check_insn(env
, ctx
, ISA_MIPS3
);
5854 TCGv t0
= tcg_temp_new();
5856 gen_load_gpr(t0
, rt
);
5857 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5864 check_insn(env
, ctx
, ASE_MT
);
5869 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5870 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5874 check_insn(env
, ctx
, ASE_MT
);
5875 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5876 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5881 if (!env
->tlb
->helper_tlbwi
)
5887 if (!env
->tlb
->helper_tlbwr
)
5893 if (!env
->tlb
->helper_tlbp
)
5899 if (!env
->tlb
->helper_tlbr
)
5905 check_insn(env
, ctx
, ISA_MIPS2
);
5907 ctx
->bstate
= BS_EXCP
;
5911 check_insn(env
, ctx
, ISA_MIPS32
);
5912 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5914 generate_exception(ctx
, EXCP_RI
);
5917 ctx
->bstate
= BS_EXCP
;
5922 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5923 /* If we get an exception, we want to restart at next instruction */
5925 save_cpu_state(ctx
, 1);
5928 ctx
->bstate
= BS_EXCP
;
5933 generate_exception(ctx
, EXCP_RI
);
5936 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5938 #endif /* !CONFIG_USER_ONLY */
5940 /* CP1 Branches (before delay slot) */
5941 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5942 int32_t cc
, int32_t offset
)
5944 target_ulong btarget
;
5945 const char *opn
= "cp1 cond branch";
5946 TCGv_i32 t0
= tcg_temp_new_i32();
5949 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5951 btarget
= ctx
->pc
+ 4 + offset
;
5955 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5956 tcg_gen_not_i32(t0
, t0
);
5957 tcg_gen_andi_i32(t0
, t0
, 1);
5958 tcg_gen_extu_i32_tl(bcond
, t0
);
5962 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5963 tcg_gen_not_i32(t0
, t0
);
5964 tcg_gen_andi_i32(t0
, t0
, 1);
5965 tcg_gen_extu_i32_tl(bcond
, t0
);
5969 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5970 tcg_gen_andi_i32(t0
, t0
, 1);
5971 tcg_gen_extu_i32_tl(bcond
, t0
);
5975 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5976 tcg_gen_andi_i32(t0
, t0
, 1);
5977 tcg_gen_extu_i32_tl(bcond
, t0
);
5980 ctx
->hflags
|= MIPS_HFLAG_BL
;
5984 TCGv_i32 t1
= tcg_temp_new_i32();
5985 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5986 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5987 tcg_gen_nor_i32(t0
, t0
, t1
);
5988 tcg_temp_free_i32(t1
);
5989 tcg_gen_andi_i32(t0
, t0
, 1);
5990 tcg_gen_extu_i32_tl(bcond
, t0
);
5996 TCGv_i32 t1
= tcg_temp_new_i32();
5997 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5998 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5999 tcg_gen_or_i32(t0
, t0
, t1
);
6000 tcg_temp_free_i32(t1
);
6001 tcg_gen_andi_i32(t0
, t0
, 1);
6002 tcg_gen_extu_i32_tl(bcond
, t0
);
6008 TCGv_i32 t1
= tcg_temp_new_i32();
6009 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6010 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6011 tcg_gen_or_i32(t0
, t0
, t1
);
6012 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
6013 tcg_gen_or_i32(t0
, t0
, t1
);
6014 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
6015 tcg_gen_nor_i32(t0
, t0
, t1
);
6016 tcg_temp_free_i32(t1
);
6017 tcg_gen_andi_i32(t0
, t0
, 1);
6018 tcg_gen_extu_i32_tl(bcond
, t0
);
6024 TCGv_i32 t1
= tcg_temp_new_i32();
6025 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6026 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6027 tcg_gen_or_i32(t0
, t0
, t1
);
6028 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
6029 tcg_gen_or_i32(t0
, t0
, t1
);
6030 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
6031 tcg_gen_or_i32(t0
, t0
, t1
);
6032 tcg_temp_free_i32(t1
);
6033 tcg_gen_andi_i32(t0
, t0
, 1);
6034 tcg_gen_extu_i32_tl(bcond
, t0
);
6038 ctx
->hflags
|= MIPS_HFLAG_BC
;
6042 generate_exception (ctx
, EXCP_RI
);
6045 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
6046 ctx
->hflags
, btarget
);
6047 ctx
->btarget
= btarget
;
6050 tcg_temp_free_i32(t0
);
6053 /* Coprocessor 1 (FPU) */
6055 #define FOP(func, fmt) (((fmt) << 21) | (func))
6058 OPC_ADD_S
= FOP(0, FMT_S
),
6059 OPC_SUB_S
= FOP(1, FMT_S
),
6060 OPC_MUL_S
= FOP(2, FMT_S
),
6061 OPC_DIV_S
= FOP(3, FMT_S
),
6062 OPC_SQRT_S
= FOP(4, FMT_S
),
6063 OPC_ABS_S
= FOP(5, FMT_S
),
6064 OPC_MOV_S
= FOP(6, FMT_S
),
6065 OPC_NEG_S
= FOP(7, FMT_S
),
6066 OPC_ROUND_L_S
= FOP(8, FMT_S
),
6067 OPC_TRUNC_L_S
= FOP(9, FMT_S
),
6068 OPC_CEIL_L_S
= FOP(10, FMT_S
),
6069 OPC_FLOOR_L_S
= FOP(11, FMT_S
),
6070 OPC_ROUND_W_S
= FOP(12, FMT_S
),
6071 OPC_TRUNC_W_S
= FOP(13, FMT_S
),
6072 OPC_CEIL_W_S
= FOP(14, FMT_S
),
6073 OPC_FLOOR_W_S
= FOP(15, FMT_S
),
6074 OPC_MOVCF_S
= FOP(17, FMT_S
),
6075 OPC_MOVZ_S
= FOP(18, FMT_S
),
6076 OPC_MOVN_S
= FOP(19, FMT_S
),
6077 OPC_RECIP_S
= FOP(21, FMT_S
),
6078 OPC_RSQRT_S
= FOP(22, FMT_S
),
6079 OPC_RECIP2_S
= FOP(28, FMT_S
),
6080 OPC_RECIP1_S
= FOP(29, FMT_S
),
6081 OPC_RSQRT1_S
= FOP(30, FMT_S
),
6082 OPC_RSQRT2_S
= FOP(31, FMT_S
),
6083 OPC_CVT_D_S
= FOP(33, FMT_S
),
6084 OPC_CVT_W_S
= FOP(36, FMT_S
),
6085 OPC_CVT_L_S
= FOP(37, FMT_S
),
6086 OPC_CVT_PS_S
= FOP(38, FMT_S
),
6087 OPC_CMP_F_S
= FOP (48, FMT_S
),
6088 OPC_CMP_UN_S
= FOP (49, FMT_S
),
6089 OPC_CMP_EQ_S
= FOP (50, FMT_S
),
6090 OPC_CMP_UEQ_S
= FOP (51, FMT_S
),
6091 OPC_CMP_OLT_S
= FOP (52, FMT_S
),
6092 OPC_CMP_ULT_S
= FOP (53, FMT_S
),
6093 OPC_CMP_OLE_S
= FOP (54, FMT_S
),
6094 OPC_CMP_ULE_S
= FOP (55, FMT_S
),
6095 OPC_CMP_SF_S
= FOP (56, FMT_S
),
6096 OPC_CMP_NGLE_S
= FOP (57, FMT_S
),
6097 OPC_CMP_SEQ_S
= FOP (58, FMT_S
),
6098 OPC_CMP_NGL_S
= FOP (59, FMT_S
),
6099 OPC_CMP_LT_S
= FOP (60, FMT_S
),
6100 OPC_CMP_NGE_S
= FOP (61, FMT_S
),
6101 OPC_CMP_LE_S
= FOP (62, FMT_S
),
6102 OPC_CMP_NGT_S
= FOP (63, FMT_S
),
6104 OPC_ADD_D
= FOP(0, FMT_D
),
6105 OPC_SUB_D
= FOP(1, FMT_D
),
6106 OPC_MUL_D
= FOP(2, FMT_D
),
6107 OPC_DIV_D
= FOP(3, FMT_D
),
6108 OPC_SQRT_D
= FOP(4, FMT_D
),
6109 OPC_ABS_D
= FOP(5, FMT_D
),
6110 OPC_MOV_D
= FOP(6, FMT_D
),
6111 OPC_NEG_D
= FOP(7, FMT_D
),
6112 OPC_ROUND_L_D
= FOP(8, FMT_D
),
6113 OPC_TRUNC_L_D
= FOP(9, FMT_D
),
6114 OPC_CEIL_L_D
= FOP(10, FMT_D
),
6115 OPC_FLOOR_L_D
= FOP(11, FMT_D
),
6116 OPC_ROUND_W_D
= FOP(12, FMT_D
),
6117 OPC_TRUNC_W_D
= FOP(13, FMT_D
),
6118 OPC_CEIL_W_D
= FOP(14, FMT_D
),
6119 OPC_FLOOR_W_D
= FOP(15, FMT_D
),
6120 OPC_MOVCF_D
= FOP(17, FMT_D
),
6121 OPC_MOVZ_D
= FOP(18, FMT_D
),
6122 OPC_MOVN_D
= FOP(19, FMT_D
),
6123 OPC_RECIP_D
= FOP(21, FMT_D
),
6124 OPC_RSQRT_D
= FOP(22, FMT_D
),
6125 OPC_RECIP2_D
= FOP(28, FMT_D
),
6126 OPC_RECIP1_D
= FOP(29, FMT_D
),
6127 OPC_RSQRT1_D
= FOP(30, FMT_D
),
6128 OPC_RSQRT2_D
= FOP(31, FMT_D
),
6129 OPC_CVT_S_D
= FOP(32, FMT_D
),
6130 OPC_CVT_W_D
= FOP(36, FMT_D
),
6131 OPC_CVT_L_D
= FOP(37, FMT_D
),
6132 OPC_CMP_F_D
= FOP (48, FMT_D
),
6133 OPC_CMP_UN_D
= FOP (49, FMT_D
),
6134 OPC_CMP_EQ_D
= FOP (50, FMT_D
),
6135 OPC_CMP_UEQ_D
= FOP (51, FMT_D
),
6136 OPC_CMP_OLT_D
= FOP (52, FMT_D
),
6137 OPC_CMP_ULT_D
= FOP (53, FMT_D
),
6138 OPC_CMP_OLE_D
= FOP (54, FMT_D
),
6139 OPC_CMP_ULE_D
= FOP (55, FMT_D
),
6140 OPC_CMP_SF_D
= FOP (56, FMT_D
),
6141 OPC_CMP_NGLE_D
= FOP (57, FMT_D
),
6142 OPC_CMP_SEQ_D
= FOP (58, FMT_D
),
6143 OPC_CMP_NGL_D
= FOP (59, FMT_D
),
6144 OPC_CMP_LT_D
= FOP (60, FMT_D
),
6145 OPC_CMP_NGE_D
= FOP (61, FMT_D
),
6146 OPC_CMP_LE_D
= FOP (62, FMT_D
),
6147 OPC_CMP_NGT_D
= FOP (63, FMT_D
),
6149 OPC_CVT_S_W
= FOP(32, FMT_W
),
6150 OPC_CVT_D_W
= FOP(33, FMT_W
),
6151 OPC_CVT_S_L
= FOP(32, FMT_L
),
6152 OPC_CVT_D_L
= FOP(33, FMT_L
),
6153 OPC_CVT_PS_PW
= FOP(38, FMT_W
),
6155 OPC_ADD_PS
= FOP(0, FMT_PS
),
6156 OPC_SUB_PS
= FOP(1, FMT_PS
),
6157 OPC_MUL_PS
= FOP(2, FMT_PS
),
6158 OPC_DIV_PS
= FOP(3, FMT_PS
),
6159 OPC_ABS_PS
= FOP(5, FMT_PS
),
6160 OPC_MOV_PS
= FOP(6, FMT_PS
),
6161 OPC_NEG_PS
= FOP(7, FMT_PS
),
6162 OPC_MOVCF_PS
= FOP(17, FMT_PS
),
6163 OPC_MOVZ_PS
= FOP(18, FMT_PS
),
6164 OPC_MOVN_PS
= FOP(19, FMT_PS
),
6165 OPC_ADDR_PS
= FOP(24, FMT_PS
),
6166 OPC_MULR_PS
= FOP(26, FMT_PS
),
6167 OPC_RECIP2_PS
= FOP(28, FMT_PS
),
6168 OPC_RECIP1_PS
= FOP(29, FMT_PS
),
6169 OPC_RSQRT1_PS
= FOP(30, FMT_PS
),
6170 OPC_RSQRT2_PS
= FOP(31, FMT_PS
),
6172 OPC_CVT_S_PU
= FOP(32, FMT_PS
),
6173 OPC_CVT_PW_PS
= FOP(36, FMT_PS
),
6174 OPC_CVT_S_PL
= FOP(40, FMT_PS
),
6175 OPC_PLL_PS
= FOP(44, FMT_PS
),
6176 OPC_PLU_PS
= FOP(45, FMT_PS
),
6177 OPC_PUL_PS
= FOP(46, FMT_PS
),
6178 OPC_PUU_PS
= FOP(47, FMT_PS
),
6179 OPC_CMP_F_PS
= FOP (48, FMT_PS
),
6180 OPC_CMP_UN_PS
= FOP (49, FMT_PS
),
6181 OPC_CMP_EQ_PS
= FOP (50, FMT_PS
),
6182 OPC_CMP_UEQ_PS
= FOP (51, FMT_PS
),
6183 OPC_CMP_OLT_PS
= FOP (52, FMT_PS
),
6184 OPC_CMP_ULT_PS
= FOP (53, FMT_PS
),
6185 OPC_CMP_OLE_PS
= FOP (54, FMT_PS
),
6186 OPC_CMP_ULE_PS
= FOP (55, FMT_PS
),
6187 OPC_CMP_SF_PS
= FOP (56, FMT_PS
),
6188 OPC_CMP_NGLE_PS
= FOP (57, FMT_PS
),
6189 OPC_CMP_SEQ_PS
= FOP (58, FMT_PS
),
6190 OPC_CMP_NGL_PS
= FOP (59, FMT_PS
),
6191 OPC_CMP_LT_PS
= FOP (60, FMT_PS
),
6192 OPC_CMP_NGE_PS
= FOP (61, FMT_PS
),
6193 OPC_CMP_LE_PS
= FOP (62, FMT_PS
),
6194 OPC_CMP_NGT_PS
= FOP (63, FMT_PS
),
6197 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
6199 const char *opn
= "cp1 move";
6200 TCGv t0
= tcg_temp_new();
6205 TCGv_i32 fp0
= tcg_temp_new_i32();
6207 gen_load_fpr32(fp0
, fs
);
6208 tcg_gen_ext_i32_tl(t0
, fp0
);
6209 tcg_temp_free_i32(fp0
);
6211 gen_store_gpr(t0
, rt
);
6215 gen_load_gpr(t0
, rt
);
6217 TCGv_i32 fp0
= tcg_temp_new_i32();
6219 tcg_gen_trunc_tl_i32(fp0
, t0
);
6220 gen_store_fpr32(fp0
, fs
);
6221 tcg_temp_free_i32(fp0
);
6226 gen_helper_1i(cfc1
, t0
, fs
);
6227 gen_store_gpr(t0
, rt
);
6231 gen_load_gpr(t0
, rt
);
6232 gen_helper_1i(ctc1
, t0
, fs
);
6235 #if defined(TARGET_MIPS64)
6237 gen_load_fpr64(ctx
, t0
, fs
);
6238 gen_store_gpr(t0
, rt
);
6242 gen_load_gpr(t0
, rt
);
6243 gen_store_fpr64(ctx
, t0
, fs
);
6249 TCGv_i32 fp0
= tcg_temp_new_i32();
6251 gen_load_fpr32h(fp0
, fs
);
6252 tcg_gen_ext_i32_tl(t0
, fp0
);
6253 tcg_temp_free_i32(fp0
);
6255 gen_store_gpr(t0
, rt
);
6259 gen_load_gpr(t0
, rt
);
6261 TCGv_i32 fp0
= tcg_temp_new_i32();
6263 tcg_gen_trunc_tl_i32(fp0
, t0
);
6264 gen_store_fpr32h(fp0
, fs
);
6265 tcg_temp_free_i32(fp0
);
6271 generate_exception (ctx
, EXCP_RI
);
6274 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
6280 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
6296 l1
= gen_new_label();
6297 t0
= tcg_temp_new_i32();
6298 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6299 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6300 tcg_temp_free_i32(t0
);
6302 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
6304 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
6309 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
6312 TCGv_i32 t0
= tcg_temp_new_i32();
6313 int l1
= gen_new_label();
6320 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6321 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6322 gen_load_fpr32(t0
, fs
);
6323 gen_store_fpr32(t0
, fd
);
6325 tcg_temp_free_i32(t0
);
6328 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
6331 TCGv_i32 t0
= tcg_temp_new_i32();
6333 int l1
= gen_new_label();
6340 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6341 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6342 tcg_temp_free_i32(t0
);
6343 fp0
= tcg_temp_new_i64();
6344 gen_load_fpr64(ctx
, fp0
, fs
);
6345 gen_store_fpr64(ctx
, fp0
, fd
);
6346 tcg_temp_free_i64(fp0
);
6350 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
6353 TCGv_i32 t0
= tcg_temp_new_i32();
6354 int l1
= gen_new_label();
6355 int l2
= gen_new_label();
6362 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6363 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6364 gen_load_fpr32(t0
, fs
);
6365 gen_store_fpr32(t0
, fd
);
6368 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
6369 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
6370 gen_load_fpr32h(t0
, fs
);
6371 gen_store_fpr32h(t0
, fd
);
6372 tcg_temp_free_i32(t0
);
6377 static void gen_farith (DisasContext
*ctx
, enum fopcode op1
,
6378 int ft
, int fs
, int fd
, int cc
)
6380 const char *opn
= "farith";
6381 const char *condnames
[] = {
6399 const char *condnames_abs
[] = {
6417 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6418 uint32_t func
= ctx
->opcode
& 0x3f;
6423 TCGv_i32 fp0
= tcg_temp_new_i32();
6424 TCGv_i32 fp1
= tcg_temp_new_i32();
6426 gen_load_fpr32(fp0
, fs
);
6427 gen_load_fpr32(fp1
, ft
);
6428 gen_helper_float_add_s(fp0
, fp0
, fp1
);
6429 tcg_temp_free_i32(fp1
);
6430 gen_store_fpr32(fp0
, fd
);
6431 tcg_temp_free_i32(fp0
);
6438 TCGv_i32 fp0
= tcg_temp_new_i32();
6439 TCGv_i32 fp1
= tcg_temp_new_i32();
6441 gen_load_fpr32(fp0
, fs
);
6442 gen_load_fpr32(fp1
, ft
);
6443 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6444 tcg_temp_free_i32(fp1
);
6445 gen_store_fpr32(fp0
, fd
);
6446 tcg_temp_free_i32(fp0
);
6453 TCGv_i32 fp0
= tcg_temp_new_i32();
6454 TCGv_i32 fp1
= tcg_temp_new_i32();
6456 gen_load_fpr32(fp0
, fs
);
6457 gen_load_fpr32(fp1
, ft
);
6458 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6459 tcg_temp_free_i32(fp1
);
6460 gen_store_fpr32(fp0
, fd
);
6461 tcg_temp_free_i32(fp0
);
6468 TCGv_i32 fp0
= tcg_temp_new_i32();
6469 TCGv_i32 fp1
= tcg_temp_new_i32();
6471 gen_load_fpr32(fp0
, fs
);
6472 gen_load_fpr32(fp1
, ft
);
6473 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6474 tcg_temp_free_i32(fp1
);
6475 gen_store_fpr32(fp0
, fd
);
6476 tcg_temp_free_i32(fp0
);
6483 TCGv_i32 fp0
= tcg_temp_new_i32();
6485 gen_load_fpr32(fp0
, fs
);
6486 gen_helper_float_sqrt_s(fp0
, fp0
);
6487 gen_store_fpr32(fp0
, fd
);
6488 tcg_temp_free_i32(fp0
);
6494 TCGv_i32 fp0
= tcg_temp_new_i32();
6496 gen_load_fpr32(fp0
, fs
);
6497 gen_helper_float_abs_s(fp0
, fp0
);
6498 gen_store_fpr32(fp0
, fd
);
6499 tcg_temp_free_i32(fp0
);
6505 TCGv_i32 fp0
= tcg_temp_new_i32();
6507 gen_load_fpr32(fp0
, fs
);
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_helper_float_chs_s(fp0
, fp0
);
6519 gen_store_fpr32(fp0
, fd
);
6520 tcg_temp_free_i32(fp0
);
6525 check_cp1_64bitmode(ctx
);
6527 TCGv_i32 fp32
= tcg_temp_new_i32();
6528 TCGv_i64 fp64
= tcg_temp_new_i64();
6530 gen_load_fpr32(fp32
, fs
);
6531 gen_helper_float_roundl_s(fp64
, fp32
);
6532 tcg_temp_free_i32(fp32
);
6533 gen_store_fpr64(ctx
, fp64
, fd
);
6534 tcg_temp_free_i64(fp64
);
6539 check_cp1_64bitmode(ctx
);
6541 TCGv_i32 fp32
= tcg_temp_new_i32();
6542 TCGv_i64 fp64
= tcg_temp_new_i64();
6544 gen_load_fpr32(fp32
, fs
);
6545 gen_helper_float_truncl_s(fp64
, fp32
);
6546 tcg_temp_free_i32(fp32
);
6547 gen_store_fpr64(ctx
, fp64
, fd
);
6548 tcg_temp_free_i64(fp64
);
6553 check_cp1_64bitmode(ctx
);
6555 TCGv_i32 fp32
= tcg_temp_new_i32();
6556 TCGv_i64 fp64
= tcg_temp_new_i64();
6558 gen_load_fpr32(fp32
, fs
);
6559 gen_helper_float_ceill_s(fp64
, fp32
);
6560 tcg_temp_free_i32(fp32
);
6561 gen_store_fpr64(ctx
, fp64
, fd
);
6562 tcg_temp_free_i64(fp64
);
6567 check_cp1_64bitmode(ctx
);
6569 TCGv_i32 fp32
= tcg_temp_new_i32();
6570 TCGv_i64 fp64
= tcg_temp_new_i64();
6572 gen_load_fpr32(fp32
, fs
);
6573 gen_helper_float_floorl_s(fp64
, fp32
);
6574 tcg_temp_free_i32(fp32
);
6575 gen_store_fpr64(ctx
, fp64
, fd
);
6576 tcg_temp_free_i64(fp64
);
6582 TCGv_i32 fp0
= tcg_temp_new_i32();
6584 gen_load_fpr32(fp0
, fs
);
6585 gen_helper_float_roundw_s(fp0
, fp0
);
6586 gen_store_fpr32(fp0
, fd
);
6587 tcg_temp_free_i32(fp0
);
6593 TCGv_i32 fp0
= tcg_temp_new_i32();
6595 gen_load_fpr32(fp0
, fs
);
6596 gen_helper_float_truncw_s(fp0
, fp0
);
6597 gen_store_fpr32(fp0
, fd
);
6598 tcg_temp_free_i32(fp0
);
6604 TCGv_i32 fp0
= tcg_temp_new_i32();
6606 gen_load_fpr32(fp0
, fs
);
6607 gen_helper_float_ceilw_s(fp0
, fp0
);
6608 gen_store_fpr32(fp0
, fd
);
6609 tcg_temp_free_i32(fp0
);
6615 TCGv_i32 fp0
= tcg_temp_new_i32();
6617 gen_load_fpr32(fp0
, fs
);
6618 gen_helper_float_floorw_s(fp0
, fp0
);
6619 gen_store_fpr32(fp0
, fd
);
6620 tcg_temp_free_i32(fp0
);
6625 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6630 int l1
= gen_new_label();
6634 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6636 fp0
= tcg_temp_new_i32();
6637 gen_load_fpr32(fp0
, fs
);
6638 gen_store_fpr32(fp0
, fd
);
6639 tcg_temp_free_i32(fp0
);
6646 int l1
= gen_new_label();
6650 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6651 fp0
= tcg_temp_new_i32();
6652 gen_load_fpr32(fp0
, fs
);
6653 gen_store_fpr32(fp0
, fd
);
6654 tcg_temp_free_i32(fp0
);
6663 TCGv_i32 fp0
= tcg_temp_new_i32();
6665 gen_load_fpr32(fp0
, fs
);
6666 gen_helper_float_recip_s(fp0
, fp0
);
6667 gen_store_fpr32(fp0
, fd
);
6668 tcg_temp_free_i32(fp0
);
6675 TCGv_i32 fp0
= tcg_temp_new_i32();
6677 gen_load_fpr32(fp0
, fs
);
6678 gen_helper_float_rsqrt_s(fp0
, fp0
);
6679 gen_store_fpr32(fp0
, fd
);
6680 tcg_temp_free_i32(fp0
);
6685 check_cp1_64bitmode(ctx
);
6687 TCGv_i32 fp0
= tcg_temp_new_i32();
6688 TCGv_i32 fp1
= tcg_temp_new_i32();
6690 gen_load_fpr32(fp0
, fs
);
6691 gen_load_fpr32(fp1
, fd
);
6692 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6693 tcg_temp_free_i32(fp1
);
6694 gen_store_fpr32(fp0
, fd
);
6695 tcg_temp_free_i32(fp0
);
6700 check_cp1_64bitmode(ctx
);
6702 TCGv_i32 fp0
= tcg_temp_new_i32();
6704 gen_load_fpr32(fp0
, fs
);
6705 gen_helper_float_recip1_s(fp0
, fp0
);
6706 gen_store_fpr32(fp0
, fd
);
6707 tcg_temp_free_i32(fp0
);
6712 check_cp1_64bitmode(ctx
);
6714 TCGv_i32 fp0
= tcg_temp_new_i32();
6716 gen_load_fpr32(fp0
, fs
);
6717 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6718 gen_store_fpr32(fp0
, fd
);
6719 tcg_temp_free_i32(fp0
);
6724 check_cp1_64bitmode(ctx
);
6726 TCGv_i32 fp0
= tcg_temp_new_i32();
6727 TCGv_i32 fp1
= tcg_temp_new_i32();
6729 gen_load_fpr32(fp0
, fs
);
6730 gen_load_fpr32(fp1
, ft
);
6731 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6732 tcg_temp_free_i32(fp1
);
6733 gen_store_fpr32(fp0
, fd
);
6734 tcg_temp_free_i32(fp0
);
6739 check_cp1_registers(ctx
, fd
);
6741 TCGv_i32 fp32
= tcg_temp_new_i32();
6742 TCGv_i64 fp64
= tcg_temp_new_i64();
6744 gen_load_fpr32(fp32
, fs
);
6745 gen_helper_float_cvtd_s(fp64
, fp32
);
6746 tcg_temp_free_i32(fp32
);
6747 gen_store_fpr64(ctx
, fp64
, fd
);
6748 tcg_temp_free_i64(fp64
);
6754 TCGv_i32 fp0
= tcg_temp_new_i32();
6756 gen_load_fpr32(fp0
, fs
);
6757 gen_helper_float_cvtw_s(fp0
, fp0
);
6758 gen_store_fpr32(fp0
, fd
);
6759 tcg_temp_free_i32(fp0
);
6764 check_cp1_64bitmode(ctx
);
6766 TCGv_i32 fp32
= tcg_temp_new_i32();
6767 TCGv_i64 fp64
= tcg_temp_new_i64();
6769 gen_load_fpr32(fp32
, fs
);
6770 gen_helper_float_cvtl_s(fp64
, fp32
);
6771 tcg_temp_free_i32(fp32
);
6772 gen_store_fpr64(ctx
, fp64
, fd
);
6773 tcg_temp_free_i64(fp64
);
6778 check_cp1_64bitmode(ctx
);
6780 TCGv_i64 fp64
= tcg_temp_new_i64();
6781 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6782 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6784 gen_load_fpr32(fp32_0
, fs
);
6785 gen_load_fpr32(fp32_1
, ft
);
6786 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6787 tcg_temp_free_i32(fp32_1
);
6788 tcg_temp_free_i32(fp32_0
);
6789 gen_store_fpr64(ctx
, fp64
, fd
);
6790 tcg_temp_free_i64(fp64
);
6803 case OPC_CMP_NGLE_S
:
6810 if (ctx
->opcode
& (1 << 6)) {
6811 gen_cmpabs_s(ctx
, func
-48, ft
, fs
, cc
);
6812 opn
= condnames_abs
[func
-48];
6814 gen_cmp_s(ctx
, func
-48, ft
, fs
, cc
);
6815 opn
= condnames
[func
-48];
6819 check_cp1_registers(ctx
, fs
| ft
| fd
);
6821 TCGv_i64 fp0
= tcg_temp_new_i64();
6822 TCGv_i64 fp1
= tcg_temp_new_i64();
6824 gen_load_fpr64(ctx
, fp0
, fs
);
6825 gen_load_fpr64(ctx
, fp1
, ft
);
6826 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6827 tcg_temp_free_i64(fp1
);
6828 gen_store_fpr64(ctx
, fp0
, fd
);
6829 tcg_temp_free_i64(fp0
);
6835 check_cp1_registers(ctx
, fs
| ft
| fd
);
6837 TCGv_i64 fp0
= tcg_temp_new_i64();
6838 TCGv_i64 fp1
= tcg_temp_new_i64();
6840 gen_load_fpr64(ctx
, fp0
, fs
);
6841 gen_load_fpr64(ctx
, fp1
, ft
);
6842 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6843 tcg_temp_free_i64(fp1
);
6844 gen_store_fpr64(ctx
, fp0
, fd
);
6845 tcg_temp_free_i64(fp0
);
6851 check_cp1_registers(ctx
, fs
| ft
| fd
);
6853 TCGv_i64 fp0
= tcg_temp_new_i64();
6854 TCGv_i64 fp1
= tcg_temp_new_i64();
6856 gen_load_fpr64(ctx
, fp0
, fs
);
6857 gen_load_fpr64(ctx
, fp1
, ft
);
6858 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6859 tcg_temp_free_i64(fp1
);
6860 gen_store_fpr64(ctx
, fp0
, fd
);
6861 tcg_temp_free_i64(fp0
);
6867 check_cp1_registers(ctx
, fs
| ft
| fd
);
6869 TCGv_i64 fp0
= tcg_temp_new_i64();
6870 TCGv_i64 fp1
= tcg_temp_new_i64();
6872 gen_load_fpr64(ctx
, fp0
, fs
);
6873 gen_load_fpr64(ctx
, fp1
, ft
);
6874 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6875 tcg_temp_free_i64(fp1
);
6876 gen_store_fpr64(ctx
, fp0
, fd
);
6877 tcg_temp_free_i64(fp0
);
6883 check_cp1_registers(ctx
, fs
| fd
);
6885 TCGv_i64 fp0
= tcg_temp_new_i64();
6887 gen_load_fpr64(ctx
, fp0
, fs
);
6888 gen_helper_float_sqrt_d(fp0
, fp0
);
6889 gen_store_fpr64(ctx
, fp0
, fd
);
6890 tcg_temp_free_i64(fp0
);
6895 check_cp1_registers(ctx
, fs
| fd
);
6897 TCGv_i64 fp0
= tcg_temp_new_i64();
6899 gen_load_fpr64(ctx
, fp0
, fs
);
6900 gen_helper_float_abs_d(fp0
, fp0
);
6901 gen_store_fpr64(ctx
, fp0
, fd
);
6902 tcg_temp_free_i64(fp0
);
6907 check_cp1_registers(ctx
, fs
| fd
);
6909 TCGv_i64 fp0
= tcg_temp_new_i64();
6911 gen_load_fpr64(ctx
, fp0
, fs
);
6912 gen_store_fpr64(ctx
, fp0
, fd
);
6913 tcg_temp_free_i64(fp0
);
6918 check_cp1_registers(ctx
, fs
| fd
);
6920 TCGv_i64 fp0
= tcg_temp_new_i64();
6922 gen_load_fpr64(ctx
, fp0
, fs
);
6923 gen_helper_float_chs_d(fp0
, fp0
);
6924 gen_store_fpr64(ctx
, fp0
, fd
);
6925 tcg_temp_free_i64(fp0
);
6930 check_cp1_64bitmode(ctx
);
6932 TCGv_i64 fp0
= tcg_temp_new_i64();
6934 gen_load_fpr64(ctx
, fp0
, fs
);
6935 gen_helper_float_roundl_d(fp0
, fp0
);
6936 gen_store_fpr64(ctx
, fp0
, fd
);
6937 tcg_temp_free_i64(fp0
);
6942 check_cp1_64bitmode(ctx
);
6944 TCGv_i64 fp0
= tcg_temp_new_i64();
6946 gen_load_fpr64(ctx
, fp0
, fs
);
6947 gen_helper_float_truncl_d(fp0
, fp0
);
6948 gen_store_fpr64(ctx
, fp0
, fd
);
6949 tcg_temp_free_i64(fp0
);
6954 check_cp1_64bitmode(ctx
);
6956 TCGv_i64 fp0
= tcg_temp_new_i64();
6958 gen_load_fpr64(ctx
, fp0
, fs
);
6959 gen_helper_float_ceill_d(fp0
, fp0
);
6960 gen_store_fpr64(ctx
, fp0
, fd
);
6961 tcg_temp_free_i64(fp0
);
6966 check_cp1_64bitmode(ctx
);
6968 TCGv_i64 fp0
= tcg_temp_new_i64();
6970 gen_load_fpr64(ctx
, fp0
, fs
);
6971 gen_helper_float_floorl_d(fp0
, fp0
);
6972 gen_store_fpr64(ctx
, fp0
, fd
);
6973 tcg_temp_free_i64(fp0
);
6978 check_cp1_registers(ctx
, fs
);
6980 TCGv_i32 fp32
= tcg_temp_new_i32();
6981 TCGv_i64 fp64
= tcg_temp_new_i64();
6983 gen_load_fpr64(ctx
, fp64
, fs
);
6984 gen_helper_float_roundw_d(fp32
, fp64
);
6985 tcg_temp_free_i64(fp64
);
6986 gen_store_fpr32(fp32
, fd
);
6987 tcg_temp_free_i32(fp32
);
6992 check_cp1_registers(ctx
, fs
);
6994 TCGv_i32 fp32
= tcg_temp_new_i32();
6995 TCGv_i64 fp64
= tcg_temp_new_i64();
6997 gen_load_fpr64(ctx
, fp64
, fs
);
6998 gen_helper_float_truncw_d(fp32
, fp64
);
6999 tcg_temp_free_i64(fp64
);
7000 gen_store_fpr32(fp32
, fd
);
7001 tcg_temp_free_i32(fp32
);
7006 check_cp1_registers(ctx
, fs
);
7008 TCGv_i32 fp32
= tcg_temp_new_i32();
7009 TCGv_i64 fp64
= tcg_temp_new_i64();
7011 gen_load_fpr64(ctx
, fp64
, fs
);
7012 gen_helper_float_ceilw_d(fp32
, fp64
);
7013 tcg_temp_free_i64(fp64
);
7014 gen_store_fpr32(fp32
, fd
);
7015 tcg_temp_free_i32(fp32
);
7020 check_cp1_registers(ctx
, fs
);
7022 TCGv_i32 fp32
= tcg_temp_new_i32();
7023 TCGv_i64 fp64
= tcg_temp_new_i64();
7025 gen_load_fpr64(ctx
, fp64
, fs
);
7026 gen_helper_float_floorw_d(fp32
, fp64
);
7027 tcg_temp_free_i64(fp64
);
7028 gen_store_fpr32(fp32
, fd
);
7029 tcg_temp_free_i32(fp32
);
7034 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7039 int l1
= gen_new_label();
7043 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7045 fp0
= tcg_temp_new_i64();
7046 gen_load_fpr64(ctx
, fp0
, fs
);
7047 gen_store_fpr64(ctx
, fp0
, fd
);
7048 tcg_temp_free_i64(fp0
);
7055 int l1
= gen_new_label();
7059 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7060 fp0
= tcg_temp_new_i64();
7061 gen_load_fpr64(ctx
, fp0
, fs
);
7062 gen_store_fpr64(ctx
, fp0
, fd
);
7063 tcg_temp_free_i64(fp0
);
7070 check_cp1_64bitmode(ctx
);
7072 TCGv_i64 fp0
= tcg_temp_new_i64();
7074 gen_load_fpr64(ctx
, fp0
, fs
);
7075 gen_helper_float_recip_d(fp0
, fp0
);
7076 gen_store_fpr64(ctx
, fp0
, fd
);
7077 tcg_temp_free_i64(fp0
);
7082 check_cp1_64bitmode(ctx
);
7084 TCGv_i64 fp0
= tcg_temp_new_i64();
7086 gen_load_fpr64(ctx
, fp0
, fs
);
7087 gen_helper_float_rsqrt_d(fp0
, fp0
);
7088 gen_store_fpr64(ctx
, fp0
, fd
);
7089 tcg_temp_free_i64(fp0
);
7094 check_cp1_64bitmode(ctx
);
7096 TCGv_i64 fp0
= tcg_temp_new_i64();
7097 TCGv_i64 fp1
= tcg_temp_new_i64();
7099 gen_load_fpr64(ctx
, fp0
, fs
);
7100 gen_load_fpr64(ctx
, fp1
, ft
);
7101 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
7102 tcg_temp_free_i64(fp1
);
7103 gen_store_fpr64(ctx
, fp0
, fd
);
7104 tcg_temp_free_i64(fp0
);
7109 check_cp1_64bitmode(ctx
);
7111 TCGv_i64 fp0
= tcg_temp_new_i64();
7113 gen_load_fpr64(ctx
, fp0
, fs
);
7114 gen_helper_float_recip1_d(fp0
, fp0
);
7115 gen_store_fpr64(ctx
, fp0
, fd
);
7116 tcg_temp_free_i64(fp0
);
7121 check_cp1_64bitmode(ctx
);
7123 TCGv_i64 fp0
= tcg_temp_new_i64();
7125 gen_load_fpr64(ctx
, fp0
, fs
);
7126 gen_helper_float_rsqrt1_d(fp0
, fp0
);
7127 gen_store_fpr64(ctx
, fp0
, fd
);
7128 tcg_temp_free_i64(fp0
);
7133 check_cp1_64bitmode(ctx
);
7135 TCGv_i64 fp0
= tcg_temp_new_i64();
7136 TCGv_i64 fp1
= tcg_temp_new_i64();
7138 gen_load_fpr64(ctx
, fp0
, fs
);
7139 gen_load_fpr64(ctx
, fp1
, ft
);
7140 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
7141 tcg_temp_free_i64(fp1
);
7142 gen_store_fpr64(ctx
, fp0
, fd
);
7143 tcg_temp_free_i64(fp0
);
7156 case OPC_CMP_NGLE_D
:
7163 if (ctx
->opcode
& (1 << 6)) {
7164 gen_cmpabs_d(ctx
, func
-48, ft
, fs
, cc
);
7165 opn
= condnames_abs
[func
-48];
7167 gen_cmp_d(ctx
, func
-48, ft
, fs
, cc
);
7168 opn
= condnames
[func
-48];
7172 check_cp1_registers(ctx
, fs
);
7174 TCGv_i32 fp32
= tcg_temp_new_i32();
7175 TCGv_i64 fp64
= tcg_temp_new_i64();
7177 gen_load_fpr64(ctx
, fp64
, fs
);
7178 gen_helper_float_cvts_d(fp32
, fp64
);
7179 tcg_temp_free_i64(fp64
);
7180 gen_store_fpr32(fp32
, fd
);
7181 tcg_temp_free_i32(fp32
);
7186 check_cp1_registers(ctx
, fs
);
7188 TCGv_i32 fp32
= tcg_temp_new_i32();
7189 TCGv_i64 fp64
= tcg_temp_new_i64();
7191 gen_load_fpr64(ctx
, fp64
, fs
);
7192 gen_helper_float_cvtw_d(fp32
, fp64
);
7193 tcg_temp_free_i64(fp64
);
7194 gen_store_fpr32(fp32
, fd
);
7195 tcg_temp_free_i32(fp32
);
7200 check_cp1_64bitmode(ctx
);
7202 TCGv_i64 fp0
= tcg_temp_new_i64();
7204 gen_load_fpr64(ctx
, fp0
, fs
);
7205 gen_helper_float_cvtl_d(fp0
, fp0
);
7206 gen_store_fpr64(ctx
, fp0
, fd
);
7207 tcg_temp_free_i64(fp0
);
7213 TCGv_i32 fp0
= tcg_temp_new_i32();
7215 gen_load_fpr32(fp0
, fs
);
7216 gen_helper_float_cvts_w(fp0
, fp0
);
7217 gen_store_fpr32(fp0
, fd
);
7218 tcg_temp_free_i32(fp0
);
7223 check_cp1_registers(ctx
, fd
);
7225 TCGv_i32 fp32
= tcg_temp_new_i32();
7226 TCGv_i64 fp64
= tcg_temp_new_i64();
7228 gen_load_fpr32(fp32
, fs
);
7229 gen_helper_float_cvtd_w(fp64
, fp32
);
7230 tcg_temp_free_i32(fp32
);
7231 gen_store_fpr64(ctx
, fp64
, fd
);
7232 tcg_temp_free_i64(fp64
);
7237 check_cp1_64bitmode(ctx
);
7239 TCGv_i32 fp32
= tcg_temp_new_i32();
7240 TCGv_i64 fp64
= tcg_temp_new_i64();
7242 gen_load_fpr64(ctx
, fp64
, fs
);
7243 gen_helper_float_cvts_l(fp32
, fp64
);
7244 tcg_temp_free_i64(fp64
);
7245 gen_store_fpr32(fp32
, fd
);
7246 tcg_temp_free_i32(fp32
);
7251 check_cp1_64bitmode(ctx
);
7253 TCGv_i64 fp0
= tcg_temp_new_i64();
7255 gen_load_fpr64(ctx
, fp0
, fs
);
7256 gen_helper_float_cvtd_l(fp0
, fp0
);
7257 gen_store_fpr64(ctx
, fp0
, fd
);
7258 tcg_temp_free_i64(fp0
);
7263 check_cp1_64bitmode(ctx
);
7265 TCGv_i64 fp0
= tcg_temp_new_i64();
7267 gen_load_fpr64(ctx
, fp0
, fs
);
7268 gen_helper_float_cvtps_pw(fp0
, fp0
);
7269 gen_store_fpr64(ctx
, fp0
, fd
);
7270 tcg_temp_free_i64(fp0
);
7275 check_cp1_64bitmode(ctx
);
7277 TCGv_i64 fp0
= tcg_temp_new_i64();
7278 TCGv_i64 fp1
= tcg_temp_new_i64();
7280 gen_load_fpr64(ctx
, fp0
, fs
);
7281 gen_load_fpr64(ctx
, fp1
, ft
);
7282 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
7283 tcg_temp_free_i64(fp1
);
7284 gen_store_fpr64(ctx
, fp0
, fd
);
7285 tcg_temp_free_i64(fp0
);
7290 check_cp1_64bitmode(ctx
);
7292 TCGv_i64 fp0
= tcg_temp_new_i64();
7293 TCGv_i64 fp1
= tcg_temp_new_i64();
7295 gen_load_fpr64(ctx
, fp0
, fs
);
7296 gen_load_fpr64(ctx
, fp1
, ft
);
7297 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
7298 tcg_temp_free_i64(fp1
);
7299 gen_store_fpr64(ctx
, fp0
, fd
);
7300 tcg_temp_free_i64(fp0
);
7305 check_cp1_64bitmode(ctx
);
7307 TCGv_i64 fp0
= tcg_temp_new_i64();
7308 TCGv_i64 fp1
= tcg_temp_new_i64();
7310 gen_load_fpr64(ctx
, fp0
, fs
);
7311 gen_load_fpr64(ctx
, fp1
, ft
);
7312 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
7313 tcg_temp_free_i64(fp1
);
7314 gen_store_fpr64(ctx
, fp0
, fd
);
7315 tcg_temp_free_i64(fp0
);
7320 check_cp1_64bitmode(ctx
);
7322 TCGv_i64 fp0
= tcg_temp_new_i64();
7324 gen_load_fpr64(ctx
, fp0
, fs
);
7325 gen_helper_float_abs_ps(fp0
, fp0
);
7326 gen_store_fpr64(ctx
, fp0
, fd
);
7327 tcg_temp_free_i64(fp0
);
7332 check_cp1_64bitmode(ctx
);
7334 TCGv_i64 fp0
= tcg_temp_new_i64();
7336 gen_load_fpr64(ctx
, fp0
, fs
);
7337 gen_store_fpr64(ctx
, fp0
, fd
);
7338 tcg_temp_free_i64(fp0
);
7343 check_cp1_64bitmode(ctx
);
7345 TCGv_i64 fp0
= tcg_temp_new_i64();
7347 gen_load_fpr64(ctx
, fp0
, fs
);
7348 gen_helper_float_chs_ps(fp0
, fp0
);
7349 gen_store_fpr64(ctx
, fp0
, fd
);
7350 tcg_temp_free_i64(fp0
);
7355 check_cp1_64bitmode(ctx
);
7356 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7360 check_cp1_64bitmode(ctx
);
7362 int l1
= gen_new_label();
7366 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7367 fp0
= tcg_temp_new_i64();
7368 gen_load_fpr64(ctx
, fp0
, fs
);
7369 gen_store_fpr64(ctx
, fp0
, fd
);
7370 tcg_temp_free_i64(fp0
);
7376 check_cp1_64bitmode(ctx
);
7378 int l1
= gen_new_label();
7382 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7383 fp0
= tcg_temp_new_i64();
7384 gen_load_fpr64(ctx
, fp0
, fs
);
7385 gen_store_fpr64(ctx
, fp0
, fd
);
7386 tcg_temp_free_i64(fp0
);
7393 check_cp1_64bitmode(ctx
);
7395 TCGv_i64 fp0
= tcg_temp_new_i64();
7396 TCGv_i64 fp1
= tcg_temp_new_i64();
7398 gen_load_fpr64(ctx
, fp0
, ft
);
7399 gen_load_fpr64(ctx
, fp1
, fs
);
7400 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
7401 tcg_temp_free_i64(fp1
);
7402 gen_store_fpr64(ctx
, fp0
, fd
);
7403 tcg_temp_free_i64(fp0
);
7408 check_cp1_64bitmode(ctx
);
7410 TCGv_i64 fp0
= tcg_temp_new_i64();
7411 TCGv_i64 fp1
= tcg_temp_new_i64();
7413 gen_load_fpr64(ctx
, fp0
, ft
);
7414 gen_load_fpr64(ctx
, fp1
, fs
);
7415 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7416 tcg_temp_free_i64(fp1
);
7417 gen_store_fpr64(ctx
, fp0
, fd
);
7418 tcg_temp_free_i64(fp0
);
7423 check_cp1_64bitmode(ctx
);
7425 TCGv_i64 fp0
= tcg_temp_new_i64();
7426 TCGv_i64 fp1
= tcg_temp_new_i64();
7428 gen_load_fpr64(ctx
, fp0
, fs
);
7429 gen_load_fpr64(ctx
, fp1
, fd
);
7430 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7431 tcg_temp_free_i64(fp1
);
7432 gen_store_fpr64(ctx
, fp0
, fd
);
7433 tcg_temp_free_i64(fp0
);
7438 check_cp1_64bitmode(ctx
);
7440 TCGv_i64 fp0
= tcg_temp_new_i64();
7442 gen_load_fpr64(ctx
, fp0
, fs
);
7443 gen_helper_float_recip1_ps(fp0
, fp0
);
7444 gen_store_fpr64(ctx
, fp0
, fd
);
7445 tcg_temp_free_i64(fp0
);
7450 check_cp1_64bitmode(ctx
);
7452 TCGv_i64 fp0
= tcg_temp_new_i64();
7454 gen_load_fpr64(ctx
, fp0
, fs
);
7455 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7456 gen_store_fpr64(ctx
, fp0
, fd
);
7457 tcg_temp_free_i64(fp0
);
7462 check_cp1_64bitmode(ctx
);
7464 TCGv_i64 fp0
= tcg_temp_new_i64();
7465 TCGv_i64 fp1
= tcg_temp_new_i64();
7467 gen_load_fpr64(ctx
, fp0
, fs
);
7468 gen_load_fpr64(ctx
, fp1
, ft
);
7469 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7470 tcg_temp_free_i64(fp1
);
7471 gen_store_fpr64(ctx
, fp0
, fd
);
7472 tcg_temp_free_i64(fp0
);
7477 check_cp1_64bitmode(ctx
);
7479 TCGv_i32 fp0
= tcg_temp_new_i32();
7481 gen_load_fpr32h(fp0
, fs
);
7482 gen_helper_float_cvts_pu(fp0
, fp0
);
7483 gen_store_fpr32(fp0
, fd
);
7484 tcg_temp_free_i32(fp0
);
7489 check_cp1_64bitmode(ctx
);
7491 TCGv_i64 fp0
= tcg_temp_new_i64();
7493 gen_load_fpr64(ctx
, fp0
, fs
);
7494 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7495 gen_store_fpr64(ctx
, fp0
, fd
);
7496 tcg_temp_free_i64(fp0
);
7501 check_cp1_64bitmode(ctx
);
7503 TCGv_i32 fp0
= tcg_temp_new_i32();
7505 gen_load_fpr32(fp0
, fs
);
7506 gen_helper_float_cvts_pl(fp0
, fp0
);
7507 gen_store_fpr32(fp0
, fd
);
7508 tcg_temp_free_i32(fp0
);
7513 check_cp1_64bitmode(ctx
);
7515 TCGv_i32 fp0
= tcg_temp_new_i32();
7516 TCGv_i32 fp1
= tcg_temp_new_i32();
7518 gen_load_fpr32(fp0
, fs
);
7519 gen_load_fpr32(fp1
, ft
);
7520 gen_store_fpr32h(fp0
, fd
);
7521 gen_store_fpr32(fp1
, fd
);
7522 tcg_temp_free_i32(fp0
);
7523 tcg_temp_free_i32(fp1
);
7528 check_cp1_64bitmode(ctx
);
7530 TCGv_i32 fp0
= tcg_temp_new_i32();
7531 TCGv_i32 fp1
= tcg_temp_new_i32();
7533 gen_load_fpr32(fp0
, fs
);
7534 gen_load_fpr32h(fp1
, ft
);
7535 gen_store_fpr32(fp1
, fd
);
7536 gen_store_fpr32h(fp0
, fd
);
7537 tcg_temp_free_i32(fp0
);
7538 tcg_temp_free_i32(fp1
);
7543 check_cp1_64bitmode(ctx
);
7545 TCGv_i32 fp0
= tcg_temp_new_i32();
7546 TCGv_i32 fp1
= tcg_temp_new_i32();
7548 gen_load_fpr32h(fp0
, fs
);
7549 gen_load_fpr32(fp1
, ft
);
7550 gen_store_fpr32(fp1
, fd
);
7551 gen_store_fpr32h(fp0
, fd
);
7552 tcg_temp_free_i32(fp0
);
7553 tcg_temp_free_i32(fp1
);
7558 check_cp1_64bitmode(ctx
);
7560 TCGv_i32 fp0
= tcg_temp_new_i32();
7561 TCGv_i32 fp1
= tcg_temp_new_i32();
7563 gen_load_fpr32h(fp0
, fs
);
7564 gen_load_fpr32h(fp1
, ft
);
7565 gen_store_fpr32(fp1
, fd
);
7566 gen_store_fpr32h(fp0
, fd
);
7567 tcg_temp_free_i32(fp0
);
7568 tcg_temp_free_i32(fp1
);
7575 case OPC_CMP_UEQ_PS
:
7576 case OPC_CMP_OLT_PS
:
7577 case OPC_CMP_ULT_PS
:
7578 case OPC_CMP_OLE_PS
:
7579 case OPC_CMP_ULE_PS
:
7581 case OPC_CMP_NGLE_PS
:
7582 case OPC_CMP_SEQ_PS
:
7583 case OPC_CMP_NGL_PS
:
7585 case OPC_CMP_NGE_PS
:
7587 case OPC_CMP_NGT_PS
:
7588 if (ctx
->opcode
& (1 << 6)) {
7589 gen_cmpabs_ps(ctx
, func
-48, ft
, fs
, cc
);
7590 opn
= condnames_abs
[func
-48];
7592 gen_cmp_ps(ctx
, func
-48, ft
, fs
, cc
);
7593 opn
= condnames
[func
-48];
7598 generate_exception (ctx
, EXCP_RI
);
7603 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7606 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7609 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7614 /* Coprocessor 3 (FPU) */
7615 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7616 int fd
, int fs
, int base
, int index
)
7618 const char *opn
= "extended float load/store";
7620 TCGv t0
= tcg_temp_new();
7623 gen_load_gpr(t0
, index
);
7624 } else if (index
== 0) {
7625 gen_load_gpr(t0
, base
);
7627 gen_load_gpr(t0
, index
);
7628 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7630 /* Don't do NOP if destination is zero: we must perform the actual
7632 save_cpu_state(ctx
, 0);
7637 TCGv_i32 fp0
= tcg_temp_new_i32();
7639 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7640 tcg_gen_trunc_tl_i32(fp0
, t0
);
7641 gen_store_fpr32(fp0
, fd
);
7642 tcg_temp_free_i32(fp0
);
7648 check_cp1_registers(ctx
, fd
);
7650 TCGv_i64 fp0
= tcg_temp_new_i64();
7652 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7653 gen_store_fpr64(ctx
, fp0
, fd
);
7654 tcg_temp_free_i64(fp0
);
7659 check_cp1_64bitmode(ctx
);
7660 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7662 TCGv_i64 fp0
= tcg_temp_new_i64();
7664 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7665 gen_store_fpr64(ctx
, fp0
, fd
);
7666 tcg_temp_free_i64(fp0
);
7673 TCGv_i32 fp0
= tcg_temp_new_i32();
7674 TCGv t1
= tcg_temp_new();
7676 gen_load_fpr32(fp0
, fs
);
7677 tcg_gen_extu_i32_tl(t1
, fp0
);
7678 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7679 tcg_temp_free_i32(fp0
);
7687 check_cp1_registers(ctx
, fs
);
7689 TCGv_i64 fp0
= tcg_temp_new_i64();
7691 gen_load_fpr64(ctx
, fp0
, fs
);
7692 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7693 tcg_temp_free_i64(fp0
);
7699 check_cp1_64bitmode(ctx
);
7700 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7702 TCGv_i64 fp0
= tcg_temp_new_i64();
7704 gen_load_fpr64(ctx
, fp0
, fs
);
7705 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7706 tcg_temp_free_i64(fp0
);
7713 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7714 regnames
[index
], regnames
[base
]);
7717 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7718 int fd
, int fr
, int fs
, int ft
)
7720 const char *opn
= "flt3_arith";
7724 check_cp1_64bitmode(ctx
);
7726 TCGv t0
= tcg_temp_local_new();
7727 TCGv_i32 fp
= tcg_temp_new_i32();
7728 TCGv_i32 fph
= tcg_temp_new_i32();
7729 int l1
= gen_new_label();
7730 int l2
= gen_new_label();
7732 gen_load_gpr(t0
, fr
);
7733 tcg_gen_andi_tl(t0
, t0
, 0x7);
7735 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7736 gen_load_fpr32(fp
, fs
);
7737 gen_load_fpr32h(fph
, fs
);
7738 gen_store_fpr32(fp
, fd
);
7739 gen_store_fpr32h(fph
, fd
);
7742 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7744 #ifdef TARGET_WORDS_BIGENDIAN
7745 gen_load_fpr32(fp
, fs
);
7746 gen_load_fpr32h(fph
, ft
);
7747 gen_store_fpr32h(fp
, fd
);
7748 gen_store_fpr32(fph
, fd
);
7750 gen_load_fpr32h(fph
, fs
);
7751 gen_load_fpr32(fp
, ft
);
7752 gen_store_fpr32(fph
, fd
);
7753 gen_store_fpr32h(fp
, fd
);
7756 tcg_temp_free_i32(fp
);
7757 tcg_temp_free_i32(fph
);
7764 TCGv_i32 fp0
= tcg_temp_new_i32();
7765 TCGv_i32 fp1
= tcg_temp_new_i32();
7766 TCGv_i32 fp2
= tcg_temp_new_i32();
7768 gen_load_fpr32(fp0
, fs
);
7769 gen_load_fpr32(fp1
, ft
);
7770 gen_load_fpr32(fp2
, fr
);
7771 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7772 tcg_temp_free_i32(fp0
);
7773 tcg_temp_free_i32(fp1
);
7774 gen_store_fpr32(fp2
, fd
);
7775 tcg_temp_free_i32(fp2
);
7781 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7783 TCGv_i64 fp0
= tcg_temp_new_i64();
7784 TCGv_i64 fp1
= tcg_temp_new_i64();
7785 TCGv_i64 fp2
= tcg_temp_new_i64();
7787 gen_load_fpr64(ctx
, fp0
, fs
);
7788 gen_load_fpr64(ctx
, fp1
, ft
);
7789 gen_load_fpr64(ctx
, fp2
, fr
);
7790 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7791 tcg_temp_free_i64(fp0
);
7792 tcg_temp_free_i64(fp1
);
7793 gen_store_fpr64(ctx
, fp2
, fd
);
7794 tcg_temp_free_i64(fp2
);
7799 check_cp1_64bitmode(ctx
);
7801 TCGv_i64 fp0
= tcg_temp_new_i64();
7802 TCGv_i64 fp1
= tcg_temp_new_i64();
7803 TCGv_i64 fp2
= tcg_temp_new_i64();
7805 gen_load_fpr64(ctx
, fp0
, fs
);
7806 gen_load_fpr64(ctx
, fp1
, ft
);
7807 gen_load_fpr64(ctx
, fp2
, fr
);
7808 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7809 tcg_temp_free_i64(fp0
);
7810 tcg_temp_free_i64(fp1
);
7811 gen_store_fpr64(ctx
, fp2
, fd
);
7812 tcg_temp_free_i64(fp2
);
7819 TCGv_i32 fp0
= tcg_temp_new_i32();
7820 TCGv_i32 fp1
= tcg_temp_new_i32();
7821 TCGv_i32 fp2
= tcg_temp_new_i32();
7823 gen_load_fpr32(fp0
, fs
);
7824 gen_load_fpr32(fp1
, ft
);
7825 gen_load_fpr32(fp2
, fr
);
7826 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7827 tcg_temp_free_i32(fp0
);
7828 tcg_temp_free_i32(fp1
);
7829 gen_store_fpr32(fp2
, fd
);
7830 tcg_temp_free_i32(fp2
);
7836 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7838 TCGv_i64 fp0
= tcg_temp_new_i64();
7839 TCGv_i64 fp1
= tcg_temp_new_i64();
7840 TCGv_i64 fp2
= tcg_temp_new_i64();
7842 gen_load_fpr64(ctx
, fp0
, fs
);
7843 gen_load_fpr64(ctx
, fp1
, ft
);
7844 gen_load_fpr64(ctx
, fp2
, fr
);
7845 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7846 tcg_temp_free_i64(fp0
);
7847 tcg_temp_free_i64(fp1
);
7848 gen_store_fpr64(ctx
, fp2
, fd
);
7849 tcg_temp_free_i64(fp2
);
7854 check_cp1_64bitmode(ctx
);
7856 TCGv_i64 fp0
= tcg_temp_new_i64();
7857 TCGv_i64 fp1
= tcg_temp_new_i64();
7858 TCGv_i64 fp2
= tcg_temp_new_i64();
7860 gen_load_fpr64(ctx
, fp0
, fs
);
7861 gen_load_fpr64(ctx
, fp1
, ft
);
7862 gen_load_fpr64(ctx
, fp2
, fr
);
7863 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7864 tcg_temp_free_i64(fp0
);
7865 tcg_temp_free_i64(fp1
);
7866 gen_store_fpr64(ctx
, fp2
, fd
);
7867 tcg_temp_free_i64(fp2
);
7874 TCGv_i32 fp0
= tcg_temp_new_i32();
7875 TCGv_i32 fp1
= tcg_temp_new_i32();
7876 TCGv_i32 fp2
= tcg_temp_new_i32();
7878 gen_load_fpr32(fp0
, fs
);
7879 gen_load_fpr32(fp1
, ft
);
7880 gen_load_fpr32(fp2
, fr
);
7881 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7882 tcg_temp_free_i32(fp0
);
7883 tcg_temp_free_i32(fp1
);
7884 gen_store_fpr32(fp2
, fd
);
7885 tcg_temp_free_i32(fp2
);
7891 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7893 TCGv_i64 fp0
= tcg_temp_new_i64();
7894 TCGv_i64 fp1
= tcg_temp_new_i64();
7895 TCGv_i64 fp2
= tcg_temp_new_i64();
7897 gen_load_fpr64(ctx
, fp0
, fs
);
7898 gen_load_fpr64(ctx
, fp1
, ft
);
7899 gen_load_fpr64(ctx
, fp2
, fr
);
7900 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7901 tcg_temp_free_i64(fp0
);
7902 tcg_temp_free_i64(fp1
);
7903 gen_store_fpr64(ctx
, fp2
, fd
);
7904 tcg_temp_free_i64(fp2
);
7909 check_cp1_64bitmode(ctx
);
7911 TCGv_i64 fp0
= tcg_temp_new_i64();
7912 TCGv_i64 fp1
= tcg_temp_new_i64();
7913 TCGv_i64 fp2
= tcg_temp_new_i64();
7915 gen_load_fpr64(ctx
, fp0
, fs
);
7916 gen_load_fpr64(ctx
, fp1
, ft
);
7917 gen_load_fpr64(ctx
, fp2
, fr
);
7918 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7919 tcg_temp_free_i64(fp0
);
7920 tcg_temp_free_i64(fp1
);
7921 gen_store_fpr64(ctx
, fp2
, fd
);
7922 tcg_temp_free_i64(fp2
);
7929 TCGv_i32 fp0
= tcg_temp_new_i32();
7930 TCGv_i32 fp1
= tcg_temp_new_i32();
7931 TCGv_i32 fp2
= tcg_temp_new_i32();
7933 gen_load_fpr32(fp0
, fs
);
7934 gen_load_fpr32(fp1
, ft
);
7935 gen_load_fpr32(fp2
, fr
);
7936 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7937 tcg_temp_free_i32(fp0
);
7938 tcg_temp_free_i32(fp1
);
7939 gen_store_fpr32(fp2
, fd
);
7940 tcg_temp_free_i32(fp2
);
7946 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7948 TCGv_i64 fp0
= tcg_temp_new_i64();
7949 TCGv_i64 fp1
= tcg_temp_new_i64();
7950 TCGv_i64 fp2
= tcg_temp_new_i64();
7952 gen_load_fpr64(ctx
, fp0
, fs
);
7953 gen_load_fpr64(ctx
, fp1
, ft
);
7954 gen_load_fpr64(ctx
, fp2
, fr
);
7955 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7956 tcg_temp_free_i64(fp0
);
7957 tcg_temp_free_i64(fp1
);
7958 gen_store_fpr64(ctx
, fp2
, fd
);
7959 tcg_temp_free_i64(fp2
);
7964 check_cp1_64bitmode(ctx
);
7966 TCGv_i64 fp0
= tcg_temp_new_i64();
7967 TCGv_i64 fp1
= tcg_temp_new_i64();
7968 TCGv_i64 fp2
= tcg_temp_new_i64();
7970 gen_load_fpr64(ctx
, fp0
, fs
);
7971 gen_load_fpr64(ctx
, fp1
, ft
);
7972 gen_load_fpr64(ctx
, fp2
, fr
);
7973 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7974 tcg_temp_free_i64(fp0
);
7975 tcg_temp_free_i64(fp1
);
7976 gen_store_fpr64(ctx
, fp2
, fd
);
7977 tcg_temp_free_i64(fp2
);
7983 generate_exception (ctx
, EXCP_RI
);
7986 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7987 fregnames
[fs
], fregnames
[ft
]);
7991 gen_rdhwr (CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
)
7995 check_insn(env
, ctx
, ISA_MIPS32R2
);
7996 t0
= tcg_temp_new();
8000 save_cpu_state(ctx
, 1);
8001 gen_helper_rdhwr_cpunum(t0
);
8002 gen_store_gpr(t0
, rt
);
8005 save_cpu_state(ctx
, 1);
8006 gen_helper_rdhwr_synci_step(t0
);
8007 gen_store_gpr(t0
, rt
);
8010 save_cpu_state(ctx
, 1);
8011 gen_helper_rdhwr_cc(t0
);
8012 gen_store_gpr(t0
, rt
);
8015 save_cpu_state(ctx
, 1);
8016 gen_helper_rdhwr_ccres(t0
);
8017 gen_store_gpr(t0
, rt
);
8020 #if defined(CONFIG_USER_ONLY)
8021 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
8022 gen_store_gpr(t0
, rt
);
8025 /* XXX: Some CPUs implement this in hardware.
8026 Not supported yet. */
8028 default: /* Invalid */
8029 MIPS_INVAL("rdhwr");
8030 generate_exception(ctx
, EXCP_RI
);
8036 static void handle_delay_slot (CPUState
*env
, DisasContext
*ctx
,
8039 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8040 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8041 /* Branches completion */
8042 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8043 ctx
->bstate
= BS_BRANCH
;
8044 save_cpu_state(ctx
, 0);
8045 /* FIXME: Need to clear can_do_io. */
8046 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
8048 /* unconditional branch */
8049 MIPS_DEBUG("unconditional branch");
8050 if (proc_hflags
& MIPS_HFLAG_BX
) {
8051 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
8053 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8056 /* blikely taken case */
8057 MIPS_DEBUG("blikely branch taken");
8058 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8061 /* Conditional branch */
8062 MIPS_DEBUG("conditional branch");
8064 int l1
= gen_new_label();
8066 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8067 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
8069 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8073 /* unconditional branch to register */
8074 MIPS_DEBUG("branch to register");
8075 if (env
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
8076 TCGv t0
= tcg_temp_new();
8077 TCGv_i32 t1
= tcg_temp_new_i32();
8079 tcg_gen_andi_tl(t0
, btarget
, 0x1);
8080 tcg_gen_trunc_tl_i32(t1
, t0
);
8082 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
8083 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
8084 tcg_gen_or_i32(hflags
, hflags
, t1
);
8085 tcg_temp_free_i32(t1
);
8087 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
8089 tcg_gen_mov_tl(cpu_PC
, btarget
);
8091 if (ctx
->singlestep_enabled
) {
8092 save_cpu_state(ctx
, 0);
8093 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8098 MIPS_DEBUG("unknown branch");
8104 /* ISA extensions (ASEs) */
8105 /* MIPS16 extension to MIPS32 */
8107 /* MIPS16 major opcodes */
8109 M16_OPC_ADDIUSP
= 0x00,
8110 M16_OPC_ADDIUPC
= 0x01,
8113 M16_OPC_BEQZ
= 0x04,
8114 M16_OPC_BNEQZ
= 0x05,
8115 M16_OPC_SHIFT
= 0x06,
8117 M16_OPC_RRIA
= 0x08,
8118 M16_OPC_ADDIU8
= 0x09,
8119 M16_OPC_SLTI
= 0x0a,
8120 M16_OPC_SLTIU
= 0x0b,
8123 M16_OPC_CMPI
= 0x0e,
8127 M16_OPC_LWSP
= 0x12,
8131 M16_OPC_LWPC
= 0x16,
8135 M16_OPC_SWSP
= 0x1a,
8139 M16_OPC_EXTEND
= 0x1e,
8143 /* I8 funct field */
8162 /* RR funct field */
8196 /* I64 funct field */
8208 /* RR ry field for CNVT */
8210 RR_RY_CNVT_ZEB
= 0x0,
8211 RR_RY_CNVT_ZEH
= 0x1,
8212 RR_RY_CNVT_ZEW
= 0x2,
8213 RR_RY_CNVT_SEB
= 0x4,
8214 RR_RY_CNVT_SEH
= 0x5,
8215 RR_RY_CNVT_SEW
= 0x6,
8218 static int xlat (int r
)
8220 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
8225 static void gen_mips16_save (DisasContext
*ctx
,
8226 int xsregs
, int aregs
,
8227 int do_ra
, int do_s0
, int do_s1
,
8230 TCGv t0
= tcg_temp_new();
8231 TCGv t1
= tcg_temp_new();
8261 generate_exception(ctx
, EXCP_RI
);
8267 gen_base_offset_addr(ctx
, t0
, 29, 12);
8268 gen_load_gpr(t1
, 7);
8269 op_st_sw(t1
, t0
, ctx
);
8272 gen_base_offset_addr(ctx
, t0
, 29, 8);
8273 gen_load_gpr(t1
, 6);
8274 op_st_sw(t1
, t0
, ctx
);
8277 gen_base_offset_addr(ctx
, t0
, 29, 4);
8278 gen_load_gpr(t1
, 5);
8279 op_st_sw(t1
, t0
, ctx
);
8282 gen_base_offset_addr(ctx
, t0
, 29, 0);
8283 gen_load_gpr(t1
, 4);
8284 op_st_sw(t1
, t0
, ctx
);
8287 gen_load_gpr(t0
, 29);
8289 #define DECR_AND_STORE(reg) do { \
8290 tcg_gen_subi_tl(t0, t0, 4); \
8291 gen_load_gpr(t1, reg); \
8292 op_st_sw(t1, t0, ctx); \
8356 generate_exception(ctx
, EXCP_RI
);
8372 #undef DECR_AND_STORE
8374 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8379 static void gen_mips16_restore (DisasContext
*ctx
,
8380 int xsregs
, int aregs
,
8381 int do_ra
, int do_s0
, int do_s1
,
8385 TCGv t0
= tcg_temp_new();
8386 TCGv t1
= tcg_temp_new();
8388 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
8390 #define DECR_AND_LOAD(reg) do { \
8391 tcg_gen_subi_tl(t0, t0, 4); \
8392 op_ld_lw(t1, t0, ctx); \
8393 gen_store_gpr(t1, reg); \
8457 generate_exception(ctx
, EXCP_RI
);
8473 #undef DECR_AND_LOAD
8475 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8480 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
8481 int is_64_bit
, int extended
)
8485 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8486 generate_exception(ctx
, EXCP_RI
);
8490 t0
= tcg_temp_new();
8492 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
8493 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
8495 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8501 #if defined(TARGET_MIPS64)
8502 static void decode_i64_mips16 (CPUState
*env
, DisasContext
*ctx
,
8503 int ry
, int funct
, int16_t offset
,
8509 offset
= extended
? offset
: offset
<< 3;
8510 gen_ld(env
, ctx
, OPC_LD
, ry
, 29, offset
);
8514 offset
= extended
? offset
: offset
<< 3;
8515 gen_st(ctx
, OPC_SD
, ry
, 29, offset
);
8519 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8520 gen_st(ctx
, OPC_SD
, 31, 29, offset
);
8524 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8525 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8528 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8529 generate_exception(ctx
, EXCP_RI
);
8531 offset
= extended
? offset
: offset
<< 3;
8532 gen_ld(env
, ctx
, OPC_LDPC
, ry
, 0, offset
);
8537 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8538 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8542 offset
= extended
? offset
: offset
<< 2;
8543 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8547 offset
= extended
? offset
: offset
<< 2;
8548 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8554 static int decode_extended_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8557 int extend
= lduw_code(ctx
->pc
+ 2);
8558 int op
, rx
, ry
, funct
, sa
;
8559 int16_t imm
, offset
;
8561 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8562 op
= (ctx
->opcode
>> 11) & 0x1f;
8563 sa
= (ctx
->opcode
>> 22) & 0x1f;
8564 funct
= (ctx
->opcode
>> 8) & 0x7;
8565 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8566 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8567 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8568 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8569 | (ctx
->opcode
& 0x1f));
8571 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8574 case M16_OPC_ADDIUSP
:
8575 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8577 case M16_OPC_ADDIUPC
:
8578 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8581 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8582 /* No delay slot, so just process as a normal instruction */
8585 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8586 /* No delay slot, so just process as a normal instruction */
8589 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8590 /* No delay slot, so just process as a normal instruction */
8593 switch (ctx
->opcode
& 0x3) {
8595 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8598 #if defined(TARGET_MIPS64)
8600 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8602 generate_exception(ctx
, EXCP_RI
);
8606 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8609 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8613 #if defined(TARGET_MIPS64)
8616 gen_ld(env
, ctx
, OPC_LD
, ry
, rx
, offset
);
8620 imm
= ctx
->opcode
& 0xf;
8621 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8622 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8623 imm
= (int16_t) (imm
<< 1) >> 1;
8624 if ((ctx
->opcode
>> 4) & 0x1) {
8625 #if defined(TARGET_MIPS64)
8627 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8629 generate_exception(ctx
, EXCP_RI
);
8632 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8635 case M16_OPC_ADDIU8
:
8636 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8639 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8642 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8647 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8650 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8653 gen_st(ctx
, OPC_SW
, 31, 29, imm
);
8656 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8660 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8661 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8662 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8663 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8664 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8665 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8666 | (ctx
->opcode
& 0xf)) << 3;
8668 if (ctx
->opcode
& (1 << 7)) {
8669 gen_mips16_save(ctx
, xsregs
, aregs
,
8670 do_ra
, do_s0
, do_s1
,
8673 gen_mips16_restore(ctx
, xsregs
, aregs
,
8674 do_ra
, do_s0
, do_s1
,
8680 generate_exception(ctx
, EXCP_RI
);
8685 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8688 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8690 #if defined(TARGET_MIPS64)
8692 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
);
8696 gen_ld(env
, ctx
, OPC_LB
, ry
, rx
, offset
);
8699 gen_ld(env
, ctx
, OPC_LH
, ry
, rx
, offset
);
8702 gen_ld(env
, ctx
, OPC_LW
, rx
, 29, offset
);
8705 gen_ld(env
, ctx
, OPC_LW
, ry
, rx
, offset
);
8708 gen_ld(env
, ctx
, OPC_LBU
, ry
, rx
, offset
);
8711 gen_ld(env
, ctx
, OPC_LHU
, ry
, rx
, offset
);
8714 gen_ld(env
, ctx
, OPC_LWPC
, rx
, 0, offset
);
8716 #if defined(TARGET_MIPS64)
8718 gen_ld(env
, ctx
, OPC_LWU
, ry
, rx
, offset
);
8722 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
8725 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
);
8728 gen_st(ctx
, OPC_SW
, rx
, 29, offset
);
8731 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
);
8733 #if defined(TARGET_MIPS64)
8735 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8739 generate_exception(ctx
, EXCP_RI
);
8746 static int decode_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8751 int op
, cnvt_op
, op1
, offset
;
8755 op
= (ctx
->opcode
>> 11) & 0x1f;
8756 sa
= (ctx
->opcode
>> 2) & 0x7;
8757 sa
= sa
== 0 ? 8 : sa
;
8758 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8759 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8760 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8761 op1
= offset
= ctx
->opcode
& 0x1f;
8766 case M16_OPC_ADDIUSP
:
8768 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8770 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8773 case M16_OPC_ADDIUPC
:
8774 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8777 offset
= (ctx
->opcode
& 0x7ff) << 1;
8778 offset
= (int16_t)(offset
<< 4) >> 4;
8779 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8780 /* No delay slot, so just process as a normal instruction */
8783 offset
= lduw_code(ctx
->pc
+ 2);
8784 offset
= (((ctx
->opcode
& 0x1f) << 21)
8785 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8787 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALXS
: OPC_JALS
;
8788 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8793 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8794 /* No delay slot, so just process as a normal instruction */
8797 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8798 /* No delay slot, so just process as a normal instruction */
8801 switch (ctx
->opcode
& 0x3) {
8803 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8806 #if defined(TARGET_MIPS64)
8808 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8810 generate_exception(ctx
, EXCP_RI
);
8814 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8817 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8821 #if defined(TARGET_MIPS64)
8824 gen_ld(env
, ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8829 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8831 if ((ctx
->opcode
>> 4) & 1) {
8832 #if defined(TARGET_MIPS64)
8834 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8836 generate_exception(ctx
, EXCP_RI
);
8839 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8843 case M16_OPC_ADDIU8
:
8845 int16_t imm
= (int8_t) ctx
->opcode
;
8847 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8852 int16_t imm
= (uint8_t) ctx
->opcode
;
8854 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8859 int16_t imm
= (uint8_t) ctx
->opcode
;
8861 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8868 funct
= (ctx
->opcode
>> 8) & 0x7;
8871 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
8872 ((int8_t)ctx
->opcode
) << 1);
8875 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
8876 ((int8_t)ctx
->opcode
) << 1);
8879 gen_st(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
8882 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
8883 ((int8_t)ctx
->opcode
) << 3);
8887 int do_ra
= ctx
->opcode
& (1 << 6);
8888 int do_s0
= ctx
->opcode
& (1 << 5);
8889 int do_s1
= ctx
->opcode
& (1 << 4);
8890 int framesize
= ctx
->opcode
& 0xf;
8892 if (framesize
== 0) {
8895 framesize
= framesize
<< 3;
8898 if (ctx
->opcode
& (1 << 7)) {
8899 gen_mips16_save(ctx
, 0, 0,
8900 do_ra
, do_s0
, do_s1
, framesize
);
8902 gen_mips16_restore(ctx
, 0, 0,
8903 do_ra
, do_s0
, do_s1
, framesize
);
8909 int rz
= xlat(ctx
->opcode
& 0x7);
8911 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
8912 ((ctx
->opcode
>> 5) & 0x7);
8913 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
8917 reg32
= ctx
->opcode
& 0x1f;
8918 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
8921 generate_exception(ctx
, EXCP_RI
);
8928 int16_t imm
= (uint8_t) ctx
->opcode
;
8930 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
8935 int16_t imm
= (uint8_t) ctx
->opcode
;
8937 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
8940 #if defined(TARGET_MIPS64)
8943 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
8947 gen_ld(env
, ctx
, OPC_LB
, ry
, rx
, offset
);
8950 gen_ld(env
, ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
8953 gen_ld(env
, ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8956 gen_ld(env
, ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
8959 gen_ld(env
, ctx
, OPC_LBU
, ry
, rx
, offset
);
8962 gen_ld(env
, ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
8965 gen_ld(env
, ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
8967 #if defined (TARGET_MIPS64)
8970 gen_ld(env
, ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
8974 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
8977 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
8980 gen_st(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8983 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
8987 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
8990 switch (ctx
->opcode
& 0x3) {
8992 mips32_op
= OPC_ADDU
;
8995 mips32_op
= OPC_SUBU
;
8997 #if defined(TARGET_MIPS64)
8999 mips32_op
= OPC_DADDU
;
9003 mips32_op
= OPC_DSUBU
;
9008 generate_exception(ctx
, EXCP_RI
);
9012 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
9021 int nd
= (ctx
->opcode
>> 7) & 0x1;
9022 int link
= (ctx
->opcode
>> 6) & 0x1;
9023 int ra
= (ctx
->opcode
>> 5) & 0x1;
9026 op
= nd
? OPC_JALRC
: OPC_JALRS
;
9031 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
9038 /* XXX: not clear which exception should be raised
9039 * when in debug mode...
9041 check_insn(env
, ctx
, ISA_MIPS32
);
9042 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9043 generate_exception(ctx
, EXCP_DBp
);
9045 generate_exception(ctx
, EXCP_DBp
);
9049 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
9052 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
9055 generate_exception(ctx
, EXCP_BREAK
);
9058 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
9061 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
9064 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
9066 #if defined (TARGET_MIPS64)
9069 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
9073 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
9076 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
9079 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
9082 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
9085 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
9088 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
9091 gen_HILO(ctx
, OPC_MFHI
, rx
);
9095 case RR_RY_CNVT_ZEB
:
9096 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9098 case RR_RY_CNVT_ZEH
:
9099 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9101 case RR_RY_CNVT_SEB
:
9102 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9104 case RR_RY_CNVT_SEH
:
9105 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9107 #if defined (TARGET_MIPS64)
9108 case RR_RY_CNVT_ZEW
:
9110 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9112 case RR_RY_CNVT_SEW
:
9114 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9118 generate_exception(ctx
, EXCP_RI
);
9123 gen_HILO(ctx
, OPC_MFLO
, rx
);
9125 #if defined (TARGET_MIPS64)
9128 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
9132 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
9136 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
9140 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
9144 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
9147 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
9150 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
9153 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
9155 #if defined (TARGET_MIPS64)
9158 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
9162 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
9166 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
9170 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
9174 generate_exception(ctx
, EXCP_RI
);
9178 case M16_OPC_EXTEND
:
9179 decode_extended_mips16_opc(env
, ctx
, is_branch
);
9182 #if defined(TARGET_MIPS64)
9184 funct
= (ctx
->opcode
>> 8) & 0x7;
9185 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
9189 generate_exception(ctx
, EXCP_RI
);
9196 /* microMIPS extension to MIPS32 */
9198 /* microMIPS32 major opcodes */
9237 /* 0x20 is reserved */
9247 /* 0x28 and 0x29 are reserved */
9257 /* 0x30 and 0x31 are reserved */
9267 /* 0x38 and 0x39 are reserved */
9278 /* POOL32A encoding of minor opcode field */
9281 /* These opcodes are distinguished only by bits 9..6; those bits are
9282 * what are recorded below. */
9308 /* The following can be distinguished by their lower 6 bits. */
9314 /* POOL32AXF encoding of minor opcode field extension */
9328 /* bits 13..12 for 0x01 */
9334 /* bits 13..12 for 0x2a */
9340 /* bits 13..12 for 0x32 */
9344 /* bits 15..12 for 0x2c */
9360 /* bits 15..12 for 0x34 */
9368 /* bits 15..12 for 0x3c */
9370 JR
= 0x0, /* alias */
9375 /* bits 15..12 for 0x05 */
9379 /* bits 15..12 for 0x0d */
9389 /* bits 15..12 for 0x15 */
9395 /* bits 15..12 for 0x1d */
9399 /* bits 15..12 for 0x2d */
9404 /* bits 15..12 for 0x35 */
9411 /* POOL32B encoding of minor opcode field (bits 15..12) */
9427 /* POOL32C encoding of minor opcode field (bits 15..12) */
9435 /* 0xa is reserved */
9442 /* 0x6 is reserved */
9448 /* POOL32F encoding of minor opcode field (bits 5..0) */
9451 /* These are the bit 7..6 values */
9462 /* These are the bit 8..6 values */
9506 CABS_COND_FMT
= 0x1c, /* MIPS3D */
9510 /* POOL32Fxf encoding of minor opcode extension field */
9548 /* POOL32I encoding of minor opcode field (bits 25..21) */
9573 /* These overlap and are distinguished by bit16 of the instruction */
9582 /* POOL16A encoding of minor opcode field */
9589 /* POOL16B encoding of minor opcode field */
9596 /* POOL16C encoding of minor opcode field */
9616 /* POOL16D encoding of minor opcode field */
9623 /* POOL16E encoding of minor opcode field */
9630 static int mmreg (int r
)
9632 static const int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
9637 /* Used for 16-bit store instructions. */
9638 static int mmreg2 (int r
)
9640 static const int map
[] = { 0, 17, 2, 3, 4, 5, 6, 7 };
9645 #define uMIPS_RD(op) ((op >> 7) & 0x7)
9646 #define uMIPS_RS(op) ((op >> 4) & 0x7)
9647 #define uMIPS_RS2(op) uMIPS_RS(op)
9648 #define uMIPS_RS1(op) ((op >> 1) & 0x7)
9649 #define uMIPS_RD5(op) ((op >> 5) & 0x1f)
9650 #define uMIPS_RS5(op) (op & 0x1f)
9652 /* Signed immediate */
9653 #define SIMM(op, start, width) \
9654 ((int32_t)(((op >> start) & ((~0U) >> (32-width))) \
9657 /* Zero-extended immediate */
9658 #define ZIMM(op, start, width) ((op >> start) & ((~0U) >> (32-width)))
9660 static void gen_addiur1sp (CPUState
*env
, DisasContext
*ctx
)
9662 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9664 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, 29, ((ctx
->opcode
>> 1) & 0x3f) << 2);
9667 static void gen_addiur2 (CPUState
*env
, DisasContext
*ctx
)
9669 static const int decoded_imm
[] = { 1, 4, 8, 12, 16, 20, 24, -1 };
9670 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9671 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9673 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, decoded_imm
[ZIMM(ctx
->opcode
, 1, 3)]);
9676 static void gen_addiusp (CPUState
*env
, DisasContext
*ctx
)
9678 int encoded
= ZIMM(ctx
->opcode
, 1, 9);
9682 decoded
= 256 + encoded
;
9683 } else if (encoded
<= 255) {
9685 } else if (encoded
<= 509) {
9686 decoded
= encoded
- 512;
9688 decoded
= encoded
- 768;
9691 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, decoded
<< 2);
9694 static void gen_addius5 (CPUState
*env
, DisasContext
*ctx
)
9696 int imm
= SIMM(ctx
->opcode
, 1, 4);
9697 int rd
= (ctx
->opcode
>> 5) & 0x1f;
9699 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rd
, imm
);
9702 static void gen_andi16 (CPUState
*env
, DisasContext
*ctx
)
9704 static const int decoded_imm
[] = { 128, 1, 2, 3, 4, 7, 8, 15, 16,
9705 31, 32, 63, 64, 255, 32768, 65535 };
9706 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9707 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9708 int encoded
= ZIMM(ctx
->opcode
, 0, 4);
9710 gen_logic_imm(env
, OPC_ANDI
, rd
, rs
, decoded_imm
[encoded
]);
9713 static void gen_ldst_multiple (DisasContext
*ctx
, uint32_t opc
, int reglist
,
9714 int base
, int16_t offset
)
9719 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
9720 generate_exception(ctx
, EXCP_RI
);
9724 t0
= tcg_temp_new();
9726 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9728 t1
= tcg_const_tl(reglist
);
9729 t2
= tcg_const_i32(ctx
->mem_idx
);
9731 save_cpu_state(ctx
, 1);
9734 gen_helper_lwm(t0
, t1
, t2
);
9737 gen_helper_swm(t0
, t1
, t2
);
9739 #ifdef TARGET_MIPS64
9741 gen_helper_ldm(t0
, t1
, t2
);
9744 gen_helper_sdm(t0
, t1
, t2
);
9748 MIPS_DEBUG("%s, %x, %d(%s)", opn
, reglist
, offset
, regnames
[base
]);
9751 tcg_temp_free_i32(t2
);
9755 static void gen_pool16c_insn (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
9757 int rd
= mmreg((ctx
->opcode
>> 3) & 0x7);
9758 int rs
= mmreg(ctx
->opcode
& 0x7);
9761 switch (((ctx
->opcode
) >> 4) & 0x3f) {
9766 gen_logic(env
, OPC_NOR
, rd
, rs
, 0);
9772 gen_logic(env
, OPC_XOR
, rd
, rd
, rs
);
9778 gen_logic(env
, OPC_AND
, rd
, rd
, rs
);
9784 gen_logic(env
, OPC_OR
, rd
, rd
, rs
);
9791 static const int lwm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9792 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9794 gen_ldst_multiple(ctx
, LWM32
, lwm_convert
[(ctx
->opcode
>> 4) & 0x3],
9803 static const int swm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9804 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9806 gen_ldst_multiple(ctx
, SWM32
, swm_convert
[(ctx
->opcode
>> 4) & 0x3],
9813 int reg
= ctx
->opcode
& 0x1f;
9815 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9822 int reg
= ctx
->opcode
& 0x1f;
9824 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9825 /* Let normal delay slot handling in our caller take us
9826 to the branch target. */
9838 int reg
= ctx
->opcode
& 0x1f;
9840 gen_compute_branch(ctx
, opc
, 2, reg
, 31, 0);
9846 gen_HILO(ctx
, OPC_MFHI
, uMIPS_RS5(ctx
->opcode
));
9850 gen_HILO(ctx
, OPC_MFLO
, uMIPS_RS5(ctx
->opcode
));
9853 generate_exception(ctx
, EXCP_BREAK
);
9856 /* XXX: not clear which exception should be raised
9857 * when in debug mode...
9859 check_insn(env
, ctx
, ISA_MIPS32
);
9860 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9861 generate_exception(ctx
, EXCP_DBp
);
9863 generate_exception(ctx
, EXCP_DBp
);
9869 int imm
= ZIMM(ctx
->opcode
, 0, 5);
9871 gen_compute_branch(ctx
, OPC_JR
, 2, 31, 0, 0);
9872 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
<< 2);
9873 /* Let normal delay slot handling in our caller take us
9874 to the branch target. */
9878 generate_exception(ctx
, EXCP_RI
);
9883 static void gen_ldxs (DisasContext
*ctx
, int base
, int index
, int rd
)
9885 TCGv t0
= tcg_temp_new();
9886 TCGv t1
= tcg_temp_new();
9888 gen_load_gpr(t0
, base
);
9891 gen_load_gpr(t1
, index
);
9892 tcg_gen_shli_tl(t1
, t1
, 2);
9893 gen_op_addr_add(ctx
, t0
, t1
, t0
);
9896 save_cpu_state(ctx
, 0);
9897 op_ld_lw(t1
, t0
, ctx
);
9898 gen_store_gpr(t1
, rd
);
9904 static void gen_ldst_pair (DisasContext
*ctx
, uint32_t opc
, int rd
,
9905 int base
, int16_t offset
)
9907 const char *opn
= "ldst_pair";
9910 if (ctx
->hflags
& MIPS_HFLAG_BMASK
|| rd
== 31 || rd
== base
) {
9911 generate_exception(ctx
, EXCP_RI
);
9915 t0
= tcg_temp_new();
9916 t1
= tcg_temp_new();
9918 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9922 save_cpu_state(ctx
, 0);
9923 op_ld_lw(t1
, t0
, ctx
);
9924 gen_store_gpr(t1
, rd
);
9925 tcg_gen_movi_tl(t1
, 4);
9926 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9927 op_ld_lw(t1
, t0
, ctx
);
9928 gen_store_gpr(t1
, rd
+1);
9932 save_cpu_state(ctx
, 1);
9933 gen_load_gpr(t1
, rd
);
9934 op_st_sw(t1
, t0
, ctx
);
9935 tcg_gen_movi_tl(t1
, 4);
9936 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9937 gen_load_gpr(t1
, rd
+1);
9938 op_st_sw(t1
, t0
, ctx
);
9941 #ifdef TARGET_MIPS64
9943 save_cpu_state(ctx
, 0);
9944 op_ld_ld(t1
, t0
, ctx
);
9945 gen_store_gpr(t1
, rd
);
9946 tcg_gen_movi_tl(t1
, 8);
9947 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9948 op_ld_ld(t1
, t0
, ctx
);
9949 gen_store_gpr(t1
, rd
+1);
9953 save_cpu_state(ctx
, 1);
9954 gen_load_gpr(t1
, rd
);
9955 op_st_sd(t1
, t0
, ctx
);
9956 tcg_gen_movi_tl(t1
, 8);
9957 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9958 gen_load_gpr(t1
, rd
+1);
9959 op_st_sd(t1
, t0
, ctx
);
9964 MIPS_DEBUG("%s, %s, %d(%s)", opn
, regnames
[rd
], offset
, regnames
[base
]);
9969 static void gen_pool32axf (CPUState
*env
, DisasContext
*ctx
, int rt
, int rs
,
9972 int extension
= (ctx
->opcode
>> 6) & 0x3f;
9973 int minor
= (ctx
->opcode
>> 12) & 0xf;
9976 switch (extension
) {
9978 mips32_op
= OPC_TEQ
;
9981 mips32_op
= OPC_TGE
;
9984 mips32_op
= OPC_TGEU
;
9987 mips32_op
= OPC_TLT
;
9990 mips32_op
= OPC_TLTU
;
9993 mips32_op
= OPC_TNE
;
9995 gen_trap(ctx
, mips32_op
, rs
, rt
, -1);
9997 #ifndef CONFIG_USER_ONLY
10001 /* Treat as NOP. */
10004 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rs
, (ctx
->opcode
>> 11) & 0x7);
10009 TCGv t0
= tcg_temp_new();
10011 gen_load_gpr(t0
, rt
);
10012 gen_mtc0(env
, ctx
, t0
, rs
, (ctx
->opcode
>> 11) & 0x7);
10020 gen_bshfl(ctx
, OPC_SEB
, rs
, rt
);
10023 gen_bshfl(ctx
, OPC_SEH
, rs
, rt
);
10026 mips32_op
= OPC_CLO
;
10029 mips32_op
= OPC_CLZ
;
10031 check_insn(env
, ctx
, ISA_MIPS32
);
10032 gen_cl(ctx
, mips32_op
, rt
, rs
);
10035 gen_rdhwr(env
, ctx
, rt
, rs
);
10038 gen_bshfl(ctx
, OPC_WSBH
, rs
, rt
);
10041 mips32_op
= OPC_MULT
;
10044 mips32_op
= OPC_MULTU
;
10047 mips32_op
= OPC_DIV
;
10050 mips32_op
= OPC_DIVU
;
10053 mips32_op
= OPC_MADD
;
10056 mips32_op
= OPC_MADDU
;
10059 mips32_op
= OPC_MSUB
;
10062 mips32_op
= OPC_MSUBU
;
10064 check_insn(env
, ctx
, ISA_MIPS32
);
10065 gen_muldiv(ctx
, mips32_op
, rs
, rt
);
10068 goto pool32axf_invalid
;
10079 generate_exception_err(ctx
, EXCP_CpU
, 2);
10082 goto pool32axf_invalid
;
10089 gen_compute_branch (ctx
, OPC_JALR
, 4, rs
, rt
, 0);
10094 gen_compute_branch (ctx
, OPC_JALRS
, 4, rs
, rt
, 0);
10098 goto pool32axf_invalid
;
10104 check_insn(env
, ctx
, ISA_MIPS32R2
);
10105 gen_load_srsgpr(rt
, rs
);
10108 check_insn(env
, ctx
, ISA_MIPS32R2
);
10109 gen_store_srsgpr(rt
, rs
);
10112 goto pool32axf_invalid
;
10115 #ifndef CONFIG_USER_ONLY
10119 mips32_op
= OPC_TLBP
;
10122 mips32_op
= OPC_TLBR
;
10125 mips32_op
= OPC_TLBWI
;
10128 mips32_op
= OPC_TLBWR
;
10131 mips32_op
= OPC_WAIT
;
10134 mips32_op
= OPC_DERET
;
10137 mips32_op
= OPC_ERET
;
10139 gen_cp0(env
, ctx
, mips32_op
, rt
, rs
);
10142 goto pool32axf_invalid
;
10149 TCGv t0
= tcg_temp_new();
10151 save_cpu_state(ctx
, 1);
10153 gen_store_gpr(t0
, rs
);
10154 /* Stop translation as we may have switched the execution mode */
10155 ctx
->bstate
= BS_STOP
;
10161 TCGv t0
= tcg_temp_new();
10163 save_cpu_state(ctx
, 1);
10165 gen_store_gpr(t0
, rs
);
10166 /* Stop translation as we may have switched the execution mode */
10167 ctx
->bstate
= BS_STOP
;
10172 goto pool32axf_invalid
;
10182 generate_exception(ctx
, EXCP_SYSCALL
);
10183 ctx
->bstate
= BS_STOP
;
10186 check_insn(env
, ctx
, ISA_MIPS32
);
10187 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
10188 generate_exception(ctx
, EXCP_DBp
);
10190 generate_exception(ctx
, EXCP_DBp
);
10194 goto pool32axf_invalid
;
10200 gen_HILO(ctx
, OPC_MFHI
, rs
);
10203 gen_HILO(ctx
, OPC_MFLO
, rs
);
10206 gen_HILO(ctx
, OPC_MTHI
, rs
);
10209 gen_HILO(ctx
, OPC_MTLO
, rs
);
10212 goto pool32axf_invalid
;
10217 MIPS_INVAL("pool32axf");
10218 generate_exception(ctx
, EXCP_RI
);
10223 /* Values for microMIPS fmt field. Variable-width, depending on which
10224 formats the instruction supports. */
10243 static void gen_pool32fxf (CPUState
*env
, DisasContext
*ctx
, int rt
, int rs
)
10245 int extension
= (ctx
->opcode
>> 6) & 0x3ff;
10246 uint32_t mips32_op
;
10248 #define FLOAT_1BIT_FMT(opc, fmt) (fmt << 8) | opc
10249 #define FLOAT_2BIT_FMT(opc, fmt) (fmt << 7) | opc
10250 #define COND_FLOAT_MOV(opc, cond) (cond << 7) | opc
10252 switch (extension
) {
10253 case FLOAT_1BIT_FMT(CFC1
, 0):
10254 mips32_op
= OPC_CFC1
;
10256 case FLOAT_1BIT_FMT(CTC1
, 0):
10257 mips32_op
= OPC_CTC1
;
10259 case FLOAT_1BIT_FMT(MFC1
, 0):
10260 mips32_op
= OPC_MFC1
;
10262 case FLOAT_1BIT_FMT(MTC1
, 0):
10263 mips32_op
= OPC_MTC1
;
10265 case FLOAT_1BIT_FMT(MFHC1
, 0):
10266 mips32_op
= OPC_MFHC1
;
10268 case FLOAT_1BIT_FMT(MTHC1
, 0):
10269 mips32_op
= OPC_MTHC1
;
10271 gen_cp1(ctx
, mips32_op
, rt
, rs
);
10274 /* Reciprocal square root */
10275 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_S
):
10276 mips32_op
= OPC_RSQRT_S
;
10278 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_D
):
10279 mips32_op
= OPC_RSQRT_D
;
10283 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_S
):
10284 mips32_op
= OPC_SQRT_S
;
10286 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_D
):
10287 mips32_op
= OPC_SQRT_D
;
10291 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_S
):
10292 mips32_op
= OPC_RECIP_S
;
10294 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_D
):
10295 mips32_op
= OPC_RECIP_D
;
10299 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_S
):
10300 mips32_op
= OPC_FLOOR_L_S
;
10302 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_D
):
10303 mips32_op
= OPC_FLOOR_L_D
;
10305 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_S
):
10306 mips32_op
= OPC_FLOOR_W_S
;
10308 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_D
):
10309 mips32_op
= OPC_FLOOR_W_D
;
10313 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_S
):
10314 mips32_op
= OPC_CEIL_L_S
;
10316 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_D
):
10317 mips32_op
= OPC_CEIL_L_D
;
10319 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_S
):
10320 mips32_op
= OPC_CEIL_W_S
;
10322 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_D
):
10323 mips32_op
= OPC_CEIL_W_D
;
10327 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_S
):
10328 mips32_op
= OPC_TRUNC_L_S
;
10330 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_D
):
10331 mips32_op
= OPC_TRUNC_L_D
;
10333 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_S
):
10334 mips32_op
= OPC_TRUNC_W_S
;
10336 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_D
):
10337 mips32_op
= OPC_TRUNC_W_D
;
10341 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_S
):
10342 mips32_op
= OPC_ROUND_L_S
;
10344 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_D
):
10345 mips32_op
= OPC_ROUND_L_D
;
10347 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_S
):
10348 mips32_op
= OPC_ROUND_W_S
;
10350 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_D
):
10351 mips32_op
= OPC_ROUND_W_D
;
10354 /* Integer to floating-point conversion */
10355 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_S
):
10356 mips32_op
= OPC_CVT_L_S
;
10358 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_D
):
10359 mips32_op
= OPC_CVT_L_D
;
10361 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_S
):
10362 mips32_op
= OPC_CVT_W_S
;
10364 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_D
):
10365 mips32_op
= OPC_CVT_W_D
;
10368 /* Paired-foo conversions */
10369 case FLOAT_1BIT_FMT(CVT_S_PL
, 0):
10370 mips32_op
= OPC_CVT_S_PL
;
10372 case FLOAT_1BIT_FMT(CVT_S_PU
, 0):
10373 mips32_op
= OPC_CVT_S_PU
;
10375 case FLOAT_1BIT_FMT(CVT_PW_PS
, 0):
10376 mips32_op
= OPC_CVT_PW_PS
;
10378 case FLOAT_1BIT_FMT(CVT_PS_PW
, 0):
10379 mips32_op
= OPC_CVT_PS_PW
;
10382 /* Floating-point moves */
10383 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_S
):
10384 mips32_op
= OPC_MOV_S
;
10386 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_D
):
10387 mips32_op
= OPC_MOV_D
;
10389 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_PS
):
10390 mips32_op
= OPC_MOV_PS
;
10393 /* Absolute value */
10394 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_S
):
10395 mips32_op
= OPC_ABS_S
;
10397 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_D
):
10398 mips32_op
= OPC_ABS_D
;
10400 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_PS
):
10401 mips32_op
= OPC_ABS_PS
;
10405 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_S
):
10406 mips32_op
= OPC_NEG_S
;
10408 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_D
):
10409 mips32_op
= OPC_NEG_D
;
10411 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_PS
):
10412 mips32_op
= OPC_NEG_PS
;
10415 /* Reciprocal square root step */
10416 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_S
):
10417 mips32_op
= OPC_RSQRT1_S
;
10419 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_D
):
10420 mips32_op
= OPC_RSQRT1_D
;
10422 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_PS
):
10423 mips32_op
= OPC_RSQRT1_PS
;
10426 /* Reciprocal step */
10427 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_S
):
10428 mips32_op
= OPC_RECIP1_S
;
10430 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_D
):
10431 mips32_op
= OPC_RECIP1_S
;
10433 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_PS
):
10434 mips32_op
= OPC_RECIP1_PS
;
10437 /* Conversions from double */
10438 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_S
):
10439 mips32_op
= OPC_CVT_D_S
;
10441 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_W
):
10442 mips32_op
= OPC_CVT_D_W
;
10444 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_L
):
10445 mips32_op
= OPC_CVT_D_L
;
10448 /* Conversions from single */
10449 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_D
):
10450 mips32_op
= OPC_CVT_S_D
;
10452 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_W
):
10453 mips32_op
= OPC_CVT_S_W
;
10455 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_L
):
10456 mips32_op
= OPC_CVT_S_L
;
10458 gen_farith(ctx
, mips32_op
, -1, rs
, rt
, 0);
10461 /* Conditional moves on floating-point codes */
10462 case COND_FLOAT_MOV(MOVT
, 0):
10463 case COND_FLOAT_MOV(MOVT
, 1):
10464 case COND_FLOAT_MOV(MOVT
, 2):
10465 case COND_FLOAT_MOV(MOVT
, 3):
10466 case COND_FLOAT_MOV(MOVT
, 4):
10467 case COND_FLOAT_MOV(MOVT
, 5):
10468 case COND_FLOAT_MOV(MOVT
, 6):
10469 case COND_FLOAT_MOV(MOVT
, 7):
10470 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 1);
10472 case COND_FLOAT_MOV(MOVF
, 0):
10473 case COND_FLOAT_MOV(MOVF
, 1):
10474 case COND_FLOAT_MOV(MOVF
, 2):
10475 case COND_FLOAT_MOV(MOVF
, 3):
10476 case COND_FLOAT_MOV(MOVF
, 4):
10477 case COND_FLOAT_MOV(MOVF
, 5):
10478 case COND_FLOAT_MOV(MOVF
, 6):
10479 case COND_FLOAT_MOV(MOVF
, 7):
10480 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 0);
10483 MIPS_INVAL("pool32fxf");
10484 generate_exception(ctx
, EXCP_RI
);
10489 static void decode_micromips32_opc (CPUState
*env
, DisasContext
*ctx
,
10490 uint16_t insn_hw1
, int *is_branch
)
10494 int rt
, rs
, rd
, rr
;
10496 uint32_t op
, minor
, mips32_op
;
10497 uint32_t cond
, fmt
, cc
;
10499 insn
= lduw_code(ctx
->pc
+ 2);
10500 ctx
->opcode
= (ctx
->opcode
<< 16) | insn
;
10502 rt
= (ctx
->opcode
>> 21) & 0x1f;
10503 rs
= (ctx
->opcode
>> 16) & 0x1f;
10504 rd
= (ctx
->opcode
>> 11) & 0x1f;
10505 rr
= (ctx
->opcode
>> 6) & 0x1f;
10506 imm
= (int16_t) ctx
->opcode
;
10508 op
= (ctx
->opcode
>> 26) & 0x3f;
10511 minor
= ctx
->opcode
& 0x3f;
10514 minor
= (ctx
->opcode
>> 6) & 0xf;
10517 mips32_op
= OPC_SLL
;
10520 mips32_op
= OPC_SRA
;
10523 mips32_op
= OPC_SRL
;
10526 mips32_op
= OPC_ROTR
;
10528 gen_shift_imm(env
, ctx
, mips32_op
, rt
, rs
, rd
);
10531 goto pool32a_invalid
;
10535 minor
= (ctx
->opcode
>> 6) & 0xf;
10539 mips32_op
= OPC_ADD
;
10542 mips32_op
= OPC_ADDU
;
10545 mips32_op
= OPC_SUB
;
10548 mips32_op
= OPC_SUBU
;
10551 mips32_op
= OPC_MUL
;
10553 gen_arith(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10557 mips32_op
= OPC_SLLV
;
10560 mips32_op
= OPC_SRLV
;
10563 mips32_op
= OPC_SRAV
;
10566 mips32_op
= OPC_ROTRV
;
10568 gen_shift(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10570 /* Logical operations */
10572 mips32_op
= OPC_AND
;
10575 mips32_op
= OPC_OR
;
10578 mips32_op
= OPC_NOR
;
10581 mips32_op
= OPC_XOR
;
10583 gen_logic(env
, mips32_op
, rd
, rs
, rt
);
10585 /* Set less than */
10587 mips32_op
= OPC_SLT
;
10590 mips32_op
= OPC_SLTU
;
10592 gen_slt(env
, mips32_op
, rd
, rs
, rt
);
10595 goto pool32a_invalid
;
10599 minor
= (ctx
->opcode
>> 6) & 0xf;
10601 /* Conditional moves */
10603 mips32_op
= OPC_MOVN
;
10606 mips32_op
= OPC_MOVZ
;
10608 gen_cond_move(env
, mips32_op
, rd
, rs
, rt
);
10611 gen_ldxs(ctx
, rs
, rt
, rd
);
10614 goto pool32a_invalid
;
10618 gen_bitops(ctx
, OPC_INS
, rt
, rs
, rr
, rd
);
10621 gen_bitops(ctx
, OPC_EXT
, rt
, rs
, rr
, rd
);
10624 gen_pool32axf(env
, ctx
, rt
, rs
, is_branch
);
10627 generate_exception(ctx
, EXCP_BREAK
);
10631 MIPS_INVAL("pool32a");
10632 generate_exception(ctx
, EXCP_RI
);
10637 minor
= (ctx
->opcode
>> 12) & 0xf;
10640 /* Treat as no-op. */
10644 /* COP2: Not implemented. */
10645 generate_exception_err(ctx
, EXCP_CpU
, 2);
10649 #ifdef TARGET_MIPS64
10653 gen_ldst_pair(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10657 #ifdef TARGET_MIPS64
10661 gen_ldst_multiple(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10664 MIPS_INVAL("pool32b");
10665 generate_exception(ctx
, EXCP_RI
);
10670 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
10671 minor
= ctx
->opcode
& 0x3f;
10672 check_cp1_enabled(ctx
);
10675 mips32_op
= OPC_ALNV_PS
;
10678 mips32_op
= OPC_MADD_S
;
10681 mips32_op
= OPC_MADD_D
;
10684 mips32_op
= OPC_MADD_PS
;
10687 mips32_op
= OPC_MSUB_S
;
10690 mips32_op
= OPC_MSUB_D
;
10693 mips32_op
= OPC_MSUB_PS
;
10696 mips32_op
= OPC_NMADD_S
;
10699 mips32_op
= OPC_NMADD_D
;
10702 mips32_op
= OPC_NMADD_PS
;
10705 mips32_op
= OPC_NMSUB_S
;
10708 mips32_op
= OPC_NMSUB_D
;
10711 mips32_op
= OPC_NMSUB_PS
;
10713 gen_flt3_arith(ctx
, mips32_op
, rd
, rr
, rs
, rt
);
10715 case CABS_COND_FMT
:
10716 cond
= (ctx
->opcode
>> 6) & 0xf;
10717 cc
= (ctx
->opcode
>> 13) & 0x7;
10718 fmt
= (ctx
->opcode
>> 10) & 0x3;
10721 gen_cmpabs_s(ctx
, cond
, rt
, rs
, cc
);
10724 gen_cmpabs_d(ctx
, cond
, rt
, rs
, cc
);
10727 gen_cmpabs_ps(ctx
, cond
, rt
, rs
, cc
);
10730 goto pool32f_invalid
;
10734 cond
= (ctx
->opcode
>> 6) & 0xf;
10735 cc
= (ctx
->opcode
>> 13) & 0x7;
10736 fmt
= (ctx
->opcode
>> 10) & 0x3;
10739 gen_cmp_s(ctx
, cond
, rt
, rs
, cc
);
10742 gen_cmp_d(ctx
, cond
, rt
, rs
, cc
);
10745 gen_cmp_ps(ctx
, cond
, rt
, rs
, cc
);
10748 goto pool32f_invalid
;
10752 gen_pool32fxf(env
, ctx
, rt
, rs
);
10756 switch ((ctx
->opcode
>> 6) & 0x7) {
10758 mips32_op
= OPC_PLL_PS
;
10761 mips32_op
= OPC_PLU_PS
;
10764 mips32_op
= OPC_PUL_PS
;
10767 mips32_op
= OPC_PUU_PS
;
10770 mips32_op
= OPC_CVT_PS_S
;
10772 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10775 goto pool32f_invalid
;
10780 switch ((ctx
->opcode
>> 6) & 0x7) {
10782 mips32_op
= OPC_LWXC1
;
10785 mips32_op
= OPC_SWXC1
;
10788 mips32_op
= OPC_LDXC1
;
10791 mips32_op
= OPC_SDXC1
;
10794 mips32_op
= OPC_LUXC1
;
10797 mips32_op
= OPC_SUXC1
;
10799 gen_flt3_ldst(ctx
, mips32_op
, rd
, rd
, rt
, rs
);
10802 goto pool32f_invalid
;
10807 fmt
= (ctx
->opcode
>> 9) & 0x3;
10808 switch ((ctx
->opcode
>> 6) & 0x7) {
10812 mips32_op
= OPC_RSQRT2_S
;
10815 mips32_op
= OPC_RSQRT2_D
;
10818 mips32_op
= OPC_RSQRT2_PS
;
10821 goto pool32f_invalid
;
10827 mips32_op
= OPC_RECIP2_S
;
10830 mips32_op
= OPC_RECIP2_D
;
10833 mips32_op
= OPC_RECIP2_PS
;
10836 goto pool32f_invalid
;
10840 mips32_op
= OPC_ADDR_PS
;
10843 mips32_op
= OPC_MULR_PS
;
10845 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10848 goto pool32f_invalid
;
10852 /* MOV[FT].fmt and PREFX */
10853 cc
= (ctx
->opcode
>> 13) & 0x7;
10854 fmt
= (ctx
->opcode
>> 9) & 0x3;
10855 switch ((ctx
->opcode
>> 6) & 0x7) {
10859 gen_movcf_s(rs
, rt
, cc
, 0);
10862 gen_movcf_d(ctx
, rs
, rt
, cc
, 0);
10865 gen_movcf_ps(rs
, rt
, cc
, 0);
10868 goto pool32f_invalid
;
10874 gen_movcf_s(rs
, rt
, cc
, 1);
10877 gen_movcf_d(ctx
, rs
, rt
, cc
, 1);
10880 gen_movcf_ps(rs
, rt
, cc
, 1);
10883 goto pool32f_invalid
;
10889 goto pool32f_invalid
;
10892 #define FINSN_3ARG_SDPS(prfx) \
10893 switch ((ctx->opcode >> 8) & 0x3) { \
10895 mips32_op = OPC_##prfx##_S; \
10898 mips32_op = OPC_##prfx##_D; \
10900 case FMT_SDPS_PS: \
10901 mips32_op = OPC_##prfx##_PS; \
10904 goto pool32f_invalid; \
10907 /* regular FP ops */
10908 switch ((ctx
->opcode
>> 6) & 0x3) {
10910 FINSN_3ARG_SDPS(ADD
);
10913 FINSN_3ARG_SDPS(SUB
);
10916 FINSN_3ARG_SDPS(MUL
);
10919 fmt
= (ctx
->opcode
>> 8) & 0x3;
10921 mips32_op
= OPC_DIV_D
;
10922 } else if (fmt
== 0) {
10923 mips32_op
= OPC_DIV_S
;
10925 goto pool32f_invalid
;
10929 goto pool32f_invalid
;
10934 switch ((ctx
->opcode
>> 6) & 0x3) {
10936 FINSN_3ARG_SDPS(MOVN
);
10939 FINSN_3ARG_SDPS(MOVZ
);
10942 goto pool32f_invalid
;
10946 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10950 MIPS_INVAL("pool32f");
10951 generate_exception(ctx
, EXCP_RI
);
10955 generate_exception_err(ctx
, EXCP_CpU
, 1);
10959 minor
= (ctx
->opcode
>> 21) & 0x1f;
10962 mips32_op
= OPC_BLTZ
;
10965 mips32_op
= OPC_BLTZAL
;
10968 mips32_op
= OPC_BLTZALS
;
10971 mips32_op
= OPC_BGEZ
;
10974 mips32_op
= OPC_BGEZAL
;
10977 mips32_op
= OPC_BGEZALS
;
10980 mips32_op
= OPC_BLEZ
;
10983 mips32_op
= OPC_BGTZ
;
10985 gen_compute_branch(ctx
, mips32_op
, 4, rs
, -1, imm
<< 1);
10991 mips32_op
= OPC_TLTI
;
10994 mips32_op
= OPC_TGEI
;
10997 mips32_op
= OPC_TLTIU
;
11000 mips32_op
= OPC_TGEIU
;
11003 mips32_op
= OPC_TNEI
;
11006 mips32_op
= OPC_TEQI
;
11008 gen_trap(ctx
, mips32_op
, rs
, -1, imm
);
11013 gen_compute_branch(ctx
, minor
== BNEZC
? OPC_BNE
: OPC_BEQ
,
11014 4, rs
, 0, imm
<< 1);
11015 /* Compact branches don't have a delay slot, so just let
11016 the normal delay slot handling take us to the branch
11020 gen_logic_imm(env
, OPC_LUI
, rs
, -1, imm
);
11026 /* COP2: Not implemented. */
11027 generate_exception_err(ctx
, EXCP_CpU
, 2);
11030 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1FANY2
: OPC_BC1F
;
11033 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1TANY2
: OPC_BC1T
;
11036 mips32_op
= OPC_BC1FANY4
;
11039 mips32_op
= OPC_BC1TANY4
;
11042 check_insn(env
, ctx
, ASE_MIPS3D
);
11045 gen_compute_branch1(env
, ctx
, mips32_op
,
11046 (ctx
->opcode
>> 18) & 0x7, imm
<< 1);
11051 /* MIPS DSP: not implemented */
11054 MIPS_INVAL("pool32i");
11055 generate_exception(ctx
, EXCP_RI
);
11060 minor
= (ctx
->opcode
>> 12) & 0xf;
11063 mips32_op
= OPC_LWL
;
11066 mips32_op
= OPC_SWL
;
11069 mips32_op
= OPC_LWR
;
11072 mips32_op
= OPC_SWR
;
11074 #if defined(TARGET_MIPS64)
11076 mips32_op
= OPC_LDL
;
11079 mips32_op
= OPC_SDL
;
11082 mips32_op
= OPC_LDR
;
11085 mips32_op
= OPC_SDR
;
11088 mips32_op
= OPC_LWU
;
11091 mips32_op
= OPC_LLD
;
11095 mips32_op
= OPC_LL
;
11098 gen_ld(env
, ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11101 gen_st(ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11104 gen_st_cond(ctx
, OPC_SC
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11106 #if defined(TARGET_MIPS64)
11108 gen_st_cond(ctx
, OPC_SCD
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11112 /* Treat as no-op */
11115 MIPS_INVAL("pool32c");
11116 generate_exception(ctx
, EXCP_RI
);
11121 mips32_op
= OPC_ADDI
;
11124 mips32_op
= OPC_ADDIU
;
11126 gen_arith_imm(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11129 /* Logical operations */
11131 mips32_op
= OPC_ORI
;
11134 mips32_op
= OPC_XORI
;
11137 mips32_op
= OPC_ANDI
;
11139 gen_logic_imm(env
, mips32_op
, rt
, rs
, imm
);
11142 /* Set less than immediate */
11144 mips32_op
= OPC_SLTI
;
11147 mips32_op
= OPC_SLTIU
;
11149 gen_slt_imm(env
, mips32_op
, rt
, rs
, imm
);
11152 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
11153 gen_compute_branch(ctx
, OPC_JALX
, 4, rt
, rs
, offset
);
11157 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1;
11158 gen_compute_branch(ctx
, OPC_JALS
, 4, rt
, rs
, offset
);
11162 gen_compute_branch(ctx
, OPC_BEQ
, 4, rt
, rs
, imm
<< 1);
11166 gen_compute_branch(ctx
, OPC_BNE
, 4, rt
, rs
, imm
<< 1);
11170 gen_compute_branch(ctx
, OPC_J
, 4, rt
, rs
,
11171 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
11175 gen_compute_branch(ctx
, OPC_JAL
, 4, rt
, rs
,
11176 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
11179 /* Floating point (COP1) */
11181 mips32_op
= OPC_LWC1
;
11184 mips32_op
= OPC_LDC1
;
11187 mips32_op
= OPC_SWC1
;
11190 mips32_op
= OPC_SDC1
;
11192 gen_cop1_ldst(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11196 int reg
= mmreg(ZIMM(ctx
->opcode
, 23, 3));
11197 int offset
= SIMM(ctx
->opcode
, 0, 23) << 2;
11199 gen_addiupc(ctx
, reg
, offset
, 0, 0);
11202 /* Loads and stores */
11204 mips32_op
= OPC_LB
;
11207 mips32_op
= OPC_LBU
;
11210 mips32_op
= OPC_LH
;
11213 mips32_op
= OPC_LHU
;
11216 mips32_op
= OPC_LW
;
11218 #ifdef TARGET_MIPS64
11220 mips32_op
= OPC_LD
;
11223 mips32_op
= OPC_SD
;
11227 mips32_op
= OPC_SB
;
11230 mips32_op
= OPC_SH
;
11233 mips32_op
= OPC_SW
;
11236 gen_ld(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11239 gen_st(ctx
, mips32_op
, rt
, rs
, imm
);
11242 generate_exception(ctx
, EXCP_RI
);
11247 static int decode_micromips_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
11251 /* make sure instructions are on a halfword boundary */
11252 if (ctx
->pc
& 0x1) {
11253 env
->CP0_BadVAddr
= ctx
->pc
;
11254 generate_exception(ctx
, EXCP_AdEL
);
11255 ctx
->bstate
= BS_STOP
;
11259 op
= (ctx
->opcode
>> 10) & 0x3f;
11260 /* Enforce properly-sized instructions in a delay slot */
11261 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
11262 int bits
= ctx
->hflags
& MIPS_HFLAG_BMASK_EXT
;
11296 case POOL48A
: /* ??? */
11301 if (bits
& MIPS_HFLAG_BDS16
) {
11302 generate_exception(ctx
, EXCP_RI
);
11303 /* Just stop translation; the user is confused. */
11304 ctx
->bstate
= BS_STOP
;
11329 if (bits
& MIPS_HFLAG_BDS32
) {
11330 generate_exception(ctx
, EXCP_RI
);
11331 /* Just stop translation; the user is confused. */
11332 ctx
->bstate
= BS_STOP
;
11343 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11344 int rs1
= mmreg(uMIPS_RS1(ctx
->opcode
));
11345 int rs2
= mmreg(uMIPS_RS2(ctx
->opcode
));
11348 switch (ctx
->opcode
& 0x1) {
11357 gen_arith(env
, ctx
, opc
, rd
, rs1
, rs2
);
11362 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11363 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
11364 int amount
= (ctx
->opcode
>> 1) & 0x7;
11366 amount
= amount
== 0 ? 8 : amount
;
11368 switch (ctx
->opcode
& 0x1) {
11377 gen_shift_imm(env
, ctx
, opc
, rd
, rs
, amount
);
11381 gen_pool16c_insn(env
, ctx
, is_branch
);
11385 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11386 int rb
= 28; /* GP */
11387 int16_t offset
= SIMM(ctx
->opcode
, 0, 7) << 2;
11389 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11393 if (ctx
->opcode
& 1) {
11394 generate_exception(ctx
, EXCP_RI
);
11397 int enc_dest
= uMIPS_RD(ctx
->opcode
);
11398 int enc_rt
= uMIPS_RS2(ctx
->opcode
);
11399 int enc_rs
= uMIPS_RS1(ctx
->opcode
);
11400 int rd
, rs
, re
, rt
;
11401 static const int rd_enc
[] = { 5, 5, 6, 4, 4, 4, 4, 4 };
11402 static const int re_enc
[] = { 6, 7, 7, 21, 22, 5, 6, 7 };
11403 static const int rs_rt_enc
[] = { 0, 17, 2, 3, 16, 18, 19, 20 };
11405 rd
= rd_enc
[enc_dest
];
11406 re
= re_enc
[enc_dest
];
11407 rs
= rs_rt_enc
[enc_rs
];
11408 rt
= rs_rt_enc
[enc_rt
];
11410 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11411 gen_arith_imm(env
, ctx
, OPC_ADDIU
, re
, rt
, 0);
11416 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11417 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11418 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11419 offset
= (offset
== 0xf ? -1 : offset
);
11421 gen_ld(env
, ctx
, OPC_LBU
, rd
, rb
, offset
);
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) << 1;
11430 gen_ld(env
, ctx
, OPC_LHU
, rd
, rb
, offset
);
11435 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11436 int rb
= 29; /* SP */
11437 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11439 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11444 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11445 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11446 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11448 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11453 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11454 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11455 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11457 gen_st(ctx
, OPC_SB
, rd
, rb
, offset
);
11462 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11463 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11464 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11466 gen_st(ctx
, OPC_SH
, rd
, rb
, offset
);
11471 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11472 int rb
= 29; /* SP */
11473 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11475 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11480 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11481 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11482 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11484 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11489 int rd
= uMIPS_RD5(ctx
->opcode
);
11490 int rs
= uMIPS_RS5(ctx
->opcode
);
11492 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11496 gen_andi16(env
, ctx
);
11499 switch (ctx
->opcode
& 0x1) {
11501 gen_addius5(env
, ctx
);
11504 gen_addiusp(env
, ctx
);
11509 switch (ctx
->opcode
& 0x1) {
11511 gen_addiur2(env
, ctx
);
11514 gen_addiur1sp(env
, ctx
);
11519 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0,
11520 SIMM(ctx
->opcode
, 0, 10) << 1);
11525 gen_compute_branch(ctx
, op
== BNEZ16
? OPC_BNE
: OPC_BEQ
, 2,
11526 mmreg(uMIPS_RD(ctx
->opcode
)),
11527 0, SIMM(ctx
->opcode
, 0, 7) << 1);
11532 int reg
= mmreg(uMIPS_RD(ctx
->opcode
));
11533 int imm
= ZIMM(ctx
->opcode
, 0, 7);
11535 imm
= (imm
== 0x7f ? -1 : imm
);
11536 tcg_gen_movi_tl(cpu_gpr
[reg
], imm
);
11546 generate_exception(ctx
, EXCP_RI
);
11549 decode_micromips32_opc (env
, ctx
, op
, is_branch
);
11556 /* SmartMIPS extension to MIPS32 */
11558 #if defined(TARGET_MIPS64)
11560 /* MDMX extension to MIPS64 */
11564 static void decode_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
11567 int rs
, rt
, rd
, sa
;
11568 uint32_t op
, op1
, op2
;
11571 /* make sure instructions are on a word boundary */
11572 if (ctx
->pc
& 0x3) {
11573 env
->CP0_BadVAddr
= ctx
->pc
;
11574 generate_exception(ctx
, EXCP_AdEL
);
11578 /* Handle blikely not taken case */
11579 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
11580 int l1
= gen_new_label();
11582 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
11583 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
11584 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
11585 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
11589 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
11590 tcg_gen_debug_insn_start(ctx
->pc
);
11592 op
= MASK_OP_MAJOR(ctx
->opcode
);
11593 rs
= (ctx
->opcode
>> 21) & 0x1f;
11594 rt
= (ctx
->opcode
>> 16) & 0x1f;
11595 rd
= (ctx
->opcode
>> 11) & 0x1f;
11596 sa
= (ctx
->opcode
>> 6) & 0x1f;
11597 imm
= (int16_t)ctx
->opcode
;
11600 op1
= MASK_SPECIAL(ctx
->opcode
);
11602 case OPC_SLL
: /* Shift with immediate */
11604 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11607 switch ((ctx
->opcode
>> 21) & 0x1f) {
11609 /* rotr is decoded as srl on non-R2 CPUs */
11610 if (env
->insn_flags
& ISA_MIPS32R2
) {
11615 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11618 generate_exception(ctx
, EXCP_RI
);
11622 case OPC_MOVN
: /* Conditional move */
11624 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
|
11625 INSN_LOONGSON2E
| INSN_LOONGSON2F
);
11626 gen_cond_move(env
, op1
, rd
, rs
, rt
);
11628 case OPC_ADD
... OPC_SUBU
:
11629 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11631 case OPC_SLLV
: /* Shifts */
11633 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11636 switch ((ctx
->opcode
>> 6) & 0x1f) {
11638 /* rotrv is decoded as srlv on non-R2 CPUs */
11639 if (env
->insn_flags
& ISA_MIPS32R2
) {
11644 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11647 generate_exception(ctx
, EXCP_RI
);
11651 case OPC_SLT
: /* Set on less than */
11653 gen_slt(env
, op1
, rd
, rs
, rt
);
11655 case OPC_AND
: /* Logic*/
11659 gen_logic(env
, op1
, rd
, rs
, rt
);
11661 case OPC_MULT
... OPC_DIVU
:
11663 check_insn(env
, ctx
, INSN_VR54XX
);
11664 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
11665 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
11667 gen_muldiv(ctx
, op1
, rs
, rt
);
11669 case OPC_JR
... OPC_JALR
:
11670 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
11673 case OPC_TGE
... OPC_TEQ
: /* Traps */
11675 gen_trap(ctx
, op1
, rs
, rt
, -1);
11677 case OPC_MFHI
: /* Move from HI/LO */
11679 gen_HILO(ctx
, op1
, rd
);
11682 case OPC_MTLO
: /* Move to HI/LO */
11683 gen_HILO(ctx
, op1
, rs
);
11685 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
11686 #ifdef MIPS_STRICT_STANDARD
11687 MIPS_INVAL("PMON / selsl");
11688 generate_exception(ctx
, EXCP_RI
);
11690 gen_helper_0i(pmon
, sa
);
11694 generate_exception(ctx
, EXCP_SYSCALL
);
11695 ctx
->bstate
= BS_STOP
;
11698 generate_exception(ctx
, EXCP_BREAK
);
11701 #ifdef MIPS_STRICT_STANDARD
11702 MIPS_INVAL("SPIM");
11703 generate_exception(ctx
, EXCP_RI
);
11705 /* Implemented as RI exception for now. */
11706 MIPS_INVAL("spim (unofficial)");
11707 generate_exception(ctx
, EXCP_RI
);
11711 /* Treat as NOP. */
11715 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
11716 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
11717 check_cp1_enabled(ctx
);
11718 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
11719 (ctx
->opcode
>> 16) & 1);
11721 generate_exception_err(ctx
, EXCP_CpU
, 1);
11725 #if defined(TARGET_MIPS64)
11726 /* MIPS64 specific opcodes */
11731 check_insn(env
, ctx
, ISA_MIPS3
);
11732 check_mips_64(ctx
);
11733 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11736 switch ((ctx
->opcode
>> 21) & 0x1f) {
11738 /* drotr is decoded as dsrl on non-R2 CPUs */
11739 if (env
->insn_flags
& ISA_MIPS32R2
) {
11744 check_insn(env
, ctx
, ISA_MIPS3
);
11745 check_mips_64(ctx
);
11746 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11749 generate_exception(ctx
, EXCP_RI
);
11754 switch ((ctx
->opcode
>> 21) & 0x1f) {
11756 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
11757 if (env
->insn_flags
& ISA_MIPS32R2
) {
11762 check_insn(env
, ctx
, ISA_MIPS3
);
11763 check_mips_64(ctx
);
11764 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11767 generate_exception(ctx
, EXCP_RI
);
11771 case OPC_DADD
... OPC_DSUBU
:
11772 check_insn(env
, ctx
, ISA_MIPS3
);
11773 check_mips_64(ctx
);
11774 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11778 check_insn(env
, ctx
, ISA_MIPS3
);
11779 check_mips_64(ctx
);
11780 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11783 switch ((ctx
->opcode
>> 6) & 0x1f) {
11785 /* drotrv is decoded as dsrlv on non-R2 CPUs */
11786 if (env
->insn_flags
& ISA_MIPS32R2
) {
11791 check_insn(env
, ctx
, ISA_MIPS3
);
11792 check_mips_64(ctx
);
11793 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11796 generate_exception(ctx
, EXCP_RI
);
11800 case OPC_DMULT
... OPC_DDIVU
:
11801 check_insn(env
, ctx
, ISA_MIPS3
);
11802 check_mips_64(ctx
);
11803 gen_muldiv(ctx
, op1
, rs
, rt
);
11806 default: /* Invalid */
11807 MIPS_INVAL("special");
11808 generate_exception(ctx
, EXCP_RI
);
11813 op1
= MASK_SPECIAL2(ctx
->opcode
);
11815 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
11816 case OPC_MSUB
... OPC_MSUBU
:
11817 check_insn(env
, ctx
, ISA_MIPS32
);
11818 gen_muldiv(ctx
, op1
, rs
, rt
);
11821 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11825 check_insn(env
, ctx
, ISA_MIPS32
);
11826 gen_cl(ctx
, op1
, rd
, rs
);
11829 /* XXX: not clear which exception should be raised
11830 * when in debug mode...
11832 check_insn(env
, ctx
, ISA_MIPS32
);
11833 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
11834 generate_exception(ctx
, EXCP_DBp
);
11836 generate_exception(ctx
, EXCP_DBp
);
11838 /* Treat as NOP. */
11841 case OPC_DIVU_G_2F
:
11842 case OPC_MULT_G_2F
:
11843 case OPC_MULTU_G_2F
:
11845 case OPC_MODU_G_2F
:
11846 check_insn(env
, ctx
, INSN_LOONGSON2F
);
11847 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11849 #if defined(TARGET_MIPS64)
11852 check_insn(env
, ctx
, ISA_MIPS64
);
11853 check_mips_64(ctx
);
11854 gen_cl(ctx
, op1
, rd
, rs
);
11856 case OPC_DMULT_G_2F
:
11857 case OPC_DMULTU_G_2F
:
11858 case OPC_DDIV_G_2F
:
11859 case OPC_DDIVU_G_2F
:
11860 case OPC_DMOD_G_2F
:
11861 case OPC_DMODU_G_2F
:
11862 check_insn(env
, ctx
, INSN_LOONGSON2F
);
11863 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11866 default: /* Invalid */
11867 MIPS_INVAL("special2");
11868 generate_exception(ctx
, EXCP_RI
);
11873 op1
= MASK_SPECIAL3(ctx
->opcode
);
11877 check_insn(env
, ctx
, ISA_MIPS32R2
);
11878 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
11881 check_insn(env
, ctx
, ISA_MIPS32R2
);
11882 op2
= MASK_BSHFL(ctx
->opcode
);
11883 gen_bshfl(ctx
, op2
, rt
, rd
);
11886 gen_rdhwr(env
, ctx
, rt
, rd
);
11889 check_insn(env
, ctx
, ASE_MT
);
11891 TCGv t0
= tcg_temp_new();
11892 TCGv t1
= tcg_temp_new();
11894 gen_load_gpr(t0
, rt
);
11895 gen_load_gpr(t1
, rs
);
11896 gen_helper_fork(t0
, t1
);
11902 check_insn(env
, ctx
, ASE_MT
);
11904 TCGv t0
= tcg_temp_new();
11906 save_cpu_state(ctx
, 1);
11907 gen_load_gpr(t0
, rs
);
11908 gen_helper_yield(t0
, t0
);
11909 gen_store_gpr(t0
, rd
);
11913 case OPC_DIV_G_2E
... OPC_DIVU_G_2E
:
11914 case OPC_MULT_G_2E
... OPC_MULTU_G_2E
:
11915 case OPC_MOD_G_2E
... OPC_MODU_G_2E
:
11916 check_insn(env
, ctx
, INSN_LOONGSON2E
);
11917 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11919 #if defined(TARGET_MIPS64)
11920 case OPC_DEXTM
... OPC_DEXT
:
11921 case OPC_DINSM
... OPC_DINS
:
11922 check_insn(env
, ctx
, ISA_MIPS64R2
);
11923 check_mips_64(ctx
);
11924 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
11927 check_insn(env
, ctx
, ISA_MIPS64R2
);
11928 check_mips_64(ctx
);
11929 op2
= MASK_DBSHFL(ctx
->opcode
);
11930 gen_bshfl(ctx
, op2
, rt
, rd
);
11932 case OPC_DDIV_G_2E
... OPC_DDIVU_G_2E
:
11933 case OPC_DMULT_G_2E
... OPC_DMULTU_G_2E
:
11934 case OPC_DMOD_G_2E
... OPC_DMODU_G_2E
:
11935 check_insn(env
, ctx
, INSN_LOONGSON2E
);
11936 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
11939 default: /* Invalid */
11940 MIPS_INVAL("special3");
11941 generate_exception(ctx
, EXCP_RI
);
11946 op1
= MASK_REGIMM(ctx
->opcode
);
11948 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
11949 case OPC_BLTZAL
... OPC_BGEZALL
:
11950 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
11953 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
11955 gen_trap(ctx
, op1
, rs
, -1, imm
);
11958 check_insn(env
, ctx
, ISA_MIPS32R2
);
11959 /* Treat as NOP. */
11961 default: /* Invalid */
11962 MIPS_INVAL("regimm");
11963 generate_exception(ctx
, EXCP_RI
);
11968 check_cp0_enabled(ctx
);
11969 op1
= MASK_CP0(ctx
->opcode
);
11975 #if defined(TARGET_MIPS64)
11979 #ifndef CONFIG_USER_ONLY
11980 gen_cp0(env
, ctx
, op1
, rt
, rd
);
11981 #endif /* !CONFIG_USER_ONLY */
11983 case OPC_C0_FIRST
... OPC_C0_LAST
:
11984 #ifndef CONFIG_USER_ONLY
11985 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
11986 #endif /* !CONFIG_USER_ONLY */
11989 #ifndef CONFIG_USER_ONLY
11991 TCGv t0
= tcg_temp_new();
11993 op2
= MASK_MFMC0(ctx
->opcode
);
11996 check_insn(env
, ctx
, ASE_MT
);
11997 gen_helper_dmt(t0
, t0
);
11998 gen_store_gpr(t0
, rt
);
12001 check_insn(env
, ctx
, ASE_MT
);
12002 gen_helper_emt(t0
, t0
);
12003 gen_store_gpr(t0
, rt
);
12006 check_insn(env
, ctx
, ASE_MT
);
12007 gen_helper_dvpe(t0
, t0
);
12008 gen_store_gpr(t0
, rt
);
12011 check_insn(env
, ctx
, ASE_MT
);
12012 gen_helper_evpe(t0
, t0
);
12013 gen_store_gpr(t0
, rt
);
12016 check_insn(env
, ctx
, ISA_MIPS32R2
);
12017 save_cpu_state(ctx
, 1);
12019 gen_store_gpr(t0
, rt
);
12020 /* Stop translation as we may have switched the execution mode */
12021 ctx
->bstate
= BS_STOP
;
12024 check_insn(env
, ctx
, ISA_MIPS32R2
);
12025 save_cpu_state(ctx
, 1);
12027 gen_store_gpr(t0
, rt
);
12028 /* Stop translation as we may have switched the execution mode */
12029 ctx
->bstate
= BS_STOP
;
12031 default: /* Invalid */
12032 MIPS_INVAL("mfmc0");
12033 generate_exception(ctx
, EXCP_RI
);
12038 #endif /* !CONFIG_USER_ONLY */
12041 check_insn(env
, ctx
, ISA_MIPS32R2
);
12042 gen_load_srsgpr(rt
, rd
);
12045 check_insn(env
, ctx
, ISA_MIPS32R2
);
12046 gen_store_srsgpr(rt
, rd
);
12050 generate_exception(ctx
, EXCP_RI
);
12054 case OPC_ADDI
: /* Arithmetic with immediate opcode */
12056 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
12058 case OPC_SLTI
: /* Set on less than with immediate opcode */
12060 gen_slt_imm(env
, op
, rt
, rs
, imm
);
12062 case OPC_ANDI
: /* Arithmetic with immediate opcode */
12066 gen_logic_imm(env
, op
, rt
, rs
, imm
);
12068 case OPC_J
... OPC_JAL
: /* Jump */
12069 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
12070 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
12073 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
12074 case OPC_BEQL
... OPC_BGTZL
:
12075 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
12078 case OPC_LB
... OPC_LWR
: /* Load and stores */
12080 gen_ld(env
, ctx
, op
, rt
, rs
, imm
);
12082 case OPC_SB
... OPC_SW
:
12084 gen_st(ctx
, op
, rt
, rs
, imm
);
12087 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
12090 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
12091 /* Treat as NOP. */
12094 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
12095 /* Treat as NOP. */
12098 /* Floating point (COP1). */
12103 gen_cop1_ldst(env
, ctx
, op
, rt
, rs
, imm
);
12107 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12108 check_cp1_enabled(ctx
);
12109 op1
= MASK_CP1(ctx
->opcode
);
12113 check_insn(env
, ctx
, ISA_MIPS32R2
);
12118 gen_cp1(ctx
, op1
, rt
, rd
);
12120 #if defined(TARGET_MIPS64)
12123 check_insn(env
, ctx
, ISA_MIPS3
);
12124 gen_cp1(ctx
, op1
, rt
, rd
);
12130 check_insn(env
, ctx
, ASE_MIPS3D
);
12133 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
12134 (rt
>> 2) & 0x7, imm
<< 2);
12142 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
12147 generate_exception (ctx
, EXCP_RI
);
12151 generate_exception_err(ctx
, EXCP_CpU
, 1);
12161 /* COP2: Not implemented. */
12162 generate_exception_err(ctx
, EXCP_CpU
, 2);
12166 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12167 check_cp1_enabled(ctx
);
12168 op1
= MASK_CP3(ctx
->opcode
);
12176 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
12179 /* Treat as NOP. */
12194 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
12198 generate_exception (ctx
, EXCP_RI
);
12202 generate_exception_err(ctx
, EXCP_CpU
, 1);
12206 #if defined(TARGET_MIPS64)
12207 /* MIPS64 opcodes */
12209 case OPC_LDL
... OPC_LDR
:
12212 check_insn(env
, ctx
, ISA_MIPS3
);
12213 check_mips_64(ctx
);
12214 gen_ld(env
, ctx
, op
, rt
, rs
, imm
);
12216 case OPC_SDL
... OPC_SDR
:
12218 check_insn(env
, ctx
, ISA_MIPS3
);
12219 check_mips_64(ctx
);
12220 gen_st(ctx
, op
, rt
, rs
, imm
);
12223 check_insn(env
, ctx
, ISA_MIPS3
);
12224 check_mips_64(ctx
);
12225 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
12229 check_insn(env
, ctx
, ISA_MIPS3
);
12230 check_mips_64(ctx
);
12231 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
12235 check_insn(env
, ctx
, ASE_MIPS16
| ASE_MICROMIPS
);
12236 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
12237 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
12241 check_insn(env
, ctx
, ASE_MDMX
);
12242 /* MDMX: Not implemented. */
12243 default: /* Invalid */
12244 MIPS_INVAL("major opcode");
12245 generate_exception(ctx
, EXCP_RI
);
12251 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
12255 target_ulong pc_start
;
12256 uint16_t *gen_opc_end
;
12265 qemu_log("search pc %d\n", search_pc
);
12268 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
12271 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
12273 ctx
.bstate
= BS_NONE
;
12274 /* Restore delay slot state from the tb context. */
12275 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
12276 restore_cpu_state(env
, &ctx
);
12277 #ifdef CONFIG_USER_ONLY
12278 ctx
.mem_idx
= MIPS_HFLAG_UM
;
12280 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
12283 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
12284 if (max_insns
== 0)
12285 max_insns
= CF_COUNT_MASK
;
12286 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
12287 gen_icount_start();
12288 while (ctx
.bstate
== BS_NONE
) {
12289 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
12290 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
12291 if (bp
->pc
== ctx
.pc
) {
12292 save_cpu_state(&ctx
, 1);
12293 ctx
.bstate
= BS_BRANCH
;
12294 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
12295 /* Include the breakpoint location or the tb won't
12296 * be flushed when it must be. */
12298 goto done_generating
;
12304 j
= gen_opc_ptr
- gen_opc_buf
;
12308 gen_opc_instr_start
[lj
++] = 0;
12310 gen_opc_pc
[lj
] = ctx
.pc
;
12311 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
12312 gen_opc_instr_start
[lj
] = 1;
12313 gen_opc_icount
[lj
] = num_insns
;
12315 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
12319 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
12320 ctx
.opcode
= ldl_code(ctx
.pc
);
12322 decode_opc(env
, &ctx
, &is_branch
);
12323 } else if (env
->insn_flags
& ASE_MICROMIPS
) {
12324 ctx
.opcode
= lduw_code(ctx
.pc
);
12325 insn_bytes
= decode_micromips_opc(env
, &ctx
, &is_branch
);
12326 } else if (env
->insn_flags
& ASE_MIPS16
) {
12327 ctx
.opcode
= lduw_code(ctx
.pc
);
12328 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
12330 generate_exception(&ctx
, EXCP_RI
);
12331 ctx
.bstate
= BS_STOP
;
12335 handle_delay_slot(env
, &ctx
, insn_bytes
);
12337 ctx
.pc
+= insn_bytes
;
12341 /* Execute a branch and its delay slot as a single instruction.
12342 This is what GDB expects and is consistent with what the
12343 hardware does (e.g. if a delay slot instruction faults, the
12344 reported PC is the PC of the branch). */
12345 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
12348 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
12351 if (gen_opc_ptr
>= gen_opc_end
)
12354 if (num_insns
>= max_insns
)
12360 if (tb
->cflags
& CF_LAST_IO
)
12362 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
12363 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
12364 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
12366 switch (ctx
.bstate
) {
12368 gen_helper_interrupt_restart();
12369 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12372 save_cpu_state(&ctx
, 0);
12373 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12376 gen_helper_interrupt_restart();
12377 tcg_gen_exit_tb(0);
12385 gen_icount_end(tb
, num_insns
);
12386 *gen_opc_ptr
= INDEX_op_end
;
12388 j
= gen_opc_ptr
- gen_opc_buf
;
12391 gen_opc_instr_start
[lj
++] = 0;
12393 tb
->size
= ctx
.pc
- pc_start
;
12394 tb
->icount
= num_insns
;
12398 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
12399 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
12400 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
12406 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
12408 gen_intermediate_code_internal(env
, tb
, 0);
12411 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
12413 gen_intermediate_code_internal(env
, tb
, 1);
12416 static void fpu_dump_state(CPUState
*env
, FILE *f
,
12417 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12421 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
12423 #define printfpr(fp) \
12426 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12427 " fd:%13g fs:%13g psu: %13g\n", \
12428 (fp)->w[FP_ENDIAN_IDX], (fp)->d, \
12429 (double)(fp)->fd, \
12430 (double)(fp)->fs[FP_ENDIAN_IDX], \
12431 (double)(fp)->fs[!FP_ENDIAN_IDX]); \
12434 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
12435 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
12436 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12437 " fd:%13g fs:%13g psu:%13g\n", \
12438 tmp.w[FP_ENDIAN_IDX], tmp.d, \
12440 (double)tmp.fs[FP_ENDIAN_IDX], \
12441 (double)tmp.fs[!FP_ENDIAN_IDX]); \
12446 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
12447 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
12448 get_float_exception_flags(&env
->active_fpu
.fp_status
));
12449 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
12450 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
12451 printfpr(&env
->active_fpu
.fpr
[i
]);
12457 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12458 /* Debug help: The architecture requires 32bit code to maintain proper
12459 sign-extended values on 64bit machines. */
12461 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
12464 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
12465 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12470 if (!SIGN_EXT_P(env
->active_tc
.PC
))
12471 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
12472 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
12473 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
12474 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
12475 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
12476 if (!SIGN_EXT_P(env
->btarget
))
12477 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
12479 for (i
= 0; i
< 32; i
++) {
12480 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
12481 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
12484 if (!SIGN_EXT_P(env
->CP0_EPC
))
12485 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
12486 if (!SIGN_EXT_P(env
->lladdr
))
12487 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
12491 void cpu_dump_state (CPUState
*env
, FILE *f
,
12492 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12497 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
12498 " LO=0x" TARGET_FMT_lx
" ds %04x "
12499 TARGET_FMT_lx
" " TARGET_FMT_ld
"\n",
12500 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
12501 env
->hflags
, env
->btarget
, env
->bcond
);
12502 for (i
= 0; i
< 32; i
++) {
12504 cpu_fprintf(f
, "GPR%02d:", i
);
12505 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
12507 cpu_fprintf(f
, "\n");
12510 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
12511 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
12512 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
12513 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
12514 if (env
->hflags
& MIPS_HFLAG_FPU
)
12515 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
12516 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12517 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
12521 static void mips_tcg_init(void)
12526 /* Initialize various static tables. */
12530 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
12531 TCGV_UNUSED(cpu_gpr
[0]);
12532 for (i
= 1; i
< 32; i
++)
12533 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
12534 offsetof(CPUState
, active_tc
.gpr
[i
]),
12536 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
12537 offsetof(CPUState
, active_tc
.PC
), "PC");
12538 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
12539 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
12540 offsetof(CPUState
, active_tc
.HI
[i
]),
12542 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
12543 offsetof(CPUState
, active_tc
.LO
[i
]),
12545 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
12546 offsetof(CPUState
, active_tc
.ACX
[i
]),
12549 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
12550 offsetof(CPUState
, active_tc
.DSPControl
),
12552 bcond
= tcg_global_mem_new(TCG_AREG0
,
12553 offsetof(CPUState
, bcond
), "bcond");
12554 btarget
= tcg_global_mem_new(TCG_AREG0
,
12555 offsetof(CPUState
, btarget
), "btarget");
12556 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
12557 offsetof(CPUState
, hflags
), "hflags");
12559 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
12560 offsetof(CPUState
, active_fpu
.fcr0
),
12562 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
12563 offsetof(CPUState
, active_fpu
.fcr31
),
12566 /* register helpers */
12567 #define GEN_HELPER 2
12568 #include "helper.h"
12573 #include "translate_init.c"
12575 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
12578 const mips_def_t
*def
;
12580 def
= cpu_mips_find_by_name(cpu_model
);
12583 env
= qemu_mallocz(sizeof(CPUMIPSState
));
12584 env
->cpu_model
= def
;
12585 env
->cpu_model_str
= cpu_model
;
12587 cpu_exec_init(env
);
12588 #ifndef CONFIG_USER_ONLY
12589 mmu_init(env
, def
);
12591 fpu_init(env
, def
);
12592 mvp_init(env
, def
);
12595 qemu_init_vcpu(env
);
12599 void cpu_reset (CPUMIPSState
*env
)
12601 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
12602 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
12603 log_cpu_state(env
, 0);
12606 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
12609 /* Reset registers to their default values */
12610 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
12611 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
12612 #ifdef TARGET_WORDS_BIGENDIAN
12613 env
->CP0_Config0
|= (1 << CP0C0_BE
);
12615 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
12616 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
12617 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
12618 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
12619 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
12620 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
12621 << env
->cpu_model
->CP0_LLAddr_shift
;
12622 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
12623 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
12624 env
->CCRes
= env
->cpu_model
->CCRes
;
12625 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
12626 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
12627 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
12628 env
->current_tc
= 0;
12629 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
12630 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
12631 #if defined(TARGET_MIPS64)
12632 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12633 env
->SEGMask
|= 3ULL << 62;
12636 env
->PABITS
= env
->cpu_model
->PABITS
;
12637 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
12638 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
12639 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
12640 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
12641 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
12642 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
12643 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
12644 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
12645 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
12646 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
12647 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
12648 env
->insn_flags
= env
->cpu_model
->insn_flags
;
12650 #if defined(CONFIG_USER_ONLY)
12651 env
->hflags
= MIPS_HFLAG_UM
;
12652 /* Enable access to the SYNCI_Step register. */
12653 env
->CP0_HWREna
|= (1 << 1);
12654 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12655 env
->hflags
|= MIPS_HFLAG_FPU
;
12657 #ifdef TARGET_MIPS64
12658 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
12659 env
->hflags
|= MIPS_HFLAG_F64
;
12663 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
12664 /* If the exception was raised from a delay slot,
12665 come back to the jump. */
12666 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
12668 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
12670 env
->active_tc
.PC
= (int32_t)0xBFC00000;
12671 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
12672 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
12673 env
->CP0_Wired
= 0;
12674 /* SMP not implemented */
12675 env
->CP0_EBase
= 0x80000000;
12676 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
12677 /* vectored interrupts not implemented, timer on int 7,
12678 no performance counters. */
12679 env
->CP0_IntCtl
= 0xe0000000;
12683 for (i
= 0; i
< 7; i
++) {
12684 env
->CP0_WatchLo
[i
] = 0;
12685 env
->CP0_WatchHi
[i
] = 0x80000000;
12687 env
->CP0_WatchLo
[7] = 0;
12688 env
->CP0_WatchHi
[7] = 0;
12690 /* Count register increments in debug mode, EJTAG version 1 */
12691 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
12692 env
->hflags
= MIPS_HFLAG_CP0
;
12694 #if defined(TARGET_MIPS64)
12695 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12696 env
->hflags
|= MIPS_HFLAG_64
;
12699 env
->exception_index
= EXCP_NONE
;
12702 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
12703 unsigned long searched_pc
, int pc_pos
, void *puc
)
12705 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
12706 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
12707 env
->hflags
|= gen_opc_hflags
[pc_pos
];