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_CLZ
= 0x20 | OPC_SPECIAL2
,
272 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
273 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
274 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
276 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
279 /* Special3 opcodes */
280 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
283 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
284 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
285 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
286 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
287 OPC_INS
= 0x04 | OPC_SPECIAL3
,
288 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
289 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
290 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
291 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
292 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
293 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
294 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
295 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
299 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
302 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
303 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
304 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
308 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
311 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
312 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
315 /* Coprocessor 0 (rs field) */
316 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
319 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
320 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
321 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
322 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
323 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
324 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
325 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
326 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
327 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
328 OPC_C0
= (0x10 << 21) | OPC_CP0
,
329 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
330 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
334 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
337 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
338 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
339 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
340 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
341 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
342 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
345 /* Coprocessor 0 (with rs == C0) */
346 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
349 OPC_TLBR
= 0x01 | OPC_C0
,
350 OPC_TLBWI
= 0x02 | OPC_C0
,
351 OPC_TLBWR
= 0x06 | OPC_C0
,
352 OPC_TLBP
= 0x08 | OPC_C0
,
353 OPC_RFE
= 0x10 | OPC_C0
,
354 OPC_ERET
= 0x18 | OPC_C0
,
355 OPC_DERET
= 0x1F | OPC_C0
,
356 OPC_WAIT
= 0x20 | OPC_C0
,
359 /* Coprocessor 1 (rs field) */
360 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
362 /* Values for the fmt field in FP instructions */
364 /* 0 - 15 are reserved */
365 FMT_S
= 16, /* single fp */
366 FMT_D
= 17, /* double fp */
367 FMT_E
= 18, /* extended fp */
368 FMT_Q
= 19, /* quad fp */
369 FMT_W
= 20, /* 32-bit fixed */
370 FMT_L
= 21, /* 64-bit fixed */
371 FMT_PS
= 22, /* paired single fp */
372 /* 23 - 31 are reserved */
376 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
377 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
378 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
379 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
380 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
381 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
382 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
383 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
384 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
385 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
386 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
387 OPC_S_FMT
= (FMT_S
<< 21) | OPC_CP1
,
388 OPC_D_FMT
= (FMT_D
<< 21) | OPC_CP1
,
389 OPC_E_FMT
= (FMT_E
<< 21) | OPC_CP1
,
390 OPC_Q_FMT
= (FMT_Q
<< 21) | OPC_CP1
,
391 OPC_W_FMT
= (FMT_W
<< 21) | OPC_CP1
,
392 OPC_L_FMT
= (FMT_L
<< 21) | OPC_CP1
,
393 OPC_PS_FMT
= (FMT_PS
<< 21) | OPC_CP1
,
396 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
397 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
400 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
401 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
402 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
403 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
407 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
408 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
412 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
413 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
416 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
419 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
420 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
421 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
422 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
423 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
424 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
425 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
426 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
427 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
430 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
433 OPC_LWXC1
= 0x00 | OPC_CP3
,
434 OPC_LDXC1
= 0x01 | OPC_CP3
,
435 OPC_LUXC1
= 0x05 | OPC_CP3
,
436 OPC_SWXC1
= 0x08 | OPC_CP3
,
437 OPC_SDXC1
= 0x09 | OPC_CP3
,
438 OPC_SUXC1
= 0x0D | OPC_CP3
,
439 OPC_PREFX
= 0x0F | OPC_CP3
,
440 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
441 OPC_MADD_S
= 0x20 | OPC_CP3
,
442 OPC_MADD_D
= 0x21 | OPC_CP3
,
443 OPC_MADD_PS
= 0x26 | OPC_CP3
,
444 OPC_MSUB_S
= 0x28 | OPC_CP3
,
445 OPC_MSUB_D
= 0x29 | OPC_CP3
,
446 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
447 OPC_NMADD_S
= 0x30 | OPC_CP3
,
448 OPC_NMADD_D
= 0x31 | OPC_CP3
,
449 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
450 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
451 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
452 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
455 /* global register indices */
456 static TCGv_ptr cpu_env
;
457 static TCGv cpu_gpr
[32], cpu_PC
;
458 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
459 static TCGv cpu_dspctrl
, btarget
, bcond
;
460 static TCGv_i32 hflags
;
461 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
463 static uint32_t gen_opc_hflags
[OPC_BUF_SIZE
];
465 #include "gen-icount.h"
467 #define gen_helper_0i(name, arg) do { \
468 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
469 gen_helper_##name(helper_tmp); \
470 tcg_temp_free_i32(helper_tmp); \
473 #define gen_helper_1i(name, arg1, arg2) do { \
474 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
475 gen_helper_##name(arg1, helper_tmp); \
476 tcg_temp_free_i32(helper_tmp); \
479 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
480 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
481 gen_helper_##name(arg1, arg2, helper_tmp); \
482 tcg_temp_free_i32(helper_tmp); \
485 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
486 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
487 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
488 tcg_temp_free_i32(helper_tmp); \
491 typedef struct DisasContext
{
492 struct TranslationBlock
*tb
;
493 target_ulong pc
, saved_pc
;
495 int singlestep_enabled
;
496 /* Routine used to access memory */
498 uint32_t hflags
, saved_hflags
;
500 target_ulong btarget
;
504 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
505 * exception condition */
506 BS_STOP
= 1, /* We want to stop translation for any reason */
507 BS_BRANCH
= 2, /* We reached a branch condition */
508 BS_EXCP
= 3, /* We reached an exception condition */
511 static const char *regnames
[] =
512 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
513 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
514 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
515 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
517 static const char *regnames_HI
[] =
518 { "HI0", "HI1", "HI2", "HI3", };
520 static const char *regnames_LO
[] =
521 { "LO0", "LO1", "LO2", "LO3", };
523 static const char *regnames_ACX
[] =
524 { "ACX0", "ACX1", "ACX2", "ACX3", };
526 static const char *fregnames
[] =
527 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
528 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
529 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
530 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
532 #ifdef MIPS_DEBUG_DISAS
533 #define MIPS_DEBUG(fmt, ...) \
534 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
535 TARGET_FMT_lx ": %08x " fmt "\n", \
536 ctx->pc, ctx->opcode , ## __VA_ARGS__)
537 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
539 #define MIPS_DEBUG(fmt, ...) do { } while(0)
540 #define LOG_DISAS(...) do { } while (0)
543 #define MIPS_INVAL(op) \
545 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
546 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
549 /* General purpose registers moves. */
550 static inline void gen_load_gpr (TCGv t
, int reg
)
553 tcg_gen_movi_tl(t
, 0);
555 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
558 static inline void gen_store_gpr (TCGv t
, int reg
)
561 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
564 /* Moves to/from ACX register. */
565 static inline void gen_load_ACX (TCGv t
, int reg
)
567 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
570 static inline void gen_store_ACX (TCGv t
, int reg
)
572 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
575 /* Moves to/from shadow registers. */
576 static inline void gen_load_srsgpr (int from
, int to
)
578 TCGv t0
= tcg_temp_new();
581 tcg_gen_movi_tl(t0
, 0);
583 TCGv_i32 t2
= tcg_temp_new_i32();
584 TCGv_ptr addr
= tcg_temp_new_ptr();
586 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
587 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
588 tcg_gen_andi_i32(t2
, t2
, 0xf);
589 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
590 tcg_gen_ext_i32_ptr(addr
, t2
);
591 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
593 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
594 tcg_temp_free_ptr(addr
);
595 tcg_temp_free_i32(t2
);
597 gen_store_gpr(t0
, to
);
601 static inline void gen_store_srsgpr (int from
, int to
)
604 TCGv t0
= tcg_temp_new();
605 TCGv_i32 t2
= tcg_temp_new_i32();
606 TCGv_ptr addr
= tcg_temp_new_ptr();
608 gen_load_gpr(t0
, from
);
609 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
610 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
611 tcg_gen_andi_i32(t2
, t2
, 0xf);
612 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
613 tcg_gen_ext_i32_ptr(addr
, t2
);
614 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
616 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
617 tcg_temp_free_ptr(addr
);
618 tcg_temp_free_i32(t2
);
623 /* Floating point register moves. */
624 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
626 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
629 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
631 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
634 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
636 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
639 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
641 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
644 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
646 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
647 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
649 TCGv_i32 t0
= tcg_temp_new_i32();
650 TCGv_i32 t1
= tcg_temp_new_i32();
651 gen_load_fpr32(t0
, reg
& ~1);
652 gen_load_fpr32(t1
, reg
| 1);
653 tcg_gen_concat_i32_i64(t
, t0
, t1
);
654 tcg_temp_free_i32(t0
);
655 tcg_temp_free_i32(t1
);
659 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
661 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
662 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
664 TCGv_i64 t0
= tcg_temp_new_i64();
665 TCGv_i32 t1
= tcg_temp_new_i32();
666 tcg_gen_trunc_i64_i32(t1
, t
);
667 gen_store_fpr32(t1
, reg
& ~1);
668 tcg_gen_shri_i64(t0
, t
, 32);
669 tcg_gen_trunc_i64_i32(t1
, t0
);
670 gen_store_fpr32(t1
, reg
| 1);
671 tcg_temp_free_i32(t1
);
672 tcg_temp_free_i64(t0
);
676 static inline int get_fp_bit (int cc
)
685 static inline void gen_save_pc(target_ulong pc
)
687 tcg_gen_movi_tl(cpu_PC
, pc
);
690 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
692 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
693 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
694 gen_save_pc(ctx
->pc
);
695 ctx
->saved_pc
= ctx
->pc
;
697 if (ctx
->hflags
!= ctx
->saved_hflags
) {
698 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
699 ctx
->saved_hflags
= ctx
->hflags
;
700 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
706 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
712 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
714 ctx
->saved_hflags
= ctx
->hflags
;
715 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
721 ctx
->btarget
= env
->btarget
;
727 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
729 TCGv_i32 texcp
= tcg_const_i32(excp
);
730 TCGv_i32 terr
= tcg_const_i32(err
);
731 save_cpu_state(ctx
, 1);
732 gen_helper_raise_exception_err(texcp
, terr
);
733 tcg_temp_free_i32(terr
);
734 tcg_temp_free_i32(texcp
);
738 generate_exception (DisasContext
*ctx
, int excp
)
740 save_cpu_state(ctx
, 1);
741 gen_helper_0i(raise_exception
, excp
);
744 /* Addresses computation */
745 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
747 tcg_gen_add_tl(ret
, arg0
, arg1
);
749 #if defined(TARGET_MIPS64)
750 /* For compatibility with 32-bit code, data reference in user mode
751 with Status_UX = 0 should be casted to 32-bit and sign extended.
752 See the MIPS64 PRA manual, section 4.10. */
753 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
754 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
755 tcg_gen_ext32s_i64(ret
, ret
);
760 static inline void check_cp0_enabled(DisasContext
*ctx
)
762 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
763 generate_exception_err(ctx
, EXCP_CpU
, 0);
766 static inline void check_cp1_enabled(DisasContext
*ctx
)
768 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
769 generate_exception_err(ctx
, EXCP_CpU
, 1);
772 /* Verify that the processor is running with COP1X instructions enabled.
773 This is associated with the nabla symbol in the MIPS32 and MIPS64
776 static inline void check_cop1x(DisasContext
*ctx
)
778 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
779 generate_exception(ctx
, EXCP_RI
);
782 /* Verify that the processor is running with 64-bit floating-point
783 operations enabled. */
785 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
787 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
788 generate_exception(ctx
, EXCP_RI
);
792 * Verify if floating point register is valid; an operation is not defined
793 * if bit 0 of any register specification is set and the FR bit in the
794 * Status register equals zero, since the register numbers specify an
795 * even-odd pair of adjacent coprocessor general registers. When the FR bit
796 * in the Status register equals one, both even and odd register numbers
797 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
799 * Multiple 64 bit wide registers can be checked by calling
800 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
802 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
804 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
805 generate_exception(ctx
, EXCP_RI
);
808 /* This code generates a "reserved instruction" exception if the
809 CPU does not support the instruction set corresponding to flags. */
810 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
812 if (unlikely(!(env
->insn_flags
& flags
)))
813 generate_exception(ctx
, EXCP_RI
);
816 /* This code generates a "reserved instruction" exception if 64-bit
817 instructions are not enabled. */
818 static inline void check_mips_64(DisasContext
*ctx
)
820 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
821 generate_exception(ctx
, EXCP_RI
);
824 /* Define small wrappers for gen_load_fpr* so that we have a uniform
825 calling interface for 32 and 64-bit FPRs. No sense in changing
826 all callers for gen_load_fpr32 when we need the CTX parameter for
828 #define gen_ldcmp_fpr32(ctx, x, y) gen_load_fpr32(x, y)
829 #define gen_ldcmp_fpr64(ctx, x, y) gen_load_fpr64(ctx, x, y)
830 #define FOP_CONDS(type, abs, fmt, ifmt, bits) \
831 static inline void gen_cmp ## type ## _ ## fmt(DisasContext *ctx, int n, \
832 int ft, int fs, int cc) \
834 TCGv_i##bits fp0 = tcg_temp_new_i##bits (); \
835 TCGv_i##bits fp1 = tcg_temp_new_i##bits (); \
838 check_cp1_64bitmode(ctx); \
844 check_cp1_registers(ctx, fs | ft); \
852 gen_ldcmp_fpr##bits (ctx, fp0, fs); \
853 gen_ldcmp_fpr##bits (ctx, fp1, ft); \
855 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, fp0, fp1, cc); break;\
856 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, fp0, fp1, cc); break;\
857 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, fp0, fp1, cc); break;\
858 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, fp0, fp1, cc); break;\
859 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, fp0, fp1, cc); break;\
860 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, fp0, fp1, cc); break;\
861 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, fp0, fp1, cc); break;\
862 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, fp0, fp1, cc); break;\
863 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, fp0, fp1, cc); break;\
864 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, fp0, fp1, cc); break;\
865 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, fp0, fp1, cc); break;\
866 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, fp0, fp1, cc); break;\
867 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, fp0, fp1, cc); break;\
868 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, fp0, fp1, cc); break;\
869 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, fp0, fp1, cc); break;\
870 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, fp0, fp1, cc); break;\
873 tcg_temp_free_i##bits (fp0); \
874 tcg_temp_free_i##bits (fp1); \
877 FOP_CONDS(, 0, d
, FMT_D
, 64)
878 FOP_CONDS(abs
, 1, d
, FMT_D
, 64)
879 FOP_CONDS(, 0, s
, FMT_S
, 32)
880 FOP_CONDS(abs
, 1, s
, FMT_S
, 32)
881 FOP_CONDS(, 0, ps
, FMT_PS
, 64)
882 FOP_CONDS(abs
, 1, ps
, FMT_PS
, 64)
884 #undef gen_ldcmp_fpr32
885 #undef gen_ldcmp_fpr64
887 /* load/store instructions. */
888 #define OP_LD(insn,fname) \
889 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
891 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
898 #if defined(TARGET_MIPS64)
904 #define OP_ST(insn,fname) \
905 static inline void op_st_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
907 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
912 #if defined(TARGET_MIPS64)
917 #ifdef CONFIG_USER_ONLY
918 #define OP_LD_ATOMIC(insn,fname) \
919 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
921 TCGv t0 = tcg_temp_new(); \
922 tcg_gen_mov_tl(t0, arg1); \
923 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
924 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
925 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
929 #define OP_LD_ATOMIC(insn,fname) \
930 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
932 gen_helper_2i(insn, ret, arg1, ctx->mem_idx); \
935 OP_LD_ATOMIC(ll
,ld32s
);
936 #if defined(TARGET_MIPS64)
937 OP_LD_ATOMIC(lld
,ld64
);
941 #ifdef CONFIG_USER_ONLY
942 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
943 static inline void op_st_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
945 TCGv t0 = tcg_temp_new(); \
946 int l1 = gen_new_label(); \
947 int l2 = gen_new_label(); \
949 tcg_gen_andi_tl(t0, arg2, almask); \
950 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
951 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
952 generate_exception(ctx, EXCP_AdES); \
954 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
955 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
956 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
957 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
958 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
959 gen_helper_0i(raise_exception, EXCP_SC); \
961 tcg_gen_movi_tl(t0, 0); \
962 gen_store_gpr(t0, rt); \
966 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
967 static inline void op_st_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
969 TCGv t0 = tcg_temp_new(); \
970 gen_helper_3i(insn, t0, arg1, arg2, ctx->mem_idx); \
971 gen_store_gpr(t0, rt); \
975 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
976 #if defined(TARGET_MIPS64)
977 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
981 static void gen_base_offset_addr (DisasContext
*ctx
, TCGv addr
,
982 int base
, int16_t offset
)
985 tcg_gen_movi_tl(addr
, offset
);
986 } else if (offset
== 0) {
987 gen_load_gpr(addr
, base
);
989 tcg_gen_movi_tl(addr
, offset
);
990 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
994 static target_ulong
pc_relative_pc (DisasContext
*ctx
)
996 target_ulong pc
= ctx
->pc
;
998 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
999 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
1004 pc
&= ~(target_ulong
)3;
1009 static void gen_ld (DisasContext
*ctx
, uint32_t opc
, int rt
,
1010 int base
, int16_t offset
)
1012 const char *opn
= "ld";
1013 TCGv t0
= tcg_temp_new();
1014 TCGv t1
= tcg_temp_new();
1016 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1017 /* Don't do NOP if destination is zero: we must perform the actual
1020 #if defined(TARGET_MIPS64)
1022 save_cpu_state(ctx
, 0);
1023 op_ld_lwu(t0
, t0
, ctx
);
1024 gen_store_gpr(t0
, rt
);
1028 save_cpu_state(ctx
, 0);
1029 op_ld_ld(t0
, t0
, ctx
);
1030 gen_store_gpr(t0
, rt
);
1034 save_cpu_state(ctx
, 0);
1035 op_ld_lld(t0
, t0
, ctx
);
1036 gen_store_gpr(t0
, rt
);
1040 save_cpu_state(ctx
, 1);
1041 gen_load_gpr(t1
, rt
);
1042 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1043 gen_store_gpr(t1
, rt
);
1047 save_cpu_state(ctx
, 1);
1048 gen_load_gpr(t1
, rt
);
1049 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1050 gen_store_gpr(t1
, rt
);
1054 save_cpu_state(ctx
, 1);
1055 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1056 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1057 op_ld_ld(t0
, t0
, ctx
);
1058 gen_store_gpr(t0
, rt
);
1063 save_cpu_state(ctx
, 1);
1064 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1065 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1066 op_ld_lw(t0
, t0
, ctx
);
1067 gen_store_gpr(t0
, rt
);
1071 save_cpu_state(ctx
, 0);
1072 op_ld_lw(t0
, t0
, ctx
);
1073 gen_store_gpr(t0
, rt
);
1077 save_cpu_state(ctx
, 0);
1078 op_ld_lh(t0
, t0
, ctx
);
1079 gen_store_gpr(t0
, rt
);
1083 save_cpu_state(ctx
, 0);
1084 op_ld_lhu(t0
, t0
, ctx
);
1085 gen_store_gpr(t0
, rt
);
1089 save_cpu_state(ctx
, 0);
1090 op_ld_lb(t0
, t0
, ctx
);
1091 gen_store_gpr(t0
, rt
);
1095 save_cpu_state(ctx
, 0);
1096 op_ld_lbu(t0
, t0
, ctx
);
1097 gen_store_gpr(t0
, rt
);
1101 save_cpu_state(ctx
, 1);
1102 gen_load_gpr(t1
, rt
);
1103 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1104 gen_store_gpr(t1
, rt
);
1108 save_cpu_state(ctx
, 1);
1109 gen_load_gpr(t1
, rt
);
1110 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1111 gen_store_gpr(t1
, rt
);
1115 save_cpu_state(ctx
, 1);
1116 op_ld_ll(t0
, t0
, ctx
);
1117 gen_store_gpr(t0
, rt
);
1121 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1127 static void gen_st (DisasContext
*ctx
, uint32_t opc
, int rt
,
1128 int base
, int16_t offset
)
1130 const char *opn
= "st";
1131 TCGv t0
= tcg_temp_new();
1132 TCGv t1
= tcg_temp_new();
1134 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1135 gen_load_gpr(t1
, rt
);
1137 #if defined(TARGET_MIPS64)
1139 save_cpu_state(ctx
, 0);
1140 op_st_sd(t1
, t0
, ctx
);
1144 save_cpu_state(ctx
, 1);
1145 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1149 save_cpu_state(ctx
, 1);
1150 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1155 save_cpu_state(ctx
, 0);
1156 op_st_sw(t1
, t0
, ctx
);
1160 save_cpu_state(ctx
, 0);
1161 op_st_sh(t1
, t0
, ctx
);
1165 save_cpu_state(ctx
, 0);
1166 op_st_sb(t1
, t0
, ctx
);
1170 save_cpu_state(ctx
, 1);
1171 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1175 save_cpu_state(ctx
, 1);
1176 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1180 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1186 /* Store conditional */
1187 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1188 int base
, int16_t offset
)
1190 const char *opn
= "st_cond";
1193 t0
= tcg_temp_local_new();
1195 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1196 /* Don't do NOP if destination is zero: we must perform the actual
1199 t1
= tcg_temp_local_new();
1200 gen_load_gpr(t1
, rt
);
1202 #if defined(TARGET_MIPS64)
1204 save_cpu_state(ctx
, 0);
1205 op_st_scd(t1
, t0
, rt
, ctx
);
1210 save_cpu_state(ctx
, 1);
1211 op_st_sc(t1
, t0
, rt
, ctx
);
1215 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1220 /* Load and store */
1221 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1222 int base
, int16_t offset
)
1224 const char *opn
= "flt_ldst";
1225 TCGv t0
= tcg_temp_new();
1227 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1228 /* Don't do NOP if destination is zero: we must perform the actual
1233 TCGv_i32 fp0
= tcg_temp_new_i32();
1235 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1236 tcg_gen_trunc_tl_i32(fp0
, t0
);
1237 gen_store_fpr32(fp0
, ft
);
1238 tcg_temp_free_i32(fp0
);
1244 TCGv_i32 fp0
= tcg_temp_new_i32();
1245 TCGv t1
= tcg_temp_new();
1247 gen_load_fpr32(fp0
, ft
);
1248 tcg_gen_extu_i32_tl(t1
, fp0
);
1249 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1251 tcg_temp_free_i32(fp0
);
1257 TCGv_i64 fp0
= tcg_temp_new_i64();
1259 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1260 gen_store_fpr64(ctx
, fp0
, ft
);
1261 tcg_temp_free_i64(fp0
);
1267 TCGv_i64 fp0
= tcg_temp_new_i64();
1269 gen_load_fpr64(ctx
, fp0
, ft
);
1270 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1271 tcg_temp_free_i64(fp0
);
1277 generate_exception(ctx
, EXCP_RI
);
1280 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1285 static void gen_cop1_ldst(CPUState
*env
, DisasContext
*ctx
,
1286 uint32_t op
, int rt
, int rs
, int16_t imm
)
1288 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
1289 check_cp1_enabled(ctx
);
1290 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
1292 generate_exception_err(ctx
, EXCP_CpU
, 1);
1296 /* Arithmetic with immediate operand */
1297 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1298 int rt
, int rs
, int16_t imm
)
1300 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1301 const char *opn
= "imm arith";
1303 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1304 /* If no destination, treat it as a NOP.
1305 For addi, we must generate the overflow exception when needed. */
1312 TCGv t0
= tcg_temp_local_new();
1313 TCGv t1
= tcg_temp_new();
1314 TCGv t2
= tcg_temp_new();
1315 int l1
= gen_new_label();
1317 gen_load_gpr(t1
, rs
);
1318 tcg_gen_addi_tl(t0
, t1
, uimm
);
1319 tcg_gen_ext32s_tl(t0
, t0
);
1321 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1322 tcg_gen_xori_tl(t2
, t0
, uimm
);
1323 tcg_gen_and_tl(t1
, t1
, t2
);
1325 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1327 /* operands of same sign, result different sign */
1328 generate_exception(ctx
, EXCP_OVERFLOW
);
1330 tcg_gen_ext32s_tl(t0
, t0
);
1331 gen_store_gpr(t0
, rt
);
1338 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1339 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1341 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1345 #if defined(TARGET_MIPS64)
1348 TCGv t0
= tcg_temp_local_new();
1349 TCGv t1
= tcg_temp_new();
1350 TCGv t2
= tcg_temp_new();
1351 int l1
= gen_new_label();
1353 gen_load_gpr(t1
, rs
);
1354 tcg_gen_addi_tl(t0
, t1
, uimm
);
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 gen_store_gpr(t0
, rt
);
1372 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1374 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1380 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1383 /* Logic with immediate operand */
1384 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1387 const char *opn
= "imm logic";
1390 /* If no destination, treat it as a NOP. */
1394 uimm
= (uint16_t)imm
;
1397 if (likely(rs
!= 0))
1398 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1400 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1405 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1407 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1411 if (likely(rs
!= 0))
1412 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1414 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1418 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1422 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1425 /* Set on less than with immediate operand */
1426 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1428 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1429 const char *opn
= "imm arith";
1433 /* If no destination, treat it as a NOP. */
1437 t0
= tcg_temp_new();
1438 gen_load_gpr(t0
, rs
);
1441 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
1445 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
1449 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1453 /* Shifts with immediate operand */
1454 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1455 int rt
, int rs
, int16_t imm
)
1457 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1458 const char *opn
= "imm shift";
1462 /* If no destination, treat it as a NOP. */
1467 t0
= tcg_temp_new();
1468 gen_load_gpr(t0
, rs
);
1471 tcg_gen_shli_tl(t0
, t0
, uimm
);
1472 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1476 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1481 tcg_gen_ext32u_tl(t0
, t0
);
1482 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1484 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1490 TCGv_i32 t1
= tcg_temp_new_i32();
1492 tcg_gen_trunc_tl_i32(t1
, t0
);
1493 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1494 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1495 tcg_temp_free_i32(t1
);
1497 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1501 #if defined(TARGET_MIPS64)
1503 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1507 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1511 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1516 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1518 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
1523 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1527 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1531 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1535 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1540 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1545 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1546 int rd
, int rs
, int rt
)
1548 const char *opn
= "arith";
1550 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1551 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1552 /* If no destination, treat it as a NOP.
1553 For add & sub, we must generate the overflow exception when needed. */
1561 TCGv t0
= tcg_temp_local_new();
1562 TCGv t1
= tcg_temp_new();
1563 TCGv t2
= tcg_temp_new();
1564 int l1
= gen_new_label();
1566 gen_load_gpr(t1
, rs
);
1567 gen_load_gpr(t2
, rt
);
1568 tcg_gen_add_tl(t0
, t1
, t2
);
1569 tcg_gen_ext32s_tl(t0
, t0
);
1570 tcg_gen_xor_tl(t1
, t1
, t2
);
1571 tcg_gen_xor_tl(t2
, t0
, t2
);
1572 tcg_gen_andc_tl(t1
, t2
, t1
);
1574 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1576 /* operands of same sign, result different sign */
1577 generate_exception(ctx
, EXCP_OVERFLOW
);
1579 gen_store_gpr(t0
, rd
);
1585 if (rs
!= 0 && rt
!= 0) {
1586 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1587 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1588 } else if (rs
== 0 && rt
!= 0) {
1589 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1590 } else if (rs
!= 0 && rt
== 0) {
1591 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1593 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1599 TCGv t0
= tcg_temp_local_new();
1600 TCGv t1
= tcg_temp_new();
1601 TCGv t2
= tcg_temp_new();
1602 int l1
= gen_new_label();
1604 gen_load_gpr(t1
, rs
);
1605 gen_load_gpr(t2
, rt
);
1606 tcg_gen_sub_tl(t0
, t1
, t2
);
1607 tcg_gen_ext32s_tl(t0
, t0
);
1608 tcg_gen_xor_tl(t2
, t1
, t2
);
1609 tcg_gen_xor_tl(t1
, t0
, t1
);
1610 tcg_gen_and_tl(t1
, t1
, t2
);
1612 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1614 /* operands of different sign, first operand and result different sign */
1615 generate_exception(ctx
, EXCP_OVERFLOW
);
1617 gen_store_gpr(t0
, rd
);
1623 if (rs
!= 0 && rt
!= 0) {
1624 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1625 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1626 } else if (rs
== 0 && rt
!= 0) {
1627 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1628 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1629 } else if (rs
!= 0 && rt
== 0) {
1630 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1632 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1636 #if defined(TARGET_MIPS64)
1639 TCGv t0
= tcg_temp_local_new();
1640 TCGv t1
= tcg_temp_new();
1641 TCGv t2
= tcg_temp_new();
1642 int l1
= gen_new_label();
1644 gen_load_gpr(t1
, rs
);
1645 gen_load_gpr(t2
, rt
);
1646 tcg_gen_add_tl(t0
, t1
, t2
);
1647 tcg_gen_xor_tl(t1
, t1
, t2
);
1648 tcg_gen_xor_tl(t2
, t0
, t2
);
1649 tcg_gen_andc_tl(t1
, t2
, t1
);
1651 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1653 /* operands of same sign, result different sign */
1654 generate_exception(ctx
, EXCP_OVERFLOW
);
1656 gen_store_gpr(t0
, rd
);
1662 if (rs
!= 0 && rt
!= 0) {
1663 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1664 } else if (rs
== 0 && rt
!= 0) {
1665 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1666 } else if (rs
!= 0 && rt
== 0) {
1667 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1669 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1675 TCGv t0
= tcg_temp_local_new();
1676 TCGv t1
= tcg_temp_new();
1677 TCGv t2
= tcg_temp_new();
1678 int l1
= gen_new_label();
1680 gen_load_gpr(t1
, rs
);
1681 gen_load_gpr(t2
, rt
);
1682 tcg_gen_sub_tl(t0
, t1
, t2
);
1683 tcg_gen_xor_tl(t2
, t1
, t2
);
1684 tcg_gen_xor_tl(t1
, t0
, t1
);
1685 tcg_gen_and_tl(t1
, t1
, t2
);
1687 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1689 /* operands of different sign, first operand and result different sign */
1690 generate_exception(ctx
, EXCP_OVERFLOW
);
1692 gen_store_gpr(t0
, rd
);
1698 if (rs
!= 0 && rt
!= 0) {
1699 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1700 } else if (rs
== 0 && rt
!= 0) {
1701 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1702 } else if (rs
!= 0 && rt
== 0) {
1703 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1705 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1711 if (likely(rs
!= 0 && rt
!= 0)) {
1712 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1713 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1715 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1720 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1723 /* Conditional move */
1724 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1726 const char *opn
= "cond move";
1730 /* If no destination, treat it as a NOP.
1731 For add & sub, we must generate the overflow exception when needed. */
1736 l1
= gen_new_label();
1739 if (likely(rt
!= 0))
1740 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1746 if (likely(rt
!= 0))
1747 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1752 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1754 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1757 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1761 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1763 const char *opn
= "logic";
1766 /* If no destination, treat it as a NOP. */
1773 if (likely(rs
!= 0 && rt
!= 0)) {
1774 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1776 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1781 if (rs
!= 0 && rt
!= 0) {
1782 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1783 } else if (rs
== 0 && rt
!= 0) {
1784 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1785 } else if (rs
!= 0 && rt
== 0) {
1786 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1788 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1793 if (likely(rs
!= 0 && rt
!= 0)) {
1794 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1795 } else if (rs
== 0 && rt
!= 0) {
1796 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1797 } else if (rs
!= 0 && rt
== 0) {
1798 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1800 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1805 if (likely(rs
!= 0 && rt
!= 0)) {
1806 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1807 } else if (rs
== 0 && rt
!= 0) {
1808 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1809 } else if (rs
!= 0 && rt
== 0) {
1810 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1812 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1817 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1820 /* Set on lower than */
1821 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1823 const char *opn
= "slt";
1827 /* If no destination, treat it as a NOP. */
1832 t0
= tcg_temp_new();
1833 t1
= tcg_temp_new();
1834 gen_load_gpr(t0
, rs
);
1835 gen_load_gpr(t1
, rt
);
1838 tcg_gen_setcond_tl(TCG_COND_LT
, cpu_gpr
[rd
], t0
, t1
);
1842 tcg_gen_setcond_tl(TCG_COND_LTU
, cpu_gpr
[rd
], t0
, t1
);
1846 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1852 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1853 int rd
, int rs
, int rt
)
1855 const char *opn
= "shifts";
1859 /* If no destination, treat it as a NOP.
1860 For add & sub, we must generate the overflow exception when needed. */
1865 t0
= tcg_temp_new();
1866 t1
= tcg_temp_new();
1867 gen_load_gpr(t0
, rs
);
1868 gen_load_gpr(t1
, rt
);
1871 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1872 tcg_gen_shl_tl(t0
, t1
, t0
);
1873 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1877 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1878 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1882 tcg_gen_ext32u_tl(t1
, t1
);
1883 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1884 tcg_gen_shr_tl(t0
, t1
, t0
);
1885 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1890 TCGv_i32 t2
= tcg_temp_new_i32();
1891 TCGv_i32 t3
= tcg_temp_new_i32();
1893 tcg_gen_trunc_tl_i32(t2
, t0
);
1894 tcg_gen_trunc_tl_i32(t3
, t1
);
1895 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1896 tcg_gen_rotr_i32(t2
, t3
, t2
);
1897 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1898 tcg_temp_free_i32(t2
);
1899 tcg_temp_free_i32(t3
);
1903 #if defined(TARGET_MIPS64)
1905 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1906 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1910 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1911 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1915 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1916 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1920 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1921 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1926 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1931 /* Arithmetic on HI/LO registers */
1932 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1934 const char *opn
= "hilo";
1936 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1943 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1947 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1952 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1954 tcg_gen_movi_tl(cpu_HI
[0], 0);
1959 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
1961 tcg_gen_movi_tl(cpu_LO
[0], 0);
1965 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1968 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1971 const char *opn
= "mul/div";
1977 #if defined(TARGET_MIPS64)
1981 t0
= tcg_temp_local_new();
1982 t1
= tcg_temp_local_new();
1985 t0
= tcg_temp_new();
1986 t1
= tcg_temp_new();
1990 gen_load_gpr(t0
, rs
);
1991 gen_load_gpr(t1
, rt
);
1995 int l1
= gen_new_label();
1996 int l2
= gen_new_label();
1998 tcg_gen_ext32s_tl(t0
, t0
);
1999 tcg_gen_ext32s_tl(t1
, t1
);
2000 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2001 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2002 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2004 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2005 tcg_gen_movi_tl(cpu_HI
[0], 0);
2008 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
2009 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
2010 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2011 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2018 int l1
= gen_new_label();
2020 tcg_gen_ext32u_tl(t0
, t0
);
2021 tcg_gen_ext32u_tl(t1
, t1
);
2022 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2023 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2024 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2025 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2026 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2033 TCGv_i64 t2
= tcg_temp_new_i64();
2034 TCGv_i64 t3
= tcg_temp_new_i64();
2036 tcg_gen_ext_tl_i64(t2
, t0
);
2037 tcg_gen_ext_tl_i64(t3
, t1
);
2038 tcg_gen_mul_i64(t2
, t2
, t3
);
2039 tcg_temp_free_i64(t3
);
2040 tcg_gen_trunc_i64_tl(t0
, t2
);
2041 tcg_gen_shri_i64(t2
, t2
, 32);
2042 tcg_gen_trunc_i64_tl(t1
, t2
);
2043 tcg_temp_free_i64(t2
);
2044 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2045 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2051 TCGv_i64 t2
= tcg_temp_new_i64();
2052 TCGv_i64 t3
= tcg_temp_new_i64();
2054 tcg_gen_ext32u_tl(t0
, t0
);
2055 tcg_gen_ext32u_tl(t1
, t1
);
2056 tcg_gen_extu_tl_i64(t2
, t0
);
2057 tcg_gen_extu_tl_i64(t3
, t1
);
2058 tcg_gen_mul_i64(t2
, t2
, t3
);
2059 tcg_temp_free_i64(t3
);
2060 tcg_gen_trunc_i64_tl(t0
, t2
);
2061 tcg_gen_shri_i64(t2
, t2
, 32);
2062 tcg_gen_trunc_i64_tl(t1
, t2
);
2063 tcg_temp_free_i64(t2
);
2064 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2065 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2069 #if defined(TARGET_MIPS64)
2072 int l1
= gen_new_label();
2073 int l2
= gen_new_label();
2075 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2076 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2077 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2078 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2079 tcg_gen_movi_tl(cpu_HI
[0], 0);
2082 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2083 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2090 int l1
= gen_new_label();
2092 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2093 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2094 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2100 gen_helper_dmult(t0
, t1
);
2104 gen_helper_dmultu(t0
, t1
);
2110 TCGv_i64 t2
= tcg_temp_new_i64();
2111 TCGv_i64 t3
= tcg_temp_new_i64();
2113 tcg_gen_ext_tl_i64(t2
, t0
);
2114 tcg_gen_ext_tl_i64(t3
, t1
);
2115 tcg_gen_mul_i64(t2
, t2
, t3
);
2116 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2117 tcg_gen_add_i64(t2
, t2
, t3
);
2118 tcg_temp_free_i64(t3
);
2119 tcg_gen_trunc_i64_tl(t0
, t2
);
2120 tcg_gen_shri_i64(t2
, t2
, 32);
2121 tcg_gen_trunc_i64_tl(t1
, t2
);
2122 tcg_temp_free_i64(t2
);
2123 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2124 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2130 TCGv_i64 t2
= tcg_temp_new_i64();
2131 TCGv_i64 t3
= tcg_temp_new_i64();
2133 tcg_gen_ext32u_tl(t0
, t0
);
2134 tcg_gen_ext32u_tl(t1
, t1
);
2135 tcg_gen_extu_tl_i64(t2
, t0
);
2136 tcg_gen_extu_tl_i64(t3
, t1
);
2137 tcg_gen_mul_i64(t2
, t2
, t3
);
2138 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2139 tcg_gen_add_i64(t2
, t2
, t3
);
2140 tcg_temp_free_i64(t3
);
2141 tcg_gen_trunc_i64_tl(t0
, t2
);
2142 tcg_gen_shri_i64(t2
, t2
, 32);
2143 tcg_gen_trunc_i64_tl(t1
, t2
);
2144 tcg_temp_free_i64(t2
);
2145 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2146 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2152 TCGv_i64 t2
= tcg_temp_new_i64();
2153 TCGv_i64 t3
= tcg_temp_new_i64();
2155 tcg_gen_ext_tl_i64(t2
, t0
);
2156 tcg_gen_ext_tl_i64(t3
, t1
);
2157 tcg_gen_mul_i64(t2
, t2
, t3
);
2158 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2159 tcg_gen_sub_i64(t2
, t3
, t2
);
2160 tcg_temp_free_i64(t3
);
2161 tcg_gen_trunc_i64_tl(t0
, t2
);
2162 tcg_gen_shri_i64(t2
, t2
, 32);
2163 tcg_gen_trunc_i64_tl(t1
, t2
);
2164 tcg_temp_free_i64(t2
);
2165 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2166 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2172 TCGv_i64 t2
= tcg_temp_new_i64();
2173 TCGv_i64 t3
= tcg_temp_new_i64();
2175 tcg_gen_ext32u_tl(t0
, t0
);
2176 tcg_gen_ext32u_tl(t1
, t1
);
2177 tcg_gen_extu_tl_i64(t2
, t0
);
2178 tcg_gen_extu_tl_i64(t3
, t1
);
2179 tcg_gen_mul_i64(t2
, t2
, t3
);
2180 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2181 tcg_gen_sub_i64(t2
, t3
, t2
);
2182 tcg_temp_free_i64(t3
);
2183 tcg_gen_trunc_i64_tl(t0
, t2
);
2184 tcg_gen_shri_i64(t2
, t2
, 32);
2185 tcg_gen_trunc_i64_tl(t1
, t2
);
2186 tcg_temp_free_i64(t2
);
2187 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2188 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2194 generate_exception(ctx
, EXCP_RI
);
2197 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2203 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2204 int rd
, int rs
, int rt
)
2206 const char *opn
= "mul vr54xx";
2207 TCGv t0
= tcg_temp_new();
2208 TCGv t1
= tcg_temp_new();
2210 gen_load_gpr(t0
, rs
);
2211 gen_load_gpr(t1
, rt
);
2214 case OPC_VR54XX_MULS
:
2215 gen_helper_muls(t0
, t0
, t1
);
2218 case OPC_VR54XX_MULSU
:
2219 gen_helper_mulsu(t0
, t0
, t1
);
2222 case OPC_VR54XX_MACC
:
2223 gen_helper_macc(t0
, t0
, t1
);
2226 case OPC_VR54XX_MACCU
:
2227 gen_helper_maccu(t0
, t0
, t1
);
2230 case OPC_VR54XX_MSAC
:
2231 gen_helper_msac(t0
, t0
, t1
);
2234 case OPC_VR54XX_MSACU
:
2235 gen_helper_msacu(t0
, t0
, t1
);
2238 case OPC_VR54XX_MULHI
:
2239 gen_helper_mulhi(t0
, t0
, t1
);
2242 case OPC_VR54XX_MULHIU
:
2243 gen_helper_mulhiu(t0
, t0
, t1
);
2246 case OPC_VR54XX_MULSHI
:
2247 gen_helper_mulshi(t0
, t0
, t1
);
2250 case OPC_VR54XX_MULSHIU
:
2251 gen_helper_mulshiu(t0
, t0
, t1
);
2254 case OPC_VR54XX_MACCHI
:
2255 gen_helper_macchi(t0
, t0
, t1
);
2258 case OPC_VR54XX_MACCHIU
:
2259 gen_helper_macchiu(t0
, t0
, t1
);
2262 case OPC_VR54XX_MSACHI
:
2263 gen_helper_msachi(t0
, t0
, t1
);
2266 case OPC_VR54XX_MSACHIU
:
2267 gen_helper_msachiu(t0
, t0
, t1
);
2271 MIPS_INVAL("mul vr54xx");
2272 generate_exception(ctx
, EXCP_RI
);
2275 gen_store_gpr(t0
, rd
);
2276 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2283 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2286 const char *opn
= "CLx";
2294 t0
= tcg_temp_new();
2295 gen_load_gpr(t0
, rs
);
2298 gen_helper_clo(cpu_gpr
[rd
], t0
);
2302 gen_helper_clz(cpu_gpr
[rd
], t0
);
2305 #if defined(TARGET_MIPS64)
2307 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2311 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2316 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2321 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2322 int rs
, int rt
, int16_t imm
)
2325 TCGv t0
= tcg_temp_new();
2326 TCGv t1
= tcg_temp_new();
2329 /* Load needed operands */
2337 /* Compare two registers */
2339 gen_load_gpr(t0
, rs
);
2340 gen_load_gpr(t1
, rt
);
2350 /* Compare register to immediate */
2351 if (rs
!= 0 || imm
!= 0) {
2352 gen_load_gpr(t0
, rs
);
2353 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2360 case OPC_TEQ
: /* rs == rs */
2361 case OPC_TEQI
: /* r0 == 0 */
2362 case OPC_TGE
: /* rs >= rs */
2363 case OPC_TGEI
: /* r0 >= 0 */
2364 case OPC_TGEU
: /* rs >= rs unsigned */
2365 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2367 generate_exception(ctx
, EXCP_TRAP
);
2369 case OPC_TLT
: /* rs < rs */
2370 case OPC_TLTI
: /* r0 < 0 */
2371 case OPC_TLTU
: /* rs < rs unsigned */
2372 case OPC_TLTIU
: /* r0 < 0 unsigned */
2373 case OPC_TNE
: /* rs != rs */
2374 case OPC_TNEI
: /* r0 != 0 */
2375 /* Never trap: treat as NOP. */
2379 int l1
= gen_new_label();
2384 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2388 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2392 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2396 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2400 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2404 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2407 generate_exception(ctx
, EXCP_TRAP
);
2414 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2416 TranslationBlock
*tb
;
2418 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2419 likely(!ctx
->singlestep_enabled
)) {
2422 tcg_gen_exit_tb((long)tb
+ n
);
2425 if (ctx
->singlestep_enabled
) {
2426 save_cpu_state(ctx
, 0);
2427 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
2433 /* Branches (before delay slot) */
2434 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2436 int rs
, int rt
, int32_t offset
)
2438 target_ulong btgt
= -1;
2440 int bcond_compute
= 0;
2441 TCGv t0
= tcg_temp_new();
2442 TCGv t1
= tcg_temp_new();
2444 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2445 #ifdef MIPS_DEBUG_DISAS
2446 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2448 generate_exception(ctx
, EXCP_RI
);
2452 /* Load needed operands */
2458 /* Compare two registers */
2460 gen_load_gpr(t0
, rs
);
2461 gen_load_gpr(t1
, rt
);
2464 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2480 /* Compare to zero */
2482 gen_load_gpr(t0
, rs
);
2485 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2492 /* Jump to immediate */
2493 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
2499 /* Jump to register */
2500 if (offset
!= 0 && offset
!= 16) {
2501 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2502 others are reserved. */
2503 MIPS_INVAL("jump hint");
2504 generate_exception(ctx
, EXCP_RI
);
2507 gen_load_gpr(btarget
, rs
);
2510 MIPS_INVAL("branch/jump");
2511 generate_exception(ctx
, EXCP_RI
);
2514 if (bcond_compute
== 0) {
2515 /* No condition to be computed */
2517 case OPC_BEQ
: /* rx == rx */
2518 case OPC_BEQL
: /* rx == rx likely */
2519 case OPC_BGEZ
: /* 0 >= 0 */
2520 case OPC_BGEZL
: /* 0 >= 0 likely */
2521 case OPC_BLEZ
: /* 0 <= 0 */
2522 case OPC_BLEZL
: /* 0 <= 0 likely */
2524 ctx
->hflags
|= MIPS_HFLAG_B
;
2525 MIPS_DEBUG("balways");
2528 case OPC_BGEZAL
: /* 0 >= 0 */
2529 case OPC_BGEZALL
: /* 0 >= 0 likely */
2530 ctx
->hflags
|= (opc
== OPC_BGEZALS
2532 : MIPS_HFLAG_BDS32
);
2533 /* Always take and link */
2535 ctx
->hflags
|= MIPS_HFLAG_B
;
2536 MIPS_DEBUG("balways and link");
2538 case OPC_BNE
: /* rx != rx */
2539 case OPC_BGTZ
: /* 0 > 0 */
2540 case OPC_BLTZ
: /* 0 < 0 */
2542 MIPS_DEBUG("bnever (NOP)");
2545 case OPC_BLTZAL
: /* 0 < 0 */
2546 ctx
->hflags
|= (opc
== OPC_BLTZALS
2548 : MIPS_HFLAG_BDS32
);
2549 /* Handle as an unconditional branch to get correct delay
2552 btgt
= ctx
->pc
+ (opc
== OPC_BLTZALS
? 6 : 8);
2553 ctx
->hflags
|= MIPS_HFLAG_B
;
2554 MIPS_DEBUG("bnever and link");
2556 case OPC_BLTZALL
: /* 0 < 0 likely */
2557 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2558 /* Skip the instruction in the delay slot */
2559 MIPS_DEBUG("bnever, link and skip");
2562 case OPC_BNEL
: /* rx != rx likely */
2563 case OPC_BGTZL
: /* 0 > 0 likely */
2564 case OPC_BLTZL
: /* 0 < 0 likely */
2565 /* Skip the instruction in the delay slot */
2566 MIPS_DEBUG("bnever and skip");
2570 ctx
->hflags
|= MIPS_HFLAG_B
;
2571 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2575 ctx
->hflags
|= MIPS_HFLAG_BX
;
2580 ctx
->hflags
|= MIPS_HFLAG_B
;
2581 ctx
->hflags
|= ((opc
== OPC_JALS
|| opc
== OPC_JALXS
)
2583 : MIPS_HFLAG_BDS32
);
2584 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2587 ctx
->hflags
|= MIPS_HFLAG_BR
;
2588 if (insn_bytes
== 4)
2589 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
2590 MIPS_DEBUG("jr %s", regnames
[rs
]);
2596 ctx
->hflags
|= MIPS_HFLAG_BR
;
2597 ctx
->hflags
|= (opc
== OPC_JALRS
2599 : MIPS_HFLAG_BDS32
);
2600 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2603 MIPS_INVAL("branch/jump");
2604 generate_exception(ctx
, EXCP_RI
);
2610 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2611 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2612 regnames
[rs
], regnames
[rt
], btgt
);
2615 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2616 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2617 regnames
[rs
], regnames
[rt
], btgt
);
2620 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2621 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2622 regnames
[rs
], regnames
[rt
], btgt
);
2625 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2626 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2627 regnames
[rs
], regnames
[rt
], btgt
);
2630 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2631 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2634 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2635 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2639 ctx
->hflags
|= (opc
== OPC_BGEZALS
2641 : MIPS_HFLAG_BDS32
);
2642 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2643 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2647 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2649 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2652 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2653 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2656 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2657 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2660 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2661 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2664 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2665 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2668 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2669 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2672 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2673 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2677 ctx
->hflags
|= (opc
== OPC_BLTZALS
2679 : MIPS_HFLAG_BDS32
);
2680 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2682 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2684 ctx
->hflags
|= MIPS_HFLAG_BC
;
2687 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2689 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2691 ctx
->hflags
|= MIPS_HFLAG_BL
;
2694 MIPS_INVAL("conditional branch/jump");
2695 generate_exception(ctx
, EXCP_RI
);
2699 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2700 blink
, ctx
->hflags
, btgt
);
2702 ctx
->btarget
= btgt
;
2704 int post_delay
= insn_bytes
;
2705 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
2707 if (opc
!= OPC_JALRC
)
2708 post_delay
+= ((ctx
->hflags
& MIPS_HFLAG_BDS16
) ? 2 : 4);
2710 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ post_delay
+ lowbit
);
2714 if (insn_bytes
== 2)
2715 ctx
->hflags
|= MIPS_HFLAG_B16
;
2720 /* special3 bitfield operations */
2721 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2722 int rs
, int lsb
, int msb
)
2724 TCGv t0
= tcg_temp_new();
2725 TCGv t1
= tcg_temp_new();
2728 gen_load_gpr(t1
, rs
);
2733 tcg_gen_shri_tl(t0
, t1
, lsb
);
2735 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2737 tcg_gen_ext32s_tl(t0
, t0
);
2740 #if defined(TARGET_MIPS64)
2742 tcg_gen_shri_tl(t0
, t1
, lsb
);
2744 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2748 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2749 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2752 tcg_gen_shri_tl(t0
, t1
, lsb
);
2753 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2759 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2760 gen_load_gpr(t0
, rt
);
2761 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2762 tcg_gen_shli_tl(t1
, t1
, lsb
);
2763 tcg_gen_andi_tl(t1
, t1
, mask
);
2764 tcg_gen_or_tl(t0
, t0
, t1
);
2765 tcg_gen_ext32s_tl(t0
, t0
);
2767 #if defined(TARGET_MIPS64)
2771 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2772 gen_load_gpr(t0
, rt
);
2773 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2774 tcg_gen_shli_tl(t1
, t1
, lsb
);
2775 tcg_gen_andi_tl(t1
, t1
, mask
);
2776 tcg_gen_or_tl(t0
, t0
, t1
);
2781 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << (lsb
+ 32);
2782 gen_load_gpr(t0
, rt
);
2783 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2784 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2785 tcg_gen_andi_tl(t1
, t1
, mask
);
2786 tcg_gen_or_tl(t0
, t0
, t1
);
2791 gen_load_gpr(t0
, rt
);
2792 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2793 gen_load_gpr(t0
, rt
);
2794 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2795 tcg_gen_shli_tl(t1
, t1
, lsb
);
2796 tcg_gen_andi_tl(t1
, t1
, mask
);
2797 tcg_gen_or_tl(t0
, t0
, t1
);
2802 MIPS_INVAL("bitops");
2803 generate_exception(ctx
, EXCP_RI
);
2808 gen_store_gpr(t0
, rt
);
2813 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2818 /* If no destination, treat it as a NOP. */
2823 t0
= tcg_temp_new();
2824 gen_load_gpr(t0
, rt
);
2828 TCGv t1
= tcg_temp_new();
2830 tcg_gen_shri_tl(t1
, t0
, 8);
2831 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2832 tcg_gen_shli_tl(t0
, t0
, 8);
2833 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2834 tcg_gen_or_tl(t0
, t0
, t1
);
2836 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2840 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2843 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2845 #if defined(TARGET_MIPS64)
2848 TCGv t1
= tcg_temp_new();
2850 tcg_gen_shri_tl(t1
, t0
, 8);
2851 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2852 tcg_gen_shli_tl(t0
, t0
, 8);
2853 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2854 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2860 TCGv t1
= tcg_temp_new();
2862 tcg_gen_shri_tl(t1
, t0
, 16);
2863 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2864 tcg_gen_shli_tl(t0
, t0
, 16);
2865 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2866 tcg_gen_or_tl(t0
, t0
, t1
);
2867 tcg_gen_shri_tl(t1
, t0
, 32);
2868 tcg_gen_shli_tl(t0
, t0
, 32);
2869 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2875 MIPS_INVAL("bsfhl");
2876 generate_exception(ctx
, EXCP_RI
);
2883 #ifndef CONFIG_USER_ONLY
2884 /* CP0 (MMU and control) */
2885 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
2887 TCGv_i32 t0
= tcg_temp_new_i32();
2889 tcg_gen_ld_i32(t0
, cpu_env
, off
);
2890 tcg_gen_ext_i32_tl(arg
, t0
);
2891 tcg_temp_free_i32(t0
);
2894 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
2896 tcg_gen_ld_tl(arg
, cpu_env
, off
);
2897 tcg_gen_ext32s_tl(arg
, arg
);
2900 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
2902 TCGv_i32 t0
= tcg_temp_new_i32();
2904 tcg_gen_trunc_tl_i32(t0
, arg
);
2905 tcg_gen_st_i32(t0
, cpu_env
, off
);
2906 tcg_temp_free_i32(t0
);
2909 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
2911 tcg_gen_ext32s_tl(arg
, arg
);
2912 tcg_gen_st_tl(arg
, cpu_env
, off
);
2915 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
2917 const char *rn
= "invalid";
2920 check_insn(env
, ctx
, ISA_MIPS32
);
2926 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
2930 check_insn(env
, ctx
, ASE_MT
);
2931 gen_helper_mfc0_mvpcontrol(arg
);
2935 check_insn(env
, ctx
, ASE_MT
);
2936 gen_helper_mfc0_mvpconf0(arg
);
2940 check_insn(env
, ctx
, ASE_MT
);
2941 gen_helper_mfc0_mvpconf1(arg
);
2951 gen_helper_mfc0_random(arg
);
2955 check_insn(env
, ctx
, ASE_MT
);
2956 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
2960 check_insn(env
, ctx
, ASE_MT
);
2961 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
2965 check_insn(env
, ctx
, ASE_MT
);
2966 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
2970 check_insn(env
, ctx
, ASE_MT
);
2971 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
2975 check_insn(env
, ctx
, ASE_MT
);
2976 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
2980 check_insn(env
, ctx
, ASE_MT
);
2981 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
2982 rn
= "VPEScheFBack";
2985 check_insn(env
, ctx
, ASE_MT
);
2986 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
2996 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2997 tcg_gen_ext32s_tl(arg
, arg
);
3001 check_insn(env
, ctx
, ASE_MT
);
3002 gen_helper_mfc0_tcstatus(arg
);
3006 check_insn(env
, ctx
, ASE_MT
);
3007 gen_helper_mfc0_tcbind(arg
);
3011 check_insn(env
, ctx
, ASE_MT
);
3012 gen_helper_mfc0_tcrestart(arg
);
3016 check_insn(env
, ctx
, ASE_MT
);
3017 gen_helper_mfc0_tchalt(arg
);
3021 check_insn(env
, ctx
, ASE_MT
);
3022 gen_helper_mfc0_tccontext(arg
);
3026 check_insn(env
, ctx
, ASE_MT
);
3027 gen_helper_mfc0_tcschedule(arg
);
3031 check_insn(env
, ctx
, ASE_MT
);
3032 gen_helper_mfc0_tcschefback(arg
);
3042 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
3043 tcg_gen_ext32s_tl(arg
, arg
);
3053 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
3054 tcg_gen_ext32s_tl(arg
, arg
);
3058 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3059 rn
= "ContextConfig";
3068 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
3072 check_insn(env
, ctx
, ISA_MIPS32R2
);
3073 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
3083 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
3087 check_insn(env
, ctx
, ISA_MIPS32R2
);
3088 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3092 check_insn(env
, ctx
, ISA_MIPS32R2
);
3093 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3097 check_insn(env
, ctx
, ISA_MIPS32R2
);
3098 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3102 check_insn(env
, ctx
, ISA_MIPS32R2
);
3103 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3107 check_insn(env
, ctx
, ISA_MIPS32R2
);
3108 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3118 check_insn(env
, ctx
, ISA_MIPS32R2
);
3119 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3129 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3130 tcg_gen_ext32s_tl(arg
, arg
);
3140 /* Mark as an IO operation because we read the time. */
3143 gen_helper_mfc0_count(arg
);
3146 ctx
->bstate
= BS_STOP
;
3150 /* 6,7 are implementation dependent */
3158 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3159 tcg_gen_ext32s_tl(arg
, arg
);
3169 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3172 /* 6,7 are implementation dependent */
3180 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3184 check_insn(env
, ctx
, ISA_MIPS32R2
);
3185 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3189 check_insn(env
, ctx
, ISA_MIPS32R2
);
3190 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3194 check_insn(env
, ctx
, ISA_MIPS32R2
);
3195 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3205 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3215 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3216 tcg_gen_ext32s_tl(arg
, arg
);
3226 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3230 check_insn(env
, ctx
, ISA_MIPS32R2
);
3231 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3241 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3245 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3249 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3253 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3256 /* 4,5 are reserved */
3257 /* 6,7 are implementation dependent */
3259 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3263 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3273 gen_helper_mfc0_lladdr(arg
);
3283 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3293 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3303 #if defined(TARGET_MIPS64)
3304 check_insn(env
, ctx
, ISA_MIPS3
);
3305 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3306 tcg_gen_ext32s_tl(arg
, arg
);
3315 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3318 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3326 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3327 rn
= "'Diagnostic"; /* implementation dependent */
3332 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3336 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3337 rn
= "TraceControl";
3340 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3341 rn
= "TraceControl2";
3344 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3345 rn
= "UserTraceData";
3348 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3359 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3360 tcg_gen_ext32s_tl(arg
, arg
);
3370 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3371 rn
= "Performance0";
3374 // gen_helper_mfc0_performance1(arg);
3375 rn
= "Performance1";
3378 // gen_helper_mfc0_performance2(arg);
3379 rn
= "Performance2";
3382 // gen_helper_mfc0_performance3(arg);
3383 rn
= "Performance3";
3386 // gen_helper_mfc0_performance4(arg);
3387 rn
= "Performance4";
3390 // gen_helper_mfc0_performance5(arg);
3391 rn
= "Performance5";
3394 // gen_helper_mfc0_performance6(arg);
3395 rn
= "Performance6";
3398 // gen_helper_mfc0_performance7(arg);
3399 rn
= "Performance7";
3406 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3412 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3425 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3432 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3445 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3452 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3462 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3463 tcg_gen_ext32s_tl(arg
, arg
);
3474 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3484 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3488 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3489 generate_exception(ctx
, EXCP_RI
);
3492 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3494 const char *rn
= "invalid";
3497 check_insn(env
, ctx
, ISA_MIPS32
);
3506 gen_helper_mtc0_index(arg
);
3510 check_insn(env
, ctx
, ASE_MT
);
3511 gen_helper_mtc0_mvpcontrol(arg
);
3515 check_insn(env
, ctx
, ASE_MT
);
3520 check_insn(env
, ctx
, ASE_MT
);
3535 check_insn(env
, ctx
, ASE_MT
);
3536 gen_helper_mtc0_vpecontrol(arg
);
3540 check_insn(env
, ctx
, ASE_MT
);
3541 gen_helper_mtc0_vpeconf0(arg
);
3545 check_insn(env
, ctx
, ASE_MT
);
3546 gen_helper_mtc0_vpeconf1(arg
);
3550 check_insn(env
, ctx
, ASE_MT
);
3551 gen_helper_mtc0_yqmask(arg
);
3555 check_insn(env
, ctx
, ASE_MT
);
3556 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3560 check_insn(env
, ctx
, ASE_MT
);
3561 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3562 rn
= "VPEScheFBack";
3565 check_insn(env
, ctx
, ASE_MT
);
3566 gen_helper_mtc0_vpeopt(arg
);
3576 gen_helper_mtc0_entrylo0(arg
);
3580 check_insn(env
, ctx
, ASE_MT
);
3581 gen_helper_mtc0_tcstatus(arg
);
3585 check_insn(env
, ctx
, ASE_MT
);
3586 gen_helper_mtc0_tcbind(arg
);
3590 check_insn(env
, ctx
, ASE_MT
);
3591 gen_helper_mtc0_tcrestart(arg
);
3595 check_insn(env
, ctx
, ASE_MT
);
3596 gen_helper_mtc0_tchalt(arg
);
3600 check_insn(env
, ctx
, ASE_MT
);
3601 gen_helper_mtc0_tccontext(arg
);
3605 check_insn(env
, ctx
, ASE_MT
);
3606 gen_helper_mtc0_tcschedule(arg
);
3610 check_insn(env
, ctx
, ASE_MT
);
3611 gen_helper_mtc0_tcschefback(arg
);
3621 gen_helper_mtc0_entrylo1(arg
);
3631 gen_helper_mtc0_context(arg
);
3635 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3636 rn
= "ContextConfig";
3645 gen_helper_mtc0_pagemask(arg
);
3649 check_insn(env
, ctx
, ISA_MIPS32R2
);
3650 gen_helper_mtc0_pagegrain(arg
);
3660 gen_helper_mtc0_wired(arg
);
3664 check_insn(env
, ctx
, ISA_MIPS32R2
);
3665 gen_helper_mtc0_srsconf0(arg
);
3669 check_insn(env
, ctx
, ISA_MIPS32R2
);
3670 gen_helper_mtc0_srsconf1(arg
);
3674 check_insn(env
, ctx
, ISA_MIPS32R2
);
3675 gen_helper_mtc0_srsconf2(arg
);
3679 check_insn(env
, ctx
, ISA_MIPS32R2
);
3680 gen_helper_mtc0_srsconf3(arg
);
3684 check_insn(env
, ctx
, ISA_MIPS32R2
);
3685 gen_helper_mtc0_srsconf4(arg
);
3695 check_insn(env
, ctx
, ISA_MIPS32R2
);
3696 gen_helper_mtc0_hwrena(arg
);
3710 gen_helper_mtc0_count(arg
);
3713 /* 6,7 are implementation dependent */
3721 gen_helper_mtc0_entryhi(arg
);
3731 gen_helper_mtc0_compare(arg
);
3734 /* 6,7 are implementation dependent */
3742 save_cpu_state(ctx
, 1);
3743 gen_helper_mtc0_status(arg
);
3744 /* BS_STOP isn't good enough here, hflags may have changed. */
3745 gen_save_pc(ctx
->pc
+ 4);
3746 ctx
->bstate
= BS_EXCP
;
3750 check_insn(env
, ctx
, ISA_MIPS32R2
);
3751 gen_helper_mtc0_intctl(arg
);
3752 /* Stop translation as we may have switched the execution mode */
3753 ctx
->bstate
= BS_STOP
;
3757 check_insn(env
, ctx
, ISA_MIPS32R2
);
3758 gen_helper_mtc0_srsctl(arg
);
3759 /* Stop translation as we may have switched the execution mode */
3760 ctx
->bstate
= BS_STOP
;
3764 check_insn(env
, ctx
, ISA_MIPS32R2
);
3765 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3766 /* Stop translation as we may have switched the execution mode */
3767 ctx
->bstate
= BS_STOP
;
3777 save_cpu_state(ctx
, 1);
3778 gen_helper_mtc0_cause(arg
);
3788 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
3802 check_insn(env
, ctx
, ISA_MIPS32R2
);
3803 gen_helper_mtc0_ebase(arg
);
3813 gen_helper_mtc0_config0(arg
);
3815 /* Stop translation as we may have switched the execution mode */
3816 ctx
->bstate
= BS_STOP
;
3819 /* ignored, read only */
3823 gen_helper_mtc0_config2(arg
);
3825 /* Stop translation as we may have switched the execution mode */
3826 ctx
->bstate
= BS_STOP
;
3829 /* ignored, read only */
3832 /* 4,5 are reserved */
3833 /* 6,7 are implementation dependent */
3843 rn
= "Invalid config selector";
3850 gen_helper_mtc0_lladdr(arg
);
3860 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
3870 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
3880 #if defined(TARGET_MIPS64)
3881 check_insn(env
, ctx
, ISA_MIPS3
);
3882 gen_helper_mtc0_xcontext(arg
);
3891 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3894 gen_helper_mtc0_framemask(arg
);
3903 rn
= "Diagnostic"; /* implementation dependent */
3908 gen_helper_mtc0_debug(arg
); /* EJTAG support */
3909 /* BS_STOP isn't good enough here, hflags may have changed. */
3910 gen_save_pc(ctx
->pc
+ 4);
3911 ctx
->bstate
= BS_EXCP
;
3915 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
3916 rn
= "TraceControl";
3917 /* Stop translation as we may have switched the execution mode */
3918 ctx
->bstate
= BS_STOP
;
3921 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
3922 rn
= "TraceControl2";
3923 /* Stop translation as we may have switched the execution mode */
3924 ctx
->bstate
= BS_STOP
;
3927 /* Stop translation as we may have switched the execution mode */
3928 ctx
->bstate
= BS_STOP
;
3929 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
3930 rn
= "UserTraceData";
3931 /* Stop translation as we may have switched the execution mode */
3932 ctx
->bstate
= BS_STOP
;
3935 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
3936 /* Stop translation as we may have switched the execution mode */
3937 ctx
->bstate
= BS_STOP
;
3948 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
3958 gen_helper_mtc0_performance0(arg
);
3959 rn
= "Performance0";
3962 // gen_helper_mtc0_performance1(arg);
3963 rn
= "Performance1";
3966 // gen_helper_mtc0_performance2(arg);
3967 rn
= "Performance2";
3970 // gen_helper_mtc0_performance3(arg);
3971 rn
= "Performance3";
3974 // gen_helper_mtc0_performance4(arg);
3975 rn
= "Performance4";
3978 // gen_helper_mtc0_performance5(arg);
3979 rn
= "Performance5";
3982 // gen_helper_mtc0_performance6(arg);
3983 rn
= "Performance6";
3986 // gen_helper_mtc0_performance7(arg);
3987 rn
= "Performance7";
4013 gen_helper_mtc0_taglo(arg
);
4020 gen_helper_mtc0_datalo(arg
);
4033 gen_helper_mtc0_taghi(arg
);
4040 gen_helper_mtc0_datahi(arg
);
4051 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
4062 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4068 /* Stop translation as we may have switched the execution mode */
4069 ctx
->bstate
= BS_STOP
;
4074 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4075 /* For simplicity assume that all writes can cause interrupts. */
4078 ctx
->bstate
= BS_STOP
;
4083 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4084 generate_exception(ctx
, EXCP_RI
);
4087 #if defined(TARGET_MIPS64)
4088 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4090 const char *rn
= "invalid";
4093 check_insn(env
, ctx
, ISA_MIPS64
);
4099 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4103 check_insn(env
, ctx
, ASE_MT
);
4104 gen_helper_mfc0_mvpcontrol(arg
);
4108 check_insn(env
, ctx
, ASE_MT
);
4109 gen_helper_mfc0_mvpconf0(arg
);
4113 check_insn(env
, ctx
, ASE_MT
);
4114 gen_helper_mfc0_mvpconf1(arg
);
4124 gen_helper_mfc0_random(arg
);
4128 check_insn(env
, ctx
, ASE_MT
);
4129 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4133 check_insn(env
, ctx
, ASE_MT
);
4134 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4138 check_insn(env
, ctx
, ASE_MT
);
4139 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4143 check_insn(env
, ctx
, ASE_MT
);
4144 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4148 check_insn(env
, ctx
, ASE_MT
);
4149 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4153 check_insn(env
, ctx
, ASE_MT
);
4154 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4155 rn
= "VPEScheFBack";
4158 check_insn(env
, ctx
, ASE_MT
);
4159 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4169 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4173 check_insn(env
, ctx
, ASE_MT
);
4174 gen_helper_mfc0_tcstatus(arg
);
4178 check_insn(env
, ctx
, ASE_MT
);
4179 gen_helper_mfc0_tcbind(arg
);
4183 check_insn(env
, ctx
, ASE_MT
);
4184 gen_helper_dmfc0_tcrestart(arg
);
4188 check_insn(env
, ctx
, ASE_MT
);
4189 gen_helper_dmfc0_tchalt(arg
);
4193 check_insn(env
, ctx
, ASE_MT
);
4194 gen_helper_dmfc0_tccontext(arg
);
4198 check_insn(env
, ctx
, ASE_MT
);
4199 gen_helper_dmfc0_tcschedule(arg
);
4203 check_insn(env
, ctx
, ASE_MT
);
4204 gen_helper_dmfc0_tcschefback(arg
);
4214 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4224 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4228 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4229 rn
= "ContextConfig";
4238 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4242 check_insn(env
, ctx
, ISA_MIPS32R2
);
4243 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4253 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4257 check_insn(env
, ctx
, ISA_MIPS32R2
);
4258 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4262 check_insn(env
, ctx
, ISA_MIPS32R2
);
4263 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4267 check_insn(env
, ctx
, ISA_MIPS32R2
);
4268 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4272 check_insn(env
, ctx
, ISA_MIPS32R2
);
4273 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4277 check_insn(env
, ctx
, ISA_MIPS32R2
);
4278 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4288 check_insn(env
, ctx
, ISA_MIPS32R2
);
4289 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4299 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4309 /* Mark as an IO operation because we read the time. */
4312 gen_helper_mfc0_count(arg
);
4315 ctx
->bstate
= BS_STOP
;
4319 /* 6,7 are implementation dependent */
4327 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4337 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4340 /* 6,7 are implementation dependent */
4348 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4352 check_insn(env
, ctx
, ISA_MIPS32R2
);
4353 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4357 check_insn(env
, ctx
, ISA_MIPS32R2
);
4358 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4362 check_insn(env
, ctx
, ISA_MIPS32R2
);
4363 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4373 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4383 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4393 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4397 check_insn(env
, ctx
, ISA_MIPS32R2
);
4398 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4408 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4412 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4416 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4420 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4423 /* 6,7 are implementation dependent */
4425 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4429 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4439 gen_helper_dmfc0_lladdr(arg
);
4449 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4459 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4469 check_insn(env
, ctx
, ISA_MIPS3
);
4470 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4478 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4481 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4489 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4490 rn
= "'Diagnostic"; /* implementation dependent */
4495 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4499 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4500 rn
= "TraceControl";
4503 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4504 rn
= "TraceControl2";
4507 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4508 rn
= "UserTraceData";
4511 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4522 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4532 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4533 rn
= "Performance0";
4536 // gen_helper_dmfc0_performance1(arg);
4537 rn
= "Performance1";
4540 // gen_helper_dmfc0_performance2(arg);
4541 rn
= "Performance2";
4544 // gen_helper_dmfc0_performance3(arg);
4545 rn
= "Performance3";
4548 // gen_helper_dmfc0_performance4(arg);
4549 rn
= "Performance4";
4552 // gen_helper_dmfc0_performance5(arg);
4553 rn
= "Performance5";
4556 // gen_helper_dmfc0_performance6(arg);
4557 rn
= "Performance6";
4560 // gen_helper_dmfc0_performance7(arg);
4561 rn
= "Performance7";
4568 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4575 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4588 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4595 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4608 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4615 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4625 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4636 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4646 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4650 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4651 generate_exception(ctx
, EXCP_RI
);
4654 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4656 const char *rn
= "invalid";
4659 check_insn(env
, ctx
, ISA_MIPS64
);
4668 gen_helper_mtc0_index(arg
);
4672 check_insn(env
, ctx
, ASE_MT
);
4673 gen_helper_mtc0_mvpcontrol(arg
);
4677 check_insn(env
, ctx
, ASE_MT
);
4682 check_insn(env
, ctx
, ASE_MT
);
4697 check_insn(env
, ctx
, ASE_MT
);
4698 gen_helper_mtc0_vpecontrol(arg
);
4702 check_insn(env
, ctx
, ASE_MT
);
4703 gen_helper_mtc0_vpeconf0(arg
);
4707 check_insn(env
, ctx
, ASE_MT
);
4708 gen_helper_mtc0_vpeconf1(arg
);
4712 check_insn(env
, ctx
, ASE_MT
);
4713 gen_helper_mtc0_yqmask(arg
);
4717 check_insn(env
, ctx
, ASE_MT
);
4718 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4722 check_insn(env
, ctx
, ASE_MT
);
4723 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4724 rn
= "VPEScheFBack";
4727 check_insn(env
, ctx
, ASE_MT
);
4728 gen_helper_mtc0_vpeopt(arg
);
4738 gen_helper_mtc0_entrylo0(arg
);
4742 check_insn(env
, ctx
, ASE_MT
);
4743 gen_helper_mtc0_tcstatus(arg
);
4747 check_insn(env
, ctx
, ASE_MT
);
4748 gen_helper_mtc0_tcbind(arg
);
4752 check_insn(env
, ctx
, ASE_MT
);
4753 gen_helper_mtc0_tcrestart(arg
);
4757 check_insn(env
, ctx
, ASE_MT
);
4758 gen_helper_mtc0_tchalt(arg
);
4762 check_insn(env
, ctx
, ASE_MT
);
4763 gen_helper_mtc0_tccontext(arg
);
4767 check_insn(env
, ctx
, ASE_MT
);
4768 gen_helper_mtc0_tcschedule(arg
);
4772 check_insn(env
, ctx
, ASE_MT
);
4773 gen_helper_mtc0_tcschefback(arg
);
4783 gen_helper_mtc0_entrylo1(arg
);
4793 gen_helper_mtc0_context(arg
);
4797 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
4798 rn
= "ContextConfig";
4807 gen_helper_mtc0_pagemask(arg
);
4811 check_insn(env
, ctx
, ISA_MIPS32R2
);
4812 gen_helper_mtc0_pagegrain(arg
);
4822 gen_helper_mtc0_wired(arg
);
4826 check_insn(env
, ctx
, ISA_MIPS32R2
);
4827 gen_helper_mtc0_srsconf0(arg
);
4831 check_insn(env
, ctx
, ISA_MIPS32R2
);
4832 gen_helper_mtc0_srsconf1(arg
);
4836 check_insn(env
, ctx
, ISA_MIPS32R2
);
4837 gen_helper_mtc0_srsconf2(arg
);
4841 check_insn(env
, ctx
, ISA_MIPS32R2
);
4842 gen_helper_mtc0_srsconf3(arg
);
4846 check_insn(env
, ctx
, ISA_MIPS32R2
);
4847 gen_helper_mtc0_srsconf4(arg
);
4857 check_insn(env
, ctx
, ISA_MIPS32R2
);
4858 gen_helper_mtc0_hwrena(arg
);
4872 gen_helper_mtc0_count(arg
);
4875 /* 6,7 are implementation dependent */
4879 /* Stop translation as we may have switched the execution mode */
4880 ctx
->bstate
= BS_STOP
;
4885 gen_helper_mtc0_entryhi(arg
);
4895 gen_helper_mtc0_compare(arg
);
4898 /* 6,7 are implementation dependent */
4902 /* Stop translation as we may have switched the execution mode */
4903 ctx
->bstate
= BS_STOP
;
4908 save_cpu_state(ctx
, 1);
4909 gen_helper_mtc0_status(arg
);
4910 /* BS_STOP isn't good enough here, hflags may have changed. */
4911 gen_save_pc(ctx
->pc
+ 4);
4912 ctx
->bstate
= BS_EXCP
;
4916 check_insn(env
, ctx
, ISA_MIPS32R2
);
4917 gen_helper_mtc0_intctl(arg
);
4918 /* Stop translation as we may have switched the execution mode */
4919 ctx
->bstate
= BS_STOP
;
4923 check_insn(env
, ctx
, ISA_MIPS32R2
);
4924 gen_helper_mtc0_srsctl(arg
);
4925 /* Stop translation as we may have switched the execution mode */
4926 ctx
->bstate
= BS_STOP
;
4930 check_insn(env
, ctx
, ISA_MIPS32R2
);
4931 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4932 /* Stop translation as we may have switched the execution mode */
4933 ctx
->bstate
= BS_STOP
;
4943 save_cpu_state(ctx
, 1);
4944 gen_helper_mtc0_cause(arg
);
4954 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4968 check_insn(env
, ctx
, ISA_MIPS32R2
);
4969 gen_helper_mtc0_ebase(arg
);
4979 gen_helper_mtc0_config0(arg
);
4981 /* Stop translation as we may have switched the execution mode */
4982 ctx
->bstate
= BS_STOP
;
4985 /* ignored, read only */
4989 gen_helper_mtc0_config2(arg
);
4991 /* Stop translation as we may have switched the execution mode */
4992 ctx
->bstate
= BS_STOP
;
4998 /* 6,7 are implementation dependent */
5000 rn
= "Invalid config selector";
5007 gen_helper_mtc0_lladdr(arg
);
5017 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
5027 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
5037 check_insn(env
, ctx
, ISA_MIPS3
);
5038 gen_helper_mtc0_xcontext(arg
);
5046 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5049 gen_helper_mtc0_framemask(arg
);
5058 rn
= "Diagnostic"; /* implementation dependent */
5063 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5064 /* BS_STOP isn't good enough here, hflags may have changed. */
5065 gen_save_pc(ctx
->pc
+ 4);
5066 ctx
->bstate
= BS_EXCP
;
5070 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5071 /* Stop translation as we may have switched the execution mode */
5072 ctx
->bstate
= BS_STOP
;
5073 rn
= "TraceControl";
5076 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5077 /* Stop translation as we may have switched the execution mode */
5078 ctx
->bstate
= BS_STOP
;
5079 rn
= "TraceControl2";
5082 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5083 /* Stop translation as we may have switched the execution mode */
5084 ctx
->bstate
= BS_STOP
;
5085 rn
= "UserTraceData";
5088 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5089 /* Stop translation as we may have switched the execution mode */
5090 ctx
->bstate
= BS_STOP
;
5101 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5111 gen_helper_mtc0_performance0(arg
);
5112 rn
= "Performance0";
5115 // gen_helper_mtc0_performance1(arg);
5116 rn
= "Performance1";
5119 // gen_helper_mtc0_performance2(arg);
5120 rn
= "Performance2";
5123 // gen_helper_mtc0_performance3(arg);
5124 rn
= "Performance3";
5127 // gen_helper_mtc0_performance4(arg);
5128 rn
= "Performance4";
5131 // gen_helper_mtc0_performance5(arg);
5132 rn
= "Performance5";
5135 // gen_helper_mtc0_performance6(arg);
5136 rn
= "Performance6";
5139 // gen_helper_mtc0_performance7(arg);
5140 rn
= "Performance7";
5166 gen_helper_mtc0_taglo(arg
);
5173 gen_helper_mtc0_datalo(arg
);
5186 gen_helper_mtc0_taghi(arg
);
5193 gen_helper_mtc0_datahi(arg
);
5204 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5215 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5221 /* Stop translation as we may have switched the execution mode */
5222 ctx
->bstate
= BS_STOP
;
5227 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5228 /* For simplicity assume that all writes can cause interrupts. */
5231 ctx
->bstate
= BS_STOP
;
5236 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5237 generate_exception(ctx
, EXCP_RI
);
5239 #endif /* TARGET_MIPS64 */
5241 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5242 int u
, int sel
, int h
)
5244 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5245 TCGv t0
= tcg_temp_local_new();
5247 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5248 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5249 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5250 tcg_gen_movi_tl(t0
, -1);
5251 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5252 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5253 tcg_gen_movi_tl(t0
, -1);
5259 gen_helper_mftc0_tcstatus(t0
);
5262 gen_helper_mftc0_tcbind(t0
);
5265 gen_helper_mftc0_tcrestart(t0
);
5268 gen_helper_mftc0_tchalt(t0
);
5271 gen_helper_mftc0_tccontext(t0
);
5274 gen_helper_mftc0_tcschedule(t0
);
5277 gen_helper_mftc0_tcschefback(t0
);
5280 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5287 gen_helper_mftc0_entryhi(t0
);
5290 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5296 gen_helper_mftc0_status(t0
);
5299 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5305 gen_helper_mftc0_debug(t0
);
5308 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5313 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5315 } else switch (sel
) {
5316 /* GPR registers. */
5318 gen_helper_1i(mftgpr
, t0
, rt
);
5320 /* Auxiliary CPU registers */
5324 gen_helper_1i(mftlo
, t0
, 0);
5327 gen_helper_1i(mfthi
, t0
, 0);
5330 gen_helper_1i(mftacx
, t0
, 0);
5333 gen_helper_1i(mftlo
, t0
, 1);
5336 gen_helper_1i(mfthi
, t0
, 1);
5339 gen_helper_1i(mftacx
, t0
, 1);
5342 gen_helper_1i(mftlo
, t0
, 2);
5345 gen_helper_1i(mfthi
, t0
, 2);
5348 gen_helper_1i(mftacx
, t0
, 2);
5351 gen_helper_1i(mftlo
, t0
, 3);
5354 gen_helper_1i(mfthi
, t0
, 3);
5357 gen_helper_1i(mftacx
, t0
, 3);
5360 gen_helper_mftdsp(t0
);
5366 /* Floating point (COP1). */
5368 /* XXX: For now we support only a single FPU context. */
5370 TCGv_i32 fp0
= tcg_temp_new_i32();
5372 gen_load_fpr32(fp0
, rt
);
5373 tcg_gen_ext_i32_tl(t0
, fp0
);
5374 tcg_temp_free_i32(fp0
);
5376 TCGv_i32 fp0
= tcg_temp_new_i32();
5378 gen_load_fpr32h(fp0
, rt
);
5379 tcg_gen_ext_i32_tl(t0
, fp0
);
5380 tcg_temp_free_i32(fp0
);
5384 /* XXX: For now we support only a single FPU context. */
5385 gen_helper_1i(cfc1
, t0
, rt
);
5387 /* COP2: Not implemented. */
5394 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5395 gen_store_gpr(t0
, rd
);
5401 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5402 generate_exception(ctx
, EXCP_RI
);
5405 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5406 int u
, int sel
, int h
)
5408 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5409 TCGv t0
= tcg_temp_local_new();
5411 gen_load_gpr(t0
, rt
);
5412 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5413 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5414 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5416 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5417 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5424 gen_helper_mttc0_tcstatus(t0
);
5427 gen_helper_mttc0_tcbind(t0
);
5430 gen_helper_mttc0_tcrestart(t0
);
5433 gen_helper_mttc0_tchalt(t0
);
5436 gen_helper_mttc0_tccontext(t0
);
5439 gen_helper_mttc0_tcschedule(t0
);
5442 gen_helper_mttc0_tcschefback(t0
);
5445 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5452 gen_helper_mttc0_entryhi(t0
);
5455 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5461 gen_helper_mttc0_status(t0
);
5464 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5470 gen_helper_mttc0_debug(t0
);
5473 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5478 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5480 } else switch (sel
) {
5481 /* GPR registers. */
5483 gen_helper_1i(mttgpr
, t0
, rd
);
5485 /* Auxiliary CPU registers */
5489 gen_helper_1i(mttlo
, t0
, 0);
5492 gen_helper_1i(mtthi
, t0
, 0);
5495 gen_helper_1i(mttacx
, t0
, 0);
5498 gen_helper_1i(mttlo
, t0
, 1);
5501 gen_helper_1i(mtthi
, t0
, 1);
5504 gen_helper_1i(mttacx
, t0
, 1);
5507 gen_helper_1i(mttlo
, t0
, 2);
5510 gen_helper_1i(mtthi
, t0
, 2);
5513 gen_helper_1i(mttacx
, t0
, 2);
5516 gen_helper_1i(mttlo
, t0
, 3);
5519 gen_helper_1i(mtthi
, t0
, 3);
5522 gen_helper_1i(mttacx
, t0
, 3);
5525 gen_helper_mttdsp(t0
);
5531 /* Floating point (COP1). */
5533 /* XXX: For now we support only a single FPU context. */
5535 TCGv_i32 fp0
= tcg_temp_new_i32();
5537 tcg_gen_trunc_tl_i32(fp0
, t0
);
5538 gen_store_fpr32(fp0
, rd
);
5539 tcg_temp_free_i32(fp0
);
5541 TCGv_i32 fp0
= tcg_temp_new_i32();
5543 tcg_gen_trunc_tl_i32(fp0
, t0
);
5544 gen_store_fpr32h(fp0
, rd
);
5545 tcg_temp_free_i32(fp0
);
5549 /* XXX: For now we support only a single FPU context. */
5550 gen_helper_1i(ctc1
, t0
, rd
);
5552 /* COP2: Not implemented. */
5559 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5565 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5566 generate_exception(ctx
, EXCP_RI
);
5569 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5571 const char *opn
= "ldst";
5579 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5584 TCGv t0
= tcg_temp_new();
5586 gen_load_gpr(t0
, rt
);
5587 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5592 #if defined(TARGET_MIPS64)
5594 check_insn(env
, ctx
, ISA_MIPS3
);
5599 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5603 check_insn(env
, ctx
, ISA_MIPS3
);
5605 TCGv t0
= tcg_temp_new();
5607 gen_load_gpr(t0
, rt
);
5608 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5615 check_insn(env
, ctx
, ASE_MT
);
5620 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5621 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5625 check_insn(env
, ctx
, ASE_MT
);
5626 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5627 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5632 if (!env
->tlb
->helper_tlbwi
)
5638 if (!env
->tlb
->helper_tlbwr
)
5644 if (!env
->tlb
->helper_tlbp
)
5650 if (!env
->tlb
->helper_tlbr
)
5656 check_insn(env
, ctx
, ISA_MIPS2
);
5658 ctx
->bstate
= BS_EXCP
;
5662 check_insn(env
, ctx
, ISA_MIPS32
);
5663 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5665 generate_exception(ctx
, EXCP_RI
);
5668 ctx
->bstate
= BS_EXCP
;
5673 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5674 /* If we get an exception, we want to restart at next instruction */
5676 save_cpu_state(ctx
, 1);
5679 ctx
->bstate
= BS_EXCP
;
5684 generate_exception(ctx
, EXCP_RI
);
5687 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5689 #endif /* !CONFIG_USER_ONLY */
5691 /* CP1 Branches (before delay slot) */
5692 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5693 int32_t cc
, int32_t offset
)
5695 target_ulong btarget
;
5696 const char *opn
= "cp1 cond branch";
5697 TCGv_i32 t0
= tcg_temp_new_i32();
5700 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5702 btarget
= ctx
->pc
+ 4 + offset
;
5706 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5707 tcg_gen_not_i32(t0
, t0
);
5708 tcg_gen_andi_i32(t0
, t0
, 1);
5709 tcg_gen_extu_i32_tl(bcond
, t0
);
5713 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5714 tcg_gen_not_i32(t0
, t0
);
5715 tcg_gen_andi_i32(t0
, t0
, 1);
5716 tcg_gen_extu_i32_tl(bcond
, t0
);
5720 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5721 tcg_gen_andi_i32(t0
, t0
, 1);
5722 tcg_gen_extu_i32_tl(bcond
, t0
);
5726 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5727 tcg_gen_andi_i32(t0
, t0
, 1);
5728 tcg_gen_extu_i32_tl(bcond
, t0
);
5731 ctx
->hflags
|= MIPS_HFLAG_BL
;
5735 TCGv_i32 t1
= tcg_temp_new_i32();
5736 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5737 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5738 tcg_gen_nor_i32(t0
, t0
, t1
);
5739 tcg_temp_free_i32(t1
);
5740 tcg_gen_andi_i32(t0
, t0
, 1);
5741 tcg_gen_extu_i32_tl(bcond
, t0
);
5747 TCGv_i32 t1
= tcg_temp_new_i32();
5748 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5749 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5750 tcg_gen_or_i32(t0
, t0
, t1
);
5751 tcg_temp_free_i32(t1
);
5752 tcg_gen_andi_i32(t0
, t0
, 1);
5753 tcg_gen_extu_i32_tl(bcond
, t0
);
5759 TCGv_i32 t1
= tcg_temp_new_i32();
5760 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5761 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5762 tcg_gen_or_i32(t0
, t0
, t1
);
5763 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5764 tcg_gen_or_i32(t0
, t0
, t1
);
5765 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5766 tcg_gen_nor_i32(t0
, t0
, t1
);
5767 tcg_temp_free_i32(t1
);
5768 tcg_gen_andi_i32(t0
, t0
, 1);
5769 tcg_gen_extu_i32_tl(bcond
, t0
);
5775 TCGv_i32 t1
= tcg_temp_new_i32();
5776 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5777 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5778 tcg_gen_or_i32(t0
, t0
, t1
);
5779 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5780 tcg_gen_or_i32(t0
, t0
, t1
);
5781 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5782 tcg_gen_or_i32(t0
, t0
, t1
);
5783 tcg_temp_free_i32(t1
);
5784 tcg_gen_andi_i32(t0
, t0
, 1);
5785 tcg_gen_extu_i32_tl(bcond
, t0
);
5789 ctx
->hflags
|= MIPS_HFLAG_BC
;
5793 generate_exception (ctx
, EXCP_RI
);
5796 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5797 ctx
->hflags
, btarget
);
5798 ctx
->btarget
= btarget
;
5801 tcg_temp_free_i32(t0
);
5804 /* Coprocessor 1 (FPU) */
5806 #define FOP(func, fmt) (((fmt) << 21) | (func))
5809 OPC_ADD_S
= FOP(0, FMT_S
),
5810 OPC_SUB_S
= FOP(1, FMT_S
),
5811 OPC_MUL_S
= FOP(2, FMT_S
),
5812 OPC_DIV_S
= FOP(3, FMT_S
),
5813 OPC_SQRT_S
= FOP(4, FMT_S
),
5814 OPC_ABS_S
= FOP(5, FMT_S
),
5815 OPC_MOV_S
= FOP(6, FMT_S
),
5816 OPC_NEG_S
= FOP(7, FMT_S
),
5817 OPC_ROUND_L_S
= FOP(8, FMT_S
),
5818 OPC_TRUNC_L_S
= FOP(9, FMT_S
),
5819 OPC_CEIL_L_S
= FOP(10, FMT_S
),
5820 OPC_FLOOR_L_S
= FOP(11, FMT_S
),
5821 OPC_ROUND_W_S
= FOP(12, FMT_S
),
5822 OPC_TRUNC_W_S
= FOP(13, FMT_S
),
5823 OPC_CEIL_W_S
= FOP(14, FMT_S
),
5824 OPC_FLOOR_W_S
= FOP(15, FMT_S
),
5825 OPC_MOVCF_S
= FOP(17, FMT_S
),
5826 OPC_MOVZ_S
= FOP(18, FMT_S
),
5827 OPC_MOVN_S
= FOP(19, FMT_S
),
5828 OPC_RECIP_S
= FOP(21, FMT_S
),
5829 OPC_RSQRT_S
= FOP(22, FMT_S
),
5830 OPC_RECIP2_S
= FOP(28, FMT_S
),
5831 OPC_RECIP1_S
= FOP(29, FMT_S
),
5832 OPC_RSQRT1_S
= FOP(30, FMT_S
),
5833 OPC_RSQRT2_S
= FOP(31, FMT_S
),
5834 OPC_CVT_D_S
= FOP(33, FMT_S
),
5835 OPC_CVT_W_S
= FOP(36, FMT_S
),
5836 OPC_CVT_L_S
= FOP(37, FMT_S
),
5837 OPC_CVT_PS_S
= FOP(38, FMT_S
),
5838 OPC_CMP_F_S
= FOP (48, FMT_S
),
5839 OPC_CMP_UN_S
= FOP (49, FMT_S
),
5840 OPC_CMP_EQ_S
= FOP (50, FMT_S
),
5841 OPC_CMP_UEQ_S
= FOP (51, FMT_S
),
5842 OPC_CMP_OLT_S
= FOP (52, FMT_S
),
5843 OPC_CMP_ULT_S
= FOP (53, FMT_S
),
5844 OPC_CMP_OLE_S
= FOP (54, FMT_S
),
5845 OPC_CMP_ULE_S
= FOP (55, FMT_S
),
5846 OPC_CMP_SF_S
= FOP (56, FMT_S
),
5847 OPC_CMP_NGLE_S
= FOP (57, FMT_S
),
5848 OPC_CMP_SEQ_S
= FOP (58, FMT_S
),
5849 OPC_CMP_NGL_S
= FOP (59, FMT_S
),
5850 OPC_CMP_LT_S
= FOP (60, FMT_S
),
5851 OPC_CMP_NGE_S
= FOP (61, FMT_S
),
5852 OPC_CMP_LE_S
= FOP (62, FMT_S
),
5853 OPC_CMP_NGT_S
= FOP (63, FMT_S
),
5855 OPC_ADD_D
= FOP(0, FMT_D
),
5856 OPC_SUB_D
= FOP(1, FMT_D
),
5857 OPC_MUL_D
= FOP(2, FMT_D
),
5858 OPC_DIV_D
= FOP(3, FMT_D
),
5859 OPC_SQRT_D
= FOP(4, FMT_D
),
5860 OPC_ABS_D
= FOP(5, FMT_D
),
5861 OPC_MOV_D
= FOP(6, FMT_D
),
5862 OPC_NEG_D
= FOP(7, FMT_D
),
5863 OPC_ROUND_L_D
= FOP(8, FMT_D
),
5864 OPC_TRUNC_L_D
= FOP(9, FMT_D
),
5865 OPC_CEIL_L_D
= FOP(10, FMT_D
),
5866 OPC_FLOOR_L_D
= FOP(11, FMT_D
),
5867 OPC_ROUND_W_D
= FOP(12, FMT_D
),
5868 OPC_TRUNC_W_D
= FOP(13, FMT_D
),
5869 OPC_CEIL_W_D
= FOP(14, FMT_D
),
5870 OPC_FLOOR_W_D
= FOP(15, FMT_D
),
5871 OPC_MOVCF_D
= FOP(17, FMT_D
),
5872 OPC_MOVZ_D
= FOP(18, FMT_D
),
5873 OPC_MOVN_D
= FOP(19, FMT_D
),
5874 OPC_RECIP_D
= FOP(21, FMT_D
),
5875 OPC_RSQRT_D
= FOP(22, FMT_D
),
5876 OPC_RECIP2_D
= FOP(28, FMT_D
),
5877 OPC_RECIP1_D
= FOP(29, FMT_D
),
5878 OPC_RSQRT1_D
= FOP(30, FMT_D
),
5879 OPC_RSQRT2_D
= FOP(31, FMT_D
),
5880 OPC_CVT_S_D
= FOP(32, FMT_D
),
5881 OPC_CVT_W_D
= FOP(36, FMT_D
),
5882 OPC_CVT_L_D
= FOP(37, FMT_D
),
5883 OPC_CMP_F_D
= FOP (48, FMT_D
),
5884 OPC_CMP_UN_D
= FOP (49, FMT_D
),
5885 OPC_CMP_EQ_D
= FOP (50, FMT_D
),
5886 OPC_CMP_UEQ_D
= FOP (51, FMT_D
),
5887 OPC_CMP_OLT_D
= FOP (52, FMT_D
),
5888 OPC_CMP_ULT_D
= FOP (53, FMT_D
),
5889 OPC_CMP_OLE_D
= FOP (54, FMT_D
),
5890 OPC_CMP_ULE_D
= FOP (55, FMT_D
),
5891 OPC_CMP_SF_D
= FOP (56, FMT_D
),
5892 OPC_CMP_NGLE_D
= FOP (57, FMT_D
),
5893 OPC_CMP_SEQ_D
= FOP (58, FMT_D
),
5894 OPC_CMP_NGL_D
= FOP (59, FMT_D
),
5895 OPC_CMP_LT_D
= FOP (60, FMT_D
),
5896 OPC_CMP_NGE_D
= FOP (61, FMT_D
),
5897 OPC_CMP_LE_D
= FOP (62, FMT_D
),
5898 OPC_CMP_NGT_D
= FOP (63, FMT_D
),
5900 OPC_CVT_S_W
= FOP(32, FMT_W
),
5901 OPC_CVT_D_W
= FOP(33, FMT_W
),
5902 OPC_CVT_S_L
= FOP(32, FMT_L
),
5903 OPC_CVT_D_L
= FOP(33, FMT_L
),
5904 OPC_CVT_PS_PW
= FOP(38, FMT_W
),
5906 OPC_ADD_PS
= FOP(0, FMT_PS
),
5907 OPC_SUB_PS
= FOP(1, FMT_PS
),
5908 OPC_MUL_PS
= FOP(2, FMT_PS
),
5909 OPC_DIV_PS
= FOP(3, FMT_PS
),
5910 OPC_ABS_PS
= FOP(5, FMT_PS
),
5911 OPC_MOV_PS
= FOP(6, FMT_PS
),
5912 OPC_NEG_PS
= FOP(7, FMT_PS
),
5913 OPC_MOVCF_PS
= FOP(17, FMT_PS
),
5914 OPC_MOVZ_PS
= FOP(18, FMT_PS
),
5915 OPC_MOVN_PS
= FOP(19, FMT_PS
),
5916 OPC_ADDR_PS
= FOP(24, FMT_PS
),
5917 OPC_MULR_PS
= FOP(26, FMT_PS
),
5918 OPC_RECIP2_PS
= FOP(28, FMT_PS
),
5919 OPC_RECIP1_PS
= FOP(29, FMT_PS
),
5920 OPC_RSQRT1_PS
= FOP(30, FMT_PS
),
5921 OPC_RSQRT2_PS
= FOP(31, FMT_PS
),
5923 OPC_CVT_S_PU
= FOP(32, FMT_PS
),
5924 OPC_CVT_PW_PS
= FOP(36, FMT_PS
),
5925 OPC_CVT_S_PL
= FOP(40, FMT_PS
),
5926 OPC_PLL_PS
= FOP(44, FMT_PS
),
5927 OPC_PLU_PS
= FOP(45, FMT_PS
),
5928 OPC_PUL_PS
= FOP(46, FMT_PS
),
5929 OPC_PUU_PS
= FOP(47, FMT_PS
),
5930 OPC_CMP_F_PS
= FOP (48, FMT_PS
),
5931 OPC_CMP_UN_PS
= FOP (49, FMT_PS
),
5932 OPC_CMP_EQ_PS
= FOP (50, FMT_PS
),
5933 OPC_CMP_UEQ_PS
= FOP (51, FMT_PS
),
5934 OPC_CMP_OLT_PS
= FOP (52, FMT_PS
),
5935 OPC_CMP_ULT_PS
= FOP (53, FMT_PS
),
5936 OPC_CMP_OLE_PS
= FOP (54, FMT_PS
),
5937 OPC_CMP_ULE_PS
= FOP (55, FMT_PS
),
5938 OPC_CMP_SF_PS
= FOP (56, FMT_PS
),
5939 OPC_CMP_NGLE_PS
= FOP (57, FMT_PS
),
5940 OPC_CMP_SEQ_PS
= FOP (58, FMT_PS
),
5941 OPC_CMP_NGL_PS
= FOP (59, FMT_PS
),
5942 OPC_CMP_LT_PS
= FOP (60, FMT_PS
),
5943 OPC_CMP_NGE_PS
= FOP (61, FMT_PS
),
5944 OPC_CMP_LE_PS
= FOP (62, FMT_PS
),
5945 OPC_CMP_NGT_PS
= FOP (63, FMT_PS
),
5948 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5950 const char *opn
= "cp1 move";
5951 TCGv t0
= tcg_temp_new();
5956 TCGv_i32 fp0
= tcg_temp_new_i32();
5958 gen_load_fpr32(fp0
, fs
);
5959 tcg_gen_ext_i32_tl(t0
, fp0
);
5960 tcg_temp_free_i32(fp0
);
5962 gen_store_gpr(t0
, rt
);
5966 gen_load_gpr(t0
, rt
);
5968 TCGv_i32 fp0
= tcg_temp_new_i32();
5970 tcg_gen_trunc_tl_i32(fp0
, t0
);
5971 gen_store_fpr32(fp0
, fs
);
5972 tcg_temp_free_i32(fp0
);
5977 gen_helper_1i(cfc1
, t0
, fs
);
5978 gen_store_gpr(t0
, rt
);
5982 gen_load_gpr(t0
, rt
);
5983 gen_helper_1i(ctc1
, t0
, fs
);
5986 #if defined(TARGET_MIPS64)
5988 gen_load_fpr64(ctx
, t0
, fs
);
5989 gen_store_gpr(t0
, rt
);
5993 gen_load_gpr(t0
, rt
);
5994 gen_store_fpr64(ctx
, t0
, fs
);
6000 TCGv_i32 fp0
= tcg_temp_new_i32();
6002 gen_load_fpr32h(fp0
, fs
);
6003 tcg_gen_ext_i32_tl(t0
, fp0
);
6004 tcg_temp_free_i32(fp0
);
6006 gen_store_gpr(t0
, rt
);
6010 gen_load_gpr(t0
, rt
);
6012 TCGv_i32 fp0
= tcg_temp_new_i32();
6014 tcg_gen_trunc_tl_i32(fp0
, t0
);
6015 gen_store_fpr32h(fp0
, fs
);
6016 tcg_temp_free_i32(fp0
);
6022 generate_exception (ctx
, EXCP_RI
);
6025 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
6031 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
6047 l1
= gen_new_label();
6048 t0
= tcg_temp_new_i32();
6049 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6050 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6051 tcg_temp_free_i32(t0
);
6053 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
6055 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
6060 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
6063 TCGv_i32 t0
= tcg_temp_new_i32();
6064 int l1
= gen_new_label();
6071 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6072 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6073 gen_load_fpr32(t0
, fs
);
6074 gen_store_fpr32(t0
, fd
);
6076 tcg_temp_free_i32(t0
);
6079 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
6082 TCGv_i32 t0
= tcg_temp_new_i32();
6084 int l1
= gen_new_label();
6091 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6092 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6093 tcg_temp_free_i32(t0
);
6094 fp0
= tcg_temp_new_i64();
6095 gen_load_fpr64(ctx
, fp0
, fs
);
6096 gen_store_fpr64(ctx
, fp0
, fd
);
6097 tcg_temp_free_i64(fp0
);
6101 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
6104 TCGv_i32 t0
= tcg_temp_new_i32();
6105 int l1
= gen_new_label();
6106 int l2
= gen_new_label();
6113 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6114 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6115 gen_load_fpr32(t0
, fs
);
6116 gen_store_fpr32(t0
, fd
);
6119 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
6120 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
6121 gen_load_fpr32h(t0
, fs
);
6122 gen_store_fpr32h(t0
, fd
);
6123 tcg_temp_free_i32(t0
);
6128 static void gen_farith (DisasContext
*ctx
, enum fopcode op1
,
6129 int ft
, int fs
, int fd
, int cc
)
6131 const char *opn
= "farith";
6132 const char *condnames
[] = {
6150 const char *condnames_abs
[] = {
6168 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6169 uint32_t func
= ctx
->opcode
& 0x3f;
6174 TCGv_i32 fp0
= tcg_temp_new_i32();
6175 TCGv_i32 fp1
= tcg_temp_new_i32();
6177 gen_load_fpr32(fp0
, fs
);
6178 gen_load_fpr32(fp1
, ft
);
6179 gen_helper_float_add_s(fp0
, fp0
, fp1
);
6180 tcg_temp_free_i32(fp1
);
6181 gen_store_fpr32(fp0
, fd
);
6182 tcg_temp_free_i32(fp0
);
6189 TCGv_i32 fp0
= tcg_temp_new_i32();
6190 TCGv_i32 fp1
= tcg_temp_new_i32();
6192 gen_load_fpr32(fp0
, fs
);
6193 gen_load_fpr32(fp1
, ft
);
6194 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6195 tcg_temp_free_i32(fp1
);
6196 gen_store_fpr32(fp0
, fd
);
6197 tcg_temp_free_i32(fp0
);
6204 TCGv_i32 fp0
= tcg_temp_new_i32();
6205 TCGv_i32 fp1
= tcg_temp_new_i32();
6207 gen_load_fpr32(fp0
, fs
);
6208 gen_load_fpr32(fp1
, ft
);
6209 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6210 tcg_temp_free_i32(fp1
);
6211 gen_store_fpr32(fp0
, fd
);
6212 tcg_temp_free_i32(fp0
);
6219 TCGv_i32 fp0
= tcg_temp_new_i32();
6220 TCGv_i32 fp1
= tcg_temp_new_i32();
6222 gen_load_fpr32(fp0
, fs
);
6223 gen_load_fpr32(fp1
, ft
);
6224 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6225 tcg_temp_free_i32(fp1
);
6226 gen_store_fpr32(fp0
, fd
);
6227 tcg_temp_free_i32(fp0
);
6234 TCGv_i32 fp0
= tcg_temp_new_i32();
6236 gen_load_fpr32(fp0
, fs
);
6237 gen_helper_float_sqrt_s(fp0
, fp0
);
6238 gen_store_fpr32(fp0
, fd
);
6239 tcg_temp_free_i32(fp0
);
6245 TCGv_i32 fp0
= tcg_temp_new_i32();
6247 gen_load_fpr32(fp0
, fs
);
6248 gen_helper_float_abs_s(fp0
, fp0
);
6249 gen_store_fpr32(fp0
, fd
);
6250 tcg_temp_free_i32(fp0
);
6256 TCGv_i32 fp0
= tcg_temp_new_i32();
6258 gen_load_fpr32(fp0
, fs
);
6259 gen_store_fpr32(fp0
, fd
);
6260 tcg_temp_free_i32(fp0
);
6266 TCGv_i32 fp0
= tcg_temp_new_i32();
6268 gen_load_fpr32(fp0
, fs
);
6269 gen_helper_float_chs_s(fp0
, fp0
);
6270 gen_store_fpr32(fp0
, fd
);
6271 tcg_temp_free_i32(fp0
);
6276 check_cp1_64bitmode(ctx
);
6278 TCGv_i32 fp32
= tcg_temp_new_i32();
6279 TCGv_i64 fp64
= tcg_temp_new_i64();
6281 gen_load_fpr32(fp32
, fs
);
6282 gen_helper_float_roundl_s(fp64
, fp32
);
6283 tcg_temp_free_i32(fp32
);
6284 gen_store_fpr64(ctx
, fp64
, fd
);
6285 tcg_temp_free_i64(fp64
);
6290 check_cp1_64bitmode(ctx
);
6292 TCGv_i32 fp32
= tcg_temp_new_i32();
6293 TCGv_i64 fp64
= tcg_temp_new_i64();
6295 gen_load_fpr32(fp32
, fs
);
6296 gen_helper_float_truncl_s(fp64
, fp32
);
6297 tcg_temp_free_i32(fp32
);
6298 gen_store_fpr64(ctx
, fp64
, fd
);
6299 tcg_temp_free_i64(fp64
);
6304 check_cp1_64bitmode(ctx
);
6306 TCGv_i32 fp32
= tcg_temp_new_i32();
6307 TCGv_i64 fp64
= tcg_temp_new_i64();
6309 gen_load_fpr32(fp32
, fs
);
6310 gen_helper_float_ceill_s(fp64
, fp32
);
6311 tcg_temp_free_i32(fp32
);
6312 gen_store_fpr64(ctx
, fp64
, fd
);
6313 tcg_temp_free_i64(fp64
);
6318 check_cp1_64bitmode(ctx
);
6320 TCGv_i32 fp32
= tcg_temp_new_i32();
6321 TCGv_i64 fp64
= tcg_temp_new_i64();
6323 gen_load_fpr32(fp32
, fs
);
6324 gen_helper_float_floorl_s(fp64
, fp32
);
6325 tcg_temp_free_i32(fp32
);
6326 gen_store_fpr64(ctx
, fp64
, fd
);
6327 tcg_temp_free_i64(fp64
);
6333 TCGv_i32 fp0
= tcg_temp_new_i32();
6335 gen_load_fpr32(fp0
, fs
);
6336 gen_helper_float_roundw_s(fp0
, fp0
);
6337 gen_store_fpr32(fp0
, fd
);
6338 tcg_temp_free_i32(fp0
);
6344 TCGv_i32 fp0
= tcg_temp_new_i32();
6346 gen_load_fpr32(fp0
, fs
);
6347 gen_helper_float_truncw_s(fp0
, fp0
);
6348 gen_store_fpr32(fp0
, fd
);
6349 tcg_temp_free_i32(fp0
);
6355 TCGv_i32 fp0
= tcg_temp_new_i32();
6357 gen_load_fpr32(fp0
, fs
);
6358 gen_helper_float_ceilw_s(fp0
, fp0
);
6359 gen_store_fpr32(fp0
, fd
);
6360 tcg_temp_free_i32(fp0
);
6366 TCGv_i32 fp0
= tcg_temp_new_i32();
6368 gen_load_fpr32(fp0
, fs
);
6369 gen_helper_float_floorw_s(fp0
, fp0
);
6370 gen_store_fpr32(fp0
, fd
);
6371 tcg_temp_free_i32(fp0
);
6376 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6381 int l1
= gen_new_label();
6385 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6387 fp0
= tcg_temp_new_i32();
6388 gen_load_fpr32(fp0
, fs
);
6389 gen_store_fpr32(fp0
, fd
);
6390 tcg_temp_free_i32(fp0
);
6397 int l1
= gen_new_label();
6401 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6402 fp0
= tcg_temp_new_i32();
6403 gen_load_fpr32(fp0
, fs
);
6404 gen_store_fpr32(fp0
, fd
);
6405 tcg_temp_free_i32(fp0
);
6414 TCGv_i32 fp0
= tcg_temp_new_i32();
6416 gen_load_fpr32(fp0
, fs
);
6417 gen_helper_float_recip_s(fp0
, fp0
);
6418 gen_store_fpr32(fp0
, fd
);
6419 tcg_temp_free_i32(fp0
);
6426 TCGv_i32 fp0
= tcg_temp_new_i32();
6428 gen_load_fpr32(fp0
, fs
);
6429 gen_helper_float_rsqrt_s(fp0
, fp0
);
6430 gen_store_fpr32(fp0
, fd
);
6431 tcg_temp_free_i32(fp0
);
6436 check_cp1_64bitmode(ctx
);
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
, fd
);
6443 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6444 tcg_temp_free_i32(fp1
);
6445 gen_store_fpr32(fp0
, fd
);
6446 tcg_temp_free_i32(fp0
);
6451 check_cp1_64bitmode(ctx
);
6453 TCGv_i32 fp0
= tcg_temp_new_i32();
6455 gen_load_fpr32(fp0
, fs
);
6456 gen_helper_float_recip1_s(fp0
, fp0
);
6457 gen_store_fpr32(fp0
, fd
);
6458 tcg_temp_free_i32(fp0
);
6463 check_cp1_64bitmode(ctx
);
6465 TCGv_i32 fp0
= tcg_temp_new_i32();
6467 gen_load_fpr32(fp0
, fs
);
6468 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6469 gen_store_fpr32(fp0
, fd
);
6470 tcg_temp_free_i32(fp0
);
6475 check_cp1_64bitmode(ctx
);
6477 TCGv_i32 fp0
= tcg_temp_new_i32();
6478 TCGv_i32 fp1
= tcg_temp_new_i32();
6480 gen_load_fpr32(fp0
, fs
);
6481 gen_load_fpr32(fp1
, ft
);
6482 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6483 tcg_temp_free_i32(fp1
);
6484 gen_store_fpr32(fp0
, fd
);
6485 tcg_temp_free_i32(fp0
);
6490 check_cp1_registers(ctx
, fd
);
6492 TCGv_i32 fp32
= tcg_temp_new_i32();
6493 TCGv_i64 fp64
= tcg_temp_new_i64();
6495 gen_load_fpr32(fp32
, fs
);
6496 gen_helper_float_cvtd_s(fp64
, fp32
);
6497 tcg_temp_free_i32(fp32
);
6498 gen_store_fpr64(ctx
, fp64
, fd
);
6499 tcg_temp_free_i64(fp64
);
6505 TCGv_i32 fp0
= tcg_temp_new_i32();
6507 gen_load_fpr32(fp0
, fs
);
6508 gen_helper_float_cvtw_s(fp0
, fp0
);
6509 gen_store_fpr32(fp0
, fd
);
6510 tcg_temp_free_i32(fp0
);
6515 check_cp1_64bitmode(ctx
);
6517 TCGv_i32 fp32
= tcg_temp_new_i32();
6518 TCGv_i64 fp64
= tcg_temp_new_i64();
6520 gen_load_fpr32(fp32
, fs
);
6521 gen_helper_float_cvtl_s(fp64
, fp32
);
6522 tcg_temp_free_i32(fp32
);
6523 gen_store_fpr64(ctx
, fp64
, fd
);
6524 tcg_temp_free_i64(fp64
);
6529 check_cp1_64bitmode(ctx
);
6531 TCGv_i64 fp64
= tcg_temp_new_i64();
6532 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6533 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6535 gen_load_fpr32(fp32_0
, fs
);
6536 gen_load_fpr32(fp32_1
, ft
);
6537 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6538 tcg_temp_free_i32(fp32_1
);
6539 tcg_temp_free_i32(fp32_0
);
6540 gen_store_fpr64(ctx
, fp64
, fd
);
6541 tcg_temp_free_i64(fp64
);
6554 case OPC_CMP_NGLE_S
:
6561 if (ctx
->opcode
& (1 << 6)) {
6562 gen_cmpabs_s(ctx
, func
-48, ft
, fs
, cc
);
6563 opn
= condnames_abs
[func
-48];
6565 gen_cmp_s(ctx
, func
-48, ft
, fs
, cc
);
6566 opn
= condnames
[func
-48];
6570 check_cp1_registers(ctx
, fs
| ft
| fd
);
6572 TCGv_i64 fp0
= tcg_temp_new_i64();
6573 TCGv_i64 fp1
= tcg_temp_new_i64();
6575 gen_load_fpr64(ctx
, fp0
, fs
);
6576 gen_load_fpr64(ctx
, fp1
, ft
);
6577 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6578 tcg_temp_free_i64(fp1
);
6579 gen_store_fpr64(ctx
, fp0
, fd
);
6580 tcg_temp_free_i64(fp0
);
6586 check_cp1_registers(ctx
, fs
| ft
| fd
);
6588 TCGv_i64 fp0
= tcg_temp_new_i64();
6589 TCGv_i64 fp1
= tcg_temp_new_i64();
6591 gen_load_fpr64(ctx
, fp0
, fs
);
6592 gen_load_fpr64(ctx
, fp1
, ft
);
6593 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6594 tcg_temp_free_i64(fp1
);
6595 gen_store_fpr64(ctx
, fp0
, fd
);
6596 tcg_temp_free_i64(fp0
);
6602 check_cp1_registers(ctx
, fs
| ft
| fd
);
6604 TCGv_i64 fp0
= tcg_temp_new_i64();
6605 TCGv_i64 fp1
= tcg_temp_new_i64();
6607 gen_load_fpr64(ctx
, fp0
, fs
);
6608 gen_load_fpr64(ctx
, fp1
, ft
);
6609 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6610 tcg_temp_free_i64(fp1
);
6611 gen_store_fpr64(ctx
, fp0
, fd
);
6612 tcg_temp_free_i64(fp0
);
6618 check_cp1_registers(ctx
, fs
| ft
| fd
);
6620 TCGv_i64 fp0
= tcg_temp_new_i64();
6621 TCGv_i64 fp1
= tcg_temp_new_i64();
6623 gen_load_fpr64(ctx
, fp0
, fs
);
6624 gen_load_fpr64(ctx
, fp1
, ft
);
6625 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6626 tcg_temp_free_i64(fp1
);
6627 gen_store_fpr64(ctx
, fp0
, fd
);
6628 tcg_temp_free_i64(fp0
);
6634 check_cp1_registers(ctx
, fs
| fd
);
6636 TCGv_i64 fp0
= tcg_temp_new_i64();
6638 gen_load_fpr64(ctx
, fp0
, fs
);
6639 gen_helper_float_sqrt_d(fp0
, fp0
);
6640 gen_store_fpr64(ctx
, fp0
, fd
);
6641 tcg_temp_free_i64(fp0
);
6646 check_cp1_registers(ctx
, fs
| fd
);
6648 TCGv_i64 fp0
= tcg_temp_new_i64();
6650 gen_load_fpr64(ctx
, fp0
, fs
);
6651 gen_helper_float_abs_d(fp0
, fp0
);
6652 gen_store_fpr64(ctx
, fp0
, fd
);
6653 tcg_temp_free_i64(fp0
);
6658 check_cp1_registers(ctx
, fs
| fd
);
6660 TCGv_i64 fp0
= tcg_temp_new_i64();
6662 gen_load_fpr64(ctx
, fp0
, fs
);
6663 gen_store_fpr64(ctx
, fp0
, fd
);
6664 tcg_temp_free_i64(fp0
);
6669 check_cp1_registers(ctx
, fs
| fd
);
6671 TCGv_i64 fp0
= tcg_temp_new_i64();
6673 gen_load_fpr64(ctx
, fp0
, fs
);
6674 gen_helper_float_chs_d(fp0
, fp0
);
6675 gen_store_fpr64(ctx
, fp0
, fd
);
6676 tcg_temp_free_i64(fp0
);
6681 check_cp1_64bitmode(ctx
);
6683 TCGv_i64 fp0
= tcg_temp_new_i64();
6685 gen_load_fpr64(ctx
, fp0
, fs
);
6686 gen_helper_float_roundl_d(fp0
, fp0
);
6687 gen_store_fpr64(ctx
, fp0
, fd
);
6688 tcg_temp_free_i64(fp0
);
6693 check_cp1_64bitmode(ctx
);
6695 TCGv_i64 fp0
= tcg_temp_new_i64();
6697 gen_load_fpr64(ctx
, fp0
, fs
);
6698 gen_helper_float_truncl_d(fp0
, fp0
);
6699 gen_store_fpr64(ctx
, fp0
, fd
);
6700 tcg_temp_free_i64(fp0
);
6705 check_cp1_64bitmode(ctx
);
6707 TCGv_i64 fp0
= tcg_temp_new_i64();
6709 gen_load_fpr64(ctx
, fp0
, fs
);
6710 gen_helper_float_ceill_d(fp0
, fp0
);
6711 gen_store_fpr64(ctx
, fp0
, fd
);
6712 tcg_temp_free_i64(fp0
);
6717 check_cp1_64bitmode(ctx
);
6719 TCGv_i64 fp0
= tcg_temp_new_i64();
6721 gen_load_fpr64(ctx
, fp0
, fs
);
6722 gen_helper_float_floorl_d(fp0
, fp0
);
6723 gen_store_fpr64(ctx
, fp0
, fd
);
6724 tcg_temp_free_i64(fp0
);
6729 check_cp1_registers(ctx
, fs
);
6731 TCGv_i32 fp32
= tcg_temp_new_i32();
6732 TCGv_i64 fp64
= tcg_temp_new_i64();
6734 gen_load_fpr64(ctx
, fp64
, fs
);
6735 gen_helper_float_roundw_d(fp32
, fp64
);
6736 tcg_temp_free_i64(fp64
);
6737 gen_store_fpr32(fp32
, fd
);
6738 tcg_temp_free_i32(fp32
);
6743 check_cp1_registers(ctx
, fs
);
6745 TCGv_i32 fp32
= tcg_temp_new_i32();
6746 TCGv_i64 fp64
= tcg_temp_new_i64();
6748 gen_load_fpr64(ctx
, fp64
, fs
);
6749 gen_helper_float_truncw_d(fp32
, fp64
);
6750 tcg_temp_free_i64(fp64
);
6751 gen_store_fpr32(fp32
, fd
);
6752 tcg_temp_free_i32(fp32
);
6757 check_cp1_registers(ctx
, fs
);
6759 TCGv_i32 fp32
= tcg_temp_new_i32();
6760 TCGv_i64 fp64
= tcg_temp_new_i64();
6762 gen_load_fpr64(ctx
, fp64
, fs
);
6763 gen_helper_float_ceilw_d(fp32
, fp64
);
6764 tcg_temp_free_i64(fp64
);
6765 gen_store_fpr32(fp32
, fd
);
6766 tcg_temp_free_i32(fp32
);
6771 check_cp1_registers(ctx
, fs
);
6773 TCGv_i32 fp32
= tcg_temp_new_i32();
6774 TCGv_i64 fp64
= tcg_temp_new_i64();
6776 gen_load_fpr64(ctx
, fp64
, fs
);
6777 gen_helper_float_floorw_d(fp32
, fp64
);
6778 tcg_temp_free_i64(fp64
);
6779 gen_store_fpr32(fp32
, fd
);
6780 tcg_temp_free_i32(fp32
);
6785 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6790 int l1
= gen_new_label();
6794 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6796 fp0
= tcg_temp_new_i64();
6797 gen_load_fpr64(ctx
, fp0
, fs
);
6798 gen_store_fpr64(ctx
, fp0
, fd
);
6799 tcg_temp_free_i64(fp0
);
6806 int l1
= gen_new_label();
6810 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6811 fp0
= tcg_temp_new_i64();
6812 gen_load_fpr64(ctx
, fp0
, fs
);
6813 gen_store_fpr64(ctx
, fp0
, fd
);
6814 tcg_temp_free_i64(fp0
);
6821 check_cp1_64bitmode(ctx
);
6823 TCGv_i64 fp0
= tcg_temp_new_i64();
6825 gen_load_fpr64(ctx
, fp0
, fs
);
6826 gen_helper_float_recip_d(fp0
, fp0
);
6827 gen_store_fpr64(ctx
, fp0
, fd
);
6828 tcg_temp_free_i64(fp0
);
6833 check_cp1_64bitmode(ctx
);
6835 TCGv_i64 fp0
= tcg_temp_new_i64();
6837 gen_load_fpr64(ctx
, fp0
, fs
);
6838 gen_helper_float_rsqrt_d(fp0
, fp0
);
6839 gen_store_fpr64(ctx
, fp0
, fd
);
6840 tcg_temp_free_i64(fp0
);
6845 check_cp1_64bitmode(ctx
);
6847 TCGv_i64 fp0
= tcg_temp_new_i64();
6848 TCGv_i64 fp1
= tcg_temp_new_i64();
6850 gen_load_fpr64(ctx
, fp0
, fs
);
6851 gen_load_fpr64(ctx
, fp1
, ft
);
6852 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6853 tcg_temp_free_i64(fp1
);
6854 gen_store_fpr64(ctx
, fp0
, fd
);
6855 tcg_temp_free_i64(fp0
);
6860 check_cp1_64bitmode(ctx
);
6862 TCGv_i64 fp0
= tcg_temp_new_i64();
6864 gen_load_fpr64(ctx
, fp0
, fs
);
6865 gen_helper_float_recip1_d(fp0
, fp0
);
6866 gen_store_fpr64(ctx
, fp0
, fd
);
6867 tcg_temp_free_i64(fp0
);
6872 check_cp1_64bitmode(ctx
);
6874 TCGv_i64 fp0
= tcg_temp_new_i64();
6876 gen_load_fpr64(ctx
, fp0
, fs
);
6877 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6878 gen_store_fpr64(ctx
, fp0
, fd
);
6879 tcg_temp_free_i64(fp0
);
6884 check_cp1_64bitmode(ctx
);
6886 TCGv_i64 fp0
= tcg_temp_new_i64();
6887 TCGv_i64 fp1
= tcg_temp_new_i64();
6889 gen_load_fpr64(ctx
, fp0
, fs
);
6890 gen_load_fpr64(ctx
, fp1
, ft
);
6891 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6892 tcg_temp_free_i64(fp1
);
6893 gen_store_fpr64(ctx
, fp0
, fd
);
6894 tcg_temp_free_i64(fp0
);
6907 case OPC_CMP_NGLE_D
:
6914 if (ctx
->opcode
& (1 << 6)) {
6915 gen_cmpabs_d(ctx
, func
-48, ft
, fs
, cc
);
6916 opn
= condnames_abs
[func
-48];
6918 gen_cmp_d(ctx
, func
-48, ft
, fs
, cc
);
6919 opn
= condnames
[func
-48];
6923 check_cp1_registers(ctx
, fs
);
6925 TCGv_i32 fp32
= tcg_temp_new_i32();
6926 TCGv_i64 fp64
= tcg_temp_new_i64();
6928 gen_load_fpr64(ctx
, fp64
, fs
);
6929 gen_helper_float_cvts_d(fp32
, fp64
);
6930 tcg_temp_free_i64(fp64
);
6931 gen_store_fpr32(fp32
, fd
);
6932 tcg_temp_free_i32(fp32
);
6937 check_cp1_registers(ctx
, fs
);
6939 TCGv_i32 fp32
= tcg_temp_new_i32();
6940 TCGv_i64 fp64
= tcg_temp_new_i64();
6942 gen_load_fpr64(ctx
, fp64
, fs
);
6943 gen_helper_float_cvtw_d(fp32
, fp64
);
6944 tcg_temp_free_i64(fp64
);
6945 gen_store_fpr32(fp32
, fd
);
6946 tcg_temp_free_i32(fp32
);
6951 check_cp1_64bitmode(ctx
);
6953 TCGv_i64 fp0
= tcg_temp_new_i64();
6955 gen_load_fpr64(ctx
, fp0
, fs
);
6956 gen_helper_float_cvtl_d(fp0
, fp0
);
6957 gen_store_fpr64(ctx
, fp0
, fd
);
6958 tcg_temp_free_i64(fp0
);
6964 TCGv_i32 fp0
= tcg_temp_new_i32();
6966 gen_load_fpr32(fp0
, fs
);
6967 gen_helper_float_cvts_w(fp0
, fp0
);
6968 gen_store_fpr32(fp0
, fd
);
6969 tcg_temp_free_i32(fp0
);
6974 check_cp1_registers(ctx
, fd
);
6976 TCGv_i32 fp32
= tcg_temp_new_i32();
6977 TCGv_i64 fp64
= tcg_temp_new_i64();
6979 gen_load_fpr32(fp32
, fs
);
6980 gen_helper_float_cvtd_w(fp64
, fp32
);
6981 tcg_temp_free_i32(fp32
);
6982 gen_store_fpr64(ctx
, fp64
, fd
);
6983 tcg_temp_free_i64(fp64
);
6988 check_cp1_64bitmode(ctx
);
6990 TCGv_i32 fp32
= tcg_temp_new_i32();
6991 TCGv_i64 fp64
= tcg_temp_new_i64();
6993 gen_load_fpr64(ctx
, fp64
, fs
);
6994 gen_helper_float_cvts_l(fp32
, fp64
);
6995 tcg_temp_free_i64(fp64
);
6996 gen_store_fpr32(fp32
, fd
);
6997 tcg_temp_free_i32(fp32
);
7002 check_cp1_64bitmode(ctx
);
7004 TCGv_i64 fp0
= tcg_temp_new_i64();
7006 gen_load_fpr64(ctx
, fp0
, fs
);
7007 gen_helper_float_cvtd_l(fp0
, fp0
);
7008 gen_store_fpr64(ctx
, fp0
, fd
);
7009 tcg_temp_free_i64(fp0
);
7014 check_cp1_64bitmode(ctx
);
7016 TCGv_i64 fp0
= tcg_temp_new_i64();
7018 gen_load_fpr64(ctx
, fp0
, fs
);
7019 gen_helper_float_cvtps_pw(fp0
, fp0
);
7020 gen_store_fpr64(ctx
, fp0
, fd
);
7021 tcg_temp_free_i64(fp0
);
7026 check_cp1_64bitmode(ctx
);
7028 TCGv_i64 fp0
= tcg_temp_new_i64();
7029 TCGv_i64 fp1
= tcg_temp_new_i64();
7031 gen_load_fpr64(ctx
, fp0
, fs
);
7032 gen_load_fpr64(ctx
, fp1
, ft
);
7033 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
7034 tcg_temp_free_i64(fp1
);
7035 gen_store_fpr64(ctx
, fp0
, fd
);
7036 tcg_temp_free_i64(fp0
);
7041 check_cp1_64bitmode(ctx
);
7043 TCGv_i64 fp0
= tcg_temp_new_i64();
7044 TCGv_i64 fp1
= tcg_temp_new_i64();
7046 gen_load_fpr64(ctx
, fp0
, fs
);
7047 gen_load_fpr64(ctx
, fp1
, ft
);
7048 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
7049 tcg_temp_free_i64(fp1
);
7050 gen_store_fpr64(ctx
, fp0
, fd
);
7051 tcg_temp_free_i64(fp0
);
7056 check_cp1_64bitmode(ctx
);
7058 TCGv_i64 fp0
= tcg_temp_new_i64();
7059 TCGv_i64 fp1
= tcg_temp_new_i64();
7061 gen_load_fpr64(ctx
, fp0
, fs
);
7062 gen_load_fpr64(ctx
, fp1
, ft
);
7063 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
7064 tcg_temp_free_i64(fp1
);
7065 gen_store_fpr64(ctx
, fp0
, fd
);
7066 tcg_temp_free_i64(fp0
);
7071 check_cp1_64bitmode(ctx
);
7073 TCGv_i64 fp0
= tcg_temp_new_i64();
7075 gen_load_fpr64(ctx
, fp0
, fs
);
7076 gen_helper_float_abs_ps(fp0
, fp0
);
7077 gen_store_fpr64(ctx
, fp0
, fd
);
7078 tcg_temp_free_i64(fp0
);
7083 check_cp1_64bitmode(ctx
);
7085 TCGv_i64 fp0
= tcg_temp_new_i64();
7087 gen_load_fpr64(ctx
, fp0
, fs
);
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();
7098 gen_load_fpr64(ctx
, fp0
, fs
);
7099 gen_helper_float_chs_ps(fp0
, fp0
);
7100 gen_store_fpr64(ctx
, fp0
, fd
);
7101 tcg_temp_free_i64(fp0
);
7106 check_cp1_64bitmode(ctx
);
7107 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7111 check_cp1_64bitmode(ctx
);
7113 int l1
= gen_new_label();
7117 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7118 fp0
= tcg_temp_new_i64();
7119 gen_load_fpr64(ctx
, fp0
, fs
);
7120 gen_store_fpr64(ctx
, fp0
, fd
);
7121 tcg_temp_free_i64(fp0
);
7127 check_cp1_64bitmode(ctx
);
7129 int l1
= gen_new_label();
7133 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7134 fp0
= tcg_temp_new_i64();
7135 gen_load_fpr64(ctx
, fp0
, fs
);
7136 gen_store_fpr64(ctx
, fp0
, fd
);
7137 tcg_temp_free_i64(fp0
);
7144 check_cp1_64bitmode(ctx
);
7146 TCGv_i64 fp0
= tcg_temp_new_i64();
7147 TCGv_i64 fp1
= tcg_temp_new_i64();
7149 gen_load_fpr64(ctx
, fp0
, ft
);
7150 gen_load_fpr64(ctx
, fp1
, fs
);
7151 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
7152 tcg_temp_free_i64(fp1
);
7153 gen_store_fpr64(ctx
, fp0
, fd
);
7154 tcg_temp_free_i64(fp0
);
7159 check_cp1_64bitmode(ctx
);
7161 TCGv_i64 fp0
= tcg_temp_new_i64();
7162 TCGv_i64 fp1
= tcg_temp_new_i64();
7164 gen_load_fpr64(ctx
, fp0
, ft
);
7165 gen_load_fpr64(ctx
, fp1
, fs
);
7166 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7167 tcg_temp_free_i64(fp1
);
7168 gen_store_fpr64(ctx
, fp0
, fd
);
7169 tcg_temp_free_i64(fp0
);
7174 check_cp1_64bitmode(ctx
);
7176 TCGv_i64 fp0
= tcg_temp_new_i64();
7177 TCGv_i64 fp1
= tcg_temp_new_i64();
7179 gen_load_fpr64(ctx
, fp0
, fs
);
7180 gen_load_fpr64(ctx
, fp1
, fd
);
7181 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7182 tcg_temp_free_i64(fp1
);
7183 gen_store_fpr64(ctx
, fp0
, fd
);
7184 tcg_temp_free_i64(fp0
);
7189 check_cp1_64bitmode(ctx
);
7191 TCGv_i64 fp0
= tcg_temp_new_i64();
7193 gen_load_fpr64(ctx
, fp0
, fs
);
7194 gen_helper_float_recip1_ps(fp0
, fp0
);
7195 gen_store_fpr64(ctx
, fp0
, fd
);
7196 tcg_temp_free_i64(fp0
);
7201 check_cp1_64bitmode(ctx
);
7203 TCGv_i64 fp0
= tcg_temp_new_i64();
7205 gen_load_fpr64(ctx
, fp0
, fs
);
7206 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7207 gen_store_fpr64(ctx
, fp0
, fd
);
7208 tcg_temp_free_i64(fp0
);
7213 check_cp1_64bitmode(ctx
);
7215 TCGv_i64 fp0
= tcg_temp_new_i64();
7216 TCGv_i64 fp1
= tcg_temp_new_i64();
7218 gen_load_fpr64(ctx
, fp0
, fs
);
7219 gen_load_fpr64(ctx
, fp1
, ft
);
7220 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7221 tcg_temp_free_i64(fp1
);
7222 gen_store_fpr64(ctx
, fp0
, fd
);
7223 tcg_temp_free_i64(fp0
);
7228 check_cp1_64bitmode(ctx
);
7230 TCGv_i32 fp0
= tcg_temp_new_i32();
7232 gen_load_fpr32h(fp0
, fs
);
7233 gen_helper_float_cvts_pu(fp0
, fp0
);
7234 gen_store_fpr32(fp0
, fd
);
7235 tcg_temp_free_i32(fp0
);
7240 check_cp1_64bitmode(ctx
);
7242 TCGv_i64 fp0
= tcg_temp_new_i64();
7244 gen_load_fpr64(ctx
, fp0
, fs
);
7245 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7246 gen_store_fpr64(ctx
, fp0
, fd
);
7247 tcg_temp_free_i64(fp0
);
7252 check_cp1_64bitmode(ctx
);
7254 TCGv_i32 fp0
= tcg_temp_new_i32();
7256 gen_load_fpr32(fp0
, fs
);
7257 gen_helper_float_cvts_pl(fp0
, fp0
);
7258 gen_store_fpr32(fp0
, fd
);
7259 tcg_temp_free_i32(fp0
);
7264 check_cp1_64bitmode(ctx
);
7266 TCGv_i32 fp0
= tcg_temp_new_i32();
7267 TCGv_i32 fp1
= tcg_temp_new_i32();
7269 gen_load_fpr32(fp0
, fs
);
7270 gen_load_fpr32(fp1
, ft
);
7271 gen_store_fpr32h(fp0
, fd
);
7272 gen_store_fpr32(fp1
, fd
);
7273 tcg_temp_free_i32(fp0
);
7274 tcg_temp_free_i32(fp1
);
7279 check_cp1_64bitmode(ctx
);
7281 TCGv_i32 fp0
= tcg_temp_new_i32();
7282 TCGv_i32 fp1
= tcg_temp_new_i32();
7284 gen_load_fpr32(fp0
, fs
);
7285 gen_load_fpr32h(fp1
, ft
);
7286 gen_store_fpr32(fp1
, fd
);
7287 gen_store_fpr32h(fp0
, fd
);
7288 tcg_temp_free_i32(fp0
);
7289 tcg_temp_free_i32(fp1
);
7294 check_cp1_64bitmode(ctx
);
7296 TCGv_i32 fp0
= tcg_temp_new_i32();
7297 TCGv_i32 fp1
= tcg_temp_new_i32();
7299 gen_load_fpr32h(fp0
, fs
);
7300 gen_load_fpr32(fp1
, ft
);
7301 gen_store_fpr32(fp1
, fd
);
7302 gen_store_fpr32h(fp0
, fd
);
7303 tcg_temp_free_i32(fp0
);
7304 tcg_temp_free_i32(fp1
);
7309 check_cp1_64bitmode(ctx
);
7311 TCGv_i32 fp0
= tcg_temp_new_i32();
7312 TCGv_i32 fp1
= tcg_temp_new_i32();
7314 gen_load_fpr32h(fp0
, fs
);
7315 gen_load_fpr32h(fp1
, ft
);
7316 gen_store_fpr32(fp1
, fd
);
7317 gen_store_fpr32h(fp0
, fd
);
7318 tcg_temp_free_i32(fp0
);
7319 tcg_temp_free_i32(fp1
);
7326 case OPC_CMP_UEQ_PS
:
7327 case OPC_CMP_OLT_PS
:
7328 case OPC_CMP_ULT_PS
:
7329 case OPC_CMP_OLE_PS
:
7330 case OPC_CMP_ULE_PS
:
7332 case OPC_CMP_NGLE_PS
:
7333 case OPC_CMP_SEQ_PS
:
7334 case OPC_CMP_NGL_PS
:
7336 case OPC_CMP_NGE_PS
:
7338 case OPC_CMP_NGT_PS
:
7339 if (ctx
->opcode
& (1 << 6)) {
7340 gen_cmpabs_ps(ctx
, func
-48, ft
, fs
, cc
);
7341 opn
= condnames_abs
[func
-48];
7343 gen_cmp_ps(ctx
, func
-48, ft
, fs
, cc
);
7344 opn
= condnames
[func
-48];
7349 generate_exception (ctx
, EXCP_RI
);
7354 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7357 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7360 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7365 /* Coprocessor 3 (FPU) */
7366 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7367 int fd
, int fs
, int base
, int index
)
7369 const char *opn
= "extended float load/store";
7371 TCGv t0
= tcg_temp_new();
7374 gen_load_gpr(t0
, index
);
7375 } else if (index
== 0) {
7376 gen_load_gpr(t0
, base
);
7378 gen_load_gpr(t0
, index
);
7379 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7381 /* Don't do NOP if destination is zero: we must perform the actual
7383 save_cpu_state(ctx
, 0);
7388 TCGv_i32 fp0
= tcg_temp_new_i32();
7390 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7391 tcg_gen_trunc_tl_i32(fp0
, t0
);
7392 gen_store_fpr32(fp0
, fd
);
7393 tcg_temp_free_i32(fp0
);
7399 check_cp1_registers(ctx
, fd
);
7401 TCGv_i64 fp0
= tcg_temp_new_i64();
7403 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7404 gen_store_fpr64(ctx
, fp0
, fd
);
7405 tcg_temp_free_i64(fp0
);
7410 check_cp1_64bitmode(ctx
);
7411 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7413 TCGv_i64 fp0
= tcg_temp_new_i64();
7415 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7416 gen_store_fpr64(ctx
, fp0
, fd
);
7417 tcg_temp_free_i64(fp0
);
7424 TCGv_i32 fp0
= tcg_temp_new_i32();
7425 TCGv t1
= tcg_temp_new();
7427 gen_load_fpr32(fp0
, fs
);
7428 tcg_gen_extu_i32_tl(t1
, fp0
);
7429 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7430 tcg_temp_free_i32(fp0
);
7438 check_cp1_registers(ctx
, fs
);
7440 TCGv_i64 fp0
= tcg_temp_new_i64();
7442 gen_load_fpr64(ctx
, fp0
, fs
);
7443 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7444 tcg_temp_free_i64(fp0
);
7450 check_cp1_64bitmode(ctx
);
7451 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7453 TCGv_i64 fp0
= tcg_temp_new_i64();
7455 gen_load_fpr64(ctx
, fp0
, fs
);
7456 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7457 tcg_temp_free_i64(fp0
);
7464 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7465 regnames
[index
], regnames
[base
]);
7468 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7469 int fd
, int fr
, int fs
, int ft
)
7471 const char *opn
= "flt3_arith";
7475 check_cp1_64bitmode(ctx
);
7477 TCGv t0
= tcg_temp_local_new();
7478 TCGv_i32 fp
= tcg_temp_new_i32();
7479 TCGv_i32 fph
= tcg_temp_new_i32();
7480 int l1
= gen_new_label();
7481 int l2
= gen_new_label();
7483 gen_load_gpr(t0
, fr
);
7484 tcg_gen_andi_tl(t0
, t0
, 0x7);
7486 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7487 gen_load_fpr32(fp
, fs
);
7488 gen_load_fpr32h(fph
, fs
);
7489 gen_store_fpr32(fp
, fd
);
7490 gen_store_fpr32h(fph
, fd
);
7493 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7495 #ifdef TARGET_WORDS_BIGENDIAN
7496 gen_load_fpr32(fp
, fs
);
7497 gen_load_fpr32h(fph
, ft
);
7498 gen_store_fpr32h(fp
, fd
);
7499 gen_store_fpr32(fph
, fd
);
7501 gen_load_fpr32h(fph
, fs
);
7502 gen_load_fpr32(fp
, ft
);
7503 gen_store_fpr32(fph
, fd
);
7504 gen_store_fpr32h(fp
, fd
);
7507 tcg_temp_free_i32(fp
);
7508 tcg_temp_free_i32(fph
);
7515 TCGv_i32 fp0
= tcg_temp_new_i32();
7516 TCGv_i32 fp1
= tcg_temp_new_i32();
7517 TCGv_i32 fp2
= tcg_temp_new_i32();
7519 gen_load_fpr32(fp0
, fs
);
7520 gen_load_fpr32(fp1
, ft
);
7521 gen_load_fpr32(fp2
, fr
);
7522 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7523 tcg_temp_free_i32(fp0
);
7524 tcg_temp_free_i32(fp1
);
7525 gen_store_fpr32(fp2
, fd
);
7526 tcg_temp_free_i32(fp2
);
7532 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7534 TCGv_i64 fp0
= tcg_temp_new_i64();
7535 TCGv_i64 fp1
= tcg_temp_new_i64();
7536 TCGv_i64 fp2
= tcg_temp_new_i64();
7538 gen_load_fpr64(ctx
, fp0
, fs
);
7539 gen_load_fpr64(ctx
, fp1
, ft
);
7540 gen_load_fpr64(ctx
, fp2
, fr
);
7541 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7542 tcg_temp_free_i64(fp0
);
7543 tcg_temp_free_i64(fp1
);
7544 gen_store_fpr64(ctx
, fp2
, fd
);
7545 tcg_temp_free_i64(fp2
);
7550 check_cp1_64bitmode(ctx
);
7552 TCGv_i64 fp0
= tcg_temp_new_i64();
7553 TCGv_i64 fp1
= tcg_temp_new_i64();
7554 TCGv_i64 fp2
= tcg_temp_new_i64();
7556 gen_load_fpr64(ctx
, fp0
, fs
);
7557 gen_load_fpr64(ctx
, fp1
, ft
);
7558 gen_load_fpr64(ctx
, fp2
, fr
);
7559 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7560 tcg_temp_free_i64(fp0
);
7561 tcg_temp_free_i64(fp1
);
7562 gen_store_fpr64(ctx
, fp2
, fd
);
7563 tcg_temp_free_i64(fp2
);
7570 TCGv_i32 fp0
= tcg_temp_new_i32();
7571 TCGv_i32 fp1
= tcg_temp_new_i32();
7572 TCGv_i32 fp2
= tcg_temp_new_i32();
7574 gen_load_fpr32(fp0
, fs
);
7575 gen_load_fpr32(fp1
, ft
);
7576 gen_load_fpr32(fp2
, fr
);
7577 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7578 tcg_temp_free_i32(fp0
);
7579 tcg_temp_free_i32(fp1
);
7580 gen_store_fpr32(fp2
, fd
);
7581 tcg_temp_free_i32(fp2
);
7587 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7589 TCGv_i64 fp0
= tcg_temp_new_i64();
7590 TCGv_i64 fp1
= tcg_temp_new_i64();
7591 TCGv_i64 fp2
= tcg_temp_new_i64();
7593 gen_load_fpr64(ctx
, fp0
, fs
);
7594 gen_load_fpr64(ctx
, fp1
, ft
);
7595 gen_load_fpr64(ctx
, fp2
, fr
);
7596 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7597 tcg_temp_free_i64(fp0
);
7598 tcg_temp_free_i64(fp1
);
7599 gen_store_fpr64(ctx
, fp2
, fd
);
7600 tcg_temp_free_i64(fp2
);
7605 check_cp1_64bitmode(ctx
);
7607 TCGv_i64 fp0
= tcg_temp_new_i64();
7608 TCGv_i64 fp1
= tcg_temp_new_i64();
7609 TCGv_i64 fp2
= tcg_temp_new_i64();
7611 gen_load_fpr64(ctx
, fp0
, fs
);
7612 gen_load_fpr64(ctx
, fp1
, ft
);
7613 gen_load_fpr64(ctx
, fp2
, fr
);
7614 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7615 tcg_temp_free_i64(fp0
);
7616 tcg_temp_free_i64(fp1
);
7617 gen_store_fpr64(ctx
, fp2
, fd
);
7618 tcg_temp_free_i64(fp2
);
7625 TCGv_i32 fp0
= tcg_temp_new_i32();
7626 TCGv_i32 fp1
= tcg_temp_new_i32();
7627 TCGv_i32 fp2
= tcg_temp_new_i32();
7629 gen_load_fpr32(fp0
, fs
);
7630 gen_load_fpr32(fp1
, ft
);
7631 gen_load_fpr32(fp2
, fr
);
7632 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7633 tcg_temp_free_i32(fp0
);
7634 tcg_temp_free_i32(fp1
);
7635 gen_store_fpr32(fp2
, fd
);
7636 tcg_temp_free_i32(fp2
);
7642 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7644 TCGv_i64 fp0
= tcg_temp_new_i64();
7645 TCGv_i64 fp1
= tcg_temp_new_i64();
7646 TCGv_i64 fp2
= tcg_temp_new_i64();
7648 gen_load_fpr64(ctx
, fp0
, fs
);
7649 gen_load_fpr64(ctx
, fp1
, ft
);
7650 gen_load_fpr64(ctx
, fp2
, fr
);
7651 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7652 tcg_temp_free_i64(fp0
);
7653 tcg_temp_free_i64(fp1
);
7654 gen_store_fpr64(ctx
, fp2
, fd
);
7655 tcg_temp_free_i64(fp2
);
7660 check_cp1_64bitmode(ctx
);
7662 TCGv_i64 fp0
= tcg_temp_new_i64();
7663 TCGv_i64 fp1
= tcg_temp_new_i64();
7664 TCGv_i64 fp2
= tcg_temp_new_i64();
7666 gen_load_fpr64(ctx
, fp0
, fs
);
7667 gen_load_fpr64(ctx
, fp1
, ft
);
7668 gen_load_fpr64(ctx
, fp2
, fr
);
7669 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7670 tcg_temp_free_i64(fp0
);
7671 tcg_temp_free_i64(fp1
);
7672 gen_store_fpr64(ctx
, fp2
, fd
);
7673 tcg_temp_free_i64(fp2
);
7680 TCGv_i32 fp0
= tcg_temp_new_i32();
7681 TCGv_i32 fp1
= tcg_temp_new_i32();
7682 TCGv_i32 fp2
= tcg_temp_new_i32();
7684 gen_load_fpr32(fp0
, fs
);
7685 gen_load_fpr32(fp1
, ft
);
7686 gen_load_fpr32(fp2
, fr
);
7687 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7688 tcg_temp_free_i32(fp0
);
7689 tcg_temp_free_i32(fp1
);
7690 gen_store_fpr32(fp2
, fd
);
7691 tcg_temp_free_i32(fp2
);
7697 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7699 TCGv_i64 fp0
= tcg_temp_new_i64();
7700 TCGv_i64 fp1
= tcg_temp_new_i64();
7701 TCGv_i64 fp2
= tcg_temp_new_i64();
7703 gen_load_fpr64(ctx
, fp0
, fs
);
7704 gen_load_fpr64(ctx
, fp1
, ft
);
7705 gen_load_fpr64(ctx
, fp2
, fr
);
7706 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7707 tcg_temp_free_i64(fp0
);
7708 tcg_temp_free_i64(fp1
);
7709 gen_store_fpr64(ctx
, fp2
, fd
);
7710 tcg_temp_free_i64(fp2
);
7715 check_cp1_64bitmode(ctx
);
7717 TCGv_i64 fp0
= tcg_temp_new_i64();
7718 TCGv_i64 fp1
= tcg_temp_new_i64();
7719 TCGv_i64 fp2
= tcg_temp_new_i64();
7721 gen_load_fpr64(ctx
, fp0
, fs
);
7722 gen_load_fpr64(ctx
, fp1
, ft
);
7723 gen_load_fpr64(ctx
, fp2
, fr
);
7724 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7725 tcg_temp_free_i64(fp0
);
7726 tcg_temp_free_i64(fp1
);
7727 gen_store_fpr64(ctx
, fp2
, fd
);
7728 tcg_temp_free_i64(fp2
);
7734 generate_exception (ctx
, EXCP_RI
);
7737 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7738 fregnames
[fs
], fregnames
[ft
]);
7742 gen_rdhwr (CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
)
7746 check_insn(env
, ctx
, ISA_MIPS32R2
);
7747 t0
= tcg_temp_new();
7751 save_cpu_state(ctx
, 1);
7752 gen_helper_rdhwr_cpunum(t0
);
7753 gen_store_gpr(t0
, rt
);
7756 save_cpu_state(ctx
, 1);
7757 gen_helper_rdhwr_synci_step(t0
);
7758 gen_store_gpr(t0
, rt
);
7761 save_cpu_state(ctx
, 1);
7762 gen_helper_rdhwr_cc(t0
);
7763 gen_store_gpr(t0
, rt
);
7766 save_cpu_state(ctx
, 1);
7767 gen_helper_rdhwr_ccres(t0
);
7768 gen_store_gpr(t0
, rt
);
7771 #if defined(CONFIG_USER_ONLY)
7772 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7773 gen_store_gpr(t0
, rt
);
7776 /* XXX: Some CPUs implement this in hardware.
7777 Not supported yet. */
7779 default: /* Invalid */
7780 MIPS_INVAL("rdhwr");
7781 generate_exception(ctx
, EXCP_RI
);
7787 static void handle_delay_slot (CPUState
*env
, DisasContext
*ctx
,
7790 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7791 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7792 /* Branches completion */
7793 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7794 ctx
->bstate
= BS_BRANCH
;
7795 save_cpu_state(ctx
, 0);
7796 /* FIXME: Need to clear can_do_io. */
7797 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
7799 /* unconditional branch */
7800 MIPS_DEBUG("unconditional branch");
7801 if (proc_hflags
& MIPS_HFLAG_BX
) {
7802 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
7804 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7807 /* blikely taken case */
7808 MIPS_DEBUG("blikely branch taken");
7809 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7812 /* Conditional branch */
7813 MIPS_DEBUG("conditional branch");
7815 int l1
= gen_new_label();
7817 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7818 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
7820 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7824 /* unconditional branch to register */
7825 MIPS_DEBUG("branch to register");
7826 if (env
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
7827 TCGv t0
= tcg_temp_new();
7828 TCGv_i32 t1
= tcg_temp_new_i32();
7830 tcg_gen_andi_tl(t0
, btarget
, 0x1);
7831 tcg_gen_trunc_tl_i32(t1
, t0
);
7833 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
7834 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
7835 tcg_gen_or_i32(hflags
, hflags
, t1
);
7836 tcg_temp_free_i32(t1
);
7838 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
7840 tcg_gen_mov_tl(cpu_PC
, btarget
);
7842 if (ctx
->singlestep_enabled
) {
7843 save_cpu_state(ctx
, 0);
7844 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
7849 MIPS_DEBUG("unknown branch");
7855 /* ISA extensions (ASEs) */
7856 /* MIPS16 extension to MIPS32 */
7858 /* MIPS16 major opcodes */
7860 M16_OPC_ADDIUSP
= 0x00,
7861 M16_OPC_ADDIUPC
= 0x01,
7864 M16_OPC_BEQZ
= 0x04,
7865 M16_OPC_BNEQZ
= 0x05,
7866 M16_OPC_SHIFT
= 0x06,
7868 M16_OPC_RRIA
= 0x08,
7869 M16_OPC_ADDIU8
= 0x09,
7870 M16_OPC_SLTI
= 0x0a,
7871 M16_OPC_SLTIU
= 0x0b,
7874 M16_OPC_CMPI
= 0x0e,
7878 M16_OPC_LWSP
= 0x12,
7882 M16_OPC_LWPC
= 0x16,
7886 M16_OPC_SWSP
= 0x1a,
7890 M16_OPC_EXTEND
= 0x1e,
7894 /* I8 funct field */
7913 /* RR funct field */
7947 /* I64 funct field */
7959 /* RR ry field for CNVT */
7961 RR_RY_CNVT_ZEB
= 0x0,
7962 RR_RY_CNVT_ZEH
= 0x1,
7963 RR_RY_CNVT_ZEW
= 0x2,
7964 RR_RY_CNVT_SEB
= 0x4,
7965 RR_RY_CNVT_SEH
= 0x5,
7966 RR_RY_CNVT_SEW
= 0x6,
7969 static int xlat (int r
)
7971 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
7976 static void gen_mips16_save (DisasContext
*ctx
,
7977 int xsregs
, int aregs
,
7978 int do_ra
, int do_s0
, int do_s1
,
7981 TCGv t0
= tcg_temp_new();
7982 TCGv t1
= tcg_temp_new();
8012 generate_exception(ctx
, EXCP_RI
);
8018 gen_base_offset_addr(ctx
, t0
, 29, 12);
8019 gen_load_gpr(t1
, 7);
8020 op_st_sw(t1
, t0
, ctx
);
8023 gen_base_offset_addr(ctx
, t0
, 29, 8);
8024 gen_load_gpr(t1
, 6);
8025 op_st_sw(t1
, t0
, ctx
);
8028 gen_base_offset_addr(ctx
, t0
, 29, 4);
8029 gen_load_gpr(t1
, 5);
8030 op_st_sw(t1
, t0
, ctx
);
8033 gen_base_offset_addr(ctx
, t0
, 29, 0);
8034 gen_load_gpr(t1
, 4);
8035 op_st_sw(t1
, t0
, ctx
);
8038 gen_load_gpr(t0
, 29);
8040 #define DECR_AND_STORE(reg) do { \
8041 tcg_gen_subi_tl(t0, t0, 4); \
8042 gen_load_gpr(t1, reg); \
8043 op_st_sw(t1, t0, ctx); \
8107 generate_exception(ctx
, EXCP_RI
);
8123 #undef DECR_AND_STORE
8125 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8130 static void gen_mips16_restore (DisasContext
*ctx
,
8131 int xsregs
, int aregs
,
8132 int do_ra
, int do_s0
, int do_s1
,
8136 TCGv t0
= tcg_temp_new();
8137 TCGv t1
= tcg_temp_new();
8139 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
8141 #define DECR_AND_LOAD(reg) do { \
8142 tcg_gen_subi_tl(t0, t0, 4); \
8143 op_ld_lw(t1, t0, ctx); \
8144 gen_store_gpr(t1, reg); \
8208 generate_exception(ctx
, EXCP_RI
);
8224 #undef DECR_AND_LOAD
8226 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8231 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
8232 int is_64_bit
, int extended
)
8236 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8237 generate_exception(ctx
, EXCP_RI
);
8241 t0
= tcg_temp_new();
8243 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
8244 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
8246 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8252 #if defined(TARGET_MIPS64)
8253 static void decode_i64_mips16 (CPUState
*env
, DisasContext
*ctx
,
8254 int ry
, int funct
, int16_t offset
,
8260 offset
= extended
? offset
: offset
<< 3;
8261 gen_ld(ctx
, OPC_LD
, ry
, 29, offset
);
8265 offset
= extended
? offset
: offset
<< 3;
8266 gen_st(ctx
, OPC_SD
, ry
, 29, offset
);
8270 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8271 gen_st(ctx
, OPC_SD
, 31, 29, offset
);
8275 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8276 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8279 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8280 generate_exception(ctx
, EXCP_RI
);
8282 offset
= extended
? offset
: offset
<< 3;
8283 gen_ld(ctx
, OPC_LDPC
, ry
, 0, offset
);
8288 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8289 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8293 offset
= extended
? offset
: offset
<< 2;
8294 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8298 offset
= extended
? offset
: offset
<< 2;
8299 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8305 static int decode_extended_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8308 int extend
= lduw_code(ctx
->pc
+ 2);
8309 int op
, rx
, ry
, funct
, sa
;
8310 int16_t imm
, offset
;
8312 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8313 op
= (ctx
->opcode
>> 11) & 0x1f;
8314 sa
= (ctx
->opcode
>> 22) & 0x1f;
8315 funct
= (ctx
->opcode
>> 8) & 0x7;
8316 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8317 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8318 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8319 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8320 | (ctx
->opcode
& 0x1f));
8322 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8325 case M16_OPC_ADDIUSP
:
8326 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8328 case M16_OPC_ADDIUPC
:
8329 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8332 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8333 /* No delay slot, so just process as a normal instruction */
8336 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8337 /* No delay slot, so just process as a normal instruction */
8340 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8341 /* No delay slot, so just process as a normal instruction */
8344 switch (ctx
->opcode
& 0x3) {
8346 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8349 #if defined(TARGET_MIPS64)
8351 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8353 generate_exception(ctx
, EXCP_RI
);
8357 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8360 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8364 #if defined(TARGET_MIPS64)
8367 gen_ld(ctx
, OPC_LD
, ry
, rx
, offset
);
8371 imm
= ctx
->opcode
& 0xf;
8372 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8373 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8374 imm
= (int16_t) (imm
<< 1) >> 1;
8375 if ((ctx
->opcode
>> 4) & 0x1) {
8376 #if defined(TARGET_MIPS64)
8378 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8380 generate_exception(ctx
, EXCP_RI
);
8383 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8386 case M16_OPC_ADDIU8
:
8387 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8390 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8393 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8398 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8401 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8404 gen_st(ctx
, OPC_SW
, 31, 29, imm
);
8407 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8411 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8412 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8413 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8414 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8415 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8416 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8417 | (ctx
->opcode
& 0xf)) << 3;
8419 if (ctx
->opcode
& (1 << 7)) {
8420 gen_mips16_save(ctx
, xsregs
, aregs
,
8421 do_ra
, do_s0
, do_s1
,
8424 gen_mips16_restore(ctx
, xsregs
, aregs
,
8425 do_ra
, do_s0
, do_s1
,
8431 generate_exception(ctx
, EXCP_RI
);
8436 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8439 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8441 #if defined(TARGET_MIPS64)
8443 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
);
8447 gen_ld(ctx
, OPC_LB
, ry
, rx
, offset
);
8450 gen_ld(ctx
, OPC_LH
, ry
, rx
, offset
);
8453 gen_ld(ctx
, OPC_LW
, rx
, 29, offset
);
8456 gen_ld(ctx
, OPC_LW
, ry
, rx
, offset
);
8459 gen_ld(ctx
, OPC_LBU
, ry
, rx
, offset
);
8462 gen_ld(ctx
, OPC_LHU
, ry
, rx
, offset
);
8465 gen_ld(ctx
, OPC_LWPC
, rx
, 0, offset
);
8467 #if defined(TARGET_MIPS64)
8469 gen_ld(ctx
, OPC_LWU
, ry
, rx
, offset
);
8473 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
8476 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
);
8479 gen_st(ctx
, OPC_SW
, rx
, 29, offset
);
8482 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
);
8484 #if defined(TARGET_MIPS64)
8486 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8490 generate_exception(ctx
, EXCP_RI
);
8497 static int decode_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8502 int op
, cnvt_op
, op1
, offset
;
8506 op
= (ctx
->opcode
>> 11) & 0x1f;
8507 sa
= (ctx
->opcode
>> 2) & 0x7;
8508 sa
= sa
== 0 ? 8 : sa
;
8509 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8510 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8511 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8512 op1
= offset
= ctx
->opcode
& 0x1f;
8517 case M16_OPC_ADDIUSP
:
8519 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8521 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8524 case M16_OPC_ADDIUPC
:
8525 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8528 offset
= (ctx
->opcode
& 0x7ff) << 1;
8529 offset
= (int16_t)(offset
<< 4) >> 4;
8530 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8531 /* No delay slot, so just process as a normal instruction */
8534 offset
= lduw_code(ctx
->pc
+ 2);
8535 offset
= (((ctx
->opcode
& 0x1f) << 21)
8536 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8538 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALXS
: OPC_JALS
;
8539 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8544 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8545 /* No delay slot, so just process as a normal instruction */
8548 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8549 /* No delay slot, so just process as a normal instruction */
8552 switch (ctx
->opcode
& 0x3) {
8554 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8557 #if defined(TARGET_MIPS64)
8559 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8561 generate_exception(ctx
, EXCP_RI
);
8565 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8568 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8572 #if defined(TARGET_MIPS64)
8575 gen_ld(ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8580 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8582 if ((ctx
->opcode
>> 4) & 1) {
8583 #if defined(TARGET_MIPS64)
8585 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8587 generate_exception(ctx
, EXCP_RI
);
8590 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8594 case M16_OPC_ADDIU8
:
8596 int16_t imm
= (int8_t) ctx
->opcode
;
8598 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8603 int16_t imm
= (uint8_t) ctx
->opcode
;
8605 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8610 int16_t imm
= (uint8_t) ctx
->opcode
;
8612 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8619 funct
= (ctx
->opcode
>> 8) & 0x7;
8622 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
8623 ((int8_t)ctx
->opcode
) << 1);
8626 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
8627 ((int8_t)ctx
->opcode
) << 1);
8630 gen_st(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
8633 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
8634 ((int8_t)ctx
->opcode
) << 3);
8638 int do_ra
= ctx
->opcode
& (1 << 6);
8639 int do_s0
= ctx
->opcode
& (1 << 5);
8640 int do_s1
= ctx
->opcode
& (1 << 4);
8641 int framesize
= ctx
->opcode
& 0xf;
8643 if (framesize
== 0) {
8646 framesize
= framesize
<< 3;
8649 if (ctx
->opcode
& (1 << 7)) {
8650 gen_mips16_save(ctx
, 0, 0,
8651 do_ra
, do_s0
, do_s1
, framesize
);
8653 gen_mips16_restore(ctx
, 0, 0,
8654 do_ra
, do_s0
, do_s1
, framesize
);
8660 int rz
= xlat(ctx
->opcode
& 0x7);
8662 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
8663 ((ctx
->opcode
>> 5) & 0x7);
8664 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
8668 reg32
= ctx
->opcode
& 0x1f;
8669 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
8672 generate_exception(ctx
, EXCP_RI
);
8679 int16_t imm
= (uint8_t) ctx
->opcode
;
8681 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
8686 int16_t imm
= (uint8_t) ctx
->opcode
;
8688 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
8691 #if defined(TARGET_MIPS64)
8694 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
8698 gen_ld(ctx
, OPC_LB
, ry
, rx
, offset
);
8701 gen_ld(ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
8704 gen_ld(ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8707 gen_ld(ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
8710 gen_ld(ctx
, OPC_LBU
, ry
, rx
, offset
);
8713 gen_ld(ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
8716 gen_ld(ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
8718 #if defined (TARGET_MIPS64)
8721 gen_ld(ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
8725 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
8728 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
8731 gen_st(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8734 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
8738 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
8741 switch (ctx
->opcode
& 0x3) {
8743 mips32_op
= OPC_ADDU
;
8746 mips32_op
= OPC_SUBU
;
8748 #if defined(TARGET_MIPS64)
8750 mips32_op
= OPC_DADDU
;
8754 mips32_op
= OPC_DSUBU
;
8759 generate_exception(ctx
, EXCP_RI
);
8763 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
8772 int nd
= (ctx
->opcode
>> 7) & 0x1;
8773 int link
= (ctx
->opcode
>> 6) & 0x1;
8774 int ra
= (ctx
->opcode
>> 5) & 0x1;
8777 op
= nd
? OPC_JALRC
: OPC_JALRS
;
8782 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
8789 /* XXX: not clear which exception should be raised
8790 * when in debug mode...
8792 check_insn(env
, ctx
, ISA_MIPS32
);
8793 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8794 generate_exception(ctx
, EXCP_DBp
);
8796 generate_exception(ctx
, EXCP_DBp
);
8800 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
8803 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
8806 generate_exception(ctx
, EXCP_BREAK
);
8809 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
8812 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
8815 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
8817 #if defined (TARGET_MIPS64)
8820 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
8824 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
8827 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
8830 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
8833 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
8836 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
8839 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
8842 gen_HILO(ctx
, OPC_MFHI
, rx
);
8846 case RR_RY_CNVT_ZEB
:
8847 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8849 case RR_RY_CNVT_ZEH
:
8850 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8852 case RR_RY_CNVT_SEB
:
8853 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8855 case RR_RY_CNVT_SEH
:
8856 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8858 #if defined (TARGET_MIPS64)
8859 case RR_RY_CNVT_ZEW
:
8861 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8863 case RR_RY_CNVT_SEW
:
8865 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8869 generate_exception(ctx
, EXCP_RI
);
8874 gen_HILO(ctx
, OPC_MFLO
, rx
);
8876 #if defined (TARGET_MIPS64)
8879 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
8883 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
8887 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
8891 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
8895 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
8898 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
8901 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
8904 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
8906 #if defined (TARGET_MIPS64)
8909 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
8913 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
8917 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
8921 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
8925 generate_exception(ctx
, EXCP_RI
);
8929 case M16_OPC_EXTEND
:
8930 decode_extended_mips16_opc(env
, ctx
, is_branch
);
8933 #if defined(TARGET_MIPS64)
8935 funct
= (ctx
->opcode
>> 8) & 0x7;
8936 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
8940 generate_exception(ctx
, EXCP_RI
);
8947 /* microMIPS extension to MIPS32 */
8949 /* microMIPS32 major opcodes */
8988 /* 0x20 is reserved */
8998 /* 0x28 and 0x29 are reserved */
9008 /* 0x30 and 0x31 are reserved */
9018 /* 0x38 and 0x39 are reserved */
9029 /* POOL32A encoding of minor opcode field */
9032 /* These opcodes are distinguished only by bits 9..6; those bits are
9033 * what are recorded below. */
9059 /* The following can be distinguished by their lower 6 bits. */
9065 /* POOL32AXF encoding of minor opcode field extension */
9079 /* bits 13..12 for 0x01 */
9085 /* bits 13..12 for 0x2a */
9091 /* bits 13..12 for 0x32 */
9095 /* bits 15..12 for 0x2c */
9111 /* bits 15..12 for 0x34 */
9119 /* bits 15..12 for 0x3c */
9121 JR
= 0x0, /* alias */
9126 /* bits 15..12 for 0x05 */
9130 /* bits 15..12 for 0x0d */
9140 /* bits 15..12 for 0x15 */
9146 /* bits 15..12 for 0x1d */
9150 /* bits 15..12 for 0x2d */
9155 /* bits 15..12 for 0x35 */
9162 /* POOL32B encoding of minor opcode field (bits 15..12) */
9178 /* POOL32C encoding of minor opcode field (bits 15..12) */
9186 /* 0xa is reserved */
9193 /* 0x6 is reserved */
9199 /* POOL32F encoding of minor opcode field (bits 5..0) */
9202 /* These are the bit 7..6 values */
9213 /* These are the bit 8..6 values */
9257 CABS_COND_FMT
= 0x1c, /* MIPS3D */
9261 /* POOL32Fxf encoding of minor opcode extension field */
9299 /* POOL32I encoding of minor opcode field (bits 25..21) */
9324 /* These overlap and are distinguished by bit16 of the instruction */
9333 /* POOL16A encoding of minor opcode field */
9340 /* POOL16B encoding of minor opcode field */
9347 /* POOL16C encoding of minor opcode field */
9367 /* POOL16D encoding of minor opcode field */
9374 /* POOL16E encoding of minor opcode field */
9381 static int mmreg (int r
)
9383 static const int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
9388 /* Used for 16-bit store instructions. */
9389 static int mmreg2 (int r
)
9391 static const int map
[] = { 0, 17, 2, 3, 4, 5, 6, 7 };
9396 #define uMIPS_RD(op) ((op >> 7) & 0x7)
9397 #define uMIPS_RS(op) ((op >> 4) & 0x7)
9398 #define uMIPS_RS2(op) uMIPS_RS(op)
9399 #define uMIPS_RS1(op) ((op >> 1) & 0x7)
9400 #define uMIPS_RD5(op) ((op >> 5) & 0x1f)
9401 #define uMIPS_RS5(op) (op & 0x1f)
9403 /* Signed immediate */
9404 #define SIMM(op, start, width) \
9405 ((int32_t)(((op >> start) & ((~0U) >> (32-width))) \
9408 /* Zero-extended immediate */
9409 #define ZIMM(op, start, width) ((op >> start) & ((~0U) >> (32-width)))
9411 static void gen_addiur1sp (CPUState
*env
, DisasContext
*ctx
)
9413 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9415 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, 29, ((ctx
->opcode
>> 1) & 0x3f) << 2);
9418 static void gen_addiur2 (CPUState
*env
, DisasContext
*ctx
)
9420 static const int decoded_imm
[] = { 1, 4, 8, 12, 16, 20, 24, -1 };
9421 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9422 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9424 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, decoded_imm
[ZIMM(ctx
->opcode
, 1, 3)]);
9427 static void gen_addiusp (CPUState
*env
, DisasContext
*ctx
)
9429 int encoded
= ZIMM(ctx
->opcode
, 1, 9);
9433 decoded
= 256 + encoded
;
9434 } else if (encoded
<= 255) {
9436 } else if (encoded
<= 509) {
9437 decoded
= encoded
- 512;
9439 decoded
= encoded
- 768;
9442 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, decoded
<< 2);
9445 static void gen_addius5 (CPUState
*env
, DisasContext
*ctx
)
9447 int imm
= SIMM(ctx
->opcode
, 1, 4);
9448 int rd
= (ctx
->opcode
>> 5) & 0x1f;
9450 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rd
, imm
);
9453 static void gen_andi16 (CPUState
*env
, DisasContext
*ctx
)
9455 static const int decoded_imm
[] = { 128, 1, 2, 3, 4, 7, 8, 15, 16,
9456 31, 32, 63, 64, 255, 32768, 65535 };
9457 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9458 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9459 int encoded
= ZIMM(ctx
->opcode
, 0, 4);
9461 gen_logic_imm(env
, OPC_ANDI
, rd
, rs
, decoded_imm
[encoded
]);
9464 static void gen_ldst_multiple (DisasContext
*ctx
, uint32_t opc
, int reglist
,
9465 int base
, int16_t offset
)
9470 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
9471 generate_exception(ctx
, EXCP_RI
);
9475 t0
= tcg_temp_new();
9477 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9479 t1
= tcg_const_tl(reglist
);
9480 t2
= tcg_const_i32(ctx
->mem_idx
);
9482 save_cpu_state(ctx
, 1);
9485 gen_helper_lwm(t0
, t1
, t2
);
9488 gen_helper_swm(t0
, t1
, t2
);
9490 #ifdef TARGET_MIPS64
9492 gen_helper_ldm(t0
, t1
, t2
);
9495 gen_helper_sdm(t0
, t1
, t2
);
9499 MIPS_DEBUG("%s, %x, %d(%s)", opn
, reglist
, offset
, regnames
[base
]);
9502 tcg_temp_free_i32(t2
);
9506 static void gen_pool16c_insn (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
9508 int rd
= mmreg((ctx
->opcode
>> 3) & 0x7);
9509 int rs
= mmreg(ctx
->opcode
& 0x7);
9512 switch (((ctx
->opcode
) >> 4) & 0x3f) {
9517 gen_logic(env
, OPC_NOR
, rd
, rs
, 0);
9523 gen_logic(env
, OPC_XOR
, rd
, rd
, rs
);
9529 gen_logic(env
, OPC_AND
, rd
, rd
, rs
);
9535 gen_logic(env
, OPC_OR
, rd
, rd
, rs
);
9542 static const int lwm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9543 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9545 gen_ldst_multiple(ctx
, LWM32
, lwm_convert
[(ctx
->opcode
>> 4) & 0x3],
9554 static const int swm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9555 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9557 gen_ldst_multiple(ctx
, SWM32
, swm_convert
[(ctx
->opcode
>> 4) & 0x3],
9564 int reg
= ctx
->opcode
& 0x1f;
9566 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9573 int reg
= ctx
->opcode
& 0x1f;
9575 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9576 /* Let normal delay slot handling in our caller take us
9577 to the branch target. */
9589 int reg
= ctx
->opcode
& 0x1f;
9591 gen_compute_branch(ctx
, opc
, 2, reg
, 31, 0);
9597 gen_HILO(ctx
, OPC_MFHI
, uMIPS_RS5(ctx
->opcode
));
9601 gen_HILO(ctx
, OPC_MFLO
, uMIPS_RS5(ctx
->opcode
));
9604 generate_exception(ctx
, EXCP_BREAK
);
9607 /* XXX: not clear which exception should be raised
9608 * when in debug mode...
9610 check_insn(env
, ctx
, ISA_MIPS32
);
9611 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9612 generate_exception(ctx
, EXCP_DBp
);
9614 generate_exception(ctx
, EXCP_DBp
);
9620 int imm
= ZIMM(ctx
->opcode
, 0, 5);
9622 gen_compute_branch(ctx
, OPC_JR
, 2, 31, 0, 0);
9623 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
<< 2);
9624 /* Let normal delay slot handling in our caller take us
9625 to the branch target. */
9629 generate_exception(ctx
, EXCP_RI
);
9634 static void gen_ldxs (DisasContext
*ctx
, int base
, int index
, int rd
)
9636 TCGv t0
= tcg_temp_new();
9637 TCGv t1
= tcg_temp_new();
9639 gen_load_gpr(t0
, base
);
9642 gen_load_gpr(t1
, index
);
9643 tcg_gen_shli_tl(t1
, t1
, 2);
9644 gen_op_addr_add(ctx
, t0
, t1
, t0
);
9647 save_cpu_state(ctx
, 0);
9648 op_ld_lw(t1
, t0
, ctx
);
9649 gen_store_gpr(t1
, rd
);
9655 static void gen_ldst_pair (DisasContext
*ctx
, uint32_t opc
, int rd
,
9656 int base
, int16_t offset
)
9658 const char *opn
= "ldst_pair";
9661 if (ctx
->hflags
& MIPS_HFLAG_BMASK
|| rd
== 31 || rd
== base
) {
9662 generate_exception(ctx
, EXCP_RI
);
9666 t0
= tcg_temp_new();
9667 t1
= tcg_temp_new();
9669 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9673 save_cpu_state(ctx
, 0);
9674 op_ld_lw(t1
, t0
, ctx
);
9675 gen_store_gpr(t1
, rd
);
9676 tcg_gen_movi_tl(t1
, 4);
9677 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9678 op_ld_lw(t1
, t0
, ctx
);
9679 gen_store_gpr(t1
, rd
+1);
9683 save_cpu_state(ctx
, 1);
9684 gen_load_gpr(t1
, rd
);
9685 op_st_sw(t1
, t0
, ctx
);
9686 tcg_gen_movi_tl(t1
, 4);
9687 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9688 gen_load_gpr(t1
, rd
+1);
9689 op_st_sw(t1
, t0
, ctx
);
9692 #ifdef TARGET_MIPS64
9694 save_cpu_state(ctx
, 0);
9695 op_ld_ld(t1
, t0
, ctx
);
9696 gen_store_gpr(t1
, rd
);
9697 tcg_gen_movi_tl(t1
, 8);
9698 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9699 op_ld_ld(t1
, t0
, ctx
);
9700 gen_store_gpr(t1
, rd
+1);
9704 save_cpu_state(ctx
, 1);
9705 gen_load_gpr(t1
, rd
);
9706 op_st_sd(t1
, t0
, ctx
);
9707 tcg_gen_movi_tl(t1
, 8);
9708 gen_op_addr_add(ctx
, t0
, t0
, t1
);
9709 gen_load_gpr(t1
, rd
+1);
9710 op_st_sd(t1
, t0
, ctx
);
9715 MIPS_DEBUG("%s, %s, %d(%s)", opn
, regnames
[rd
], offset
, regnames
[base
]);
9720 static void gen_pool32axf (CPUState
*env
, DisasContext
*ctx
, int rt
, int rs
,
9723 int extension
= (ctx
->opcode
>> 6) & 0x3f;
9724 int minor
= (ctx
->opcode
>> 12) & 0xf;
9727 switch (extension
) {
9729 mips32_op
= OPC_TEQ
;
9732 mips32_op
= OPC_TGE
;
9735 mips32_op
= OPC_TGEU
;
9738 mips32_op
= OPC_TLT
;
9741 mips32_op
= OPC_TLTU
;
9744 mips32_op
= OPC_TNE
;
9746 gen_trap(ctx
, mips32_op
, rs
, rt
, -1);
9748 #ifndef CONFIG_USER_ONLY
9755 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rs
, (ctx
->opcode
>> 11) & 0x7);
9760 TCGv t0
= tcg_temp_new();
9762 gen_load_gpr(t0
, rt
);
9763 gen_mtc0(env
, ctx
, t0
, rs
, (ctx
->opcode
>> 11) & 0x7);
9771 gen_bshfl(ctx
, OPC_SEB
, rs
, rt
);
9774 gen_bshfl(ctx
, OPC_SEH
, rs
, rt
);
9777 mips32_op
= OPC_CLO
;
9780 mips32_op
= OPC_CLZ
;
9782 check_insn(env
, ctx
, ISA_MIPS32
);
9783 gen_cl(ctx
, mips32_op
, rt
, rs
);
9786 gen_rdhwr(env
, ctx
, rt
, rs
);
9789 gen_bshfl(ctx
, OPC_WSBH
, rs
, rt
);
9792 mips32_op
= OPC_MULT
;
9795 mips32_op
= OPC_MULTU
;
9798 mips32_op
= OPC_DIV
;
9801 mips32_op
= OPC_DIVU
;
9804 mips32_op
= OPC_MADD
;
9807 mips32_op
= OPC_MADDU
;
9810 mips32_op
= OPC_MSUB
;
9813 mips32_op
= OPC_MSUBU
;
9815 check_insn(env
, ctx
, ISA_MIPS32
);
9816 gen_muldiv(ctx
, mips32_op
, rs
, rt
);
9819 goto pool32axf_invalid
;
9830 generate_exception_err(ctx
, EXCP_CpU
, 2);
9833 goto pool32axf_invalid
;
9840 gen_compute_branch (ctx
, OPC_JALR
, 4, rs
, rt
, 0);
9845 gen_compute_branch (ctx
, OPC_JALRS
, 4, rs
, rt
, 0);
9849 goto pool32axf_invalid
;
9855 check_insn(env
, ctx
, ISA_MIPS32R2
);
9856 gen_load_srsgpr(rt
, rs
);
9859 check_insn(env
, ctx
, ISA_MIPS32R2
);
9860 gen_store_srsgpr(rt
, rs
);
9863 goto pool32axf_invalid
;
9866 #ifndef CONFIG_USER_ONLY
9870 mips32_op
= OPC_TLBP
;
9873 mips32_op
= OPC_TLBR
;
9876 mips32_op
= OPC_TLBWI
;
9879 mips32_op
= OPC_TLBWR
;
9882 mips32_op
= OPC_WAIT
;
9885 mips32_op
= OPC_DERET
;
9888 mips32_op
= OPC_ERET
;
9890 gen_cp0(env
, ctx
, mips32_op
, rt
, rs
);
9893 goto pool32axf_invalid
;
9900 TCGv t0
= tcg_temp_new();
9902 save_cpu_state(ctx
, 1);
9904 gen_store_gpr(t0
, rs
);
9905 /* Stop translation as we may have switched the execution mode */
9906 ctx
->bstate
= BS_STOP
;
9912 TCGv t0
= tcg_temp_new();
9914 save_cpu_state(ctx
, 1);
9916 gen_store_gpr(t0
, rs
);
9917 /* Stop translation as we may have switched the execution mode */
9918 ctx
->bstate
= BS_STOP
;
9923 goto pool32axf_invalid
;
9933 generate_exception(ctx
, EXCP_SYSCALL
);
9934 ctx
->bstate
= BS_STOP
;
9937 check_insn(env
, ctx
, ISA_MIPS32
);
9938 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9939 generate_exception(ctx
, EXCP_DBp
);
9941 generate_exception(ctx
, EXCP_DBp
);
9945 goto pool32axf_invalid
;
9951 gen_HILO(ctx
, OPC_MFHI
, rs
);
9954 gen_HILO(ctx
, OPC_MFLO
, rs
);
9957 gen_HILO(ctx
, OPC_MTHI
, rs
);
9960 gen_HILO(ctx
, OPC_MTLO
, rs
);
9963 goto pool32axf_invalid
;
9968 MIPS_INVAL("pool32axf");
9969 generate_exception(ctx
, EXCP_RI
);
9974 /* Values for microMIPS fmt field. Variable-width, depending on which
9975 formats the instruction supports. */
9994 static void gen_pool32fxf (CPUState
*env
, DisasContext
*ctx
, int rt
, int rs
)
9996 int extension
= (ctx
->opcode
>> 6) & 0x3ff;
9999 #define FLOAT_1BIT_FMT(opc, fmt) (fmt << 8) | opc
10000 #define FLOAT_2BIT_FMT(opc, fmt) (fmt << 7) | opc
10001 #define COND_FLOAT_MOV(opc, cond) (cond << 7) | opc
10003 switch (extension
) {
10004 case FLOAT_1BIT_FMT(CFC1
, 0):
10005 mips32_op
= OPC_CFC1
;
10007 case FLOAT_1BIT_FMT(CTC1
, 0):
10008 mips32_op
= OPC_CTC1
;
10010 case FLOAT_1BIT_FMT(MFC1
, 0):
10011 mips32_op
= OPC_MFC1
;
10013 case FLOAT_1BIT_FMT(MTC1
, 0):
10014 mips32_op
= OPC_MTC1
;
10016 case FLOAT_1BIT_FMT(MFHC1
, 0):
10017 mips32_op
= OPC_MFHC1
;
10019 case FLOAT_1BIT_FMT(MTHC1
, 0):
10020 mips32_op
= OPC_MTHC1
;
10022 gen_cp1(ctx
, mips32_op
, rt
, rs
);
10025 /* Reciprocal square root */
10026 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_S
):
10027 mips32_op
= OPC_RSQRT_S
;
10029 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_D
):
10030 mips32_op
= OPC_RSQRT_D
;
10034 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_S
):
10035 mips32_op
= OPC_SQRT_S
;
10037 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_D
):
10038 mips32_op
= OPC_SQRT_D
;
10042 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_S
):
10043 mips32_op
= OPC_RECIP_S
;
10045 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_D
):
10046 mips32_op
= OPC_RECIP_D
;
10050 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_S
):
10051 mips32_op
= OPC_FLOOR_L_S
;
10053 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_D
):
10054 mips32_op
= OPC_FLOOR_L_D
;
10056 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_S
):
10057 mips32_op
= OPC_FLOOR_W_S
;
10059 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_D
):
10060 mips32_op
= OPC_FLOOR_W_D
;
10064 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_S
):
10065 mips32_op
= OPC_CEIL_L_S
;
10067 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_D
):
10068 mips32_op
= OPC_CEIL_L_D
;
10070 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_S
):
10071 mips32_op
= OPC_CEIL_W_S
;
10073 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_D
):
10074 mips32_op
= OPC_CEIL_W_D
;
10078 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_S
):
10079 mips32_op
= OPC_TRUNC_L_S
;
10081 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_D
):
10082 mips32_op
= OPC_TRUNC_L_D
;
10084 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_S
):
10085 mips32_op
= OPC_TRUNC_W_S
;
10087 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_D
):
10088 mips32_op
= OPC_TRUNC_W_D
;
10092 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_S
):
10093 mips32_op
= OPC_ROUND_L_S
;
10095 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_D
):
10096 mips32_op
= OPC_ROUND_L_D
;
10098 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_S
):
10099 mips32_op
= OPC_ROUND_W_S
;
10101 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_D
):
10102 mips32_op
= OPC_ROUND_W_D
;
10105 /* Integer to floating-point conversion */
10106 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_S
):
10107 mips32_op
= OPC_CVT_L_S
;
10109 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_D
):
10110 mips32_op
= OPC_CVT_L_D
;
10112 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_S
):
10113 mips32_op
= OPC_CVT_W_S
;
10115 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_D
):
10116 mips32_op
= OPC_CVT_W_D
;
10119 /* Paired-foo conversions */
10120 case FLOAT_1BIT_FMT(CVT_S_PL
, 0):
10121 mips32_op
= OPC_CVT_S_PL
;
10123 case FLOAT_1BIT_FMT(CVT_S_PU
, 0):
10124 mips32_op
= OPC_CVT_S_PU
;
10126 case FLOAT_1BIT_FMT(CVT_PW_PS
, 0):
10127 mips32_op
= OPC_CVT_PW_PS
;
10129 case FLOAT_1BIT_FMT(CVT_PS_PW
, 0):
10130 mips32_op
= OPC_CVT_PS_PW
;
10133 /* Floating-point moves */
10134 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_S
):
10135 mips32_op
= OPC_MOV_S
;
10137 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_D
):
10138 mips32_op
= OPC_MOV_D
;
10140 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_PS
):
10141 mips32_op
= OPC_MOV_PS
;
10144 /* Absolute value */
10145 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_S
):
10146 mips32_op
= OPC_ABS_S
;
10148 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_D
):
10149 mips32_op
= OPC_ABS_D
;
10151 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_PS
):
10152 mips32_op
= OPC_ABS_PS
;
10156 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_S
):
10157 mips32_op
= OPC_NEG_S
;
10159 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_D
):
10160 mips32_op
= OPC_NEG_D
;
10162 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_PS
):
10163 mips32_op
= OPC_NEG_PS
;
10166 /* Reciprocal square root step */
10167 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_S
):
10168 mips32_op
= OPC_RSQRT1_S
;
10170 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_D
):
10171 mips32_op
= OPC_RSQRT1_D
;
10173 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_PS
):
10174 mips32_op
= OPC_RSQRT1_PS
;
10177 /* Reciprocal step */
10178 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_S
):
10179 mips32_op
= OPC_RECIP1_S
;
10181 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_D
):
10182 mips32_op
= OPC_RECIP1_S
;
10184 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_PS
):
10185 mips32_op
= OPC_RECIP1_PS
;
10188 /* Conversions from double */
10189 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_S
):
10190 mips32_op
= OPC_CVT_D_S
;
10192 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_W
):
10193 mips32_op
= OPC_CVT_D_W
;
10195 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_L
):
10196 mips32_op
= OPC_CVT_D_L
;
10199 /* Conversions from single */
10200 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_D
):
10201 mips32_op
= OPC_CVT_S_D
;
10203 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_W
):
10204 mips32_op
= OPC_CVT_S_W
;
10206 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_L
):
10207 mips32_op
= OPC_CVT_S_L
;
10209 gen_farith(ctx
, mips32_op
, -1, rs
, rt
, 0);
10212 /* Conditional moves on floating-point codes */
10213 case COND_FLOAT_MOV(MOVT
, 0):
10214 case COND_FLOAT_MOV(MOVT
, 1):
10215 case COND_FLOAT_MOV(MOVT
, 2):
10216 case COND_FLOAT_MOV(MOVT
, 3):
10217 case COND_FLOAT_MOV(MOVT
, 4):
10218 case COND_FLOAT_MOV(MOVT
, 5):
10219 case COND_FLOAT_MOV(MOVT
, 6):
10220 case COND_FLOAT_MOV(MOVT
, 7):
10221 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 1);
10223 case COND_FLOAT_MOV(MOVF
, 0):
10224 case COND_FLOAT_MOV(MOVF
, 1):
10225 case COND_FLOAT_MOV(MOVF
, 2):
10226 case COND_FLOAT_MOV(MOVF
, 3):
10227 case COND_FLOAT_MOV(MOVF
, 4):
10228 case COND_FLOAT_MOV(MOVF
, 5):
10229 case COND_FLOAT_MOV(MOVF
, 6):
10230 case COND_FLOAT_MOV(MOVF
, 7):
10231 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 0);
10234 MIPS_INVAL("pool32fxf");
10235 generate_exception(ctx
, EXCP_RI
);
10240 static void decode_micromips32_opc (CPUState
*env
, DisasContext
*ctx
,
10241 uint16_t insn_hw1
, int *is_branch
)
10245 int rt
, rs
, rd
, rr
;
10247 uint32_t op
, minor
, mips32_op
;
10248 uint32_t cond
, fmt
, cc
;
10250 insn
= lduw_code(ctx
->pc
+ 2);
10251 ctx
->opcode
= (ctx
->opcode
<< 16) | insn
;
10253 rt
= (ctx
->opcode
>> 21) & 0x1f;
10254 rs
= (ctx
->opcode
>> 16) & 0x1f;
10255 rd
= (ctx
->opcode
>> 11) & 0x1f;
10256 rr
= (ctx
->opcode
>> 6) & 0x1f;
10257 imm
= (int16_t) ctx
->opcode
;
10259 op
= (ctx
->opcode
>> 26) & 0x3f;
10262 minor
= ctx
->opcode
& 0x3f;
10265 minor
= (ctx
->opcode
>> 6) & 0xf;
10268 mips32_op
= OPC_SLL
;
10271 mips32_op
= OPC_SRA
;
10274 mips32_op
= OPC_SRL
;
10277 mips32_op
= OPC_ROTR
;
10279 gen_shift_imm(env
, ctx
, mips32_op
, rt
, rs
, rd
);
10282 goto pool32a_invalid
;
10286 minor
= (ctx
->opcode
>> 6) & 0xf;
10290 mips32_op
= OPC_ADD
;
10293 mips32_op
= OPC_ADDU
;
10296 mips32_op
= OPC_SUB
;
10299 mips32_op
= OPC_SUBU
;
10302 mips32_op
= OPC_MUL
;
10304 gen_arith(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10308 mips32_op
= OPC_SLLV
;
10311 mips32_op
= OPC_SRLV
;
10314 mips32_op
= OPC_SRAV
;
10317 mips32_op
= OPC_ROTRV
;
10319 gen_shift(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10321 /* Logical operations */
10323 mips32_op
= OPC_AND
;
10326 mips32_op
= OPC_OR
;
10329 mips32_op
= OPC_NOR
;
10332 mips32_op
= OPC_XOR
;
10334 gen_logic(env
, mips32_op
, rd
, rs
, rt
);
10336 /* Set less than */
10338 mips32_op
= OPC_SLT
;
10341 mips32_op
= OPC_SLTU
;
10343 gen_slt(env
, mips32_op
, rd
, rs
, rt
);
10346 goto pool32a_invalid
;
10350 minor
= (ctx
->opcode
>> 6) & 0xf;
10352 /* Conditional moves */
10354 mips32_op
= OPC_MOVN
;
10357 mips32_op
= OPC_MOVZ
;
10359 gen_cond_move(env
, mips32_op
, rd
, rs
, rt
);
10362 gen_ldxs(ctx
, rs
, rt
, rd
);
10365 goto pool32a_invalid
;
10369 gen_bitops(ctx
, OPC_INS
, rt
, rs
, rr
, rd
);
10372 gen_bitops(ctx
, OPC_EXT
, rt
, rs
, rr
, rd
);
10375 gen_pool32axf(env
, ctx
, rt
, rs
, is_branch
);
10378 generate_exception(ctx
, EXCP_BREAK
);
10382 MIPS_INVAL("pool32a");
10383 generate_exception(ctx
, EXCP_RI
);
10388 minor
= (ctx
->opcode
>> 12) & 0xf;
10391 /* Treat as no-op. */
10395 /* COP2: Not implemented. */
10396 generate_exception_err(ctx
, EXCP_CpU
, 2);
10400 #ifdef TARGET_MIPS64
10404 gen_ldst_pair(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10408 #ifdef TARGET_MIPS64
10412 gen_ldst_multiple(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10415 MIPS_INVAL("pool32b");
10416 generate_exception(ctx
, EXCP_RI
);
10421 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
10422 minor
= ctx
->opcode
& 0x3f;
10423 check_cp1_enabled(ctx
);
10426 mips32_op
= OPC_ALNV_PS
;
10429 mips32_op
= OPC_MADD_S
;
10432 mips32_op
= OPC_MADD_D
;
10435 mips32_op
= OPC_MADD_PS
;
10438 mips32_op
= OPC_MSUB_S
;
10441 mips32_op
= OPC_MSUB_D
;
10444 mips32_op
= OPC_MSUB_PS
;
10447 mips32_op
= OPC_NMADD_S
;
10450 mips32_op
= OPC_NMADD_D
;
10453 mips32_op
= OPC_NMADD_PS
;
10456 mips32_op
= OPC_NMSUB_S
;
10459 mips32_op
= OPC_NMSUB_D
;
10462 mips32_op
= OPC_NMSUB_PS
;
10464 gen_flt3_arith(ctx
, mips32_op
, rd
, rr
, rs
, rt
);
10466 case CABS_COND_FMT
:
10467 cond
= (ctx
->opcode
>> 6) & 0xf;
10468 cc
= (ctx
->opcode
>> 13) & 0x7;
10469 fmt
= (ctx
->opcode
>> 10) & 0x3;
10472 gen_cmpabs_s(ctx
, cond
, rt
, rs
, cc
);
10475 gen_cmpabs_d(ctx
, cond
, rt
, rs
, cc
);
10478 gen_cmpabs_ps(ctx
, cond
, rt
, rs
, cc
);
10481 goto pool32f_invalid
;
10485 cond
= (ctx
->opcode
>> 6) & 0xf;
10486 cc
= (ctx
->opcode
>> 13) & 0x7;
10487 fmt
= (ctx
->opcode
>> 10) & 0x3;
10490 gen_cmp_s(ctx
, cond
, rt
, rs
, cc
);
10493 gen_cmp_d(ctx
, cond
, rt
, rs
, cc
);
10496 gen_cmp_ps(ctx
, cond
, rt
, rs
, cc
);
10499 goto pool32f_invalid
;
10503 gen_pool32fxf(env
, ctx
, rt
, rs
);
10507 switch ((ctx
->opcode
>> 6) & 0x7) {
10509 mips32_op
= OPC_PLL_PS
;
10512 mips32_op
= OPC_PLU_PS
;
10515 mips32_op
= OPC_PUL_PS
;
10518 mips32_op
= OPC_PUU_PS
;
10521 mips32_op
= OPC_CVT_PS_S
;
10523 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10526 goto pool32f_invalid
;
10531 switch ((ctx
->opcode
>> 6) & 0x7) {
10533 mips32_op
= OPC_LWXC1
;
10536 mips32_op
= OPC_SWXC1
;
10539 mips32_op
= OPC_LDXC1
;
10542 mips32_op
= OPC_SDXC1
;
10545 mips32_op
= OPC_LUXC1
;
10548 mips32_op
= OPC_SUXC1
;
10550 gen_flt3_ldst(ctx
, mips32_op
, rd
, rd
, rt
, rs
);
10553 goto pool32f_invalid
;
10558 fmt
= (ctx
->opcode
>> 9) & 0x3;
10559 switch ((ctx
->opcode
>> 6) & 0x7) {
10563 mips32_op
= OPC_RSQRT2_S
;
10566 mips32_op
= OPC_RSQRT2_D
;
10569 mips32_op
= OPC_RSQRT2_PS
;
10572 goto pool32f_invalid
;
10578 mips32_op
= OPC_RECIP2_S
;
10581 mips32_op
= OPC_RECIP2_D
;
10584 mips32_op
= OPC_RECIP2_PS
;
10587 goto pool32f_invalid
;
10591 mips32_op
= OPC_ADDR_PS
;
10594 mips32_op
= OPC_MULR_PS
;
10596 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10599 goto pool32f_invalid
;
10603 /* MOV[FT].fmt and PREFX */
10604 cc
= (ctx
->opcode
>> 13) & 0x7;
10605 fmt
= (ctx
->opcode
>> 9) & 0x3;
10606 switch ((ctx
->opcode
>> 6) & 0x7) {
10610 gen_movcf_s(rs
, rt
, cc
, 0);
10613 gen_movcf_d(ctx
, rs
, rt
, cc
, 0);
10616 gen_movcf_ps(rs
, rt
, cc
, 0);
10619 goto pool32f_invalid
;
10625 gen_movcf_s(rs
, rt
, cc
, 1);
10628 gen_movcf_d(ctx
, rs
, rt
, cc
, 1);
10631 gen_movcf_ps(rs
, rt
, cc
, 1);
10634 goto pool32f_invalid
;
10640 goto pool32f_invalid
;
10643 #define FINSN_3ARG_SDPS(prfx) \
10644 switch ((ctx->opcode >> 8) & 0x3) { \
10646 mips32_op = OPC_##prfx##_S; \
10649 mips32_op = OPC_##prfx##_D; \
10651 case FMT_SDPS_PS: \
10652 mips32_op = OPC_##prfx##_PS; \
10655 goto pool32f_invalid; \
10658 /* regular FP ops */
10659 switch ((ctx
->opcode
>> 6) & 0x3) {
10661 FINSN_3ARG_SDPS(ADD
);
10664 FINSN_3ARG_SDPS(SUB
);
10667 FINSN_3ARG_SDPS(MUL
);
10670 fmt
= (ctx
->opcode
>> 8) & 0x3;
10672 mips32_op
= OPC_DIV_D
;
10673 } else if (fmt
== 0) {
10674 mips32_op
= OPC_DIV_S
;
10676 goto pool32f_invalid
;
10680 goto pool32f_invalid
;
10685 switch ((ctx
->opcode
>> 6) & 0x3) {
10687 FINSN_3ARG_SDPS(MOVN
);
10690 FINSN_3ARG_SDPS(MOVZ
);
10693 goto pool32f_invalid
;
10697 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10701 MIPS_INVAL("pool32f");
10702 generate_exception(ctx
, EXCP_RI
);
10706 generate_exception_err(ctx
, EXCP_CpU
, 1);
10710 minor
= (ctx
->opcode
>> 21) & 0x1f;
10713 mips32_op
= OPC_BLTZ
;
10716 mips32_op
= OPC_BLTZAL
;
10719 mips32_op
= OPC_BLTZALS
;
10722 mips32_op
= OPC_BGEZ
;
10725 mips32_op
= OPC_BGEZAL
;
10728 mips32_op
= OPC_BGEZALS
;
10731 mips32_op
= OPC_BLEZ
;
10734 mips32_op
= OPC_BGTZ
;
10736 gen_compute_branch(ctx
, mips32_op
, 4, rs
, -1, imm
<< 1);
10742 mips32_op
= OPC_TLTI
;
10745 mips32_op
= OPC_TGEI
;
10748 mips32_op
= OPC_TLTIU
;
10751 mips32_op
= OPC_TGEIU
;
10754 mips32_op
= OPC_TNEI
;
10757 mips32_op
= OPC_TEQI
;
10759 gen_trap(ctx
, mips32_op
, rs
, -1, imm
);
10764 gen_compute_branch(ctx
, minor
== BNEZC
? OPC_BNE
: OPC_BEQ
,
10765 4, rs
, 0, imm
<< 1);
10766 /* Compact branches don't have a delay slot, so just let
10767 the normal delay slot handling take us to the branch
10771 gen_logic_imm(env
, OPC_LUI
, rs
, -1, imm
);
10777 /* COP2: Not implemented. */
10778 generate_exception_err(ctx
, EXCP_CpU
, 2);
10781 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1FANY2
: OPC_BC1F
;
10784 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1TANY2
: OPC_BC1T
;
10787 mips32_op
= OPC_BC1FANY4
;
10790 mips32_op
= OPC_BC1TANY4
;
10793 check_insn(env
, ctx
, ASE_MIPS3D
);
10796 gen_compute_branch1(env
, ctx
, mips32_op
,
10797 (ctx
->opcode
>> 18) & 0x7, imm
<< 1);
10802 /* MIPS DSP: not implemented */
10805 MIPS_INVAL("pool32i");
10806 generate_exception(ctx
, EXCP_RI
);
10811 minor
= (ctx
->opcode
>> 12) & 0xf;
10814 mips32_op
= OPC_LWL
;
10817 mips32_op
= OPC_SWL
;
10820 mips32_op
= OPC_LWR
;
10823 mips32_op
= OPC_SWR
;
10825 #if defined(TARGET_MIPS64)
10827 mips32_op
= OPC_LDL
;
10830 mips32_op
= OPC_SDL
;
10833 mips32_op
= OPC_LDR
;
10836 mips32_op
= OPC_SDR
;
10839 mips32_op
= OPC_LWU
;
10842 mips32_op
= OPC_LLD
;
10846 mips32_op
= OPC_LL
;
10849 gen_ld(ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10852 gen_st(ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10855 gen_st_cond(ctx
, OPC_SC
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10857 #if defined(TARGET_MIPS64)
10859 gen_st_cond(ctx
, OPC_SCD
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10863 /* Treat as no-op */
10866 MIPS_INVAL("pool32c");
10867 generate_exception(ctx
, EXCP_RI
);
10872 mips32_op
= OPC_ADDI
;
10875 mips32_op
= OPC_ADDIU
;
10877 gen_arith_imm(env
, ctx
, mips32_op
, rt
, rs
, imm
);
10880 /* Logical operations */
10882 mips32_op
= OPC_ORI
;
10885 mips32_op
= OPC_XORI
;
10888 mips32_op
= OPC_ANDI
;
10890 gen_logic_imm(env
, mips32_op
, rt
, rs
, imm
);
10893 /* Set less than immediate */
10895 mips32_op
= OPC_SLTI
;
10898 mips32_op
= OPC_SLTIU
;
10900 gen_slt_imm(env
, mips32_op
, rt
, rs
, imm
);
10903 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
10904 gen_compute_branch(ctx
, OPC_JALX
, 4, rt
, rs
, offset
);
10908 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1;
10909 gen_compute_branch(ctx
, OPC_JALS
, 4, rt
, rs
, offset
);
10913 gen_compute_branch(ctx
, OPC_BEQ
, 4, rt
, rs
, imm
<< 1);
10917 gen_compute_branch(ctx
, OPC_BNE
, 4, rt
, rs
, imm
<< 1);
10921 gen_compute_branch(ctx
, OPC_J
, 4, rt
, rs
,
10922 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
10926 gen_compute_branch(ctx
, OPC_JAL
, 4, rt
, rs
,
10927 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
10930 /* Floating point (COP1) */
10932 mips32_op
= OPC_LWC1
;
10935 mips32_op
= OPC_LDC1
;
10938 mips32_op
= OPC_SWC1
;
10941 mips32_op
= OPC_SDC1
;
10943 gen_cop1_ldst(env
, ctx
, mips32_op
, rt
, rs
, imm
);
10947 int reg
= mmreg(ZIMM(ctx
->opcode
, 23, 3));
10948 int offset
= SIMM(ctx
->opcode
, 0, 23) << 2;
10950 gen_addiupc(ctx
, reg
, offset
, 0, 0);
10953 /* Loads and stores */
10955 mips32_op
= OPC_LB
;
10958 mips32_op
= OPC_LBU
;
10961 mips32_op
= OPC_LH
;
10964 mips32_op
= OPC_LHU
;
10967 mips32_op
= OPC_LW
;
10969 #ifdef TARGET_MIPS64
10971 mips32_op
= OPC_LD
;
10974 mips32_op
= OPC_SD
;
10978 mips32_op
= OPC_SB
;
10981 mips32_op
= OPC_SH
;
10984 mips32_op
= OPC_SW
;
10987 gen_ld(ctx
, mips32_op
, rt
, rs
, imm
);
10990 gen_st(ctx
, mips32_op
, rt
, rs
, imm
);
10993 generate_exception(ctx
, EXCP_RI
);
10998 static int decode_micromips_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
11002 /* make sure instructions are on a halfword boundary */
11003 if (ctx
->pc
& 0x1) {
11004 env
->CP0_BadVAddr
= ctx
->pc
;
11005 generate_exception(ctx
, EXCP_AdEL
);
11006 ctx
->bstate
= BS_STOP
;
11010 op
= (ctx
->opcode
>> 10) & 0x3f;
11011 /* Enforce properly-sized instructions in a delay slot */
11012 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
11013 int bits
= ctx
->hflags
& MIPS_HFLAG_BMASK_EXT
;
11047 case POOL48A
: /* ??? */
11052 if (bits
& MIPS_HFLAG_BDS16
) {
11053 generate_exception(ctx
, EXCP_RI
);
11054 /* Just stop translation; the user is confused. */
11055 ctx
->bstate
= BS_STOP
;
11080 if (bits
& MIPS_HFLAG_BDS32
) {
11081 generate_exception(ctx
, EXCP_RI
);
11082 /* Just stop translation; the user is confused. */
11083 ctx
->bstate
= BS_STOP
;
11094 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11095 int rs1
= mmreg(uMIPS_RS1(ctx
->opcode
));
11096 int rs2
= mmreg(uMIPS_RS2(ctx
->opcode
));
11099 switch (ctx
->opcode
& 0x1) {
11108 gen_arith(env
, ctx
, opc
, rd
, rs1
, rs2
);
11113 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11114 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
11115 int amount
= (ctx
->opcode
>> 1) & 0x7;
11117 amount
= amount
== 0 ? 8 : amount
;
11119 switch (ctx
->opcode
& 0x1) {
11128 gen_shift_imm(env
, ctx
, opc
, rd
, rs
, amount
);
11132 gen_pool16c_insn(env
, ctx
, is_branch
);
11136 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11137 int rb
= 28; /* GP */
11138 int16_t offset
= SIMM(ctx
->opcode
, 0, 7) << 2;
11140 gen_ld(ctx
, OPC_LW
, rd
, rb
, offset
);
11144 if (ctx
->opcode
& 1) {
11145 generate_exception(ctx
, EXCP_RI
);
11148 int enc_dest
= uMIPS_RD(ctx
->opcode
);
11149 int enc_rt
= uMIPS_RS2(ctx
->opcode
);
11150 int enc_rs
= uMIPS_RS1(ctx
->opcode
);
11151 int rd
, rs
, re
, rt
;
11152 static const int rd_enc
[] = { 5, 5, 6, 4, 4, 4, 4, 4 };
11153 static const int re_enc
[] = { 6, 7, 7, 21, 22, 5, 6, 7 };
11154 static const int rs_rt_enc
[] = { 0, 17, 2, 3, 16, 18, 19, 20 };
11156 rd
= rd_enc
[enc_dest
];
11157 re
= re_enc
[enc_dest
];
11158 rs
= rs_rt_enc
[enc_rs
];
11159 rt
= rs_rt_enc
[enc_rt
];
11161 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11162 gen_arith_imm(env
, ctx
, OPC_ADDIU
, re
, rt
, 0);
11167 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11168 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11169 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11170 offset
= (offset
== 0xf ? -1 : offset
);
11172 gen_ld(ctx
, OPC_LBU
, rd
, rb
, offset
);
11177 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11178 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11179 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11181 gen_ld(ctx
, OPC_LHU
, rd
, rb
, offset
);
11186 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11187 int rb
= 29; /* SP */
11188 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11190 gen_ld(ctx
, OPC_LW
, rd
, rb
, offset
);
11195 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11196 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11197 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11199 gen_ld(ctx
, OPC_LW
, rd
, rb
, offset
);
11204 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11205 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11206 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11208 gen_st(ctx
, OPC_SB
, rd
, rb
, offset
);
11213 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11214 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11215 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11217 gen_st(ctx
, OPC_SH
, rd
, rb
, offset
);
11222 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11223 int rb
= 29; /* SP */
11224 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11226 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11231 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11232 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11233 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11235 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11240 int rd
= uMIPS_RD5(ctx
->opcode
);
11241 int rs
= uMIPS_RS5(ctx
->opcode
);
11243 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11247 gen_andi16(env
, ctx
);
11250 switch (ctx
->opcode
& 0x1) {
11252 gen_addius5(env
, ctx
);
11255 gen_addiusp(env
, ctx
);
11260 switch (ctx
->opcode
& 0x1) {
11262 gen_addiur2(env
, ctx
);
11265 gen_addiur1sp(env
, ctx
);
11270 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0,
11271 SIMM(ctx
->opcode
, 0, 10) << 1);
11276 gen_compute_branch(ctx
, op
== BNEZ16
? OPC_BNE
: OPC_BEQ
, 2,
11277 mmreg(uMIPS_RD(ctx
->opcode
)),
11278 0, SIMM(ctx
->opcode
, 0, 7) << 1);
11283 int reg
= mmreg(uMIPS_RD(ctx
->opcode
));
11284 int imm
= ZIMM(ctx
->opcode
, 0, 7);
11286 imm
= (imm
== 0x7f ? -1 : imm
);
11287 tcg_gen_movi_tl(cpu_gpr
[reg
], imm
);
11297 generate_exception(ctx
, EXCP_RI
);
11300 decode_micromips32_opc (env
, ctx
, op
, is_branch
);
11307 /* SmartMIPS extension to MIPS32 */
11309 #if defined(TARGET_MIPS64)
11311 /* MDMX extension to MIPS64 */
11315 static void decode_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
11318 int rs
, rt
, rd
, sa
;
11319 uint32_t op
, op1
, op2
;
11322 /* make sure instructions are on a word boundary */
11323 if (ctx
->pc
& 0x3) {
11324 env
->CP0_BadVAddr
= ctx
->pc
;
11325 generate_exception(ctx
, EXCP_AdEL
);
11329 /* Handle blikely not taken case */
11330 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
11331 int l1
= gen_new_label();
11333 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
11334 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
11335 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
11336 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
11340 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
11341 tcg_gen_debug_insn_start(ctx
->pc
);
11343 op
= MASK_OP_MAJOR(ctx
->opcode
);
11344 rs
= (ctx
->opcode
>> 21) & 0x1f;
11345 rt
= (ctx
->opcode
>> 16) & 0x1f;
11346 rd
= (ctx
->opcode
>> 11) & 0x1f;
11347 sa
= (ctx
->opcode
>> 6) & 0x1f;
11348 imm
= (int16_t)ctx
->opcode
;
11351 op1
= MASK_SPECIAL(ctx
->opcode
);
11353 case OPC_SLL
: /* Shift with immediate */
11355 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11358 switch ((ctx
->opcode
>> 21) & 0x1f) {
11360 /* rotr is decoded as srl on non-R2 CPUs */
11361 if (env
->insn_flags
& ISA_MIPS32R2
) {
11366 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11369 generate_exception(ctx
, EXCP_RI
);
11373 case OPC_MOVN
: /* Conditional move */
11375 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
|
11376 INSN_LOONGSON2E
| INSN_LOONGSON2F
);
11377 gen_cond_move(env
, op1
, rd
, rs
, rt
);
11379 case OPC_ADD
... OPC_SUBU
:
11380 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11382 case OPC_SLLV
: /* Shifts */
11384 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11387 switch ((ctx
->opcode
>> 6) & 0x1f) {
11389 /* rotrv is decoded as srlv on non-R2 CPUs */
11390 if (env
->insn_flags
& ISA_MIPS32R2
) {
11395 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11398 generate_exception(ctx
, EXCP_RI
);
11402 case OPC_SLT
: /* Set on less than */
11404 gen_slt(env
, op1
, rd
, rs
, rt
);
11406 case OPC_AND
: /* Logic*/
11410 gen_logic(env
, op1
, rd
, rs
, rt
);
11412 case OPC_MULT
... OPC_DIVU
:
11414 check_insn(env
, ctx
, INSN_VR54XX
);
11415 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
11416 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
11418 gen_muldiv(ctx
, op1
, rs
, rt
);
11420 case OPC_JR
... OPC_JALR
:
11421 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
11424 case OPC_TGE
... OPC_TEQ
: /* Traps */
11426 gen_trap(ctx
, op1
, rs
, rt
, -1);
11428 case OPC_MFHI
: /* Move from HI/LO */
11430 gen_HILO(ctx
, op1
, rd
);
11433 case OPC_MTLO
: /* Move to HI/LO */
11434 gen_HILO(ctx
, op1
, rs
);
11436 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
11437 #ifdef MIPS_STRICT_STANDARD
11438 MIPS_INVAL("PMON / selsl");
11439 generate_exception(ctx
, EXCP_RI
);
11441 gen_helper_0i(pmon
, sa
);
11445 generate_exception(ctx
, EXCP_SYSCALL
);
11446 ctx
->bstate
= BS_STOP
;
11449 generate_exception(ctx
, EXCP_BREAK
);
11452 #ifdef MIPS_STRICT_STANDARD
11453 MIPS_INVAL("SPIM");
11454 generate_exception(ctx
, EXCP_RI
);
11456 /* Implemented as RI exception for now. */
11457 MIPS_INVAL("spim (unofficial)");
11458 generate_exception(ctx
, EXCP_RI
);
11462 /* Treat as NOP. */
11466 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
11467 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
11468 check_cp1_enabled(ctx
);
11469 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
11470 (ctx
->opcode
>> 16) & 1);
11472 generate_exception_err(ctx
, EXCP_CpU
, 1);
11476 #if defined(TARGET_MIPS64)
11477 /* MIPS64 specific opcodes */
11482 check_insn(env
, ctx
, ISA_MIPS3
);
11483 check_mips_64(ctx
);
11484 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11487 switch ((ctx
->opcode
>> 21) & 0x1f) {
11489 /* drotr is decoded as dsrl on non-R2 CPUs */
11490 if (env
->insn_flags
& ISA_MIPS32R2
) {
11495 check_insn(env
, ctx
, ISA_MIPS3
);
11496 check_mips_64(ctx
);
11497 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11500 generate_exception(ctx
, EXCP_RI
);
11505 switch ((ctx
->opcode
>> 21) & 0x1f) {
11507 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
11508 if (env
->insn_flags
& ISA_MIPS32R2
) {
11513 check_insn(env
, ctx
, ISA_MIPS3
);
11514 check_mips_64(ctx
);
11515 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11518 generate_exception(ctx
, EXCP_RI
);
11522 case OPC_DADD
... OPC_DSUBU
:
11523 check_insn(env
, ctx
, ISA_MIPS3
);
11524 check_mips_64(ctx
);
11525 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11529 check_insn(env
, ctx
, ISA_MIPS3
);
11530 check_mips_64(ctx
);
11531 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11534 switch ((ctx
->opcode
>> 6) & 0x1f) {
11536 /* drotrv is decoded as dsrlv on non-R2 CPUs */
11537 if (env
->insn_flags
& ISA_MIPS32R2
) {
11542 check_insn(env
, ctx
, ISA_MIPS3
);
11543 check_mips_64(ctx
);
11544 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11547 generate_exception(ctx
, EXCP_RI
);
11551 case OPC_DMULT
... OPC_DDIVU
:
11552 check_insn(env
, ctx
, ISA_MIPS3
);
11553 check_mips_64(ctx
);
11554 gen_muldiv(ctx
, op1
, rs
, rt
);
11557 default: /* Invalid */
11558 MIPS_INVAL("special");
11559 generate_exception(ctx
, EXCP_RI
);
11564 op1
= MASK_SPECIAL2(ctx
->opcode
);
11566 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
11567 case OPC_MSUB
... OPC_MSUBU
:
11568 check_insn(env
, ctx
, ISA_MIPS32
);
11569 gen_muldiv(ctx
, op1
, rs
, rt
);
11572 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11576 check_insn(env
, ctx
, ISA_MIPS32
);
11577 gen_cl(ctx
, op1
, rd
, rs
);
11580 /* XXX: not clear which exception should be raised
11581 * when in debug mode...
11583 check_insn(env
, ctx
, ISA_MIPS32
);
11584 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
11585 generate_exception(ctx
, EXCP_DBp
);
11587 generate_exception(ctx
, EXCP_DBp
);
11589 /* Treat as NOP. */
11591 #if defined(TARGET_MIPS64)
11594 check_insn(env
, ctx
, ISA_MIPS64
);
11595 check_mips_64(ctx
);
11596 gen_cl(ctx
, op1
, rd
, rs
);
11599 default: /* Invalid */
11600 MIPS_INVAL("special2");
11601 generate_exception(ctx
, EXCP_RI
);
11606 op1
= MASK_SPECIAL3(ctx
->opcode
);
11610 check_insn(env
, ctx
, ISA_MIPS32R2
);
11611 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
11614 check_insn(env
, ctx
, ISA_MIPS32R2
);
11615 op2
= MASK_BSHFL(ctx
->opcode
);
11616 gen_bshfl(ctx
, op2
, rt
, rd
);
11619 gen_rdhwr(env
, ctx
, rt
, rd
);
11622 check_insn(env
, ctx
, ASE_MT
);
11624 TCGv t0
= tcg_temp_new();
11625 TCGv t1
= tcg_temp_new();
11627 gen_load_gpr(t0
, rt
);
11628 gen_load_gpr(t1
, rs
);
11629 gen_helper_fork(t0
, t1
);
11635 check_insn(env
, ctx
, ASE_MT
);
11637 TCGv t0
= tcg_temp_new();
11639 save_cpu_state(ctx
, 1);
11640 gen_load_gpr(t0
, rs
);
11641 gen_helper_yield(t0
, t0
);
11642 gen_store_gpr(t0
, rd
);
11646 #if defined(TARGET_MIPS64)
11647 case OPC_DEXTM
... OPC_DEXT
:
11648 case OPC_DINSM
... OPC_DINS
:
11649 check_insn(env
, ctx
, ISA_MIPS64R2
);
11650 check_mips_64(ctx
);
11651 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
11654 check_insn(env
, ctx
, ISA_MIPS64R2
);
11655 check_mips_64(ctx
);
11656 op2
= MASK_DBSHFL(ctx
->opcode
);
11657 gen_bshfl(ctx
, op2
, rt
, rd
);
11660 default: /* Invalid */
11661 MIPS_INVAL("special3");
11662 generate_exception(ctx
, EXCP_RI
);
11667 op1
= MASK_REGIMM(ctx
->opcode
);
11669 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
11670 case OPC_BLTZAL
... OPC_BGEZALL
:
11671 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
11674 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
11676 gen_trap(ctx
, op1
, rs
, -1, imm
);
11679 check_insn(env
, ctx
, ISA_MIPS32R2
);
11680 /* Treat as NOP. */
11682 default: /* Invalid */
11683 MIPS_INVAL("regimm");
11684 generate_exception(ctx
, EXCP_RI
);
11689 check_cp0_enabled(ctx
);
11690 op1
= MASK_CP0(ctx
->opcode
);
11696 #if defined(TARGET_MIPS64)
11700 #ifndef CONFIG_USER_ONLY
11701 gen_cp0(env
, ctx
, op1
, rt
, rd
);
11702 #endif /* !CONFIG_USER_ONLY */
11704 case OPC_C0_FIRST
... OPC_C0_LAST
:
11705 #ifndef CONFIG_USER_ONLY
11706 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
11707 #endif /* !CONFIG_USER_ONLY */
11710 #ifndef CONFIG_USER_ONLY
11712 TCGv t0
= tcg_temp_new();
11714 op2
= MASK_MFMC0(ctx
->opcode
);
11717 check_insn(env
, ctx
, ASE_MT
);
11718 gen_helper_dmt(t0
, t0
);
11719 gen_store_gpr(t0
, rt
);
11722 check_insn(env
, ctx
, ASE_MT
);
11723 gen_helper_emt(t0
, t0
);
11724 gen_store_gpr(t0
, rt
);
11727 check_insn(env
, ctx
, ASE_MT
);
11728 gen_helper_dvpe(t0
, t0
);
11729 gen_store_gpr(t0
, rt
);
11732 check_insn(env
, ctx
, ASE_MT
);
11733 gen_helper_evpe(t0
, t0
);
11734 gen_store_gpr(t0
, rt
);
11737 check_insn(env
, ctx
, ISA_MIPS32R2
);
11738 save_cpu_state(ctx
, 1);
11740 gen_store_gpr(t0
, rt
);
11741 /* Stop translation as we may have switched the execution mode */
11742 ctx
->bstate
= BS_STOP
;
11745 check_insn(env
, ctx
, ISA_MIPS32R2
);
11746 save_cpu_state(ctx
, 1);
11748 gen_store_gpr(t0
, rt
);
11749 /* Stop translation as we may have switched the execution mode */
11750 ctx
->bstate
= BS_STOP
;
11752 default: /* Invalid */
11753 MIPS_INVAL("mfmc0");
11754 generate_exception(ctx
, EXCP_RI
);
11759 #endif /* !CONFIG_USER_ONLY */
11762 check_insn(env
, ctx
, ISA_MIPS32R2
);
11763 gen_load_srsgpr(rt
, rd
);
11766 check_insn(env
, ctx
, ISA_MIPS32R2
);
11767 gen_store_srsgpr(rt
, rd
);
11771 generate_exception(ctx
, EXCP_RI
);
11775 case OPC_ADDI
: /* Arithmetic with immediate opcode */
11777 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
11779 case OPC_SLTI
: /* Set on less than with immediate opcode */
11781 gen_slt_imm(env
, op
, rt
, rs
, imm
);
11783 case OPC_ANDI
: /* Arithmetic with immediate opcode */
11787 gen_logic_imm(env
, op
, rt
, rs
, imm
);
11789 case OPC_J
... OPC_JAL
: /* Jump */
11790 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
11791 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
11794 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
11795 case OPC_BEQL
... OPC_BGTZL
:
11796 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
11799 case OPC_LB
... OPC_LWR
: /* Load and stores */
11801 gen_ld(ctx
, op
, rt
, rs
, imm
);
11803 case OPC_SB
... OPC_SW
:
11805 gen_st(ctx
, op
, rt
, rs
, imm
);
11808 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
11811 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
11812 /* Treat as NOP. */
11815 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
11816 /* Treat as NOP. */
11819 /* Floating point (COP1). */
11824 gen_cop1_ldst(env
, ctx
, op
, rt
, rs
, imm
);
11828 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
11829 check_cp1_enabled(ctx
);
11830 op1
= MASK_CP1(ctx
->opcode
);
11834 check_insn(env
, ctx
, ISA_MIPS32R2
);
11839 gen_cp1(ctx
, op1
, rt
, rd
);
11841 #if defined(TARGET_MIPS64)
11844 check_insn(env
, ctx
, ISA_MIPS3
);
11845 gen_cp1(ctx
, op1
, rt
, rd
);
11851 check_insn(env
, ctx
, ASE_MIPS3D
);
11854 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
11855 (rt
>> 2) & 0x7, imm
<< 2);
11863 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
11868 generate_exception (ctx
, EXCP_RI
);
11872 generate_exception_err(ctx
, EXCP_CpU
, 1);
11882 /* COP2: Not implemented. */
11883 generate_exception_err(ctx
, EXCP_CpU
, 2);
11887 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
11888 check_cp1_enabled(ctx
);
11889 op1
= MASK_CP3(ctx
->opcode
);
11897 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
11900 /* Treat as NOP. */
11915 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
11919 generate_exception (ctx
, EXCP_RI
);
11923 generate_exception_err(ctx
, EXCP_CpU
, 1);
11927 #if defined(TARGET_MIPS64)
11928 /* MIPS64 opcodes */
11930 case OPC_LDL
... OPC_LDR
:
11933 check_insn(env
, ctx
, ISA_MIPS3
);
11934 check_mips_64(ctx
);
11935 gen_ld(ctx
, op
, rt
, rs
, imm
);
11937 case OPC_SDL
... OPC_SDR
:
11939 check_insn(env
, ctx
, ISA_MIPS3
);
11940 check_mips_64(ctx
);
11941 gen_st(ctx
, op
, rt
, rs
, imm
);
11944 check_insn(env
, ctx
, ISA_MIPS3
);
11945 check_mips_64(ctx
);
11946 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
11950 check_insn(env
, ctx
, ISA_MIPS3
);
11951 check_mips_64(ctx
);
11952 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
11956 check_insn(env
, ctx
, ASE_MIPS16
| ASE_MICROMIPS
);
11957 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
11958 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
11962 check_insn(env
, ctx
, ASE_MDMX
);
11963 /* MDMX: Not implemented. */
11964 default: /* Invalid */
11965 MIPS_INVAL("major opcode");
11966 generate_exception(ctx
, EXCP_RI
);
11972 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
11976 target_ulong pc_start
;
11977 uint16_t *gen_opc_end
;
11986 qemu_log("search pc %d\n", search_pc
);
11989 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
11992 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
11994 ctx
.bstate
= BS_NONE
;
11995 /* Restore delay slot state from the tb context. */
11996 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
11997 restore_cpu_state(env
, &ctx
);
11998 #ifdef CONFIG_USER_ONLY
11999 ctx
.mem_idx
= MIPS_HFLAG_UM
;
12001 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
12004 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
12005 if (max_insns
== 0)
12006 max_insns
= CF_COUNT_MASK
;
12007 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
12008 gen_icount_start();
12009 while (ctx
.bstate
== BS_NONE
) {
12010 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
12011 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
12012 if (bp
->pc
== ctx
.pc
) {
12013 save_cpu_state(&ctx
, 1);
12014 ctx
.bstate
= BS_BRANCH
;
12015 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
12016 /* Include the breakpoint location or the tb won't
12017 * be flushed when it must be. */
12019 goto done_generating
;
12025 j
= gen_opc_ptr
- gen_opc_buf
;
12029 gen_opc_instr_start
[lj
++] = 0;
12031 gen_opc_pc
[lj
] = ctx
.pc
;
12032 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
12033 gen_opc_instr_start
[lj
] = 1;
12034 gen_opc_icount
[lj
] = num_insns
;
12036 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
12040 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
12041 ctx
.opcode
= ldl_code(ctx
.pc
);
12043 decode_opc(env
, &ctx
, &is_branch
);
12044 } else if (env
->insn_flags
& ASE_MICROMIPS
) {
12045 ctx
.opcode
= lduw_code(ctx
.pc
);
12046 insn_bytes
= decode_micromips_opc(env
, &ctx
, &is_branch
);
12047 } else if (env
->insn_flags
& ASE_MIPS16
) {
12048 ctx
.opcode
= lduw_code(ctx
.pc
);
12049 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
12051 generate_exception(&ctx
, EXCP_RI
);
12052 ctx
.bstate
= BS_STOP
;
12056 handle_delay_slot(env
, &ctx
, insn_bytes
);
12058 ctx
.pc
+= insn_bytes
;
12062 /* Execute a branch and its delay slot as a single instruction.
12063 This is what GDB expects and is consistent with what the
12064 hardware does (e.g. if a delay slot instruction faults, the
12065 reported PC is the PC of the branch). */
12066 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
12069 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
12072 if (gen_opc_ptr
>= gen_opc_end
)
12075 if (num_insns
>= max_insns
)
12081 if (tb
->cflags
& CF_LAST_IO
)
12083 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
12084 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
12085 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
12087 switch (ctx
.bstate
) {
12089 gen_helper_interrupt_restart();
12090 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12093 save_cpu_state(&ctx
, 0);
12094 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12097 gen_helper_interrupt_restart();
12098 tcg_gen_exit_tb(0);
12106 gen_icount_end(tb
, num_insns
);
12107 *gen_opc_ptr
= INDEX_op_end
;
12109 j
= gen_opc_ptr
- gen_opc_buf
;
12112 gen_opc_instr_start
[lj
++] = 0;
12114 tb
->size
= ctx
.pc
- pc_start
;
12115 tb
->icount
= num_insns
;
12119 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
12120 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
12121 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
12127 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
12129 gen_intermediate_code_internal(env
, tb
, 0);
12132 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
12134 gen_intermediate_code_internal(env
, tb
, 1);
12137 static void fpu_dump_state(CPUState
*env
, FILE *f
,
12138 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12142 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
12144 #define printfpr(fp) \
12147 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12148 " fd:%13g fs:%13g psu: %13g\n", \
12149 (fp)->w[FP_ENDIAN_IDX], (fp)->d, \
12150 (double)(fp)->fd, \
12151 (double)(fp)->fs[FP_ENDIAN_IDX], \
12152 (double)(fp)->fs[!FP_ENDIAN_IDX]); \
12155 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
12156 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
12157 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12158 " fd:%13g fs:%13g psu:%13g\n", \
12159 tmp.w[FP_ENDIAN_IDX], tmp.d, \
12161 (double)tmp.fs[FP_ENDIAN_IDX], \
12162 (double)tmp.fs[!FP_ENDIAN_IDX]); \
12167 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
12168 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
12169 get_float_exception_flags(&env
->active_fpu
.fp_status
));
12170 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
12171 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
12172 printfpr(&env
->active_fpu
.fpr
[i
]);
12178 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12179 /* Debug help: The architecture requires 32bit code to maintain proper
12180 sign-extended values on 64bit machines. */
12182 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
12185 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
12186 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12191 if (!SIGN_EXT_P(env
->active_tc
.PC
))
12192 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
12193 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
12194 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
12195 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
12196 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
12197 if (!SIGN_EXT_P(env
->btarget
))
12198 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
12200 for (i
= 0; i
< 32; i
++) {
12201 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
12202 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
12205 if (!SIGN_EXT_P(env
->CP0_EPC
))
12206 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
12207 if (!SIGN_EXT_P(env
->lladdr
))
12208 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
12212 void cpu_dump_state (CPUState
*env
, FILE *f
,
12213 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
12218 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
12219 " LO=0x" TARGET_FMT_lx
" ds %04x "
12220 TARGET_FMT_lx
" " TARGET_FMT_ld
"\n",
12221 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
12222 env
->hflags
, env
->btarget
, env
->bcond
);
12223 for (i
= 0; i
< 32; i
++) {
12225 cpu_fprintf(f
, "GPR%02d:", i
);
12226 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
12228 cpu_fprintf(f
, "\n");
12231 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
12232 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
12233 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
12234 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
12235 if (env
->hflags
& MIPS_HFLAG_FPU
)
12236 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
12237 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12238 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
12242 static void mips_tcg_init(void)
12247 /* Initialize various static tables. */
12251 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
12252 TCGV_UNUSED(cpu_gpr
[0]);
12253 for (i
= 1; i
< 32; i
++)
12254 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
12255 offsetof(CPUState
, active_tc
.gpr
[i
]),
12257 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
12258 offsetof(CPUState
, active_tc
.PC
), "PC");
12259 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
12260 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
12261 offsetof(CPUState
, active_tc
.HI
[i
]),
12263 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
12264 offsetof(CPUState
, active_tc
.LO
[i
]),
12266 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
12267 offsetof(CPUState
, active_tc
.ACX
[i
]),
12270 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
12271 offsetof(CPUState
, active_tc
.DSPControl
),
12273 bcond
= tcg_global_mem_new(TCG_AREG0
,
12274 offsetof(CPUState
, bcond
), "bcond");
12275 btarget
= tcg_global_mem_new(TCG_AREG0
,
12276 offsetof(CPUState
, btarget
), "btarget");
12277 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
12278 offsetof(CPUState
, hflags
), "hflags");
12280 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
12281 offsetof(CPUState
, active_fpu
.fcr0
),
12283 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
12284 offsetof(CPUState
, active_fpu
.fcr31
),
12287 /* register helpers */
12288 #define GEN_HELPER 2
12289 #include "helper.h"
12294 #include "translate_init.c"
12296 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
12299 const mips_def_t
*def
;
12301 def
= cpu_mips_find_by_name(cpu_model
);
12304 env
= qemu_mallocz(sizeof(CPUMIPSState
));
12305 env
->cpu_model
= def
;
12306 env
->cpu_model_str
= cpu_model
;
12308 cpu_exec_init(env
);
12309 #ifndef CONFIG_USER_ONLY
12310 mmu_init(env
, def
);
12312 fpu_init(env
, def
);
12313 mvp_init(env
, def
);
12316 qemu_init_vcpu(env
);
12320 void cpu_reset (CPUMIPSState
*env
)
12322 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
12323 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
12324 log_cpu_state(env
, 0);
12327 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
12330 /* Reset registers to their default values */
12331 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
12332 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
12333 #ifdef TARGET_WORDS_BIGENDIAN
12334 env
->CP0_Config0
|= (1 << CP0C0_BE
);
12336 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
12337 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
12338 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
12339 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
12340 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
12341 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
12342 << env
->cpu_model
->CP0_LLAddr_shift
;
12343 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
12344 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
12345 env
->CCRes
= env
->cpu_model
->CCRes
;
12346 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
12347 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
12348 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
12349 env
->current_tc
= 0;
12350 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
12351 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
12352 #if defined(TARGET_MIPS64)
12353 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12354 env
->SEGMask
|= 3ULL << 62;
12357 env
->PABITS
= env
->cpu_model
->PABITS
;
12358 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
12359 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
12360 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
12361 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
12362 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
12363 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
12364 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
12365 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
12366 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
12367 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
12368 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
12369 env
->insn_flags
= env
->cpu_model
->insn_flags
;
12371 #if defined(CONFIG_USER_ONLY)
12372 env
->hflags
= MIPS_HFLAG_UM
;
12373 /* Enable access to the SYNCI_Step register. */
12374 env
->CP0_HWREna
|= (1 << 1);
12375 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12376 env
->hflags
|= MIPS_HFLAG_FPU
;
12378 #ifdef TARGET_MIPS64
12379 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
12380 env
->hflags
|= MIPS_HFLAG_F64
;
12384 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
12385 /* If the exception was raised from a delay slot,
12386 come back to the jump. */
12387 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
12389 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
12391 env
->active_tc
.PC
= (int32_t)0xBFC00000;
12392 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
12393 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
12394 env
->CP0_Wired
= 0;
12395 /* SMP not implemented */
12396 env
->CP0_EBase
= 0x80000000;
12397 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
12398 /* vectored interrupts not implemented, timer on int 7,
12399 no performance counters. */
12400 env
->CP0_IntCtl
= 0xe0000000;
12404 for (i
= 0; i
< 7; i
++) {
12405 env
->CP0_WatchLo
[i
] = 0;
12406 env
->CP0_WatchHi
[i
] = 0x80000000;
12408 env
->CP0_WatchLo
[7] = 0;
12409 env
->CP0_WatchHi
[7] = 0;
12411 /* Count register increments in debug mode, EJTAG version 1 */
12412 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
12413 env
->hflags
= MIPS_HFLAG_CP0
;
12415 #if defined(TARGET_MIPS64)
12416 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12417 env
->hflags
|= MIPS_HFLAG_64
;
12420 env
->exception_index
= EXCP_NONE
;
12423 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
12424 unsigned long searched_pc
, int pc_pos
, void *puc
)
12426 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
12427 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
12428 env
->hflags
|= gen_opc_hflags
[pc_pos
];