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/>.
31 //#define MIPS_DEBUG_DISAS
32 //#define MIPS_DEBUG_SIGN_EXTENSIONS
34 /* MIPS major opcodes */
35 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
38 /* indirect opcode tables */
39 OPC_SPECIAL
= (0x00 << 26),
40 OPC_REGIMM
= (0x01 << 26),
41 OPC_CP0
= (0x10 << 26),
42 OPC_CP1
= (0x11 << 26),
43 OPC_CP2
= (0x12 << 26),
44 OPC_CP3
= (0x13 << 26),
45 OPC_SPECIAL2
= (0x1C << 26),
46 OPC_SPECIAL3
= (0x1F << 26),
47 /* arithmetic with immediate */
48 OPC_ADDI
= (0x08 << 26),
49 OPC_ADDIU
= (0x09 << 26),
50 OPC_SLTI
= (0x0A << 26),
51 OPC_SLTIU
= (0x0B << 26),
52 /* logic with immediate */
53 OPC_ANDI
= (0x0C << 26),
54 OPC_ORI
= (0x0D << 26),
55 OPC_XORI
= (0x0E << 26),
56 OPC_LUI
= (0x0F << 26),
57 /* arithmetic with immediate */
58 OPC_DADDI
= (0x18 << 26),
59 OPC_DADDIU
= (0x19 << 26),
60 /* Jump and branches */
62 OPC_JAL
= (0x03 << 26),
63 OPC_JALS
= OPC_JAL
| 0x5,
64 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
65 OPC_BEQL
= (0x14 << 26),
66 OPC_BNE
= (0x05 << 26),
67 OPC_BNEL
= (0x15 << 26),
68 OPC_BLEZ
= (0x06 << 26),
69 OPC_BLEZL
= (0x16 << 26),
70 OPC_BGTZ
= (0x07 << 26),
71 OPC_BGTZL
= (0x17 << 26),
72 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
73 OPC_JALXS
= OPC_JALX
| 0x5,
75 OPC_LDL
= (0x1A << 26),
76 OPC_LDR
= (0x1B << 26),
77 OPC_LB
= (0x20 << 26),
78 OPC_LH
= (0x21 << 26),
79 OPC_LWL
= (0x22 << 26),
80 OPC_LW
= (0x23 << 26),
81 OPC_LWPC
= OPC_LW
| 0x5,
82 OPC_LBU
= (0x24 << 26),
83 OPC_LHU
= (0x25 << 26),
84 OPC_LWR
= (0x26 << 26),
85 OPC_LWU
= (0x27 << 26),
86 OPC_SB
= (0x28 << 26),
87 OPC_SH
= (0x29 << 26),
88 OPC_SWL
= (0x2A << 26),
89 OPC_SW
= (0x2B << 26),
90 OPC_SDL
= (0x2C << 26),
91 OPC_SDR
= (0x2D << 26),
92 OPC_SWR
= (0x2E << 26),
93 OPC_LL
= (0x30 << 26),
94 OPC_LLD
= (0x34 << 26),
95 OPC_LD
= (0x37 << 26),
96 OPC_LDPC
= OPC_LD
| 0x5,
97 OPC_SC
= (0x38 << 26),
98 OPC_SCD
= (0x3C << 26),
99 OPC_SD
= (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1
= (0x31 << 26),
102 OPC_LWC2
= (0x32 << 26),
103 OPC_LDC1
= (0x35 << 26),
104 OPC_LDC2
= (0x36 << 26),
105 OPC_SWC1
= (0x39 << 26),
106 OPC_SWC2
= (0x3A << 26),
107 OPC_SDC1
= (0x3D << 26),
108 OPC_SDC2
= (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX
= (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE
= (0x2F << 26),
113 OPC_PREF
= (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL
= 0x00 | OPC_SPECIAL
,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
128 OPC_ROTR
= OPC_SRL
| (1 << 21),
129 OPC_SRA
= 0x03 | OPC_SPECIAL
,
130 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
131 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
132 OPC_ROTRV
= OPC_SRLV
| (1 << 6),
133 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
134 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
135 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
136 OPC_DROTRV
= OPC_DSRLV
| (1 << 6),
137 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
138 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
139 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
140 OPC_DROTR
= OPC_DSRL
| (1 << 21),
141 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
142 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
143 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
144 OPC_DROTR32
= OPC_DSRL32
| (1 << 21),
145 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
146 /* Multiplication / division */
147 OPC_MULT
= 0x18 | OPC_SPECIAL
,
148 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
149 OPC_DIV
= 0x1A | OPC_SPECIAL
,
150 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
151 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
152 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
153 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
154 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
155 /* 2 registers arithmetic / logic */
156 OPC_ADD
= 0x20 | OPC_SPECIAL
,
157 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
158 OPC_SUB
= 0x22 | OPC_SPECIAL
,
159 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
160 OPC_AND
= 0x24 | OPC_SPECIAL
,
161 OPC_OR
= 0x25 | OPC_SPECIAL
,
162 OPC_XOR
= 0x26 | OPC_SPECIAL
,
163 OPC_NOR
= 0x27 | OPC_SPECIAL
,
164 OPC_SLT
= 0x2A | OPC_SPECIAL
,
165 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
166 OPC_DADD
= 0x2C | OPC_SPECIAL
,
167 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
168 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
169 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
171 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
172 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
173 OPC_JALRC
= OPC_JALR
| (0x5 << 6),
174 OPC_JALRS
= 0x10 | OPC_SPECIAL
| (0x5 << 6),
176 OPC_TGE
= 0x30 | OPC_SPECIAL
,
177 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
178 OPC_TLT
= 0x32 | OPC_SPECIAL
,
179 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
180 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
181 OPC_TNE
= 0x36 | OPC_SPECIAL
,
182 /* HI / LO registers load & stores */
183 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
184 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
185 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
186 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
187 /* Conditional moves */
188 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
189 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
191 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
194 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* unofficial */
195 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
196 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
197 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
198 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
200 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
201 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
202 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
203 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
204 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
205 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
206 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
209 /* Multiplication variants of the vr54xx. */
210 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
213 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
214 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
215 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
216 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
217 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
218 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
219 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
220 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
221 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
222 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
223 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
224 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
225 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
226 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
229 /* REGIMM (rt field) opcodes */
230 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
233 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
234 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
235 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
236 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
237 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
238 OPC_BLTZALS
= OPC_BLTZAL
| 0x5, /* microMIPS */
239 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
240 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
241 OPC_BGEZALS
= OPC_BGEZAL
| 0x5, /* microMIPS */
242 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
243 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
244 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
245 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
246 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
247 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
248 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
249 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
252 /* Special2 opcodes */
253 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
256 /* Multiply & xxx operations */
257 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
258 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
259 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
260 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
261 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
263 OPC_MULT_G_2F
= 0x10 | OPC_SPECIAL2
,
264 OPC_DMULT_G_2F
= 0x11 | OPC_SPECIAL2
,
265 OPC_MULTU_G_2F
= 0x12 | OPC_SPECIAL2
,
266 OPC_DMULTU_G_2F
= 0x13 | OPC_SPECIAL2
,
267 OPC_DIV_G_2F
= 0x14 | OPC_SPECIAL2
,
268 OPC_DDIV_G_2F
= 0x15 | OPC_SPECIAL2
,
269 OPC_DIVU_G_2F
= 0x16 | OPC_SPECIAL2
,
270 OPC_DDIVU_G_2F
= 0x17 | OPC_SPECIAL2
,
271 OPC_MOD_G_2F
= 0x1c | OPC_SPECIAL2
,
272 OPC_DMOD_G_2F
= 0x1d | OPC_SPECIAL2
,
273 OPC_MODU_G_2F
= 0x1e | OPC_SPECIAL2
,
274 OPC_DMODU_G_2F
= 0x1f | OPC_SPECIAL2
,
276 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
277 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
278 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
279 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
281 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
284 /* Special3 opcodes */
285 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
288 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
289 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
290 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
291 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
292 OPC_INS
= 0x04 | OPC_SPECIAL3
,
293 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
294 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
295 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
296 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
297 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
298 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
299 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
300 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
303 OPC_MULT_G_2E
= 0x18 | OPC_SPECIAL3
,
304 OPC_MULTU_G_2E
= 0x19 | OPC_SPECIAL3
,
305 OPC_DIV_G_2E
= 0x1A | OPC_SPECIAL3
,
306 OPC_DIVU_G_2E
= 0x1B | OPC_SPECIAL3
,
307 OPC_DMULT_G_2E
= 0x1C | OPC_SPECIAL3
,
308 OPC_DMULTU_G_2E
= 0x1D | OPC_SPECIAL3
,
309 OPC_DDIV_G_2E
= 0x1E | OPC_SPECIAL3
,
310 OPC_DDIVU_G_2E
= 0x1F | OPC_SPECIAL3
,
311 OPC_MOD_G_2E
= 0x22 | OPC_SPECIAL3
,
312 OPC_MODU_G_2E
= 0x23 | OPC_SPECIAL3
,
313 OPC_DMOD_G_2E
= 0x26 | OPC_SPECIAL3
,
314 OPC_DMODU_G_2E
= 0x27 | OPC_SPECIAL3
,
318 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
321 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
322 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
323 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
327 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
330 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
331 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
334 /* Coprocessor 0 (rs field) */
335 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
338 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
339 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
340 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
341 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
342 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
343 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
344 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
345 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
346 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
347 OPC_C0
= (0x10 << 21) | OPC_CP0
,
348 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
349 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
353 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
356 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
357 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
358 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
359 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
360 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
361 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
364 /* Coprocessor 0 (with rs == C0) */
365 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
368 OPC_TLBR
= 0x01 | OPC_C0
,
369 OPC_TLBWI
= 0x02 | OPC_C0
,
370 OPC_TLBWR
= 0x06 | OPC_C0
,
371 OPC_TLBP
= 0x08 | OPC_C0
,
372 OPC_RFE
= 0x10 | OPC_C0
,
373 OPC_ERET
= 0x18 | OPC_C0
,
374 OPC_DERET
= 0x1F | OPC_C0
,
375 OPC_WAIT
= 0x20 | OPC_C0
,
378 /* Coprocessor 1 (rs field) */
379 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
381 /* Values for the fmt field in FP instructions */
383 /* 0 - 15 are reserved */
384 FMT_S
= 16, /* single fp */
385 FMT_D
= 17, /* double fp */
386 FMT_E
= 18, /* extended fp */
387 FMT_Q
= 19, /* quad fp */
388 FMT_W
= 20, /* 32-bit fixed */
389 FMT_L
= 21, /* 64-bit fixed */
390 FMT_PS
= 22, /* paired single fp */
391 /* 23 - 31 are reserved */
395 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
396 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
397 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
398 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
399 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
400 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
401 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
402 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
403 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
404 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
405 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
406 OPC_S_FMT
= (FMT_S
<< 21) | OPC_CP1
,
407 OPC_D_FMT
= (FMT_D
<< 21) | OPC_CP1
,
408 OPC_E_FMT
= (FMT_E
<< 21) | OPC_CP1
,
409 OPC_Q_FMT
= (FMT_Q
<< 21) | OPC_CP1
,
410 OPC_W_FMT
= (FMT_W
<< 21) | OPC_CP1
,
411 OPC_L_FMT
= (FMT_L
<< 21) | OPC_CP1
,
412 OPC_PS_FMT
= (FMT_PS
<< 21) | OPC_CP1
,
415 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
416 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
419 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
420 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
421 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
422 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
426 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
427 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
431 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
432 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
435 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
438 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
439 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
440 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
441 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
442 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
443 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
444 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
445 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
446 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
449 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
452 OPC_LWXC1
= 0x00 | OPC_CP3
,
453 OPC_LDXC1
= 0x01 | OPC_CP3
,
454 OPC_LUXC1
= 0x05 | OPC_CP3
,
455 OPC_SWXC1
= 0x08 | OPC_CP3
,
456 OPC_SDXC1
= 0x09 | OPC_CP3
,
457 OPC_SUXC1
= 0x0D | OPC_CP3
,
458 OPC_PREFX
= 0x0F | OPC_CP3
,
459 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
460 OPC_MADD_S
= 0x20 | OPC_CP3
,
461 OPC_MADD_D
= 0x21 | OPC_CP3
,
462 OPC_MADD_PS
= 0x26 | OPC_CP3
,
463 OPC_MSUB_S
= 0x28 | OPC_CP3
,
464 OPC_MSUB_D
= 0x29 | OPC_CP3
,
465 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
466 OPC_NMADD_S
= 0x30 | OPC_CP3
,
467 OPC_NMADD_D
= 0x31 | OPC_CP3
,
468 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
469 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
470 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
471 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
474 /* global register indices */
475 static TCGv_ptr cpu_env
;
476 static TCGv cpu_gpr
[32], cpu_PC
;
477 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
478 static TCGv cpu_dspctrl
, btarget
, bcond
;
479 static TCGv_i32 hflags
;
480 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
482 static uint32_t gen_opc_hflags
[OPC_BUF_SIZE
];
484 #include "gen-icount.h"
486 #define gen_helper_0e0i(name, arg) do { \
487 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
488 gen_helper_##name(cpu_env, helper_tmp); \
489 tcg_temp_free_i32(helper_tmp); \
492 #define gen_helper_0e1i(name, arg1, arg2) do { \
493 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
494 gen_helper_##name(cpu_env, arg1, helper_tmp); \
495 tcg_temp_free_i32(helper_tmp); \
498 #define gen_helper_1e0i(name, ret, arg1) do { \
499 TCGv_i32 helper_tmp = tcg_const_i32(arg1); \
500 gen_helper_##name(ret, cpu_env, helper_tmp); \
501 tcg_temp_free_i32(helper_tmp); \
504 #define gen_helper_1e1i(name, ret, arg1, arg2) do { \
505 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
506 gen_helper_##name(ret, cpu_env, arg1, helper_tmp); \
507 tcg_temp_free_i32(helper_tmp); \
510 #define gen_helper_0e2i(name, arg1, arg2, arg3) do { \
511 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
512 gen_helper_##name(cpu_env, arg1, arg2, helper_tmp); \
513 tcg_temp_free_i32(helper_tmp); \
516 #define gen_helper_1e2i(name, ret, arg1, arg2, arg3) do { \
517 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
518 gen_helper_##name(ret, cpu_env, arg1, arg2, helper_tmp); \
519 tcg_temp_free_i32(helper_tmp); \
522 #define gen_helper_0e3i(name, arg1, arg2, arg3, arg4) do { \
523 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
524 gen_helper_##name(cpu_env, arg1, arg2, arg3, helper_tmp); \
525 tcg_temp_free_i32(helper_tmp); \
528 typedef struct DisasContext
{
529 struct TranslationBlock
*tb
;
530 target_ulong pc
, saved_pc
;
532 int singlestep_enabled
;
533 /* Routine used to access memory */
535 uint32_t hflags
, saved_hflags
;
537 target_ulong btarget
;
541 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
542 * exception condition */
543 BS_STOP
= 1, /* We want to stop translation for any reason */
544 BS_BRANCH
= 2, /* We reached a branch condition */
545 BS_EXCP
= 3, /* We reached an exception condition */
548 static const char *regnames
[] =
549 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
550 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
551 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
552 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
554 static const char *regnames_HI
[] =
555 { "HI0", "HI1", "HI2", "HI3", };
557 static const char *regnames_LO
[] =
558 { "LO0", "LO1", "LO2", "LO3", };
560 static const char *regnames_ACX
[] =
561 { "ACX0", "ACX1", "ACX2", "ACX3", };
563 static const char *fregnames
[] =
564 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
565 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
566 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
567 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
569 #ifdef MIPS_DEBUG_DISAS
570 #define MIPS_DEBUG(fmt, ...) \
571 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
572 TARGET_FMT_lx ": %08x " fmt "\n", \
573 ctx->pc, ctx->opcode , ## __VA_ARGS__)
574 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
576 #define MIPS_DEBUG(fmt, ...) do { } while(0)
577 #define LOG_DISAS(...) do { } while (0)
580 #define MIPS_INVAL(op) \
582 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
583 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
586 /* General purpose registers moves. */
587 static inline void gen_load_gpr (TCGv t
, int reg
)
590 tcg_gen_movi_tl(t
, 0);
592 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
595 static inline void gen_store_gpr (TCGv t
, int reg
)
598 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
601 /* Moves to/from ACX register. */
602 static inline void gen_load_ACX (TCGv t
, int reg
)
604 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
607 static inline void gen_store_ACX (TCGv t
, int reg
)
609 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
612 /* Moves to/from shadow registers. */
613 static inline void gen_load_srsgpr (int from
, int to
)
615 TCGv t0
= tcg_temp_new();
618 tcg_gen_movi_tl(t0
, 0);
620 TCGv_i32 t2
= tcg_temp_new_i32();
621 TCGv_ptr addr
= tcg_temp_new_ptr();
623 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
624 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
625 tcg_gen_andi_i32(t2
, t2
, 0xf);
626 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
627 tcg_gen_ext_i32_ptr(addr
, t2
);
628 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
630 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
631 tcg_temp_free_ptr(addr
);
632 tcg_temp_free_i32(t2
);
634 gen_store_gpr(t0
, to
);
638 static inline void gen_store_srsgpr (int from
, int to
)
641 TCGv t0
= tcg_temp_new();
642 TCGv_i32 t2
= tcg_temp_new_i32();
643 TCGv_ptr addr
= tcg_temp_new_ptr();
645 gen_load_gpr(t0
, from
);
646 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
647 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
648 tcg_gen_andi_i32(t2
, t2
, 0xf);
649 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
650 tcg_gen_ext_i32_ptr(addr
, t2
);
651 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
653 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
654 tcg_temp_free_ptr(addr
);
655 tcg_temp_free_i32(t2
);
660 /* Floating point register moves. */
661 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
663 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUMIPSState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
666 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
668 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUMIPSState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
671 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
673 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUMIPSState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
676 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
678 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUMIPSState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
681 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
683 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
684 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUMIPSState
, active_fpu
.fpr
[reg
].d
));
686 TCGv_i32 t0
= tcg_temp_new_i32();
687 TCGv_i32 t1
= tcg_temp_new_i32();
688 gen_load_fpr32(t0
, reg
& ~1);
689 gen_load_fpr32(t1
, reg
| 1);
690 tcg_gen_concat_i32_i64(t
, t0
, t1
);
691 tcg_temp_free_i32(t0
);
692 tcg_temp_free_i32(t1
);
696 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
698 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
699 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUMIPSState
, active_fpu
.fpr
[reg
].d
));
701 TCGv_i64 t0
= tcg_temp_new_i64();
702 TCGv_i32 t1
= tcg_temp_new_i32();
703 tcg_gen_trunc_i64_i32(t1
, t
);
704 gen_store_fpr32(t1
, reg
& ~1);
705 tcg_gen_shri_i64(t0
, t
, 32);
706 tcg_gen_trunc_i64_i32(t1
, t0
);
707 gen_store_fpr32(t1
, reg
| 1);
708 tcg_temp_free_i32(t1
);
709 tcg_temp_free_i64(t0
);
713 static inline int get_fp_bit (int cc
)
722 static inline void gen_save_pc(target_ulong pc
)
724 tcg_gen_movi_tl(cpu_PC
, pc
);
727 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
729 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
730 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
731 gen_save_pc(ctx
->pc
);
732 ctx
->saved_pc
= ctx
->pc
;
734 if (ctx
->hflags
!= ctx
->saved_hflags
) {
735 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
736 ctx
->saved_hflags
= ctx
->hflags
;
737 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
743 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
749 static inline void restore_cpu_state (CPUMIPSState
*env
, DisasContext
*ctx
)
751 ctx
->saved_hflags
= ctx
->hflags
;
752 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
758 ctx
->btarget
= env
->btarget
;
764 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
766 TCGv_i32 texcp
= tcg_const_i32(excp
);
767 TCGv_i32 terr
= tcg_const_i32(err
);
768 save_cpu_state(ctx
, 1);
769 gen_helper_raise_exception_err(cpu_env
, texcp
, terr
);
770 tcg_temp_free_i32(terr
);
771 tcg_temp_free_i32(texcp
);
775 generate_exception (DisasContext
*ctx
, int excp
)
777 save_cpu_state(ctx
, 1);
778 gen_helper_0e0i(raise_exception
, excp
);
781 /* Addresses computation */
782 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
784 tcg_gen_add_tl(ret
, arg0
, arg1
);
786 #if defined(TARGET_MIPS64)
787 /* For compatibility with 32-bit code, data reference in user mode
788 with Status_UX = 0 should be casted to 32-bit and sign extended.
789 See the MIPS64 PRA manual, section 4.10. */
790 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
791 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
792 tcg_gen_ext32s_i64(ret
, ret
);
797 static inline void check_cp0_enabled(DisasContext
*ctx
)
799 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
800 generate_exception_err(ctx
, EXCP_CpU
, 0);
803 static inline void check_cp1_enabled(DisasContext
*ctx
)
805 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
806 generate_exception_err(ctx
, EXCP_CpU
, 1);
809 /* Verify that the processor is running with COP1X instructions enabled.
810 This is associated with the nabla symbol in the MIPS32 and MIPS64
813 static inline void check_cop1x(DisasContext
*ctx
)
815 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
816 generate_exception(ctx
, EXCP_RI
);
819 /* Verify that the processor is running with 64-bit floating-point
820 operations enabled. */
822 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
824 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
825 generate_exception(ctx
, EXCP_RI
);
829 * Verify if floating point register is valid; an operation is not defined
830 * if bit 0 of any register specification is set and the FR bit in the
831 * Status register equals zero, since the register numbers specify an
832 * even-odd pair of adjacent coprocessor general registers. When the FR bit
833 * in the Status register equals one, both even and odd register numbers
834 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
836 * Multiple 64 bit wide registers can be checked by calling
837 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
839 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
841 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
842 generate_exception(ctx
, EXCP_RI
);
845 /* This code generates a "reserved instruction" exception if the
846 CPU does not support the instruction set corresponding to flags. */
847 static inline void check_insn(CPUMIPSState
*env
, DisasContext
*ctx
, int flags
)
849 if (unlikely(!(env
->insn_flags
& flags
)))
850 generate_exception(ctx
, EXCP_RI
);
853 /* This code generates a "reserved instruction" exception if 64-bit
854 instructions are not enabled. */
855 static inline void check_mips_64(DisasContext
*ctx
)
857 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
858 generate_exception(ctx
, EXCP_RI
);
861 /* Define small wrappers for gen_load_fpr* so that we have a uniform
862 calling interface for 32 and 64-bit FPRs. No sense in changing
863 all callers for gen_load_fpr32 when we need the CTX parameter for
865 #define gen_ldcmp_fpr32(ctx, x, y) gen_load_fpr32(x, y)
866 #define gen_ldcmp_fpr64(ctx, x, y) gen_load_fpr64(ctx, x, y)
867 #define FOP_CONDS(type, abs, fmt, ifmt, bits) \
868 static inline void gen_cmp ## type ## _ ## fmt(DisasContext *ctx, int n, \
869 int ft, int fs, int cc) \
871 TCGv_i##bits fp0 = tcg_temp_new_i##bits (); \
872 TCGv_i##bits fp1 = tcg_temp_new_i##bits (); \
875 check_cp1_64bitmode(ctx); \
881 check_cp1_registers(ctx, fs | ft); \
889 gen_ldcmp_fpr##bits (ctx, fp0, fs); \
890 gen_ldcmp_fpr##bits (ctx, fp1, ft); \
892 case 0: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _f, fp0, fp1, cc); break;\
893 case 1: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _un, fp0, fp1, cc); break;\
894 case 2: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _eq, fp0, fp1, cc); break;\
895 case 3: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ueq, fp0, fp1, cc); break;\
896 case 4: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _olt, fp0, fp1, cc); break;\
897 case 5: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ult, fp0, fp1, cc); break;\
898 case 6: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ole, fp0, fp1, cc); break;\
899 case 7: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ule, fp0, fp1, cc); break;\
900 case 8: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _sf, fp0, fp1, cc); break;\
901 case 9: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngle, fp0, fp1, cc); break;\
902 case 10: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _seq, fp0, fp1, cc); break;\
903 case 11: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngl, fp0, fp1, cc); break;\
904 case 12: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _lt, fp0, fp1, cc); break;\
905 case 13: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _nge, fp0, fp1, cc); break;\
906 case 14: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _le, fp0, fp1, cc); break;\
907 case 15: gen_helper_0e2i(cmp ## type ## _ ## fmt ## _ngt, fp0, fp1, cc); break;\
910 tcg_temp_free_i##bits (fp0); \
911 tcg_temp_free_i##bits (fp1); \
914 FOP_CONDS(, 0, d
, FMT_D
, 64)
915 FOP_CONDS(abs
, 1, d
, FMT_D
, 64)
916 FOP_CONDS(, 0, s
, FMT_S
, 32)
917 FOP_CONDS(abs
, 1, s
, FMT_S
, 32)
918 FOP_CONDS(, 0, ps
, FMT_PS
, 64)
919 FOP_CONDS(abs
, 1, ps
, FMT_PS
, 64)
921 #undef gen_ldcmp_fpr32
922 #undef gen_ldcmp_fpr64
924 /* load/store instructions. */
925 #define OP_LD(insn,fname) \
926 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
928 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
935 #if defined(TARGET_MIPS64)
941 #define OP_ST(insn,fname) \
942 static inline void op_st_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
944 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
949 #if defined(TARGET_MIPS64)
954 #ifdef CONFIG_USER_ONLY
955 #define OP_LD_ATOMIC(insn,fname) \
956 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
958 TCGv t0 = tcg_temp_new(); \
959 tcg_gen_mov_tl(t0, arg1); \
960 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
961 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUMIPSState, lladdr)); \
962 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUMIPSState, llval)); \
966 #define OP_LD_ATOMIC(insn,fname) \
967 static inline void op_ld_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
969 gen_helper_1e1i(insn, ret, arg1, ctx->mem_idx); \
972 OP_LD_ATOMIC(ll
,ld32s
);
973 #if defined(TARGET_MIPS64)
974 OP_LD_ATOMIC(lld
,ld64
);
978 #ifdef CONFIG_USER_ONLY
979 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
980 static inline void op_st_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
982 TCGv t0 = tcg_temp_new(); \
983 int l1 = gen_new_label(); \
984 int l2 = gen_new_label(); \
986 tcg_gen_andi_tl(t0, arg2, almask); \
987 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
988 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUMIPSState, CP0_BadVAddr)); \
989 generate_exception(ctx, EXCP_AdES); \
991 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUMIPSState, lladdr)); \
992 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
993 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
994 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUMIPSState, llreg)); \
995 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUMIPSState, llnewval)); \
996 gen_helper_0e0i(raise_exception, EXCP_SC); \
998 tcg_gen_movi_tl(t0, 0); \
999 gen_store_gpr(t0, rt); \
1000 tcg_temp_free(t0); \
1003 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
1004 static inline void op_st_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
1006 TCGv t0 = tcg_temp_new(); \
1007 gen_helper_1e2i(insn, t0, arg1, arg2, ctx->mem_idx); \
1008 gen_store_gpr(t0, rt); \
1009 tcg_temp_free(t0); \
1012 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
1013 #if defined(TARGET_MIPS64)
1014 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
1018 static void gen_base_offset_addr (DisasContext
*ctx
, TCGv addr
,
1019 int base
, int16_t offset
)
1022 tcg_gen_movi_tl(addr
, offset
);
1023 } else if (offset
== 0) {
1024 gen_load_gpr(addr
, base
);
1026 tcg_gen_movi_tl(addr
, offset
);
1027 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
1031 static target_ulong
pc_relative_pc (DisasContext
*ctx
)
1033 target_ulong pc
= ctx
->pc
;
1035 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1036 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
1041 pc
&= ~(target_ulong
)3;
1046 static void gen_ld (CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t opc
,
1047 int rt
, int base
, int16_t offset
)
1049 const char *opn
= "ld";
1052 if (rt
== 0 && env
->insn_flags
& (INSN_LOONGSON2E
| INSN_LOONGSON2F
)) {
1053 /* Loongson CPU uses a load to zero register for prefetch.
1054 We emulate it as a NOP. On other CPU we must perform the
1055 actual memory access. */
1060 t0
= tcg_temp_new();
1061 t1
= tcg_temp_new();
1062 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1065 #if defined(TARGET_MIPS64)
1067 save_cpu_state(ctx
, 0);
1068 op_ld_lwu(t0
, t0
, ctx
);
1069 gen_store_gpr(t0
, rt
);
1073 save_cpu_state(ctx
, 0);
1074 op_ld_ld(t0
, t0
, ctx
);
1075 gen_store_gpr(t0
, rt
);
1079 save_cpu_state(ctx
, 1);
1080 op_ld_lld(t0
, t0
, ctx
);
1081 gen_store_gpr(t0
, rt
);
1085 save_cpu_state(ctx
, 1);
1086 gen_load_gpr(t1
, rt
);
1087 gen_helper_1e2i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1088 gen_store_gpr(t1
, rt
);
1092 save_cpu_state(ctx
, 1);
1093 gen_load_gpr(t1
, rt
);
1094 gen_helper_1e2i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1095 gen_store_gpr(t1
, rt
);
1099 save_cpu_state(ctx
, 0);
1100 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1101 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1102 op_ld_ld(t0
, t0
, ctx
);
1103 gen_store_gpr(t0
, rt
);
1108 save_cpu_state(ctx
, 0);
1109 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1110 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1111 op_ld_lw(t0
, t0
, ctx
);
1112 gen_store_gpr(t0
, rt
);
1116 save_cpu_state(ctx
, 0);
1117 op_ld_lw(t0
, t0
, ctx
);
1118 gen_store_gpr(t0
, rt
);
1122 save_cpu_state(ctx
, 0);
1123 op_ld_lh(t0
, t0
, ctx
);
1124 gen_store_gpr(t0
, rt
);
1128 save_cpu_state(ctx
, 0);
1129 op_ld_lhu(t0
, t0
, ctx
);
1130 gen_store_gpr(t0
, rt
);
1134 save_cpu_state(ctx
, 0);
1135 op_ld_lb(t0
, t0
, ctx
);
1136 gen_store_gpr(t0
, rt
);
1140 save_cpu_state(ctx
, 0);
1141 op_ld_lbu(t0
, t0
, ctx
);
1142 gen_store_gpr(t0
, rt
);
1146 save_cpu_state(ctx
, 1);
1147 gen_load_gpr(t1
, rt
);
1148 gen_helper_1e2i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1149 gen_store_gpr(t1
, rt
);
1153 save_cpu_state(ctx
, 1);
1154 gen_load_gpr(t1
, rt
);
1155 gen_helper_1e2i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1156 gen_store_gpr(t1
, rt
);
1160 save_cpu_state(ctx
, 1);
1161 op_ld_ll(t0
, t0
, ctx
);
1162 gen_store_gpr(t0
, rt
);
1166 (void)opn
; /* avoid a compiler warning */
1167 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1173 static void gen_st (DisasContext
*ctx
, uint32_t opc
, int rt
,
1174 int base
, int16_t offset
)
1176 const char *opn
= "st";
1177 TCGv t0
= tcg_temp_new();
1178 TCGv t1
= tcg_temp_new();
1180 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1181 gen_load_gpr(t1
, rt
);
1183 #if defined(TARGET_MIPS64)
1185 save_cpu_state(ctx
, 0);
1186 op_st_sd(t1
, t0
, ctx
);
1190 save_cpu_state(ctx
, 1);
1191 gen_helper_0e2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1195 save_cpu_state(ctx
, 1);
1196 gen_helper_0e2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1201 save_cpu_state(ctx
, 0);
1202 op_st_sw(t1
, t0
, ctx
);
1206 save_cpu_state(ctx
, 0);
1207 op_st_sh(t1
, t0
, ctx
);
1211 save_cpu_state(ctx
, 0);
1212 op_st_sb(t1
, t0
, ctx
);
1216 save_cpu_state(ctx
, 1);
1217 gen_helper_0e2i(swl
, t1
, t0
, ctx
->mem_idx
);
1221 save_cpu_state(ctx
, 1);
1222 gen_helper_0e2i(swr
, t1
, t0
, ctx
->mem_idx
);
1226 (void)opn
; /* avoid a compiler warning */
1227 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1233 /* Store conditional */
1234 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1235 int base
, int16_t offset
)
1237 const char *opn
= "st_cond";
1240 t0
= tcg_temp_local_new();
1242 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1243 /* Don't do NOP if destination is zero: we must perform the actual
1246 t1
= tcg_temp_local_new();
1247 gen_load_gpr(t1
, rt
);
1249 #if defined(TARGET_MIPS64)
1251 save_cpu_state(ctx
, 1);
1252 op_st_scd(t1
, t0
, rt
, ctx
);
1257 save_cpu_state(ctx
, 1);
1258 op_st_sc(t1
, t0
, rt
, ctx
);
1262 (void)opn
; /* avoid a compiler warning */
1263 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1268 /* Load and store */
1269 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1270 int base
, int16_t offset
)
1272 const char *opn
= "flt_ldst";
1273 TCGv t0
= tcg_temp_new();
1275 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1276 /* Don't do NOP if destination is zero: we must perform the actual
1281 TCGv_i32 fp0
= tcg_temp_new_i32();
1283 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1284 tcg_gen_trunc_tl_i32(fp0
, t0
);
1285 gen_store_fpr32(fp0
, ft
);
1286 tcg_temp_free_i32(fp0
);
1292 TCGv_i32 fp0
= tcg_temp_new_i32();
1293 TCGv t1
= tcg_temp_new();
1295 gen_load_fpr32(fp0
, ft
);
1296 tcg_gen_extu_i32_tl(t1
, fp0
);
1297 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1299 tcg_temp_free_i32(fp0
);
1305 TCGv_i64 fp0
= tcg_temp_new_i64();
1307 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1308 gen_store_fpr64(ctx
, fp0
, ft
);
1309 tcg_temp_free_i64(fp0
);
1315 TCGv_i64 fp0
= tcg_temp_new_i64();
1317 gen_load_fpr64(ctx
, fp0
, ft
);
1318 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1319 tcg_temp_free_i64(fp0
);
1325 generate_exception(ctx
, EXCP_RI
);
1328 (void)opn
; /* avoid a compiler warning */
1329 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1334 static void gen_cop1_ldst(CPUMIPSState
*env
, DisasContext
*ctx
,
1335 uint32_t op
, int rt
, int rs
, int16_t imm
)
1337 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
1338 check_cp1_enabled(ctx
);
1339 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
1341 generate_exception_err(ctx
, EXCP_CpU
, 1);
1345 /* Arithmetic with immediate operand */
1346 static void gen_arith_imm (CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t opc
,
1347 int rt
, int rs
, int16_t imm
)
1349 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1350 const char *opn
= "imm arith";
1352 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1353 /* If no destination, treat it as a NOP.
1354 For addi, we must generate the overflow exception when needed. */
1361 TCGv t0
= tcg_temp_local_new();
1362 TCGv t1
= tcg_temp_new();
1363 TCGv t2
= tcg_temp_new();
1364 int l1
= gen_new_label();
1366 gen_load_gpr(t1
, rs
);
1367 tcg_gen_addi_tl(t0
, t1
, uimm
);
1368 tcg_gen_ext32s_tl(t0
, t0
);
1370 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1371 tcg_gen_xori_tl(t2
, t0
, uimm
);
1372 tcg_gen_and_tl(t1
, t1
, t2
);
1374 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1376 /* operands of same sign, result different sign */
1377 generate_exception(ctx
, EXCP_OVERFLOW
);
1379 tcg_gen_ext32s_tl(t0
, t0
);
1380 gen_store_gpr(t0
, rt
);
1387 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1388 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1390 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1394 #if defined(TARGET_MIPS64)
1397 TCGv t0
= tcg_temp_local_new();
1398 TCGv t1
= tcg_temp_new();
1399 TCGv t2
= tcg_temp_new();
1400 int l1
= gen_new_label();
1402 gen_load_gpr(t1
, rs
);
1403 tcg_gen_addi_tl(t0
, t1
, uimm
);
1405 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1406 tcg_gen_xori_tl(t2
, t0
, uimm
);
1407 tcg_gen_and_tl(t1
, t1
, t2
);
1409 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1411 /* operands of same sign, result different sign */
1412 generate_exception(ctx
, EXCP_OVERFLOW
);
1414 gen_store_gpr(t0
, rt
);
1421 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1423 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1429 (void)opn
; /* avoid a compiler warning */
1430 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1433 /* Logic with immediate operand */
1434 static void gen_logic_imm (CPUMIPSState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1437 const char *opn
= "imm logic";
1440 /* If no destination, treat it as a NOP. */
1444 uimm
= (uint16_t)imm
;
1447 if (likely(rs
!= 0))
1448 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1450 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1455 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1457 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1461 if (likely(rs
!= 0))
1462 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1464 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1468 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1472 (void)opn
; /* avoid a compiler warning */
1473 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1476 /* Set on less than with immediate operand */
1477 static void gen_slt_imm (CPUMIPSState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1479 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1480 const char *opn
= "imm arith";
1484 /* If no destination, treat it as a NOP. */
1488 t0
= tcg_temp_new();
1489 gen_load_gpr(t0
, rs
);
1492 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
1496 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
1500 (void)opn
; /* avoid a compiler warning */
1501 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1505 /* Shifts with immediate operand */
1506 static void gen_shift_imm(CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t opc
,
1507 int rt
, int rs
, int16_t imm
)
1509 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1510 const char *opn
= "imm shift";
1514 /* If no destination, treat it as a NOP. */
1519 t0
= tcg_temp_new();
1520 gen_load_gpr(t0
, rs
);
1523 tcg_gen_shli_tl(t0
, t0
, uimm
);
1524 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1528 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1533 tcg_gen_ext32u_tl(t0
, t0
);
1534 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1536 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1542 TCGv_i32 t1
= tcg_temp_new_i32();
1544 tcg_gen_trunc_tl_i32(t1
, t0
);
1545 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1546 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1547 tcg_temp_free_i32(t1
);
1549 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1553 #if defined(TARGET_MIPS64)
1555 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1559 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1563 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1568 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1570 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
1575 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1579 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1583 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1587 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1592 (void)opn
; /* avoid a compiler warning */
1593 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1598 static void gen_arith (CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t opc
,
1599 int rd
, int rs
, int rt
)
1601 const char *opn
= "arith";
1603 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1604 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1605 /* If no destination, treat it as a NOP.
1606 For add & sub, we must generate the overflow exception when needed. */
1614 TCGv t0
= tcg_temp_local_new();
1615 TCGv t1
= tcg_temp_new();
1616 TCGv t2
= tcg_temp_new();
1617 int l1
= gen_new_label();
1619 gen_load_gpr(t1
, rs
);
1620 gen_load_gpr(t2
, rt
);
1621 tcg_gen_add_tl(t0
, t1
, t2
);
1622 tcg_gen_ext32s_tl(t0
, t0
);
1623 tcg_gen_xor_tl(t1
, t1
, t2
);
1624 tcg_gen_xor_tl(t2
, t0
, t2
);
1625 tcg_gen_andc_tl(t1
, t2
, t1
);
1627 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1629 /* operands of same sign, result different sign */
1630 generate_exception(ctx
, EXCP_OVERFLOW
);
1632 gen_store_gpr(t0
, rd
);
1638 if (rs
!= 0 && rt
!= 0) {
1639 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1640 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1641 } else if (rs
== 0 && rt
!= 0) {
1642 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1643 } else if (rs
!= 0 && rt
== 0) {
1644 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1646 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1652 TCGv t0
= tcg_temp_local_new();
1653 TCGv t1
= tcg_temp_new();
1654 TCGv t2
= tcg_temp_new();
1655 int l1
= gen_new_label();
1657 gen_load_gpr(t1
, rs
);
1658 gen_load_gpr(t2
, rt
);
1659 tcg_gen_sub_tl(t0
, t1
, t2
);
1660 tcg_gen_ext32s_tl(t0
, t0
);
1661 tcg_gen_xor_tl(t2
, t1
, t2
);
1662 tcg_gen_xor_tl(t1
, t0
, t1
);
1663 tcg_gen_and_tl(t1
, t1
, t2
);
1665 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1667 /* operands of different sign, first operand and result different sign */
1668 generate_exception(ctx
, EXCP_OVERFLOW
);
1670 gen_store_gpr(t0
, rd
);
1676 if (rs
!= 0 && rt
!= 0) {
1677 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1678 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1679 } else if (rs
== 0 && rt
!= 0) {
1680 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1681 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1682 } else if (rs
!= 0 && rt
== 0) {
1683 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1685 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1689 #if defined(TARGET_MIPS64)
1692 TCGv t0
= tcg_temp_local_new();
1693 TCGv t1
= tcg_temp_new();
1694 TCGv t2
= tcg_temp_new();
1695 int l1
= gen_new_label();
1697 gen_load_gpr(t1
, rs
);
1698 gen_load_gpr(t2
, rt
);
1699 tcg_gen_add_tl(t0
, t1
, t2
);
1700 tcg_gen_xor_tl(t1
, t1
, t2
);
1701 tcg_gen_xor_tl(t2
, t0
, t2
);
1702 tcg_gen_andc_tl(t1
, t2
, t1
);
1704 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1706 /* operands of same sign, result different sign */
1707 generate_exception(ctx
, EXCP_OVERFLOW
);
1709 gen_store_gpr(t0
, rd
);
1715 if (rs
!= 0 && rt
!= 0) {
1716 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1717 } else if (rs
== 0 && rt
!= 0) {
1718 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1719 } else if (rs
!= 0 && rt
== 0) {
1720 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1722 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1728 TCGv t0
= tcg_temp_local_new();
1729 TCGv t1
= tcg_temp_new();
1730 TCGv t2
= tcg_temp_new();
1731 int l1
= gen_new_label();
1733 gen_load_gpr(t1
, rs
);
1734 gen_load_gpr(t2
, rt
);
1735 tcg_gen_sub_tl(t0
, t1
, t2
);
1736 tcg_gen_xor_tl(t2
, t1
, t2
);
1737 tcg_gen_xor_tl(t1
, t0
, t1
);
1738 tcg_gen_and_tl(t1
, t1
, t2
);
1740 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1742 /* operands of different sign, first operand and result different sign */
1743 generate_exception(ctx
, EXCP_OVERFLOW
);
1745 gen_store_gpr(t0
, rd
);
1751 if (rs
!= 0 && rt
!= 0) {
1752 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1753 } else if (rs
== 0 && rt
!= 0) {
1754 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1755 } else if (rs
!= 0 && rt
== 0) {
1756 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1758 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1764 if (likely(rs
!= 0 && rt
!= 0)) {
1765 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1766 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1768 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1773 (void)opn
; /* avoid a compiler warning */
1774 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1777 /* Conditional move */
1778 static void gen_cond_move (CPUMIPSState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1780 const char *opn
= "cond move";
1784 /* If no destination, treat it as a NOP.
1785 For add & sub, we must generate the overflow exception when needed. */
1790 l1
= gen_new_label();
1793 if (likely(rt
!= 0))
1794 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1800 if (likely(rt
!= 0))
1801 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1806 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1808 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1811 (void)opn
; /* avoid a compiler warning */
1812 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1816 static void gen_logic (CPUMIPSState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1818 const char *opn
= "logic";
1821 /* If no destination, treat it as a NOP. */
1828 if (likely(rs
!= 0 && rt
!= 0)) {
1829 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1831 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1836 if (rs
!= 0 && rt
!= 0) {
1837 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1838 } else if (rs
== 0 && rt
!= 0) {
1839 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1840 } else if (rs
!= 0 && rt
== 0) {
1841 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1843 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1848 if (likely(rs
!= 0 && rt
!= 0)) {
1849 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1850 } else if (rs
== 0 && rt
!= 0) {
1851 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1852 } else if (rs
!= 0 && rt
== 0) {
1853 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1855 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1860 if (likely(rs
!= 0 && rt
!= 0)) {
1861 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1862 } else if (rs
== 0 && rt
!= 0) {
1863 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1864 } else if (rs
!= 0 && rt
== 0) {
1865 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1867 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1872 (void)opn
; /* avoid a compiler warning */
1873 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1876 /* Set on lower than */
1877 static void gen_slt (CPUMIPSState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1879 const char *opn
= "slt";
1883 /* If no destination, treat it as a NOP. */
1888 t0
= tcg_temp_new();
1889 t1
= tcg_temp_new();
1890 gen_load_gpr(t0
, rs
);
1891 gen_load_gpr(t1
, rt
);
1894 tcg_gen_setcond_tl(TCG_COND_LT
, cpu_gpr
[rd
], t0
, t1
);
1898 tcg_gen_setcond_tl(TCG_COND_LTU
, cpu_gpr
[rd
], t0
, t1
);
1902 (void)opn
; /* avoid a compiler warning */
1903 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1909 static void gen_shift (CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t opc
,
1910 int rd
, int rs
, int rt
)
1912 const char *opn
= "shifts";
1916 /* If no destination, treat it as a NOP.
1917 For add & sub, we must generate the overflow exception when needed. */
1922 t0
= tcg_temp_new();
1923 t1
= tcg_temp_new();
1924 gen_load_gpr(t0
, rs
);
1925 gen_load_gpr(t1
, rt
);
1928 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1929 tcg_gen_shl_tl(t0
, t1
, t0
);
1930 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1934 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1935 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1939 tcg_gen_ext32u_tl(t1
, t1
);
1940 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1941 tcg_gen_shr_tl(t0
, t1
, t0
);
1942 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1947 TCGv_i32 t2
= tcg_temp_new_i32();
1948 TCGv_i32 t3
= tcg_temp_new_i32();
1950 tcg_gen_trunc_tl_i32(t2
, t0
);
1951 tcg_gen_trunc_tl_i32(t3
, t1
);
1952 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1953 tcg_gen_rotr_i32(t2
, t3
, t2
);
1954 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1955 tcg_temp_free_i32(t2
);
1956 tcg_temp_free_i32(t3
);
1960 #if defined(TARGET_MIPS64)
1962 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1963 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1967 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1968 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1972 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1973 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1977 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1978 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1983 (void)opn
; /* avoid a compiler warning */
1984 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1989 /* Arithmetic on HI/LO registers */
1990 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1992 const char *opn
= "hilo";
1994 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
2001 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
2005 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
2010 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
2012 tcg_gen_movi_tl(cpu_HI
[0], 0);
2017 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
2019 tcg_gen_movi_tl(cpu_LO
[0], 0);
2023 (void)opn
; /* avoid a compiler warning */
2024 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
2027 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
2030 const char *opn
= "mul/div";
2036 #if defined(TARGET_MIPS64)
2040 t0
= tcg_temp_local_new();
2041 t1
= tcg_temp_local_new();
2044 t0
= tcg_temp_new();
2045 t1
= tcg_temp_new();
2049 gen_load_gpr(t0
, rs
);
2050 gen_load_gpr(t1
, rt
);
2054 int l1
= gen_new_label();
2055 int l2
= gen_new_label();
2057 tcg_gen_ext32s_tl(t0
, t0
);
2058 tcg_gen_ext32s_tl(t1
, t1
);
2059 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2060 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2061 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2063 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2064 tcg_gen_movi_tl(cpu_HI
[0], 0);
2067 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
2068 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
2069 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2070 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2077 int l1
= gen_new_label();
2079 tcg_gen_ext32u_tl(t0
, t0
);
2080 tcg_gen_ext32u_tl(t1
, t1
);
2081 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2082 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2083 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2084 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2085 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2092 TCGv_i64 t2
= tcg_temp_new_i64();
2093 TCGv_i64 t3
= tcg_temp_new_i64();
2095 tcg_gen_ext_tl_i64(t2
, t0
);
2096 tcg_gen_ext_tl_i64(t3
, t1
);
2097 tcg_gen_mul_i64(t2
, t2
, t3
);
2098 tcg_temp_free_i64(t3
);
2099 tcg_gen_trunc_i64_tl(t0
, t2
);
2100 tcg_gen_shri_i64(t2
, t2
, 32);
2101 tcg_gen_trunc_i64_tl(t1
, t2
);
2102 tcg_temp_free_i64(t2
);
2103 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2104 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2110 TCGv_i64 t2
= tcg_temp_new_i64();
2111 TCGv_i64 t3
= tcg_temp_new_i64();
2113 tcg_gen_ext32u_tl(t0
, t0
);
2114 tcg_gen_ext32u_tl(t1
, t1
);
2115 tcg_gen_extu_tl_i64(t2
, t0
);
2116 tcg_gen_extu_tl_i64(t3
, t1
);
2117 tcg_gen_mul_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
);
2128 #if defined(TARGET_MIPS64)
2131 int l1
= gen_new_label();
2132 int l2
= gen_new_label();
2134 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2135 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2136 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2137 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2138 tcg_gen_movi_tl(cpu_HI
[0], 0);
2141 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2142 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2149 int l1
= gen_new_label();
2151 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2152 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2153 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2159 gen_helper_dmult(cpu_env
, t0
, t1
);
2163 gen_helper_dmultu(cpu_env
, t0
, t1
);
2169 TCGv_i64 t2
= tcg_temp_new_i64();
2170 TCGv_i64 t3
= tcg_temp_new_i64();
2172 tcg_gen_ext_tl_i64(t2
, t0
);
2173 tcg_gen_ext_tl_i64(t3
, t1
);
2174 tcg_gen_mul_i64(t2
, t2
, t3
);
2175 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2176 tcg_gen_add_i64(t2
, t2
, t3
);
2177 tcg_temp_free_i64(t3
);
2178 tcg_gen_trunc_i64_tl(t0
, t2
);
2179 tcg_gen_shri_i64(t2
, t2
, 32);
2180 tcg_gen_trunc_i64_tl(t1
, t2
);
2181 tcg_temp_free_i64(t2
);
2182 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2183 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2189 TCGv_i64 t2
= tcg_temp_new_i64();
2190 TCGv_i64 t3
= tcg_temp_new_i64();
2192 tcg_gen_ext32u_tl(t0
, t0
);
2193 tcg_gen_ext32u_tl(t1
, t1
);
2194 tcg_gen_extu_tl_i64(t2
, t0
);
2195 tcg_gen_extu_tl_i64(t3
, t1
);
2196 tcg_gen_mul_i64(t2
, t2
, t3
);
2197 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2198 tcg_gen_add_i64(t2
, t2
, t3
);
2199 tcg_temp_free_i64(t3
);
2200 tcg_gen_trunc_i64_tl(t0
, t2
);
2201 tcg_gen_shri_i64(t2
, t2
, 32);
2202 tcg_gen_trunc_i64_tl(t1
, t2
);
2203 tcg_temp_free_i64(t2
);
2204 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2205 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2211 TCGv_i64 t2
= tcg_temp_new_i64();
2212 TCGv_i64 t3
= tcg_temp_new_i64();
2214 tcg_gen_ext_tl_i64(t2
, t0
);
2215 tcg_gen_ext_tl_i64(t3
, t1
);
2216 tcg_gen_mul_i64(t2
, t2
, t3
);
2217 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2218 tcg_gen_sub_i64(t2
, t3
, t2
);
2219 tcg_temp_free_i64(t3
);
2220 tcg_gen_trunc_i64_tl(t0
, t2
);
2221 tcg_gen_shri_i64(t2
, t2
, 32);
2222 tcg_gen_trunc_i64_tl(t1
, t2
);
2223 tcg_temp_free_i64(t2
);
2224 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2225 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2231 TCGv_i64 t2
= tcg_temp_new_i64();
2232 TCGv_i64 t3
= tcg_temp_new_i64();
2234 tcg_gen_ext32u_tl(t0
, t0
);
2235 tcg_gen_ext32u_tl(t1
, t1
);
2236 tcg_gen_extu_tl_i64(t2
, t0
);
2237 tcg_gen_extu_tl_i64(t3
, t1
);
2238 tcg_gen_mul_i64(t2
, t2
, t3
);
2239 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2240 tcg_gen_sub_i64(t2
, t3
, t2
);
2241 tcg_temp_free_i64(t3
);
2242 tcg_gen_trunc_i64_tl(t0
, t2
);
2243 tcg_gen_shri_i64(t2
, t2
, 32);
2244 tcg_gen_trunc_i64_tl(t1
, t2
);
2245 tcg_temp_free_i64(t2
);
2246 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2247 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2253 generate_exception(ctx
, EXCP_RI
);
2256 (void)opn
; /* avoid a compiler warning */
2257 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2263 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2264 int rd
, int rs
, int rt
)
2266 const char *opn
= "mul vr54xx";
2267 TCGv t0
= tcg_temp_new();
2268 TCGv t1
= tcg_temp_new();
2270 gen_load_gpr(t0
, rs
);
2271 gen_load_gpr(t1
, rt
);
2274 case OPC_VR54XX_MULS
:
2275 gen_helper_muls(t0
, cpu_env
, t0
, t1
);
2278 case OPC_VR54XX_MULSU
:
2279 gen_helper_mulsu(t0
, cpu_env
, t0
, t1
);
2282 case OPC_VR54XX_MACC
:
2283 gen_helper_macc(t0
, cpu_env
, t0
, t1
);
2286 case OPC_VR54XX_MACCU
:
2287 gen_helper_maccu(t0
, cpu_env
, t0
, t1
);
2290 case OPC_VR54XX_MSAC
:
2291 gen_helper_msac(t0
, cpu_env
, t0
, t1
);
2294 case OPC_VR54XX_MSACU
:
2295 gen_helper_msacu(t0
, cpu_env
, t0
, t1
);
2298 case OPC_VR54XX_MULHI
:
2299 gen_helper_mulhi(t0
, cpu_env
, t0
, t1
);
2302 case OPC_VR54XX_MULHIU
:
2303 gen_helper_mulhiu(t0
, cpu_env
, t0
, t1
);
2306 case OPC_VR54XX_MULSHI
:
2307 gen_helper_mulshi(t0
, cpu_env
, t0
, t1
);
2310 case OPC_VR54XX_MULSHIU
:
2311 gen_helper_mulshiu(t0
, cpu_env
, t0
, t1
);
2314 case OPC_VR54XX_MACCHI
:
2315 gen_helper_macchi(t0
, cpu_env
, t0
, t1
);
2318 case OPC_VR54XX_MACCHIU
:
2319 gen_helper_macchiu(t0
, cpu_env
, t0
, t1
);
2322 case OPC_VR54XX_MSACHI
:
2323 gen_helper_msachi(t0
, cpu_env
, t0
, t1
);
2326 case OPC_VR54XX_MSACHIU
:
2327 gen_helper_msachiu(t0
, cpu_env
, t0
, t1
);
2331 MIPS_INVAL("mul vr54xx");
2332 generate_exception(ctx
, EXCP_RI
);
2335 gen_store_gpr(t0
, rd
);
2336 (void)opn
; /* avoid a compiler warning */
2337 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2344 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2347 const char *opn
= "CLx";
2355 t0
= tcg_temp_new();
2356 gen_load_gpr(t0
, rs
);
2359 gen_helper_clo(cpu_gpr
[rd
], t0
);
2363 gen_helper_clz(cpu_gpr
[rd
], t0
);
2366 #if defined(TARGET_MIPS64)
2368 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2372 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2377 (void)opn
; /* avoid a compiler warning */
2378 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2382 /* Godson integer instructions */
2383 static void gen_loongson_integer (DisasContext
*ctx
, uint32_t opc
,
2384 int rd
, int rs
, int rt
)
2386 const char *opn
= "loongson";
2398 case OPC_MULTU_G_2E
:
2399 case OPC_MULTU_G_2F
:
2400 #if defined(TARGET_MIPS64)
2401 case OPC_DMULT_G_2E
:
2402 case OPC_DMULT_G_2F
:
2403 case OPC_DMULTU_G_2E
:
2404 case OPC_DMULTU_G_2F
:
2406 t0
= tcg_temp_new();
2407 t1
= tcg_temp_new();
2410 t0
= tcg_temp_local_new();
2411 t1
= tcg_temp_local_new();
2415 gen_load_gpr(t0
, rs
);
2416 gen_load_gpr(t1
, rt
);
2421 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2422 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2425 case OPC_MULTU_G_2E
:
2426 case OPC_MULTU_G_2F
:
2427 tcg_gen_ext32u_tl(t0
, t0
);
2428 tcg_gen_ext32u_tl(t1
, t1
);
2429 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2430 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2436 int l1
= gen_new_label();
2437 int l2
= gen_new_label();
2438 int l3
= gen_new_label();
2439 tcg_gen_ext32s_tl(t0
, t0
);
2440 tcg_gen_ext32s_tl(t1
, t1
);
2441 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2442 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2445 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2446 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2447 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
2450 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
2451 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2459 int l1
= gen_new_label();
2460 int l2
= gen_new_label();
2461 tcg_gen_ext32u_tl(t0
, t0
);
2462 tcg_gen_ext32u_tl(t1
, t1
);
2463 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2464 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2467 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
2468 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2476 int l1
= gen_new_label();
2477 int l2
= gen_new_label();
2478 int l3
= gen_new_label();
2479 tcg_gen_ext32u_tl(t0
, t0
);
2480 tcg_gen_ext32u_tl(t1
, t1
);
2481 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2482 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2483 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2485 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2488 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
2489 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2497 int l1
= gen_new_label();
2498 int l2
= gen_new_label();
2499 tcg_gen_ext32u_tl(t0
, t0
);
2500 tcg_gen_ext32u_tl(t1
, t1
);
2501 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2502 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2505 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
2506 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
2511 #if defined(TARGET_MIPS64)
2512 case OPC_DMULT_G_2E
:
2513 case OPC_DMULT_G_2F
:
2514 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2517 case OPC_DMULTU_G_2E
:
2518 case OPC_DMULTU_G_2F
:
2519 tcg_gen_mul_tl(cpu_gpr
[rd
], t0
, t1
);
2525 int l1
= gen_new_label();
2526 int l2
= gen_new_label();
2527 int l3
= gen_new_label();
2528 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2529 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2532 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2533 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2534 tcg_gen_mov_tl(cpu_gpr
[rd
], t0
);
2537 tcg_gen_div_tl(cpu_gpr
[rd
], t0
, t1
);
2542 case OPC_DDIVU_G_2E
:
2543 case OPC_DDIVU_G_2F
:
2545 int l1
= gen_new_label();
2546 int l2
= gen_new_label();
2547 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2548 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2551 tcg_gen_divu_tl(cpu_gpr
[rd
], t0
, t1
);
2559 int l1
= gen_new_label();
2560 int l2
= gen_new_label();
2561 int l3
= gen_new_label();
2562 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2563 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2564 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2566 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2569 tcg_gen_rem_tl(cpu_gpr
[rd
], t0
, t1
);
2574 case OPC_DMODU_G_2E
:
2575 case OPC_DMODU_G_2F
:
2577 int l1
= gen_new_label();
2578 int l2
= gen_new_label();
2579 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
2580 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
2583 tcg_gen_remu_tl(cpu_gpr
[rd
], t0
, t1
);
2591 (void)opn
; /* avoid a compiler warning */
2592 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2598 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2599 int rs
, int rt
, int16_t imm
)
2602 TCGv t0
= tcg_temp_new();
2603 TCGv t1
= tcg_temp_new();
2606 /* Load needed operands */
2614 /* Compare two registers */
2616 gen_load_gpr(t0
, rs
);
2617 gen_load_gpr(t1
, rt
);
2627 /* Compare register to immediate */
2628 if (rs
!= 0 || imm
!= 0) {
2629 gen_load_gpr(t0
, rs
);
2630 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2637 case OPC_TEQ
: /* rs == rs */
2638 case OPC_TEQI
: /* r0 == 0 */
2639 case OPC_TGE
: /* rs >= rs */
2640 case OPC_TGEI
: /* r0 >= 0 */
2641 case OPC_TGEU
: /* rs >= rs unsigned */
2642 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2644 generate_exception(ctx
, EXCP_TRAP
);
2646 case OPC_TLT
: /* rs < rs */
2647 case OPC_TLTI
: /* r0 < 0 */
2648 case OPC_TLTU
: /* rs < rs unsigned */
2649 case OPC_TLTIU
: /* r0 < 0 unsigned */
2650 case OPC_TNE
: /* rs != rs */
2651 case OPC_TNEI
: /* r0 != 0 */
2652 /* Never trap: treat as NOP. */
2656 int l1
= gen_new_label();
2661 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2665 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2669 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2673 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2677 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2681 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2684 generate_exception(ctx
, EXCP_TRAP
);
2691 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2693 TranslationBlock
*tb
;
2695 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2696 likely(!ctx
->singlestep_enabled
)) {
2699 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
2702 if (ctx
->singlestep_enabled
) {
2703 save_cpu_state(ctx
, 0);
2704 gen_helper_0e0i(raise_exception
, EXCP_DEBUG
);
2710 /* Branches (before delay slot) */
2711 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2713 int rs
, int rt
, int32_t offset
)
2715 target_ulong btgt
= -1;
2717 int bcond_compute
= 0;
2718 TCGv t0
= tcg_temp_new();
2719 TCGv t1
= tcg_temp_new();
2721 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2722 #ifdef MIPS_DEBUG_DISAS
2723 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2725 generate_exception(ctx
, EXCP_RI
);
2729 /* Load needed operands */
2735 /* Compare two registers */
2737 gen_load_gpr(t0
, rs
);
2738 gen_load_gpr(t1
, rt
);
2741 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2757 /* Compare to zero */
2759 gen_load_gpr(t0
, rs
);
2762 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2769 /* Jump to immediate */
2770 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
2776 /* Jump to register */
2777 if (offset
!= 0 && offset
!= 16) {
2778 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2779 others are reserved. */
2780 MIPS_INVAL("jump hint");
2781 generate_exception(ctx
, EXCP_RI
);
2784 gen_load_gpr(btarget
, rs
);
2787 MIPS_INVAL("branch/jump");
2788 generate_exception(ctx
, EXCP_RI
);
2791 if (bcond_compute
== 0) {
2792 /* No condition to be computed */
2794 case OPC_BEQ
: /* rx == rx */
2795 case OPC_BEQL
: /* rx == rx likely */
2796 case OPC_BGEZ
: /* 0 >= 0 */
2797 case OPC_BGEZL
: /* 0 >= 0 likely */
2798 case OPC_BLEZ
: /* 0 <= 0 */
2799 case OPC_BLEZL
: /* 0 <= 0 likely */
2801 ctx
->hflags
|= MIPS_HFLAG_B
;
2802 MIPS_DEBUG("balways");
2805 case OPC_BGEZAL
: /* 0 >= 0 */
2806 case OPC_BGEZALL
: /* 0 >= 0 likely */
2807 ctx
->hflags
|= (opc
== OPC_BGEZALS
2809 : MIPS_HFLAG_BDS32
);
2810 /* Always take and link */
2812 ctx
->hflags
|= MIPS_HFLAG_B
;
2813 MIPS_DEBUG("balways and link");
2815 case OPC_BNE
: /* rx != rx */
2816 case OPC_BGTZ
: /* 0 > 0 */
2817 case OPC_BLTZ
: /* 0 < 0 */
2819 MIPS_DEBUG("bnever (NOP)");
2822 case OPC_BLTZAL
: /* 0 < 0 */
2823 ctx
->hflags
|= (opc
== OPC_BLTZALS
2825 : MIPS_HFLAG_BDS32
);
2826 /* Handle as an unconditional branch to get correct delay
2829 btgt
= ctx
->pc
+ (opc
== OPC_BLTZALS
? 6 : 8);
2830 ctx
->hflags
|= MIPS_HFLAG_B
;
2831 MIPS_DEBUG("bnever and link");
2833 case OPC_BLTZALL
: /* 0 < 0 likely */
2834 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2835 /* Skip the instruction in the delay slot */
2836 MIPS_DEBUG("bnever, link and skip");
2839 case OPC_BNEL
: /* rx != rx likely */
2840 case OPC_BGTZL
: /* 0 > 0 likely */
2841 case OPC_BLTZL
: /* 0 < 0 likely */
2842 /* Skip the instruction in the delay slot */
2843 MIPS_DEBUG("bnever and skip");
2847 ctx
->hflags
|= MIPS_HFLAG_B
;
2848 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2852 ctx
->hflags
|= MIPS_HFLAG_BX
;
2857 ctx
->hflags
|= MIPS_HFLAG_B
;
2858 ctx
->hflags
|= ((opc
== OPC_JALS
|| opc
== OPC_JALXS
)
2860 : MIPS_HFLAG_BDS32
);
2861 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2864 ctx
->hflags
|= MIPS_HFLAG_BR
;
2865 if (insn_bytes
== 4)
2866 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
2867 MIPS_DEBUG("jr %s", regnames
[rs
]);
2873 ctx
->hflags
|= MIPS_HFLAG_BR
;
2874 ctx
->hflags
|= (opc
== OPC_JALRS
2876 : MIPS_HFLAG_BDS32
);
2877 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2880 MIPS_INVAL("branch/jump");
2881 generate_exception(ctx
, EXCP_RI
);
2887 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2888 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2889 regnames
[rs
], regnames
[rt
], btgt
);
2892 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2893 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2894 regnames
[rs
], regnames
[rt
], btgt
);
2897 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2898 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2899 regnames
[rs
], regnames
[rt
], btgt
);
2902 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2903 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2904 regnames
[rs
], regnames
[rt
], btgt
);
2907 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2908 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2911 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2912 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2916 ctx
->hflags
|= (opc
== OPC_BGEZALS
2918 : MIPS_HFLAG_BDS32
);
2919 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2920 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2924 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2926 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2929 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2930 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2933 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2934 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2937 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2938 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2941 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2942 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2945 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2946 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2949 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2950 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2954 ctx
->hflags
|= (opc
== OPC_BLTZALS
2956 : MIPS_HFLAG_BDS32
);
2957 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2959 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2961 ctx
->hflags
|= MIPS_HFLAG_BC
;
2964 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2966 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2968 ctx
->hflags
|= MIPS_HFLAG_BL
;
2971 MIPS_INVAL("conditional branch/jump");
2972 generate_exception(ctx
, EXCP_RI
);
2976 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2977 blink
, ctx
->hflags
, btgt
);
2979 ctx
->btarget
= btgt
;
2981 int post_delay
= insn_bytes
;
2982 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
2984 if (opc
!= OPC_JALRC
)
2985 post_delay
+= ((ctx
->hflags
& MIPS_HFLAG_BDS16
) ? 2 : 4);
2987 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ post_delay
+ lowbit
);
2991 if (insn_bytes
== 2)
2992 ctx
->hflags
|= MIPS_HFLAG_B16
;
2997 /* special3 bitfield operations */
2998 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2999 int rs
, int lsb
, int msb
)
3001 TCGv t0
= tcg_temp_new();
3002 TCGv t1
= tcg_temp_new();
3005 gen_load_gpr(t1
, rs
);
3010 tcg_gen_shri_tl(t0
, t1
, lsb
);
3012 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
3014 tcg_gen_ext32s_tl(t0
, t0
);
3017 #if defined(TARGET_MIPS64)
3019 tcg_gen_shri_tl(t0
, t1
, lsb
);
3021 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
3025 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
3026 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
3029 tcg_gen_shri_tl(t0
, t1
, lsb
);
3030 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
3036 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
3037 gen_load_gpr(t0
, rt
);
3038 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3039 tcg_gen_shli_tl(t1
, t1
, lsb
);
3040 tcg_gen_andi_tl(t1
, t1
, mask
);
3041 tcg_gen_or_tl(t0
, t0
, t1
);
3042 tcg_gen_ext32s_tl(t0
, t0
);
3044 #if defined(TARGET_MIPS64)
3048 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
3049 gen_load_gpr(t0
, rt
);
3050 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3051 tcg_gen_shli_tl(t1
, t1
, lsb
);
3052 tcg_gen_andi_tl(t1
, t1
, mask
);
3053 tcg_gen_or_tl(t0
, t0
, t1
);
3058 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << (lsb
+ 32);
3059 gen_load_gpr(t0
, rt
);
3060 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3061 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
3062 tcg_gen_andi_tl(t1
, t1
, mask
);
3063 tcg_gen_or_tl(t0
, t0
, t1
);
3068 gen_load_gpr(t0
, rt
);
3069 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
3070 gen_load_gpr(t0
, rt
);
3071 tcg_gen_andi_tl(t0
, t0
, ~mask
);
3072 tcg_gen_shli_tl(t1
, t1
, lsb
);
3073 tcg_gen_andi_tl(t1
, t1
, mask
);
3074 tcg_gen_or_tl(t0
, t0
, t1
);
3079 MIPS_INVAL("bitops");
3080 generate_exception(ctx
, EXCP_RI
);
3085 gen_store_gpr(t0
, rt
);
3090 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
3095 /* If no destination, treat it as a NOP. */
3100 t0
= tcg_temp_new();
3101 gen_load_gpr(t0
, rt
);
3105 TCGv t1
= tcg_temp_new();
3107 tcg_gen_shri_tl(t1
, t0
, 8);
3108 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
3109 tcg_gen_shli_tl(t0
, t0
, 8);
3110 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
3111 tcg_gen_or_tl(t0
, t0
, t1
);
3113 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
3117 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
3120 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
3122 #if defined(TARGET_MIPS64)
3125 TCGv t1
= tcg_temp_new();
3127 tcg_gen_shri_tl(t1
, t0
, 8);
3128 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
3129 tcg_gen_shli_tl(t0
, t0
, 8);
3130 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
3131 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
3137 TCGv t1
= tcg_temp_new();
3139 tcg_gen_shri_tl(t1
, t0
, 16);
3140 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
3141 tcg_gen_shli_tl(t0
, t0
, 16);
3142 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
3143 tcg_gen_or_tl(t0
, t0
, t1
);
3144 tcg_gen_shri_tl(t1
, t0
, 32);
3145 tcg_gen_shli_tl(t0
, t0
, 32);
3146 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
3152 MIPS_INVAL("bsfhl");
3153 generate_exception(ctx
, EXCP_RI
);
3160 #ifndef CONFIG_USER_ONLY
3161 /* CP0 (MMU and control) */
3162 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
3164 TCGv_i32 t0
= tcg_temp_new_i32();
3166 tcg_gen_ld_i32(t0
, cpu_env
, off
);
3167 tcg_gen_ext_i32_tl(arg
, t0
);
3168 tcg_temp_free_i32(t0
);
3171 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
3173 tcg_gen_ld_tl(arg
, cpu_env
, off
);
3174 tcg_gen_ext32s_tl(arg
, arg
);
3177 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
3179 TCGv_i32 t0
= tcg_temp_new_i32();
3181 tcg_gen_trunc_tl_i32(t0
, arg
);
3182 tcg_gen_st_i32(t0
, cpu_env
, off
);
3183 tcg_temp_free_i32(t0
);
3186 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
3188 tcg_gen_ext32s_tl(arg
, arg
);
3189 tcg_gen_st_tl(arg
, cpu_env
, off
);
3192 static void gen_mfc0 (CPUMIPSState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3194 const char *rn
= "invalid";
3197 check_insn(env
, ctx
, ISA_MIPS32
);
3203 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Index
));
3207 check_insn(env
, ctx
, ASE_MT
);
3208 gen_helper_mfc0_mvpcontrol(arg
, cpu_env
);
3212 check_insn(env
, ctx
, ASE_MT
);
3213 gen_helper_mfc0_mvpconf0(arg
, cpu_env
);
3217 check_insn(env
, ctx
, ASE_MT
);
3218 gen_helper_mfc0_mvpconf1(arg
, cpu_env
);
3228 gen_helper_mfc0_random(arg
, cpu_env
);
3232 check_insn(env
, ctx
, ASE_MT
);
3233 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEControl
));
3237 check_insn(env
, ctx
, ASE_MT
);
3238 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf0
));
3242 check_insn(env
, ctx
, ASE_MT
);
3243 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf1
));
3247 check_insn(env
, ctx
, ASE_MT
);
3248 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_YQMask
));
3252 check_insn(env
, ctx
, ASE_MT
);
3253 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
3257 check_insn(env
, ctx
, ASE_MT
);
3258 gen_mfc0_load64(arg
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
3259 rn
= "VPEScheFBack";
3262 check_insn(env
, ctx
, ASE_MT
);
3263 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEOpt
));
3273 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryLo0
));
3274 tcg_gen_ext32s_tl(arg
, arg
);
3278 check_insn(env
, ctx
, ASE_MT
);
3279 gen_helper_mfc0_tcstatus(arg
, cpu_env
);
3283 check_insn(env
, ctx
, ASE_MT
);
3284 gen_helper_mfc0_tcbind(arg
, cpu_env
);
3288 check_insn(env
, ctx
, ASE_MT
);
3289 gen_helper_mfc0_tcrestart(arg
, cpu_env
);
3293 check_insn(env
, ctx
, ASE_MT
);
3294 gen_helper_mfc0_tchalt(arg
, cpu_env
);
3298 check_insn(env
, ctx
, ASE_MT
);
3299 gen_helper_mfc0_tccontext(arg
, cpu_env
);
3303 check_insn(env
, ctx
, ASE_MT
);
3304 gen_helper_mfc0_tcschedule(arg
, cpu_env
);
3308 check_insn(env
, ctx
, ASE_MT
);
3309 gen_helper_mfc0_tcschefback(arg
, cpu_env
);
3319 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryLo1
));
3320 tcg_gen_ext32s_tl(arg
, arg
);
3330 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_Context
));
3331 tcg_gen_ext32s_tl(arg
, arg
);
3335 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3336 rn
= "ContextConfig";
3345 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageMask
));
3349 check_insn(env
, ctx
, ISA_MIPS32R2
);
3350 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageGrain
));
3360 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Wired
));
3364 check_insn(env
, ctx
, ISA_MIPS32R2
);
3365 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf0
));
3369 check_insn(env
, ctx
, ISA_MIPS32R2
);
3370 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf1
));
3374 check_insn(env
, ctx
, ISA_MIPS32R2
);
3375 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf2
));
3379 check_insn(env
, ctx
, ISA_MIPS32R2
);
3380 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf3
));
3384 check_insn(env
, ctx
, ISA_MIPS32R2
);
3385 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf4
));
3395 check_insn(env
, ctx
, ISA_MIPS32R2
);
3396 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_HWREna
));
3406 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_BadVAddr
));
3407 tcg_gen_ext32s_tl(arg
, arg
);
3417 /* Mark as an IO operation because we read the time. */
3420 gen_helper_mfc0_count(arg
, cpu_env
);
3424 /* Break the TB to be able to take timer interrupts immediately
3425 after reading count. */
3426 ctx
->bstate
= BS_STOP
;
3429 /* 6,7 are implementation dependent */
3437 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryHi
));
3438 tcg_gen_ext32s_tl(arg
, arg
);
3448 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Compare
));
3451 /* 6,7 are implementation dependent */
3459 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Status
));
3463 check_insn(env
, ctx
, ISA_MIPS32R2
);
3464 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_IntCtl
));
3468 check_insn(env
, ctx
, ISA_MIPS32R2
);
3469 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
3473 check_insn(env
, ctx
, ISA_MIPS32R2
);
3474 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
3484 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Cause
));
3494 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EPC
));
3495 tcg_gen_ext32s_tl(arg
, arg
);
3505 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PRid
));
3509 check_insn(env
, ctx
, ISA_MIPS32R2
);
3510 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_EBase
));
3520 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config0
));
3524 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config1
));
3528 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config2
));
3532 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config3
));
3535 /* 4,5 are reserved */
3536 /* 6,7 are implementation dependent */
3538 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config6
));
3542 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config7
));
3552 gen_helper_mfc0_lladdr(arg
, cpu_env
);
3562 gen_helper_1e0i(mfc0_watchlo
, arg
, sel
);
3572 gen_helper_1e0i(mfc0_watchhi
, arg
, sel
);
3582 #if defined(TARGET_MIPS64)
3583 check_insn(env
, ctx
, ISA_MIPS3
);
3584 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_XContext
));
3585 tcg_gen_ext32s_tl(arg
, arg
);
3594 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3597 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Framemask
));
3605 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3606 rn
= "'Diagnostic"; /* implementation dependent */
3611 gen_helper_mfc0_debug(arg
, cpu_env
); /* EJTAG support */
3615 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3616 rn
= "TraceControl";
3619 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3620 rn
= "TraceControl2";
3623 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3624 rn
= "UserTraceData";
3627 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3638 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
3639 tcg_gen_ext32s_tl(arg
, arg
);
3649 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Performance0
));
3650 rn
= "Performance0";
3653 // gen_helper_mfc0_performance1(arg);
3654 rn
= "Performance1";
3657 // gen_helper_mfc0_performance2(arg);
3658 rn
= "Performance2";
3661 // gen_helper_mfc0_performance3(arg);
3662 rn
= "Performance3";
3665 // gen_helper_mfc0_performance4(arg);
3666 rn
= "Performance4";
3669 // gen_helper_mfc0_performance5(arg);
3670 rn
= "Performance5";
3673 // gen_helper_mfc0_performance6(arg);
3674 rn
= "Performance6";
3677 // gen_helper_mfc0_performance7(arg);
3678 rn
= "Performance7";
3685 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3691 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3704 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagLo
));
3711 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataLo
));
3724 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagHi
));
3731 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataHi
));
3741 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
3742 tcg_gen_ext32s_tl(arg
, arg
);
3753 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
3763 (void)rn
; /* avoid a compiler warning */
3764 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3768 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3769 generate_exception(ctx
, EXCP_RI
);
3772 static void gen_mtc0 (CPUMIPSState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3774 const char *rn
= "invalid";
3777 check_insn(env
, ctx
, ISA_MIPS32
);
3786 gen_helper_mtc0_index(cpu_env
, arg
);
3790 check_insn(env
, ctx
, ASE_MT
);
3791 gen_helper_mtc0_mvpcontrol(cpu_env
, arg
);
3795 check_insn(env
, ctx
, ASE_MT
);
3800 check_insn(env
, ctx
, ASE_MT
);
3815 check_insn(env
, ctx
, ASE_MT
);
3816 gen_helper_mtc0_vpecontrol(cpu_env
, arg
);
3820 check_insn(env
, ctx
, ASE_MT
);
3821 gen_helper_mtc0_vpeconf0(cpu_env
, arg
);
3825 check_insn(env
, ctx
, ASE_MT
);
3826 gen_helper_mtc0_vpeconf1(cpu_env
, arg
);
3830 check_insn(env
, ctx
, ASE_MT
);
3831 gen_helper_mtc0_yqmask(cpu_env
, arg
);
3835 check_insn(env
, ctx
, ASE_MT
);
3836 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
3840 check_insn(env
, ctx
, ASE_MT
);
3841 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
3842 rn
= "VPEScheFBack";
3845 check_insn(env
, ctx
, ASE_MT
);
3846 gen_helper_mtc0_vpeopt(cpu_env
, arg
);
3856 gen_helper_mtc0_entrylo0(cpu_env
, arg
);
3860 check_insn(env
, ctx
, ASE_MT
);
3861 gen_helper_mtc0_tcstatus(cpu_env
, arg
);
3865 check_insn(env
, ctx
, ASE_MT
);
3866 gen_helper_mtc0_tcbind(cpu_env
, arg
);
3870 check_insn(env
, ctx
, ASE_MT
);
3871 gen_helper_mtc0_tcrestart(cpu_env
, arg
);
3875 check_insn(env
, ctx
, ASE_MT
);
3876 gen_helper_mtc0_tchalt(cpu_env
, arg
);
3880 check_insn(env
, ctx
, ASE_MT
);
3881 gen_helper_mtc0_tccontext(cpu_env
, arg
);
3885 check_insn(env
, ctx
, ASE_MT
);
3886 gen_helper_mtc0_tcschedule(cpu_env
, arg
);
3890 check_insn(env
, ctx
, ASE_MT
);
3891 gen_helper_mtc0_tcschefback(cpu_env
, arg
);
3901 gen_helper_mtc0_entrylo1(cpu_env
, arg
);
3911 gen_helper_mtc0_context(cpu_env
, arg
);
3915 // gen_helper_mtc0_contextconfig(cpu_env, arg); /* SmartMIPS ASE */
3916 rn
= "ContextConfig";
3925 gen_helper_mtc0_pagemask(cpu_env
, arg
);
3929 check_insn(env
, ctx
, ISA_MIPS32R2
);
3930 gen_helper_mtc0_pagegrain(cpu_env
, arg
);
3940 gen_helper_mtc0_wired(cpu_env
, arg
);
3944 check_insn(env
, ctx
, ISA_MIPS32R2
);
3945 gen_helper_mtc0_srsconf0(cpu_env
, arg
);
3949 check_insn(env
, ctx
, ISA_MIPS32R2
);
3950 gen_helper_mtc0_srsconf1(cpu_env
, arg
);
3954 check_insn(env
, ctx
, ISA_MIPS32R2
);
3955 gen_helper_mtc0_srsconf2(cpu_env
, arg
);
3959 check_insn(env
, ctx
, ISA_MIPS32R2
);
3960 gen_helper_mtc0_srsconf3(cpu_env
, arg
);
3964 check_insn(env
, ctx
, ISA_MIPS32R2
);
3965 gen_helper_mtc0_srsconf4(cpu_env
, arg
);
3975 check_insn(env
, ctx
, ISA_MIPS32R2
);
3976 gen_helper_mtc0_hwrena(cpu_env
, arg
);
3990 gen_helper_mtc0_count(cpu_env
, arg
);
3993 /* 6,7 are implementation dependent */
4001 gen_helper_mtc0_entryhi(cpu_env
, arg
);
4011 gen_helper_mtc0_compare(cpu_env
, arg
);
4014 /* 6,7 are implementation dependent */
4022 save_cpu_state(ctx
, 1);
4023 gen_helper_mtc0_status(cpu_env
, arg
);
4024 /* BS_STOP isn't good enough here, hflags may have changed. */
4025 gen_save_pc(ctx
->pc
+ 4);
4026 ctx
->bstate
= BS_EXCP
;
4030 check_insn(env
, ctx
, ISA_MIPS32R2
);
4031 gen_helper_mtc0_intctl(cpu_env
, arg
);
4032 /* Stop translation as we may have switched the execution mode */
4033 ctx
->bstate
= BS_STOP
;
4037 check_insn(env
, ctx
, ISA_MIPS32R2
);
4038 gen_helper_mtc0_srsctl(cpu_env
, arg
);
4039 /* Stop translation as we may have switched the execution mode */
4040 ctx
->bstate
= BS_STOP
;
4044 check_insn(env
, ctx
, ISA_MIPS32R2
);
4045 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
4046 /* Stop translation as we may have switched the execution mode */
4047 ctx
->bstate
= BS_STOP
;
4057 save_cpu_state(ctx
, 1);
4058 gen_helper_mtc0_cause(cpu_env
, arg
);
4068 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_EPC
));
4082 check_insn(env
, ctx
, ISA_MIPS32R2
);
4083 gen_helper_mtc0_ebase(cpu_env
, arg
);
4093 gen_helper_mtc0_config0(cpu_env
, arg
);
4095 /* Stop translation as we may have switched the execution mode */
4096 ctx
->bstate
= BS_STOP
;
4099 /* ignored, read only */
4103 gen_helper_mtc0_config2(cpu_env
, arg
);
4105 /* Stop translation as we may have switched the execution mode */
4106 ctx
->bstate
= BS_STOP
;
4109 /* ignored, read only */
4112 /* 4,5 are reserved */
4113 /* 6,7 are implementation dependent */
4123 rn
= "Invalid config selector";
4130 gen_helper_mtc0_lladdr(cpu_env
, arg
);
4140 gen_helper_0e1i(mtc0_watchlo
, arg
, sel
);
4150 gen_helper_0e1i(mtc0_watchhi
, arg
, sel
);
4160 #if defined(TARGET_MIPS64)
4161 check_insn(env
, ctx
, ISA_MIPS3
);
4162 gen_helper_mtc0_xcontext(cpu_env
, arg
);
4171 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4174 gen_helper_mtc0_framemask(cpu_env
, arg
);
4183 rn
= "Diagnostic"; /* implementation dependent */
4188 gen_helper_mtc0_debug(cpu_env
, arg
); /* EJTAG support */
4189 /* BS_STOP isn't good enough here, hflags may have changed. */
4190 gen_save_pc(ctx
->pc
+ 4);
4191 ctx
->bstate
= BS_EXCP
;
4195 // gen_helper_mtc0_tracecontrol(cpu_env, arg); /* PDtrace support */
4196 rn
= "TraceControl";
4197 /* Stop translation as we may have switched the execution mode */
4198 ctx
->bstate
= BS_STOP
;
4201 // gen_helper_mtc0_tracecontrol2(cpu_env, arg); /* PDtrace support */
4202 rn
= "TraceControl2";
4203 /* Stop translation as we may have switched the execution mode */
4204 ctx
->bstate
= BS_STOP
;
4207 /* Stop translation as we may have switched the execution mode */
4208 ctx
->bstate
= BS_STOP
;
4209 // gen_helper_mtc0_usertracedata(cpu_env, arg); /* PDtrace support */
4210 rn
= "UserTraceData";
4211 /* Stop translation as we may have switched the execution mode */
4212 ctx
->bstate
= BS_STOP
;
4215 // gen_helper_mtc0_tracebpc(cpu_env, arg); /* PDtrace support */
4216 /* Stop translation as we may have switched the execution mode */
4217 ctx
->bstate
= BS_STOP
;
4228 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_DEPC
));
4238 gen_helper_mtc0_performance0(cpu_env
, arg
);
4239 rn
= "Performance0";
4242 // gen_helper_mtc0_performance1(arg);
4243 rn
= "Performance1";
4246 // gen_helper_mtc0_performance2(arg);
4247 rn
= "Performance2";
4250 // gen_helper_mtc0_performance3(arg);
4251 rn
= "Performance3";
4254 // gen_helper_mtc0_performance4(arg);
4255 rn
= "Performance4";
4258 // gen_helper_mtc0_performance5(arg);
4259 rn
= "Performance5";
4262 // gen_helper_mtc0_performance6(arg);
4263 rn
= "Performance6";
4266 // gen_helper_mtc0_performance7(arg);
4267 rn
= "Performance7";
4293 gen_helper_mtc0_taglo(cpu_env
, arg
);
4300 gen_helper_mtc0_datalo(cpu_env
, arg
);
4313 gen_helper_mtc0_taghi(cpu_env
, arg
);
4320 gen_helper_mtc0_datahi(cpu_env
, arg
);
4331 gen_mtc0_store64(arg
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
4342 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
4348 /* Stop translation as we may have switched the execution mode */
4349 ctx
->bstate
= BS_STOP
;
4354 (void)rn
; /* avoid a compiler warning */
4355 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4356 /* For simplicity assume that all writes can cause interrupts. */
4359 ctx
->bstate
= BS_STOP
;
4364 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4365 generate_exception(ctx
, EXCP_RI
);
4368 #if defined(TARGET_MIPS64)
4369 static void gen_dmfc0 (CPUMIPSState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4371 const char *rn
= "invalid";
4374 check_insn(env
, ctx
, ISA_MIPS64
);
4380 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Index
));
4384 check_insn(env
, ctx
, ASE_MT
);
4385 gen_helper_mfc0_mvpcontrol(arg
, cpu_env
);
4389 check_insn(env
, ctx
, ASE_MT
);
4390 gen_helper_mfc0_mvpconf0(arg
, cpu_env
);
4394 check_insn(env
, ctx
, ASE_MT
);
4395 gen_helper_mfc0_mvpconf1(arg
, cpu_env
);
4405 gen_helper_mfc0_random(arg
, cpu_env
);
4409 check_insn(env
, ctx
, ASE_MT
);
4410 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEControl
));
4414 check_insn(env
, ctx
, ASE_MT
);
4415 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf0
));
4419 check_insn(env
, ctx
, ASE_MT
);
4420 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEConf1
));
4424 check_insn(env
, ctx
, ASE_MT
);
4425 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_YQMask
));
4429 check_insn(env
, ctx
, ASE_MT
);
4430 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
4434 check_insn(env
, ctx
, ASE_MT
);
4435 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
4436 rn
= "VPEScheFBack";
4439 check_insn(env
, ctx
, ASE_MT
);
4440 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_VPEOpt
));
4450 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryLo0
));
4454 check_insn(env
, ctx
, ASE_MT
);
4455 gen_helper_mfc0_tcstatus(arg
, cpu_env
);
4459 check_insn(env
, ctx
, ASE_MT
);
4460 gen_helper_mfc0_tcbind(arg
, cpu_env
);
4464 check_insn(env
, ctx
, ASE_MT
);
4465 gen_helper_dmfc0_tcrestart(arg
, cpu_env
);
4469 check_insn(env
, ctx
, ASE_MT
);
4470 gen_helper_dmfc0_tchalt(arg
, cpu_env
);
4474 check_insn(env
, ctx
, ASE_MT
);
4475 gen_helper_dmfc0_tccontext(arg
, cpu_env
);
4479 check_insn(env
, ctx
, ASE_MT
);
4480 gen_helper_dmfc0_tcschedule(arg
, cpu_env
);
4484 check_insn(env
, ctx
, ASE_MT
);
4485 gen_helper_dmfc0_tcschefback(arg
, cpu_env
);
4495 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryLo1
));
4505 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_Context
));
4509 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4510 rn
= "ContextConfig";
4519 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageMask
));
4523 check_insn(env
, ctx
, ISA_MIPS32R2
);
4524 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PageGrain
));
4534 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Wired
));
4538 check_insn(env
, ctx
, ISA_MIPS32R2
);
4539 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf0
));
4543 check_insn(env
, ctx
, ISA_MIPS32R2
);
4544 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf1
));
4548 check_insn(env
, ctx
, ISA_MIPS32R2
);
4549 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf2
));
4553 check_insn(env
, ctx
, ISA_MIPS32R2
);
4554 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf3
));
4558 check_insn(env
, ctx
, ISA_MIPS32R2
);
4559 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSConf4
));
4569 check_insn(env
, ctx
, ISA_MIPS32R2
);
4570 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_HWREna
));
4580 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_BadVAddr
));
4590 /* Mark as an IO operation because we read the time. */
4593 gen_helper_mfc0_count(arg
, cpu_env
);
4597 /* Break the TB to be able to take timer interrupts immediately
4598 after reading count. */
4599 ctx
->bstate
= BS_STOP
;
4602 /* 6,7 are implementation dependent */
4610 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EntryHi
));
4620 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Compare
));
4623 /* 6,7 are implementation dependent */
4631 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Status
));
4635 check_insn(env
, ctx
, ISA_MIPS32R2
);
4636 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_IntCtl
));
4640 check_insn(env
, ctx
, ISA_MIPS32R2
);
4641 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSCtl
));
4645 check_insn(env
, ctx
, ISA_MIPS32R2
);
4646 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
4656 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Cause
));
4666 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EPC
));
4676 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_PRid
));
4680 check_insn(env
, ctx
, ISA_MIPS32R2
);
4681 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_EBase
));
4691 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config0
));
4695 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config1
));
4699 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config2
));
4703 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config3
));
4706 /* 6,7 are implementation dependent */
4708 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config6
));
4712 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Config7
));
4722 gen_helper_dmfc0_lladdr(arg
, cpu_env
);
4732 gen_helper_1e0i(dmfc0_watchlo
, arg
, sel
);
4742 gen_helper_1e0i(mfc0_watchhi
, arg
, sel
);
4752 check_insn(env
, ctx
, ISA_MIPS3
);
4753 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_XContext
));
4761 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4764 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Framemask
));
4772 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4773 rn
= "'Diagnostic"; /* implementation dependent */
4778 gen_helper_mfc0_debug(arg
, cpu_env
); /* EJTAG support */
4782 // gen_helper_dmfc0_tracecontrol(arg, cpu_env); /* PDtrace support */
4783 rn
= "TraceControl";
4786 // gen_helper_dmfc0_tracecontrol2(arg, cpu_env); /* PDtrace support */
4787 rn
= "TraceControl2";
4790 // gen_helper_dmfc0_usertracedata(arg, cpu_env); /* PDtrace support */
4791 rn
= "UserTraceData";
4794 // gen_helper_dmfc0_tracebpc(arg, cpu_env); /* PDtrace support */
4805 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
4815 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_Performance0
));
4816 rn
= "Performance0";
4819 // gen_helper_dmfc0_performance1(arg);
4820 rn
= "Performance1";
4823 // gen_helper_dmfc0_performance2(arg);
4824 rn
= "Performance2";
4827 // gen_helper_dmfc0_performance3(arg);
4828 rn
= "Performance3";
4831 // gen_helper_dmfc0_performance4(arg);
4832 rn
= "Performance4";
4835 // gen_helper_dmfc0_performance5(arg);
4836 rn
= "Performance5";
4839 // gen_helper_dmfc0_performance6(arg);
4840 rn
= "Performance6";
4843 // gen_helper_dmfc0_performance7(arg);
4844 rn
= "Performance7";
4851 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4858 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4871 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagLo
));
4878 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataLo
));
4891 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_TagHi
));
4898 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DataHi
));
4908 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
4919 gen_mfc0_load32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
4929 (void)rn
; /* avoid a compiler warning */
4930 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4934 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4935 generate_exception(ctx
, EXCP_RI
);
4938 static void gen_dmtc0 (CPUMIPSState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4940 const char *rn
= "invalid";
4943 check_insn(env
, ctx
, ISA_MIPS64
);
4952 gen_helper_mtc0_index(cpu_env
, arg
);
4956 check_insn(env
, ctx
, ASE_MT
);
4957 gen_helper_mtc0_mvpcontrol(cpu_env
, arg
);
4961 check_insn(env
, ctx
, ASE_MT
);
4966 check_insn(env
, ctx
, ASE_MT
);
4981 check_insn(env
, ctx
, ASE_MT
);
4982 gen_helper_mtc0_vpecontrol(cpu_env
, arg
);
4986 check_insn(env
, ctx
, ASE_MT
);
4987 gen_helper_mtc0_vpeconf0(cpu_env
, arg
);
4991 check_insn(env
, ctx
, ASE_MT
);
4992 gen_helper_mtc0_vpeconf1(cpu_env
, arg
);
4996 check_insn(env
, ctx
, ASE_MT
);
4997 gen_helper_mtc0_yqmask(cpu_env
, arg
);
5001 check_insn(env
, ctx
, ASE_MT
);
5002 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_VPESchedule
));
5006 check_insn(env
, ctx
, ASE_MT
);
5007 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_VPEScheFBack
));
5008 rn
= "VPEScheFBack";
5011 check_insn(env
, ctx
, ASE_MT
);
5012 gen_helper_mtc0_vpeopt(cpu_env
, arg
);
5022 gen_helper_mtc0_entrylo0(cpu_env
, arg
);
5026 check_insn(env
, ctx
, ASE_MT
);
5027 gen_helper_mtc0_tcstatus(cpu_env
, arg
);
5031 check_insn(env
, ctx
, ASE_MT
);
5032 gen_helper_mtc0_tcbind(cpu_env
, arg
);
5036 check_insn(env
, ctx
, ASE_MT
);
5037 gen_helper_mtc0_tcrestart(cpu_env
, arg
);
5041 check_insn(env
, ctx
, ASE_MT
);
5042 gen_helper_mtc0_tchalt(cpu_env
, arg
);
5046 check_insn(env
, ctx
, ASE_MT
);
5047 gen_helper_mtc0_tccontext(cpu_env
, arg
);
5051 check_insn(env
, ctx
, ASE_MT
);
5052 gen_helper_mtc0_tcschedule(cpu_env
, arg
);
5056 check_insn(env
, ctx
, ASE_MT
);
5057 gen_helper_mtc0_tcschefback(cpu_env
, arg
);
5067 gen_helper_mtc0_entrylo1(cpu_env
, arg
);
5077 gen_helper_mtc0_context(cpu_env
, arg
);
5081 // gen_helper_mtc0_contextconfig(cpu_env, arg); /* SmartMIPS ASE */
5082 rn
= "ContextConfig";
5091 gen_helper_mtc0_pagemask(cpu_env
, arg
);
5095 check_insn(env
, ctx
, ISA_MIPS32R2
);
5096 gen_helper_mtc0_pagegrain(cpu_env
, arg
);
5106 gen_helper_mtc0_wired(cpu_env
, arg
);
5110 check_insn(env
, ctx
, ISA_MIPS32R2
);
5111 gen_helper_mtc0_srsconf0(cpu_env
, arg
);
5115 check_insn(env
, ctx
, ISA_MIPS32R2
);
5116 gen_helper_mtc0_srsconf1(cpu_env
, arg
);
5120 check_insn(env
, ctx
, ISA_MIPS32R2
);
5121 gen_helper_mtc0_srsconf2(cpu_env
, arg
);
5125 check_insn(env
, ctx
, ISA_MIPS32R2
);
5126 gen_helper_mtc0_srsconf3(cpu_env
, arg
);
5130 check_insn(env
, ctx
, ISA_MIPS32R2
);
5131 gen_helper_mtc0_srsconf4(cpu_env
, arg
);
5141 check_insn(env
, ctx
, ISA_MIPS32R2
);
5142 gen_helper_mtc0_hwrena(cpu_env
, arg
);
5156 gen_helper_mtc0_count(cpu_env
, arg
);
5159 /* 6,7 are implementation dependent */
5163 /* Stop translation as we may have switched the execution mode */
5164 ctx
->bstate
= BS_STOP
;
5169 gen_helper_mtc0_entryhi(cpu_env
, arg
);
5179 gen_helper_mtc0_compare(cpu_env
, arg
);
5182 /* 6,7 are implementation dependent */
5186 /* Stop translation as we may have switched the execution mode */
5187 ctx
->bstate
= BS_STOP
;
5192 save_cpu_state(ctx
, 1);
5193 gen_helper_mtc0_status(cpu_env
, arg
);
5194 /* BS_STOP isn't good enough here, hflags may have changed. */
5195 gen_save_pc(ctx
->pc
+ 4);
5196 ctx
->bstate
= BS_EXCP
;
5200 check_insn(env
, ctx
, ISA_MIPS32R2
);
5201 gen_helper_mtc0_intctl(cpu_env
, arg
);
5202 /* Stop translation as we may have switched the execution mode */
5203 ctx
->bstate
= BS_STOP
;
5207 check_insn(env
, ctx
, ISA_MIPS32R2
);
5208 gen_helper_mtc0_srsctl(cpu_env
, arg
);
5209 /* Stop translation as we may have switched the execution mode */
5210 ctx
->bstate
= BS_STOP
;
5214 check_insn(env
, ctx
, ISA_MIPS32R2
);
5215 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_SRSMap
));
5216 /* Stop translation as we may have switched the execution mode */
5217 ctx
->bstate
= BS_STOP
;
5227 save_cpu_state(ctx
, 1);
5228 /* Mark as an IO operation because we may trigger a software
5233 gen_helper_mtc0_cause(cpu_env
, arg
);
5237 /* Stop translation as we may have triggered an intetrupt */
5238 ctx
->bstate
= BS_STOP
;
5248 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_EPC
));
5262 check_insn(env
, ctx
, ISA_MIPS32R2
);
5263 gen_helper_mtc0_ebase(cpu_env
, arg
);
5273 gen_helper_mtc0_config0(cpu_env
, arg
);
5275 /* Stop translation as we may have switched the execution mode */
5276 ctx
->bstate
= BS_STOP
;
5279 /* ignored, read only */
5283 gen_helper_mtc0_config2(cpu_env
, arg
);
5285 /* Stop translation as we may have switched the execution mode */
5286 ctx
->bstate
= BS_STOP
;
5292 /* 6,7 are implementation dependent */
5294 rn
= "Invalid config selector";
5301 gen_helper_mtc0_lladdr(cpu_env
, arg
);
5311 gen_helper_0e1i(mtc0_watchlo
, arg
, sel
);
5321 gen_helper_0e1i(mtc0_watchhi
, arg
, sel
);
5331 check_insn(env
, ctx
, ISA_MIPS3
);
5332 gen_helper_mtc0_xcontext(cpu_env
, arg
);
5340 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5343 gen_helper_mtc0_framemask(cpu_env
, arg
);
5352 rn
= "Diagnostic"; /* implementation dependent */
5357 gen_helper_mtc0_debug(cpu_env
, arg
); /* EJTAG support */
5358 /* BS_STOP isn't good enough here, hflags may have changed. */
5359 gen_save_pc(ctx
->pc
+ 4);
5360 ctx
->bstate
= BS_EXCP
;
5364 // gen_helper_mtc0_tracecontrol(cpu_env, arg); /* PDtrace support */
5365 /* Stop translation as we may have switched the execution mode */
5366 ctx
->bstate
= BS_STOP
;
5367 rn
= "TraceControl";
5370 // gen_helper_mtc0_tracecontrol2(cpu_env, arg); /* PDtrace support */
5371 /* Stop translation as we may have switched the execution mode */
5372 ctx
->bstate
= BS_STOP
;
5373 rn
= "TraceControl2";
5376 // gen_helper_mtc0_usertracedata(cpu_env, arg); /* PDtrace support */
5377 /* Stop translation as we may have switched the execution mode */
5378 ctx
->bstate
= BS_STOP
;
5379 rn
= "UserTraceData";
5382 // gen_helper_mtc0_tracebpc(cpu_env, arg); /* PDtrace support */
5383 /* Stop translation as we may have switched the execution mode */
5384 ctx
->bstate
= BS_STOP
;
5395 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_DEPC
));
5405 gen_helper_mtc0_performance0(cpu_env
, arg
);
5406 rn
= "Performance0";
5409 // gen_helper_mtc0_performance1(cpu_env, arg);
5410 rn
= "Performance1";
5413 // gen_helper_mtc0_performance2(cpu_env, arg);
5414 rn
= "Performance2";
5417 // gen_helper_mtc0_performance3(cpu_env, arg);
5418 rn
= "Performance3";
5421 // gen_helper_mtc0_performance4(cpu_env, arg);
5422 rn
= "Performance4";
5425 // gen_helper_mtc0_performance5(cpu_env, arg);
5426 rn
= "Performance5";
5429 // gen_helper_mtc0_performance6(cpu_env, arg);
5430 rn
= "Performance6";
5433 // gen_helper_mtc0_performance7(cpu_env, arg);
5434 rn
= "Performance7";
5460 gen_helper_mtc0_taglo(cpu_env
, arg
);
5467 gen_helper_mtc0_datalo(cpu_env
, arg
);
5480 gen_helper_mtc0_taghi(cpu_env
, arg
);
5487 gen_helper_mtc0_datahi(cpu_env
, arg
);
5498 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUMIPSState
, CP0_ErrorEPC
));
5509 gen_mtc0_store32(arg
, offsetof(CPUMIPSState
, CP0_DESAVE
));
5515 /* Stop translation as we may have switched the execution mode */
5516 ctx
->bstate
= BS_STOP
;
5521 (void)rn
; /* avoid a compiler warning */
5522 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5523 /* For simplicity assume that all writes can cause interrupts. */
5526 ctx
->bstate
= BS_STOP
;
5531 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5532 generate_exception(ctx
, EXCP_RI
);
5534 #endif /* TARGET_MIPS64 */
5536 static void gen_mftr(CPUMIPSState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5537 int u
, int sel
, int h
)
5539 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5540 TCGv t0
= tcg_temp_local_new();
5542 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5543 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5544 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5545 tcg_gen_movi_tl(t0
, -1);
5546 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5547 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5548 tcg_gen_movi_tl(t0
, -1);
5554 gen_helper_mftc0_vpecontrol(t0
, cpu_env
);
5557 gen_helper_mftc0_vpeconf0(t0
, cpu_env
);
5567 gen_helper_mftc0_tcstatus(t0
, cpu_env
);
5570 gen_helper_mftc0_tcbind(t0
, cpu_env
);
5573 gen_helper_mftc0_tcrestart(t0
, cpu_env
);
5576 gen_helper_mftc0_tchalt(t0
, cpu_env
);
5579 gen_helper_mftc0_tccontext(t0
, cpu_env
);
5582 gen_helper_mftc0_tcschedule(t0
, cpu_env
);
5585 gen_helper_mftc0_tcschefback(t0
, cpu_env
);
5588 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5595 gen_helper_mftc0_entryhi(t0
, cpu_env
);
5598 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5604 gen_helper_mftc0_status(t0
, cpu_env
);
5607 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5613 gen_helper_mftc0_cause(t0
, cpu_env
);
5623 gen_helper_mftc0_epc(t0
, cpu_env
);
5633 gen_helper_mftc0_ebase(t0
, cpu_env
);
5643 gen_helper_mftc0_configx(t0
, cpu_env
, tcg_const_tl(sel
));
5653 gen_helper_mftc0_debug(t0
, cpu_env
);
5656 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5661 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5663 } else switch (sel
) {
5664 /* GPR registers. */
5666 gen_helper_1e0i(mftgpr
, t0
, rt
);
5668 /* Auxiliary CPU registers */
5672 gen_helper_1e0i(mftlo
, t0
, 0);
5675 gen_helper_1e0i(mfthi
, t0
, 0);
5678 gen_helper_1e0i(mftacx
, t0
, 0);
5681 gen_helper_1e0i(mftlo
, t0
, 1);
5684 gen_helper_1e0i(mfthi
, t0
, 1);
5687 gen_helper_1e0i(mftacx
, t0
, 1);
5690 gen_helper_1e0i(mftlo
, t0
, 2);
5693 gen_helper_1e0i(mfthi
, t0
, 2);
5696 gen_helper_1e0i(mftacx
, t0
, 2);
5699 gen_helper_1e0i(mftlo
, t0
, 3);
5702 gen_helper_1e0i(mfthi
, t0
, 3);
5705 gen_helper_1e0i(mftacx
, t0
, 3);
5708 gen_helper_mftdsp(t0
, cpu_env
);
5714 /* Floating point (COP1). */
5716 /* XXX: For now we support only a single FPU context. */
5718 TCGv_i32 fp0
= tcg_temp_new_i32();
5720 gen_load_fpr32(fp0
, rt
);
5721 tcg_gen_ext_i32_tl(t0
, fp0
);
5722 tcg_temp_free_i32(fp0
);
5724 TCGv_i32 fp0
= tcg_temp_new_i32();
5726 gen_load_fpr32h(fp0
, rt
);
5727 tcg_gen_ext_i32_tl(t0
, fp0
);
5728 tcg_temp_free_i32(fp0
);
5732 /* XXX: For now we support only a single FPU context. */
5733 gen_helper_1e0i(cfc1
, t0
, rt
);
5735 /* COP2: Not implemented. */
5742 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5743 gen_store_gpr(t0
, rd
);
5749 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5750 generate_exception(ctx
, EXCP_RI
);
5753 static void gen_mttr(CPUMIPSState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5754 int u
, int sel
, int h
)
5756 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5757 TCGv t0
= tcg_temp_local_new();
5759 gen_load_gpr(t0
, rt
);
5760 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5761 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5762 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5764 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5765 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5772 gen_helper_mttc0_vpecontrol(cpu_env
, t0
);
5775 gen_helper_mttc0_vpeconf0(cpu_env
, t0
);
5785 gen_helper_mttc0_tcstatus(cpu_env
, t0
);
5788 gen_helper_mttc0_tcbind(cpu_env
, t0
);
5791 gen_helper_mttc0_tcrestart(cpu_env
, t0
);
5794 gen_helper_mttc0_tchalt(cpu_env
, t0
);
5797 gen_helper_mttc0_tccontext(cpu_env
, t0
);
5800 gen_helper_mttc0_tcschedule(cpu_env
, t0
);
5803 gen_helper_mttc0_tcschefback(cpu_env
, t0
);
5806 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5813 gen_helper_mttc0_entryhi(cpu_env
, t0
);
5816 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5822 gen_helper_mttc0_status(cpu_env
, t0
);
5825 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5831 gen_helper_mttc0_cause(cpu_env
, t0
);
5841 gen_helper_mttc0_ebase(cpu_env
, t0
);
5851 gen_helper_mttc0_debug(cpu_env
, t0
);
5854 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5859 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5861 } else switch (sel
) {
5862 /* GPR registers. */
5864 gen_helper_0e1i(mttgpr
, t0
, rd
);
5866 /* Auxiliary CPU registers */
5870 gen_helper_0e1i(mttlo
, t0
, 0);
5873 gen_helper_0e1i(mtthi
, t0
, 0);
5876 gen_helper_0e1i(mttacx
, t0
, 0);
5879 gen_helper_0e1i(mttlo
, t0
, 1);
5882 gen_helper_0e1i(mtthi
, t0
, 1);
5885 gen_helper_0e1i(mttacx
, t0
, 1);
5888 gen_helper_0e1i(mttlo
, t0
, 2);
5891 gen_helper_0e1i(mtthi
, t0
, 2);
5894 gen_helper_0e1i(mttacx
, t0
, 2);
5897 gen_helper_0e1i(mttlo
, t0
, 3);
5900 gen_helper_0e1i(mtthi
, t0
, 3);
5903 gen_helper_0e1i(mttacx
, t0
, 3);
5906 gen_helper_mttdsp(cpu_env
, t0
);
5912 /* Floating point (COP1). */
5914 /* XXX: For now we support only a single FPU context. */
5916 TCGv_i32 fp0
= tcg_temp_new_i32();
5918 tcg_gen_trunc_tl_i32(fp0
, t0
);
5919 gen_store_fpr32(fp0
, rd
);
5920 tcg_temp_free_i32(fp0
);
5922 TCGv_i32 fp0
= tcg_temp_new_i32();
5924 tcg_gen_trunc_tl_i32(fp0
, t0
);
5925 gen_store_fpr32h(fp0
, rd
);
5926 tcg_temp_free_i32(fp0
);
5930 /* XXX: For now we support only a single FPU context. */
5931 gen_helper_0e1i(ctc1
, t0
, rd
);
5933 /* COP2: Not implemented. */
5940 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5946 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5947 generate_exception(ctx
, EXCP_RI
);
5950 static void gen_cp0 (CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5952 const char *opn
= "ldst";
5954 check_cp0_enabled(ctx
);
5961 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5966 TCGv t0
= tcg_temp_new();
5968 gen_load_gpr(t0
, rt
);
5969 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5974 #if defined(TARGET_MIPS64)
5976 check_insn(env
, ctx
, ISA_MIPS3
);
5981 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5985 check_insn(env
, ctx
, ISA_MIPS3
);
5987 TCGv t0
= tcg_temp_new();
5989 gen_load_gpr(t0
, rt
);
5990 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5997 check_insn(env
, ctx
, ASE_MT
);
6002 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
6003 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
6007 check_insn(env
, ctx
, ASE_MT
);
6008 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
6009 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
6014 if (!env
->tlb
->helper_tlbwi
)
6016 gen_helper_tlbwi(cpu_env
);
6020 if (!env
->tlb
->helper_tlbwr
)
6022 gen_helper_tlbwr(cpu_env
);
6026 if (!env
->tlb
->helper_tlbp
)
6028 gen_helper_tlbp(cpu_env
);
6032 if (!env
->tlb
->helper_tlbr
)
6034 gen_helper_tlbr(cpu_env
);
6038 check_insn(env
, ctx
, ISA_MIPS2
);
6039 gen_helper_eret(cpu_env
);
6040 ctx
->bstate
= BS_EXCP
;
6044 check_insn(env
, ctx
, ISA_MIPS32
);
6045 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6047 generate_exception(ctx
, EXCP_RI
);
6049 gen_helper_deret(cpu_env
);
6050 ctx
->bstate
= BS_EXCP
;
6055 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
6056 /* If we get an exception, we want to restart at next instruction */
6058 save_cpu_state(ctx
, 1);
6060 gen_helper_wait(cpu_env
);
6061 ctx
->bstate
= BS_EXCP
;
6066 generate_exception(ctx
, EXCP_RI
);
6069 (void)opn
; /* avoid a compiler warning */
6070 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
6072 #endif /* !CONFIG_USER_ONLY */
6074 /* CP1 Branches (before delay slot) */
6075 static void gen_compute_branch1 (CPUMIPSState
*env
, DisasContext
*ctx
, uint32_t op
,
6076 int32_t cc
, int32_t offset
)
6078 target_ulong btarget
;
6079 const char *opn
= "cp1 cond branch";
6080 TCGv_i32 t0
= tcg_temp_new_i32();
6083 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6085 btarget
= ctx
->pc
+ 4 + offset
;
6089 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6090 tcg_gen_not_i32(t0
, t0
);
6091 tcg_gen_andi_i32(t0
, t0
, 1);
6092 tcg_gen_extu_i32_tl(bcond
, t0
);
6096 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6097 tcg_gen_not_i32(t0
, t0
);
6098 tcg_gen_andi_i32(t0
, t0
, 1);
6099 tcg_gen_extu_i32_tl(bcond
, t0
);
6103 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6104 tcg_gen_andi_i32(t0
, t0
, 1);
6105 tcg_gen_extu_i32_tl(bcond
, t0
);
6109 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6110 tcg_gen_andi_i32(t0
, t0
, 1);
6111 tcg_gen_extu_i32_tl(bcond
, t0
);
6114 ctx
->hflags
|= MIPS_HFLAG_BL
;
6118 TCGv_i32 t1
= tcg_temp_new_i32();
6119 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6120 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6121 tcg_gen_nand_i32(t0
, t0
, t1
);
6122 tcg_temp_free_i32(t1
);
6123 tcg_gen_andi_i32(t0
, t0
, 1);
6124 tcg_gen_extu_i32_tl(bcond
, t0
);
6130 TCGv_i32 t1
= tcg_temp_new_i32();
6131 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6132 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6133 tcg_gen_or_i32(t0
, t0
, t1
);
6134 tcg_temp_free_i32(t1
);
6135 tcg_gen_andi_i32(t0
, t0
, 1);
6136 tcg_gen_extu_i32_tl(bcond
, t0
);
6142 TCGv_i32 t1
= tcg_temp_new_i32();
6143 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6144 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6145 tcg_gen_and_i32(t0
, t0
, t1
);
6146 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
6147 tcg_gen_and_i32(t0
, t0
, t1
);
6148 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
6149 tcg_gen_nand_i32(t0
, t0
, t1
);
6150 tcg_temp_free_i32(t1
);
6151 tcg_gen_andi_i32(t0
, t0
, 1);
6152 tcg_gen_extu_i32_tl(bcond
, t0
);
6158 TCGv_i32 t1
= tcg_temp_new_i32();
6159 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
6160 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
6161 tcg_gen_or_i32(t0
, t0
, t1
);
6162 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
6163 tcg_gen_or_i32(t0
, t0
, t1
);
6164 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
6165 tcg_gen_or_i32(t0
, t0
, t1
);
6166 tcg_temp_free_i32(t1
);
6167 tcg_gen_andi_i32(t0
, t0
, 1);
6168 tcg_gen_extu_i32_tl(bcond
, t0
);
6172 ctx
->hflags
|= MIPS_HFLAG_BC
;
6176 generate_exception (ctx
, EXCP_RI
);
6179 (void)opn
; /* avoid a compiler warning */
6180 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
6181 ctx
->hflags
, btarget
);
6182 ctx
->btarget
= btarget
;
6185 tcg_temp_free_i32(t0
);
6188 /* Coprocessor 1 (FPU) */
6190 #define FOP(func, fmt) (((fmt) << 21) | (func))
6193 OPC_ADD_S
= FOP(0, FMT_S
),
6194 OPC_SUB_S
= FOP(1, FMT_S
),
6195 OPC_MUL_S
= FOP(2, FMT_S
),
6196 OPC_DIV_S
= FOP(3, FMT_S
),
6197 OPC_SQRT_S
= FOP(4, FMT_S
),
6198 OPC_ABS_S
= FOP(5, FMT_S
),
6199 OPC_MOV_S
= FOP(6, FMT_S
),
6200 OPC_NEG_S
= FOP(7, FMT_S
),
6201 OPC_ROUND_L_S
= FOP(8, FMT_S
),
6202 OPC_TRUNC_L_S
= FOP(9, FMT_S
),
6203 OPC_CEIL_L_S
= FOP(10, FMT_S
),
6204 OPC_FLOOR_L_S
= FOP(11, FMT_S
),
6205 OPC_ROUND_W_S
= FOP(12, FMT_S
),
6206 OPC_TRUNC_W_S
= FOP(13, FMT_S
),
6207 OPC_CEIL_W_S
= FOP(14, FMT_S
),
6208 OPC_FLOOR_W_S
= FOP(15, FMT_S
),
6209 OPC_MOVCF_S
= FOP(17, FMT_S
),
6210 OPC_MOVZ_S
= FOP(18, FMT_S
),
6211 OPC_MOVN_S
= FOP(19, FMT_S
),
6212 OPC_RECIP_S
= FOP(21, FMT_S
),
6213 OPC_RSQRT_S
= FOP(22, FMT_S
),
6214 OPC_RECIP2_S
= FOP(28, FMT_S
),
6215 OPC_RECIP1_S
= FOP(29, FMT_S
),
6216 OPC_RSQRT1_S
= FOP(30, FMT_S
),
6217 OPC_RSQRT2_S
= FOP(31, FMT_S
),
6218 OPC_CVT_D_S
= FOP(33, FMT_S
),
6219 OPC_CVT_W_S
= FOP(36, FMT_S
),
6220 OPC_CVT_L_S
= FOP(37, FMT_S
),
6221 OPC_CVT_PS_S
= FOP(38, FMT_S
),
6222 OPC_CMP_F_S
= FOP (48, FMT_S
),
6223 OPC_CMP_UN_S
= FOP (49, FMT_S
),
6224 OPC_CMP_EQ_S
= FOP (50, FMT_S
),
6225 OPC_CMP_UEQ_S
= FOP (51, FMT_S
),
6226 OPC_CMP_OLT_S
= FOP (52, FMT_S
),
6227 OPC_CMP_ULT_S
= FOP (53, FMT_S
),
6228 OPC_CMP_OLE_S
= FOP (54, FMT_S
),
6229 OPC_CMP_ULE_S
= FOP (55, FMT_S
),
6230 OPC_CMP_SF_S
= FOP (56, FMT_S
),
6231 OPC_CMP_NGLE_S
= FOP (57, FMT_S
),
6232 OPC_CMP_SEQ_S
= FOP (58, FMT_S
),
6233 OPC_CMP_NGL_S
= FOP (59, FMT_S
),
6234 OPC_CMP_LT_S
= FOP (60, FMT_S
),
6235 OPC_CMP_NGE_S
= FOP (61, FMT_S
),
6236 OPC_CMP_LE_S
= FOP (62, FMT_S
),
6237 OPC_CMP_NGT_S
= FOP (63, FMT_S
),
6239 OPC_ADD_D
= FOP(0, FMT_D
),
6240 OPC_SUB_D
= FOP(1, FMT_D
),
6241 OPC_MUL_D
= FOP(2, FMT_D
),
6242 OPC_DIV_D
= FOP(3, FMT_D
),
6243 OPC_SQRT_D
= FOP(4, FMT_D
),
6244 OPC_ABS_D
= FOP(5, FMT_D
),
6245 OPC_MOV_D
= FOP(6, FMT_D
),
6246 OPC_NEG_D
= FOP(7, FMT_D
),
6247 OPC_ROUND_L_D
= FOP(8, FMT_D
),
6248 OPC_TRUNC_L_D
= FOP(9, FMT_D
),
6249 OPC_CEIL_L_D
= FOP(10, FMT_D
),
6250 OPC_FLOOR_L_D
= FOP(11, FMT_D
),
6251 OPC_ROUND_W_D
= FOP(12, FMT_D
),
6252 OPC_TRUNC_W_D
= FOP(13, FMT_D
),
6253 OPC_CEIL_W_D
= FOP(14, FMT_D
),
6254 OPC_FLOOR_W_D
= FOP(15, FMT_D
),
6255 OPC_MOVCF_D
= FOP(17, FMT_D
),
6256 OPC_MOVZ_D
= FOP(18, FMT_D
),
6257 OPC_MOVN_D
= FOP(19, FMT_D
),
6258 OPC_RECIP_D
= FOP(21, FMT_D
),
6259 OPC_RSQRT_D
= FOP(22, FMT_D
),
6260 OPC_RECIP2_D
= FOP(28, FMT_D
),
6261 OPC_RECIP1_D
= FOP(29, FMT_D
),
6262 OPC_RSQRT1_D
= FOP(30, FMT_D
),
6263 OPC_RSQRT2_D
= FOP(31, FMT_D
),
6264 OPC_CVT_S_D
= FOP(32, FMT_D
),
6265 OPC_CVT_W_D
= FOP(36, FMT_D
),
6266 OPC_CVT_L_D
= FOP(37, FMT_D
),
6267 OPC_CMP_F_D
= FOP (48, FMT_D
),
6268 OPC_CMP_UN_D
= FOP (49, FMT_D
),
6269 OPC_CMP_EQ_D
= FOP (50, FMT_D
),
6270 OPC_CMP_UEQ_D
= FOP (51, FMT_D
),
6271 OPC_CMP_OLT_D
= FOP (52, FMT_D
),
6272 OPC_CMP_ULT_D
= FOP (53, FMT_D
),
6273 OPC_CMP_OLE_D
= FOP (54, FMT_D
),
6274 OPC_CMP_ULE_D
= FOP (55, FMT_D
),
6275 OPC_CMP_SF_D
= FOP (56, FMT_D
),
6276 OPC_CMP_NGLE_D
= FOP (57, FMT_D
),
6277 OPC_CMP_SEQ_D
= FOP (58, FMT_D
),
6278 OPC_CMP_NGL_D
= FOP (59, FMT_D
),
6279 OPC_CMP_LT_D
= FOP (60, FMT_D
),
6280 OPC_CMP_NGE_D
= FOP (61, FMT_D
),
6281 OPC_CMP_LE_D
= FOP (62, FMT_D
),
6282 OPC_CMP_NGT_D
= FOP (63, FMT_D
),
6284 OPC_CVT_S_W
= FOP(32, FMT_W
),
6285 OPC_CVT_D_W
= FOP(33, FMT_W
),
6286 OPC_CVT_S_L
= FOP(32, FMT_L
),
6287 OPC_CVT_D_L
= FOP(33, FMT_L
),
6288 OPC_CVT_PS_PW
= FOP(38, FMT_W
),
6290 OPC_ADD_PS
= FOP(0, FMT_PS
),
6291 OPC_SUB_PS
= FOP(1, FMT_PS
),
6292 OPC_MUL_PS
= FOP(2, FMT_PS
),
6293 OPC_DIV_PS
= FOP(3, FMT_PS
),
6294 OPC_ABS_PS
= FOP(5, FMT_PS
),
6295 OPC_MOV_PS
= FOP(6, FMT_PS
),
6296 OPC_NEG_PS
= FOP(7, FMT_PS
),
6297 OPC_MOVCF_PS
= FOP(17, FMT_PS
),
6298 OPC_MOVZ_PS
= FOP(18, FMT_PS
),
6299 OPC_MOVN_PS
= FOP(19, FMT_PS
),
6300 OPC_ADDR_PS
= FOP(24, FMT_PS
),
6301 OPC_MULR_PS
= FOP(26, FMT_PS
),
6302 OPC_RECIP2_PS
= FOP(28, FMT_PS
),
6303 OPC_RECIP1_PS
= FOP(29, FMT_PS
),
6304 OPC_RSQRT1_PS
= FOP(30, FMT_PS
),
6305 OPC_RSQRT2_PS
= FOP(31, FMT_PS
),
6307 OPC_CVT_S_PU
= FOP(32, FMT_PS
),
6308 OPC_CVT_PW_PS
= FOP(36, FMT_PS
),
6309 OPC_CVT_S_PL
= FOP(40, FMT_PS
),
6310 OPC_PLL_PS
= FOP(44, FMT_PS
),
6311 OPC_PLU_PS
= FOP(45, FMT_PS
),
6312 OPC_PUL_PS
= FOP(46, FMT_PS
),
6313 OPC_PUU_PS
= FOP(47, FMT_PS
),
6314 OPC_CMP_F_PS
= FOP (48, FMT_PS
),
6315 OPC_CMP_UN_PS
= FOP (49, FMT_PS
),
6316 OPC_CMP_EQ_PS
= FOP (50, FMT_PS
),
6317 OPC_CMP_UEQ_PS
= FOP (51, FMT_PS
),
6318 OPC_CMP_OLT_PS
= FOP (52, FMT_PS
),
6319 OPC_CMP_ULT_PS
= FOP (53, FMT_PS
),
6320 OPC_CMP_OLE_PS
= FOP (54, FMT_PS
),
6321 OPC_CMP_ULE_PS
= FOP (55, FMT_PS
),
6322 OPC_CMP_SF_PS
= FOP (56, FMT_PS
),
6323 OPC_CMP_NGLE_PS
= FOP (57, FMT_PS
),
6324 OPC_CMP_SEQ_PS
= FOP (58, FMT_PS
),
6325 OPC_CMP_NGL_PS
= FOP (59, FMT_PS
),
6326 OPC_CMP_LT_PS
= FOP (60, FMT_PS
),
6327 OPC_CMP_NGE_PS
= FOP (61, FMT_PS
),
6328 OPC_CMP_LE_PS
= FOP (62, FMT_PS
),
6329 OPC_CMP_NGT_PS
= FOP (63, FMT_PS
),
6332 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
6334 const char *opn
= "cp1 move";
6335 TCGv t0
= tcg_temp_new();
6340 TCGv_i32 fp0
= tcg_temp_new_i32();
6342 gen_load_fpr32(fp0
, fs
);
6343 tcg_gen_ext_i32_tl(t0
, fp0
);
6344 tcg_temp_free_i32(fp0
);
6346 gen_store_gpr(t0
, rt
);
6350 gen_load_gpr(t0
, rt
);
6352 TCGv_i32 fp0
= tcg_temp_new_i32();
6354 tcg_gen_trunc_tl_i32(fp0
, t0
);
6355 gen_store_fpr32(fp0
, fs
);
6356 tcg_temp_free_i32(fp0
);
6361 gen_helper_1e0i(cfc1
, t0
, fs
);
6362 gen_store_gpr(t0
, rt
);
6366 gen_load_gpr(t0
, rt
);
6367 gen_helper_0e1i(ctc1
, t0
, fs
);
6370 #if defined(TARGET_MIPS64)
6372 gen_load_fpr64(ctx
, t0
, fs
);
6373 gen_store_gpr(t0
, rt
);
6377 gen_load_gpr(t0
, rt
);
6378 gen_store_fpr64(ctx
, t0
, fs
);
6384 TCGv_i32 fp0
= tcg_temp_new_i32();
6386 gen_load_fpr32h(fp0
, fs
);
6387 tcg_gen_ext_i32_tl(t0
, fp0
);
6388 tcg_temp_free_i32(fp0
);
6390 gen_store_gpr(t0
, rt
);
6394 gen_load_gpr(t0
, rt
);
6396 TCGv_i32 fp0
= tcg_temp_new_i32();
6398 tcg_gen_trunc_tl_i32(fp0
, t0
);
6399 gen_store_fpr32h(fp0
, fs
);
6400 tcg_temp_free_i32(fp0
);
6406 generate_exception (ctx
, EXCP_RI
);
6409 (void)opn
; /* avoid a compiler warning */
6410 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
6416 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
6432 l1
= gen_new_label();
6433 t0
= tcg_temp_new_i32();
6434 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6435 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6436 tcg_temp_free_i32(t0
);
6438 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
6440 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
6445 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
6448 TCGv_i32 t0
= tcg_temp_new_i32();
6449 int l1
= gen_new_label();
6456 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6457 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6458 gen_load_fpr32(t0
, fs
);
6459 gen_store_fpr32(t0
, fd
);
6461 tcg_temp_free_i32(t0
);
6464 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
6467 TCGv_i32 t0
= tcg_temp_new_i32();
6469 int l1
= gen_new_label();
6476 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6477 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6478 tcg_temp_free_i32(t0
);
6479 fp0
= tcg_temp_new_i64();
6480 gen_load_fpr64(ctx
, fp0
, fs
);
6481 gen_store_fpr64(ctx
, fp0
, fd
);
6482 tcg_temp_free_i64(fp0
);
6486 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
6489 TCGv_i32 t0
= tcg_temp_new_i32();
6490 int l1
= gen_new_label();
6491 int l2
= gen_new_label();
6498 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6499 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6500 gen_load_fpr32(t0
, fs
);
6501 gen_store_fpr32(t0
, fd
);
6504 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
6505 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
6506 gen_load_fpr32h(t0
, fs
);
6507 gen_store_fpr32h(t0
, fd
);
6508 tcg_temp_free_i32(t0
);
6513 static void gen_farith (DisasContext
*ctx
, enum fopcode op1
,
6514 int ft
, int fs
, int fd
, int cc
)
6516 const char *opn
= "farith";
6517 const char *condnames
[] = {
6535 const char *condnames_abs
[] = {
6553 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6554 uint32_t func
= ctx
->opcode
& 0x3f;
6559 TCGv_i32 fp0
= tcg_temp_new_i32();
6560 TCGv_i32 fp1
= tcg_temp_new_i32();
6562 gen_load_fpr32(fp0
, fs
);
6563 gen_load_fpr32(fp1
, ft
);
6564 gen_helper_float_add_s(fp0
, cpu_env
, fp0
, fp1
);
6565 tcg_temp_free_i32(fp1
);
6566 gen_store_fpr32(fp0
, fd
);
6567 tcg_temp_free_i32(fp0
);
6574 TCGv_i32 fp0
= tcg_temp_new_i32();
6575 TCGv_i32 fp1
= tcg_temp_new_i32();
6577 gen_load_fpr32(fp0
, fs
);
6578 gen_load_fpr32(fp1
, ft
);
6579 gen_helper_float_sub_s(fp0
, cpu_env
, fp0
, fp1
);
6580 tcg_temp_free_i32(fp1
);
6581 gen_store_fpr32(fp0
, fd
);
6582 tcg_temp_free_i32(fp0
);
6589 TCGv_i32 fp0
= tcg_temp_new_i32();
6590 TCGv_i32 fp1
= tcg_temp_new_i32();
6592 gen_load_fpr32(fp0
, fs
);
6593 gen_load_fpr32(fp1
, ft
);
6594 gen_helper_float_mul_s(fp0
, cpu_env
, fp0
, fp1
);
6595 tcg_temp_free_i32(fp1
);
6596 gen_store_fpr32(fp0
, fd
);
6597 tcg_temp_free_i32(fp0
);
6604 TCGv_i32 fp0
= tcg_temp_new_i32();
6605 TCGv_i32 fp1
= tcg_temp_new_i32();
6607 gen_load_fpr32(fp0
, fs
);
6608 gen_load_fpr32(fp1
, ft
);
6609 gen_helper_float_div_s(fp0
, cpu_env
, fp0
, fp1
);
6610 tcg_temp_free_i32(fp1
);
6611 gen_store_fpr32(fp0
, fd
);
6612 tcg_temp_free_i32(fp0
);
6619 TCGv_i32 fp0
= tcg_temp_new_i32();
6621 gen_load_fpr32(fp0
, fs
);
6622 gen_helper_float_sqrt_s(fp0
, cpu_env
, fp0
);
6623 gen_store_fpr32(fp0
, fd
);
6624 tcg_temp_free_i32(fp0
);
6630 TCGv_i32 fp0
= tcg_temp_new_i32();
6632 gen_load_fpr32(fp0
, fs
);
6633 gen_helper_float_abs_s(fp0
, fp0
);
6634 gen_store_fpr32(fp0
, fd
);
6635 tcg_temp_free_i32(fp0
);
6641 TCGv_i32 fp0
= tcg_temp_new_i32();
6643 gen_load_fpr32(fp0
, fs
);
6644 gen_store_fpr32(fp0
, fd
);
6645 tcg_temp_free_i32(fp0
);
6651 TCGv_i32 fp0
= tcg_temp_new_i32();
6653 gen_load_fpr32(fp0
, fs
);
6654 gen_helper_float_chs_s(fp0
, fp0
);
6655 gen_store_fpr32(fp0
, fd
);
6656 tcg_temp_free_i32(fp0
);
6661 check_cp1_64bitmode(ctx
);
6663 TCGv_i32 fp32
= tcg_temp_new_i32();
6664 TCGv_i64 fp64
= tcg_temp_new_i64();
6666 gen_load_fpr32(fp32
, fs
);
6667 gen_helper_float_roundl_s(fp64
, cpu_env
, fp32
);
6668 tcg_temp_free_i32(fp32
);
6669 gen_store_fpr64(ctx
, fp64
, fd
);
6670 tcg_temp_free_i64(fp64
);
6675 check_cp1_64bitmode(ctx
);
6677 TCGv_i32 fp32
= tcg_temp_new_i32();
6678 TCGv_i64 fp64
= tcg_temp_new_i64();
6680 gen_load_fpr32(fp32
, fs
);
6681 gen_helper_float_truncl_s(fp64
, cpu_env
, fp32
);
6682 tcg_temp_free_i32(fp32
);
6683 gen_store_fpr64(ctx
, fp64
, fd
);
6684 tcg_temp_free_i64(fp64
);
6689 check_cp1_64bitmode(ctx
);
6691 TCGv_i32 fp32
= tcg_temp_new_i32();
6692 TCGv_i64 fp64
= tcg_temp_new_i64();
6694 gen_load_fpr32(fp32
, fs
);
6695 gen_helper_float_ceill_s(fp64
, cpu_env
, fp32
);
6696 tcg_temp_free_i32(fp32
);
6697 gen_store_fpr64(ctx
, fp64
, fd
);
6698 tcg_temp_free_i64(fp64
);
6703 check_cp1_64bitmode(ctx
);
6705 TCGv_i32 fp32
= tcg_temp_new_i32();
6706 TCGv_i64 fp64
= tcg_temp_new_i64();
6708 gen_load_fpr32(fp32
, fs
);
6709 gen_helper_float_floorl_s(fp64
, cpu_env
, fp32
);
6710 tcg_temp_free_i32(fp32
);
6711 gen_store_fpr64(ctx
, fp64
, fd
);
6712 tcg_temp_free_i64(fp64
);
6718 TCGv_i32 fp0
= tcg_temp_new_i32();
6720 gen_load_fpr32(fp0
, fs
);
6721 gen_helper_float_roundw_s(fp0
, cpu_env
, fp0
);
6722 gen_store_fpr32(fp0
, fd
);
6723 tcg_temp_free_i32(fp0
);
6729 TCGv_i32 fp0
= tcg_temp_new_i32();
6731 gen_load_fpr32(fp0
, fs
);
6732 gen_helper_float_truncw_s(fp0
, cpu_env
, fp0
);
6733 gen_store_fpr32(fp0
, fd
);
6734 tcg_temp_free_i32(fp0
);
6740 TCGv_i32 fp0
= tcg_temp_new_i32();
6742 gen_load_fpr32(fp0
, fs
);
6743 gen_helper_float_ceilw_s(fp0
, cpu_env
, fp0
);
6744 gen_store_fpr32(fp0
, fd
);
6745 tcg_temp_free_i32(fp0
);
6751 TCGv_i32 fp0
= tcg_temp_new_i32();
6753 gen_load_fpr32(fp0
, fs
);
6754 gen_helper_float_floorw_s(fp0
, cpu_env
, fp0
);
6755 gen_store_fpr32(fp0
, fd
);
6756 tcg_temp_free_i32(fp0
);
6761 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6766 int l1
= gen_new_label();
6770 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6772 fp0
= tcg_temp_new_i32();
6773 gen_load_fpr32(fp0
, fs
);
6774 gen_store_fpr32(fp0
, fd
);
6775 tcg_temp_free_i32(fp0
);
6782 int l1
= gen_new_label();
6786 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6787 fp0
= tcg_temp_new_i32();
6788 gen_load_fpr32(fp0
, fs
);
6789 gen_store_fpr32(fp0
, fd
);
6790 tcg_temp_free_i32(fp0
);
6799 TCGv_i32 fp0
= tcg_temp_new_i32();
6801 gen_load_fpr32(fp0
, fs
);
6802 gen_helper_float_recip_s(fp0
, cpu_env
, fp0
);
6803 gen_store_fpr32(fp0
, fd
);
6804 tcg_temp_free_i32(fp0
);
6811 TCGv_i32 fp0
= tcg_temp_new_i32();
6813 gen_load_fpr32(fp0
, fs
);
6814 gen_helper_float_rsqrt_s(fp0
, cpu_env
, fp0
);
6815 gen_store_fpr32(fp0
, fd
);
6816 tcg_temp_free_i32(fp0
);
6821 check_cp1_64bitmode(ctx
);
6823 TCGv_i32 fp0
= tcg_temp_new_i32();
6824 TCGv_i32 fp1
= tcg_temp_new_i32();
6826 gen_load_fpr32(fp0
, fs
);
6827 gen_load_fpr32(fp1
, ft
);
6828 gen_helper_float_recip2_s(fp0
, cpu_env
, fp0
, fp1
);
6829 tcg_temp_free_i32(fp1
);
6830 gen_store_fpr32(fp0
, fd
);
6831 tcg_temp_free_i32(fp0
);
6836 check_cp1_64bitmode(ctx
);
6838 TCGv_i32 fp0
= tcg_temp_new_i32();
6840 gen_load_fpr32(fp0
, fs
);
6841 gen_helper_float_recip1_s(fp0
, cpu_env
, fp0
);
6842 gen_store_fpr32(fp0
, fd
);
6843 tcg_temp_free_i32(fp0
);
6848 check_cp1_64bitmode(ctx
);
6850 TCGv_i32 fp0
= tcg_temp_new_i32();
6852 gen_load_fpr32(fp0
, fs
);
6853 gen_helper_float_rsqrt1_s(fp0
, cpu_env
, fp0
);
6854 gen_store_fpr32(fp0
, fd
);
6855 tcg_temp_free_i32(fp0
);
6860 check_cp1_64bitmode(ctx
);
6862 TCGv_i32 fp0
= tcg_temp_new_i32();
6863 TCGv_i32 fp1
= tcg_temp_new_i32();
6865 gen_load_fpr32(fp0
, fs
);
6866 gen_load_fpr32(fp1
, ft
);
6867 gen_helper_float_rsqrt2_s(fp0
, cpu_env
, fp0
, fp1
);
6868 tcg_temp_free_i32(fp1
);
6869 gen_store_fpr32(fp0
, fd
);
6870 tcg_temp_free_i32(fp0
);
6875 check_cp1_registers(ctx
, fd
);
6877 TCGv_i32 fp32
= tcg_temp_new_i32();
6878 TCGv_i64 fp64
= tcg_temp_new_i64();
6880 gen_load_fpr32(fp32
, fs
);
6881 gen_helper_float_cvtd_s(fp64
, cpu_env
, fp32
);
6882 tcg_temp_free_i32(fp32
);
6883 gen_store_fpr64(ctx
, fp64
, fd
);
6884 tcg_temp_free_i64(fp64
);
6890 TCGv_i32 fp0
= tcg_temp_new_i32();
6892 gen_load_fpr32(fp0
, fs
);
6893 gen_helper_float_cvtw_s(fp0
, cpu_env
, fp0
);
6894 gen_store_fpr32(fp0
, fd
);
6895 tcg_temp_free_i32(fp0
);
6900 check_cp1_64bitmode(ctx
);
6902 TCGv_i32 fp32
= tcg_temp_new_i32();
6903 TCGv_i64 fp64
= tcg_temp_new_i64();
6905 gen_load_fpr32(fp32
, fs
);
6906 gen_helper_float_cvtl_s(fp64
, cpu_env
, fp32
);
6907 tcg_temp_free_i32(fp32
);
6908 gen_store_fpr64(ctx
, fp64
, fd
);
6909 tcg_temp_free_i64(fp64
);
6914 check_cp1_64bitmode(ctx
);
6916 TCGv_i64 fp64
= tcg_temp_new_i64();
6917 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6918 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6920 gen_load_fpr32(fp32_0
, fs
);
6921 gen_load_fpr32(fp32_1
, ft
);
6922 tcg_gen_concat_i32_i64(fp64
, fp32_1
, fp32_0
);
6923 tcg_temp_free_i32(fp32_1
);
6924 tcg_temp_free_i32(fp32_0
);
6925 gen_store_fpr64(ctx
, fp64
, fd
);
6926 tcg_temp_free_i64(fp64
);
6939 case OPC_CMP_NGLE_S
:
6946 if (ctx
->opcode
& (1 << 6)) {
6947 gen_cmpabs_s(ctx
, func
-48, ft
, fs
, cc
);
6948 opn
= condnames_abs
[func
-48];
6950 gen_cmp_s(ctx
, func
-48, ft
, fs
, cc
);
6951 opn
= condnames
[func
-48];
6955 check_cp1_registers(ctx
, fs
| ft
| fd
);
6957 TCGv_i64 fp0
= tcg_temp_new_i64();
6958 TCGv_i64 fp1
= tcg_temp_new_i64();
6960 gen_load_fpr64(ctx
, fp0
, fs
);
6961 gen_load_fpr64(ctx
, fp1
, ft
);
6962 gen_helper_float_add_d(fp0
, cpu_env
, fp0
, fp1
);
6963 tcg_temp_free_i64(fp1
);
6964 gen_store_fpr64(ctx
, fp0
, fd
);
6965 tcg_temp_free_i64(fp0
);
6971 check_cp1_registers(ctx
, fs
| ft
| fd
);
6973 TCGv_i64 fp0
= tcg_temp_new_i64();
6974 TCGv_i64 fp1
= tcg_temp_new_i64();
6976 gen_load_fpr64(ctx
, fp0
, fs
);
6977 gen_load_fpr64(ctx
, fp1
, ft
);
6978 gen_helper_float_sub_d(fp0
, cpu_env
, fp0
, fp1
);
6979 tcg_temp_free_i64(fp1
);
6980 gen_store_fpr64(ctx
, fp0
, fd
);
6981 tcg_temp_free_i64(fp0
);
6987 check_cp1_registers(ctx
, fs
| ft
| fd
);
6989 TCGv_i64 fp0
= tcg_temp_new_i64();
6990 TCGv_i64 fp1
= tcg_temp_new_i64();
6992 gen_load_fpr64(ctx
, fp0
, fs
);
6993 gen_load_fpr64(ctx
, fp1
, ft
);
6994 gen_helper_float_mul_d(fp0
, cpu_env
, fp0
, fp1
);
6995 tcg_temp_free_i64(fp1
);
6996 gen_store_fpr64(ctx
, fp0
, fd
);
6997 tcg_temp_free_i64(fp0
);
7003 check_cp1_registers(ctx
, fs
| ft
| fd
);
7005 TCGv_i64 fp0
= tcg_temp_new_i64();
7006 TCGv_i64 fp1
= tcg_temp_new_i64();
7008 gen_load_fpr64(ctx
, fp0
, fs
);
7009 gen_load_fpr64(ctx
, fp1
, ft
);
7010 gen_helper_float_div_d(fp0
, cpu_env
, fp0
, fp1
);
7011 tcg_temp_free_i64(fp1
);
7012 gen_store_fpr64(ctx
, fp0
, fd
);
7013 tcg_temp_free_i64(fp0
);
7019 check_cp1_registers(ctx
, fs
| fd
);
7021 TCGv_i64 fp0
= tcg_temp_new_i64();
7023 gen_load_fpr64(ctx
, fp0
, fs
);
7024 gen_helper_float_sqrt_d(fp0
, cpu_env
, fp0
);
7025 gen_store_fpr64(ctx
, fp0
, fd
);
7026 tcg_temp_free_i64(fp0
);
7031 check_cp1_registers(ctx
, fs
| fd
);
7033 TCGv_i64 fp0
= tcg_temp_new_i64();
7035 gen_load_fpr64(ctx
, fp0
, fs
);
7036 gen_helper_float_abs_d(fp0
, fp0
);
7037 gen_store_fpr64(ctx
, fp0
, fd
);
7038 tcg_temp_free_i64(fp0
);
7043 check_cp1_registers(ctx
, fs
| fd
);
7045 TCGv_i64 fp0
= tcg_temp_new_i64();
7047 gen_load_fpr64(ctx
, fp0
, fs
);
7048 gen_store_fpr64(ctx
, fp0
, fd
);
7049 tcg_temp_free_i64(fp0
);
7054 check_cp1_registers(ctx
, fs
| fd
);
7056 TCGv_i64 fp0
= tcg_temp_new_i64();
7058 gen_load_fpr64(ctx
, fp0
, fs
);
7059 gen_helper_float_chs_d(fp0
, fp0
);
7060 gen_store_fpr64(ctx
, fp0
, fd
);
7061 tcg_temp_free_i64(fp0
);
7066 check_cp1_64bitmode(ctx
);
7068 TCGv_i64 fp0
= tcg_temp_new_i64();
7070 gen_load_fpr64(ctx
, fp0
, fs
);
7071 gen_helper_float_roundl_d(fp0
, cpu_env
, fp0
);
7072 gen_store_fpr64(ctx
, fp0
, fd
);
7073 tcg_temp_free_i64(fp0
);
7078 check_cp1_64bitmode(ctx
);
7080 TCGv_i64 fp0
= tcg_temp_new_i64();
7082 gen_load_fpr64(ctx
, fp0
, fs
);
7083 gen_helper_float_truncl_d(fp0
, cpu_env
, fp0
);
7084 gen_store_fpr64(ctx
, fp0
, fd
);
7085 tcg_temp_free_i64(fp0
);
7090 check_cp1_64bitmode(ctx
);
7092 TCGv_i64 fp0
= tcg_temp_new_i64();
7094 gen_load_fpr64(ctx
, fp0
, fs
);
7095 gen_helper_float_ceill_d(fp0
, cpu_env
, fp0
);
7096 gen_store_fpr64(ctx
, fp0
, fd
);
7097 tcg_temp_free_i64(fp0
);
7102 check_cp1_64bitmode(ctx
);
7104 TCGv_i64 fp0
= tcg_temp_new_i64();
7106 gen_load_fpr64(ctx
, fp0
, fs
);
7107 gen_helper_float_floorl_d(fp0
, cpu_env
, fp0
);
7108 gen_store_fpr64(ctx
, fp0
, fd
);
7109 tcg_temp_free_i64(fp0
);
7114 check_cp1_registers(ctx
, fs
);
7116 TCGv_i32 fp32
= tcg_temp_new_i32();
7117 TCGv_i64 fp64
= tcg_temp_new_i64();
7119 gen_load_fpr64(ctx
, fp64
, fs
);
7120 gen_helper_float_roundw_d(fp32
, cpu_env
, fp64
);
7121 tcg_temp_free_i64(fp64
);
7122 gen_store_fpr32(fp32
, fd
);
7123 tcg_temp_free_i32(fp32
);
7128 check_cp1_registers(ctx
, fs
);
7130 TCGv_i32 fp32
= tcg_temp_new_i32();
7131 TCGv_i64 fp64
= tcg_temp_new_i64();
7133 gen_load_fpr64(ctx
, fp64
, fs
);
7134 gen_helper_float_truncw_d(fp32
, cpu_env
, fp64
);
7135 tcg_temp_free_i64(fp64
);
7136 gen_store_fpr32(fp32
, fd
);
7137 tcg_temp_free_i32(fp32
);
7142 check_cp1_registers(ctx
, fs
);
7144 TCGv_i32 fp32
= tcg_temp_new_i32();
7145 TCGv_i64 fp64
= tcg_temp_new_i64();
7147 gen_load_fpr64(ctx
, fp64
, fs
);
7148 gen_helper_float_ceilw_d(fp32
, cpu_env
, fp64
);
7149 tcg_temp_free_i64(fp64
);
7150 gen_store_fpr32(fp32
, fd
);
7151 tcg_temp_free_i32(fp32
);
7156 check_cp1_registers(ctx
, fs
);
7158 TCGv_i32 fp32
= tcg_temp_new_i32();
7159 TCGv_i64 fp64
= tcg_temp_new_i64();
7161 gen_load_fpr64(ctx
, fp64
, fs
);
7162 gen_helper_float_floorw_d(fp32
, cpu_env
, fp64
);
7163 tcg_temp_free_i64(fp64
);
7164 gen_store_fpr32(fp32
, fd
);
7165 tcg_temp_free_i32(fp32
);
7170 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7175 int l1
= gen_new_label();
7179 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7181 fp0
= tcg_temp_new_i64();
7182 gen_load_fpr64(ctx
, fp0
, fs
);
7183 gen_store_fpr64(ctx
, fp0
, fd
);
7184 tcg_temp_free_i64(fp0
);
7191 int l1
= gen_new_label();
7195 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7196 fp0
= tcg_temp_new_i64();
7197 gen_load_fpr64(ctx
, fp0
, fs
);
7198 gen_store_fpr64(ctx
, fp0
, fd
);
7199 tcg_temp_free_i64(fp0
);
7206 check_cp1_64bitmode(ctx
);
7208 TCGv_i64 fp0
= tcg_temp_new_i64();
7210 gen_load_fpr64(ctx
, fp0
, fs
);
7211 gen_helper_float_recip_d(fp0
, cpu_env
, fp0
);
7212 gen_store_fpr64(ctx
, fp0
, fd
);
7213 tcg_temp_free_i64(fp0
);
7218 check_cp1_64bitmode(ctx
);
7220 TCGv_i64 fp0
= tcg_temp_new_i64();
7222 gen_load_fpr64(ctx
, fp0
, fs
);
7223 gen_helper_float_rsqrt_d(fp0
, cpu_env
, fp0
);
7224 gen_store_fpr64(ctx
, fp0
, fd
);
7225 tcg_temp_free_i64(fp0
);
7230 check_cp1_64bitmode(ctx
);
7232 TCGv_i64 fp0
= tcg_temp_new_i64();
7233 TCGv_i64 fp1
= tcg_temp_new_i64();
7235 gen_load_fpr64(ctx
, fp0
, fs
);
7236 gen_load_fpr64(ctx
, fp1
, ft
);
7237 gen_helper_float_recip2_d(fp0
, cpu_env
, fp0
, fp1
);
7238 tcg_temp_free_i64(fp1
);
7239 gen_store_fpr64(ctx
, fp0
, fd
);
7240 tcg_temp_free_i64(fp0
);
7245 check_cp1_64bitmode(ctx
);
7247 TCGv_i64 fp0
= tcg_temp_new_i64();
7249 gen_load_fpr64(ctx
, fp0
, fs
);
7250 gen_helper_float_recip1_d(fp0
, cpu_env
, fp0
);
7251 gen_store_fpr64(ctx
, fp0
, fd
);
7252 tcg_temp_free_i64(fp0
);
7257 check_cp1_64bitmode(ctx
);
7259 TCGv_i64 fp0
= tcg_temp_new_i64();
7261 gen_load_fpr64(ctx
, fp0
, fs
);
7262 gen_helper_float_rsqrt1_d(fp0
, cpu_env
, fp0
);
7263 gen_store_fpr64(ctx
, fp0
, fd
);
7264 tcg_temp_free_i64(fp0
);
7269 check_cp1_64bitmode(ctx
);
7271 TCGv_i64 fp0
= tcg_temp_new_i64();
7272 TCGv_i64 fp1
= tcg_temp_new_i64();
7274 gen_load_fpr64(ctx
, fp0
, fs
);
7275 gen_load_fpr64(ctx
, fp1
, ft
);
7276 gen_helper_float_rsqrt2_d(fp0
, cpu_env
, fp0
, fp1
);
7277 tcg_temp_free_i64(fp1
);
7278 gen_store_fpr64(ctx
, fp0
, fd
);
7279 tcg_temp_free_i64(fp0
);
7292 case OPC_CMP_NGLE_D
:
7299 if (ctx
->opcode
& (1 << 6)) {
7300 gen_cmpabs_d(ctx
, func
-48, ft
, fs
, cc
);
7301 opn
= condnames_abs
[func
-48];
7303 gen_cmp_d(ctx
, func
-48, ft
, fs
, cc
);
7304 opn
= condnames
[func
-48];
7308 check_cp1_registers(ctx
, fs
);
7310 TCGv_i32 fp32
= tcg_temp_new_i32();
7311 TCGv_i64 fp64
= tcg_temp_new_i64();
7313 gen_load_fpr64(ctx
, fp64
, fs
);
7314 gen_helper_float_cvts_d(fp32
, cpu_env
, fp64
);
7315 tcg_temp_free_i64(fp64
);
7316 gen_store_fpr32(fp32
, fd
);
7317 tcg_temp_free_i32(fp32
);
7322 check_cp1_registers(ctx
, fs
);
7324 TCGv_i32 fp32
= tcg_temp_new_i32();
7325 TCGv_i64 fp64
= tcg_temp_new_i64();
7327 gen_load_fpr64(ctx
, fp64
, fs
);
7328 gen_helper_float_cvtw_d(fp32
, cpu_env
, fp64
);
7329 tcg_temp_free_i64(fp64
);
7330 gen_store_fpr32(fp32
, fd
);
7331 tcg_temp_free_i32(fp32
);
7336 check_cp1_64bitmode(ctx
);
7338 TCGv_i64 fp0
= tcg_temp_new_i64();
7340 gen_load_fpr64(ctx
, fp0
, fs
);
7341 gen_helper_float_cvtl_d(fp0
, cpu_env
, fp0
);
7342 gen_store_fpr64(ctx
, fp0
, fd
);
7343 tcg_temp_free_i64(fp0
);
7349 TCGv_i32 fp0
= tcg_temp_new_i32();
7351 gen_load_fpr32(fp0
, fs
);
7352 gen_helper_float_cvts_w(fp0
, cpu_env
, fp0
);
7353 gen_store_fpr32(fp0
, fd
);
7354 tcg_temp_free_i32(fp0
);
7359 check_cp1_registers(ctx
, fd
);
7361 TCGv_i32 fp32
= tcg_temp_new_i32();
7362 TCGv_i64 fp64
= tcg_temp_new_i64();
7364 gen_load_fpr32(fp32
, fs
);
7365 gen_helper_float_cvtd_w(fp64
, cpu_env
, fp32
);
7366 tcg_temp_free_i32(fp32
);
7367 gen_store_fpr64(ctx
, fp64
, fd
);
7368 tcg_temp_free_i64(fp64
);
7373 check_cp1_64bitmode(ctx
);
7375 TCGv_i32 fp32
= tcg_temp_new_i32();
7376 TCGv_i64 fp64
= tcg_temp_new_i64();
7378 gen_load_fpr64(ctx
, fp64
, fs
);
7379 gen_helper_float_cvts_l(fp32
, cpu_env
, fp64
);
7380 tcg_temp_free_i64(fp64
);
7381 gen_store_fpr32(fp32
, fd
);
7382 tcg_temp_free_i32(fp32
);
7387 check_cp1_64bitmode(ctx
);
7389 TCGv_i64 fp0
= tcg_temp_new_i64();
7391 gen_load_fpr64(ctx
, fp0
, fs
);
7392 gen_helper_float_cvtd_l(fp0
, cpu_env
, fp0
);
7393 gen_store_fpr64(ctx
, fp0
, fd
);
7394 tcg_temp_free_i64(fp0
);
7399 check_cp1_64bitmode(ctx
);
7401 TCGv_i64 fp0
= tcg_temp_new_i64();
7403 gen_load_fpr64(ctx
, fp0
, fs
);
7404 gen_helper_float_cvtps_pw(fp0
, cpu_env
, fp0
);
7405 gen_store_fpr64(ctx
, fp0
, fd
);
7406 tcg_temp_free_i64(fp0
);
7411 check_cp1_64bitmode(ctx
);
7413 TCGv_i64 fp0
= tcg_temp_new_i64();
7414 TCGv_i64 fp1
= tcg_temp_new_i64();
7416 gen_load_fpr64(ctx
, fp0
, fs
);
7417 gen_load_fpr64(ctx
, fp1
, ft
);
7418 gen_helper_float_add_ps(fp0
, cpu_env
, fp0
, fp1
);
7419 tcg_temp_free_i64(fp1
);
7420 gen_store_fpr64(ctx
, fp0
, fd
);
7421 tcg_temp_free_i64(fp0
);
7426 check_cp1_64bitmode(ctx
);
7428 TCGv_i64 fp0
= tcg_temp_new_i64();
7429 TCGv_i64 fp1
= tcg_temp_new_i64();
7431 gen_load_fpr64(ctx
, fp0
, fs
);
7432 gen_load_fpr64(ctx
, fp1
, ft
);
7433 gen_helper_float_sub_ps(fp0
, cpu_env
, fp0
, fp1
);
7434 tcg_temp_free_i64(fp1
);
7435 gen_store_fpr64(ctx
, fp0
, fd
);
7436 tcg_temp_free_i64(fp0
);
7441 check_cp1_64bitmode(ctx
);
7443 TCGv_i64 fp0
= tcg_temp_new_i64();
7444 TCGv_i64 fp1
= tcg_temp_new_i64();
7446 gen_load_fpr64(ctx
, fp0
, fs
);
7447 gen_load_fpr64(ctx
, fp1
, ft
);
7448 gen_helper_float_mul_ps(fp0
, cpu_env
, fp0
, fp1
);
7449 tcg_temp_free_i64(fp1
);
7450 gen_store_fpr64(ctx
, fp0
, fd
);
7451 tcg_temp_free_i64(fp0
);
7456 check_cp1_64bitmode(ctx
);
7458 TCGv_i64 fp0
= tcg_temp_new_i64();
7460 gen_load_fpr64(ctx
, fp0
, fs
);
7461 gen_helper_float_abs_ps(fp0
, fp0
);
7462 gen_store_fpr64(ctx
, fp0
, fd
);
7463 tcg_temp_free_i64(fp0
);
7468 check_cp1_64bitmode(ctx
);
7470 TCGv_i64 fp0
= tcg_temp_new_i64();
7472 gen_load_fpr64(ctx
, fp0
, fs
);
7473 gen_store_fpr64(ctx
, fp0
, fd
);
7474 tcg_temp_free_i64(fp0
);
7479 check_cp1_64bitmode(ctx
);
7481 TCGv_i64 fp0
= tcg_temp_new_i64();
7483 gen_load_fpr64(ctx
, fp0
, fs
);
7484 gen_helper_float_chs_ps(fp0
, fp0
);
7485 gen_store_fpr64(ctx
, fp0
, fd
);
7486 tcg_temp_free_i64(fp0
);
7491 check_cp1_64bitmode(ctx
);
7492 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7496 check_cp1_64bitmode(ctx
);
7498 int l1
= gen_new_label();
7502 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7503 fp0
= tcg_temp_new_i64();
7504 gen_load_fpr64(ctx
, fp0
, fs
);
7505 gen_store_fpr64(ctx
, fp0
, fd
);
7506 tcg_temp_free_i64(fp0
);
7512 check_cp1_64bitmode(ctx
);
7514 int l1
= gen_new_label();
7518 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7519 fp0
= tcg_temp_new_i64();
7520 gen_load_fpr64(ctx
, fp0
, fs
);
7521 gen_store_fpr64(ctx
, fp0
, fd
);
7522 tcg_temp_free_i64(fp0
);
7529 check_cp1_64bitmode(ctx
);
7531 TCGv_i64 fp0
= tcg_temp_new_i64();
7532 TCGv_i64 fp1
= tcg_temp_new_i64();
7534 gen_load_fpr64(ctx
, fp0
, ft
);
7535 gen_load_fpr64(ctx
, fp1
, fs
);
7536 gen_helper_float_addr_ps(fp0
, cpu_env
, fp0
, fp1
);
7537 tcg_temp_free_i64(fp1
);
7538 gen_store_fpr64(ctx
, fp0
, fd
);
7539 tcg_temp_free_i64(fp0
);
7544 check_cp1_64bitmode(ctx
);
7546 TCGv_i64 fp0
= tcg_temp_new_i64();
7547 TCGv_i64 fp1
= tcg_temp_new_i64();
7549 gen_load_fpr64(ctx
, fp0
, ft
);
7550 gen_load_fpr64(ctx
, fp1
, fs
);
7551 gen_helper_float_mulr_ps(fp0
, cpu_env
, fp0
, fp1
);
7552 tcg_temp_free_i64(fp1
);
7553 gen_store_fpr64(ctx
, fp0
, fd
);
7554 tcg_temp_free_i64(fp0
);
7559 check_cp1_64bitmode(ctx
);
7561 TCGv_i64 fp0
= tcg_temp_new_i64();
7562 TCGv_i64 fp1
= tcg_temp_new_i64();
7564 gen_load_fpr64(ctx
, fp0
, fs
);
7565 gen_load_fpr64(ctx
, fp1
, ft
);
7566 gen_helper_float_recip2_ps(fp0
, cpu_env
, fp0
, fp1
);
7567 tcg_temp_free_i64(fp1
);
7568 gen_store_fpr64(ctx
, fp0
, fd
);
7569 tcg_temp_free_i64(fp0
);
7574 check_cp1_64bitmode(ctx
);
7576 TCGv_i64 fp0
= tcg_temp_new_i64();
7578 gen_load_fpr64(ctx
, fp0
, fs
);
7579 gen_helper_float_recip1_ps(fp0
, cpu_env
, fp0
);
7580 gen_store_fpr64(ctx
, fp0
, fd
);
7581 tcg_temp_free_i64(fp0
);
7586 check_cp1_64bitmode(ctx
);
7588 TCGv_i64 fp0
= tcg_temp_new_i64();
7590 gen_load_fpr64(ctx
, fp0
, fs
);
7591 gen_helper_float_rsqrt1_ps(fp0
, cpu_env
, fp0
);
7592 gen_store_fpr64(ctx
, fp0
, fd
);
7593 tcg_temp_free_i64(fp0
);
7598 check_cp1_64bitmode(ctx
);
7600 TCGv_i64 fp0
= tcg_temp_new_i64();
7601 TCGv_i64 fp1
= tcg_temp_new_i64();
7603 gen_load_fpr64(ctx
, fp0
, fs
);
7604 gen_load_fpr64(ctx
, fp1
, ft
);
7605 gen_helper_float_rsqrt2_ps(fp0
, cpu_env
, fp0
, fp1
);
7606 tcg_temp_free_i64(fp1
);
7607 gen_store_fpr64(ctx
, fp0
, fd
);
7608 tcg_temp_free_i64(fp0
);
7613 check_cp1_64bitmode(ctx
);
7615 TCGv_i32 fp0
= tcg_temp_new_i32();
7617 gen_load_fpr32h(fp0
, fs
);
7618 gen_helper_float_cvts_pu(fp0
, cpu_env
, fp0
);
7619 gen_store_fpr32(fp0
, fd
);
7620 tcg_temp_free_i32(fp0
);
7625 check_cp1_64bitmode(ctx
);
7627 TCGv_i64 fp0
= tcg_temp_new_i64();
7629 gen_load_fpr64(ctx
, fp0
, fs
);
7630 gen_helper_float_cvtpw_ps(fp0
, cpu_env
, fp0
);
7631 gen_store_fpr64(ctx
, fp0
, fd
);
7632 tcg_temp_free_i64(fp0
);
7637 check_cp1_64bitmode(ctx
);
7639 TCGv_i32 fp0
= tcg_temp_new_i32();
7641 gen_load_fpr32(fp0
, fs
);
7642 gen_helper_float_cvts_pl(fp0
, cpu_env
, fp0
);
7643 gen_store_fpr32(fp0
, fd
);
7644 tcg_temp_free_i32(fp0
);
7649 check_cp1_64bitmode(ctx
);
7651 TCGv_i32 fp0
= tcg_temp_new_i32();
7652 TCGv_i32 fp1
= tcg_temp_new_i32();
7654 gen_load_fpr32(fp0
, fs
);
7655 gen_load_fpr32(fp1
, ft
);
7656 gen_store_fpr32h(fp0
, fd
);
7657 gen_store_fpr32(fp1
, fd
);
7658 tcg_temp_free_i32(fp0
);
7659 tcg_temp_free_i32(fp1
);
7664 check_cp1_64bitmode(ctx
);
7666 TCGv_i32 fp0
= tcg_temp_new_i32();
7667 TCGv_i32 fp1
= tcg_temp_new_i32();
7669 gen_load_fpr32(fp0
, fs
);
7670 gen_load_fpr32h(fp1
, ft
);
7671 gen_store_fpr32(fp1
, fd
);
7672 gen_store_fpr32h(fp0
, fd
);
7673 tcg_temp_free_i32(fp0
);
7674 tcg_temp_free_i32(fp1
);
7679 check_cp1_64bitmode(ctx
);
7681 TCGv_i32 fp0
= tcg_temp_new_i32();
7682 TCGv_i32 fp1
= tcg_temp_new_i32();
7684 gen_load_fpr32h(fp0
, fs
);
7685 gen_load_fpr32(fp1
, ft
);
7686 gen_store_fpr32(fp1
, fd
);
7687 gen_store_fpr32h(fp0
, fd
);
7688 tcg_temp_free_i32(fp0
);
7689 tcg_temp_free_i32(fp1
);
7694 check_cp1_64bitmode(ctx
);
7696 TCGv_i32 fp0
= tcg_temp_new_i32();
7697 TCGv_i32 fp1
= tcg_temp_new_i32();
7699 gen_load_fpr32h(fp0
, fs
);
7700 gen_load_fpr32h(fp1
, ft
);
7701 gen_store_fpr32(fp1
, fd
);
7702 gen_store_fpr32h(fp0
, fd
);
7703 tcg_temp_free_i32(fp0
);
7704 tcg_temp_free_i32(fp1
);
7711 case OPC_CMP_UEQ_PS
:
7712 case OPC_CMP_OLT_PS
:
7713 case OPC_CMP_ULT_PS
:
7714 case OPC_CMP_OLE_PS
:
7715 case OPC_CMP_ULE_PS
:
7717 case OPC_CMP_NGLE_PS
:
7718 case OPC_CMP_SEQ_PS
:
7719 case OPC_CMP_NGL_PS
:
7721 case OPC_CMP_NGE_PS
:
7723 case OPC_CMP_NGT_PS
:
7724 if (ctx
->opcode
& (1 << 6)) {
7725 gen_cmpabs_ps(ctx
, func
-48, ft
, fs
, cc
);
7726 opn
= condnames_abs
[func
-48];
7728 gen_cmp_ps(ctx
, func
-48, ft
, fs
, cc
);
7729 opn
= condnames
[func
-48];
7734 generate_exception (ctx
, EXCP_RI
);
7737 (void)opn
; /* avoid a compiler warning */
7740 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7743 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7746 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7751 /* Coprocessor 3 (FPU) */
7752 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7753 int fd
, int fs
, int base
, int index
)
7755 const char *opn
= "extended float load/store";
7757 TCGv t0
= tcg_temp_new();
7760 gen_load_gpr(t0
, index
);
7761 } else if (index
== 0) {
7762 gen_load_gpr(t0
, base
);
7764 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], cpu_gpr
[index
]);
7766 /* Don't do NOP if destination is zero: we must perform the actual
7768 save_cpu_state(ctx
, 0);
7773 TCGv_i32 fp0
= tcg_temp_new_i32();
7775 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7776 tcg_gen_trunc_tl_i32(fp0
, t0
);
7777 gen_store_fpr32(fp0
, fd
);
7778 tcg_temp_free_i32(fp0
);
7784 check_cp1_registers(ctx
, fd
);
7786 TCGv_i64 fp0
= tcg_temp_new_i64();
7788 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7789 gen_store_fpr64(ctx
, fp0
, fd
);
7790 tcg_temp_free_i64(fp0
);
7795 check_cp1_64bitmode(ctx
);
7796 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7798 TCGv_i64 fp0
= tcg_temp_new_i64();
7800 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7801 gen_store_fpr64(ctx
, fp0
, fd
);
7802 tcg_temp_free_i64(fp0
);
7809 TCGv_i32 fp0
= tcg_temp_new_i32();
7810 TCGv t1
= tcg_temp_new();
7812 gen_load_fpr32(fp0
, fs
);
7813 tcg_gen_extu_i32_tl(t1
, fp0
);
7814 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7815 tcg_temp_free_i32(fp0
);
7823 check_cp1_registers(ctx
, fs
);
7825 TCGv_i64 fp0
= tcg_temp_new_i64();
7827 gen_load_fpr64(ctx
, fp0
, fs
);
7828 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7829 tcg_temp_free_i64(fp0
);
7835 check_cp1_64bitmode(ctx
);
7836 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7838 TCGv_i64 fp0
= tcg_temp_new_i64();
7840 gen_load_fpr64(ctx
, fp0
, fs
);
7841 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7842 tcg_temp_free_i64(fp0
);
7849 (void)opn
; (void)store
; /* avoid compiler warnings */
7850 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7851 regnames
[index
], regnames
[base
]);
7854 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7855 int fd
, int fr
, int fs
, int ft
)
7857 const char *opn
= "flt3_arith";
7861 check_cp1_64bitmode(ctx
);
7863 TCGv t0
= tcg_temp_local_new();
7864 TCGv_i32 fp
= tcg_temp_new_i32();
7865 TCGv_i32 fph
= tcg_temp_new_i32();
7866 int l1
= gen_new_label();
7867 int l2
= gen_new_label();
7869 gen_load_gpr(t0
, fr
);
7870 tcg_gen_andi_tl(t0
, t0
, 0x7);
7872 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7873 gen_load_fpr32(fp
, fs
);
7874 gen_load_fpr32h(fph
, fs
);
7875 gen_store_fpr32(fp
, fd
);
7876 gen_store_fpr32h(fph
, fd
);
7879 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7881 #ifdef TARGET_WORDS_BIGENDIAN
7882 gen_load_fpr32(fp
, fs
);
7883 gen_load_fpr32h(fph
, ft
);
7884 gen_store_fpr32h(fp
, fd
);
7885 gen_store_fpr32(fph
, fd
);
7887 gen_load_fpr32h(fph
, fs
);
7888 gen_load_fpr32(fp
, ft
);
7889 gen_store_fpr32(fph
, fd
);
7890 gen_store_fpr32h(fp
, fd
);
7893 tcg_temp_free_i32(fp
);
7894 tcg_temp_free_i32(fph
);
7901 TCGv_i32 fp0
= tcg_temp_new_i32();
7902 TCGv_i32 fp1
= tcg_temp_new_i32();
7903 TCGv_i32 fp2
= tcg_temp_new_i32();
7905 gen_load_fpr32(fp0
, fs
);
7906 gen_load_fpr32(fp1
, ft
);
7907 gen_load_fpr32(fp2
, fr
);
7908 gen_helper_float_muladd_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
7909 tcg_temp_free_i32(fp0
);
7910 tcg_temp_free_i32(fp1
);
7911 gen_store_fpr32(fp2
, fd
);
7912 tcg_temp_free_i32(fp2
);
7918 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7920 TCGv_i64 fp0
= tcg_temp_new_i64();
7921 TCGv_i64 fp1
= tcg_temp_new_i64();
7922 TCGv_i64 fp2
= tcg_temp_new_i64();
7924 gen_load_fpr64(ctx
, fp0
, fs
);
7925 gen_load_fpr64(ctx
, fp1
, ft
);
7926 gen_load_fpr64(ctx
, fp2
, fr
);
7927 gen_helper_float_muladd_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
7928 tcg_temp_free_i64(fp0
);
7929 tcg_temp_free_i64(fp1
);
7930 gen_store_fpr64(ctx
, fp2
, fd
);
7931 tcg_temp_free_i64(fp2
);
7936 check_cp1_64bitmode(ctx
);
7938 TCGv_i64 fp0
= tcg_temp_new_i64();
7939 TCGv_i64 fp1
= tcg_temp_new_i64();
7940 TCGv_i64 fp2
= tcg_temp_new_i64();
7942 gen_load_fpr64(ctx
, fp0
, fs
);
7943 gen_load_fpr64(ctx
, fp1
, ft
);
7944 gen_load_fpr64(ctx
, fp2
, fr
);
7945 gen_helper_float_muladd_ps(fp2
, cpu_env
, fp0
, fp1
, fp2
);
7946 tcg_temp_free_i64(fp0
);
7947 tcg_temp_free_i64(fp1
);
7948 gen_store_fpr64(ctx
, fp2
, fd
);
7949 tcg_temp_free_i64(fp2
);
7956 TCGv_i32 fp0
= tcg_temp_new_i32();
7957 TCGv_i32 fp1
= tcg_temp_new_i32();
7958 TCGv_i32 fp2
= tcg_temp_new_i32();
7960 gen_load_fpr32(fp0
, fs
);
7961 gen_load_fpr32(fp1
, ft
);
7962 gen_load_fpr32(fp2
, fr
);
7963 gen_helper_float_mulsub_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
7964 tcg_temp_free_i32(fp0
);
7965 tcg_temp_free_i32(fp1
);
7966 gen_store_fpr32(fp2
, fd
);
7967 tcg_temp_free_i32(fp2
);
7973 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7975 TCGv_i64 fp0
= tcg_temp_new_i64();
7976 TCGv_i64 fp1
= tcg_temp_new_i64();
7977 TCGv_i64 fp2
= tcg_temp_new_i64();
7979 gen_load_fpr64(ctx
, fp0
, fs
);
7980 gen_load_fpr64(ctx
, fp1
, ft
);
7981 gen_load_fpr64(ctx
, fp2
, fr
);
7982 gen_helper_float_mulsub_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
7983 tcg_temp_free_i64(fp0
);
7984 tcg_temp_free_i64(fp1
);
7985 gen_store_fpr64(ctx
, fp2
, fd
);
7986 tcg_temp_free_i64(fp2
);
7991 check_cp1_64bitmode(ctx
);
7993 TCGv_i64 fp0
= tcg_temp_new_i64();
7994 TCGv_i64 fp1
= tcg_temp_new_i64();
7995 TCGv_i64 fp2
= tcg_temp_new_i64();
7997 gen_load_fpr64(ctx
, fp0
, fs
);
7998 gen_load_fpr64(ctx
, fp1
, ft
);
7999 gen_load_fpr64(ctx
, fp2
, fr
);
8000 gen_helper_float_mulsub_ps(fp2
, cpu_env
, fp0
, fp1
, fp2
);
8001 tcg_temp_free_i64(fp0
);
8002 tcg_temp_free_i64(fp1
);
8003 gen_store_fpr64(ctx
, fp2
, fd
);
8004 tcg_temp_free_i64(fp2
);
8011 TCGv_i32 fp0
= tcg_temp_new_i32();
8012 TCGv_i32 fp1
= tcg_temp_new_i32();
8013 TCGv_i32 fp2
= tcg_temp_new_i32();
8015 gen_load_fpr32(fp0
, fs
);
8016 gen_load_fpr32(fp1
, ft
);
8017 gen_load_fpr32(fp2
, fr
);
8018 gen_helper_float_nmuladd_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
8019 tcg_temp_free_i32(fp0
);
8020 tcg_temp_free_i32(fp1
);
8021 gen_store_fpr32(fp2
, fd
);
8022 tcg_temp_free_i32(fp2
);
8028 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
8030 TCGv_i64 fp0
= tcg_temp_new_i64();
8031 TCGv_i64 fp1
= tcg_temp_new_i64();
8032 TCGv_i64 fp2
= tcg_temp_new_i64();
8034 gen_load_fpr64(ctx
, fp0
, fs
);
8035 gen_load_fpr64(ctx
, fp1
, ft
);
8036 gen_load_fpr64(ctx
, fp2
, fr
);
8037 gen_helper_float_nmuladd_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
8038 tcg_temp_free_i64(fp0
);
8039 tcg_temp_free_i64(fp1
);
8040 gen_store_fpr64(ctx
, fp2
, fd
);
8041 tcg_temp_free_i64(fp2
);
8046 check_cp1_64bitmode(ctx
);
8048 TCGv_i64 fp0
= tcg_temp_new_i64();
8049 TCGv_i64 fp1
= tcg_temp_new_i64();
8050 TCGv_i64 fp2
= tcg_temp_new_i64();
8052 gen_load_fpr64(ctx
, fp0
, fs
);
8053 gen_load_fpr64(ctx
, fp1
, ft
);
8054 gen_load_fpr64(ctx
, fp2
, fr
);
8055 gen_helper_float_nmuladd_ps(fp2
, cpu_env
, fp0
, fp1
, fp2
);
8056 tcg_temp_free_i64(fp0
);
8057 tcg_temp_free_i64(fp1
);
8058 gen_store_fpr64(ctx
, fp2
, fd
);
8059 tcg_temp_free_i64(fp2
);
8066 TCGv_i32 fp0
= tcg_temp_new_i32();
8067 TCGv_i32 fp1
= tcg_temp_new_i32();
8068 TCGv_i32 fp2
= tcg_temp_new_i32();
8070 gen_load_fpr32(fp0
, fs
);
8071 gen_load_fpr32(fp1
, ft
);
8072 gen_load_fpr32(fp2
, fr
);
8073 gen_helper_float_nmulsub_s(fp2
, cpu_env
, fp0
, fp1
, fp2
);
8074 tcg_temp_free_i32(fp0
);
8075 tcg_temp_free_i32(fp1
);
8076 gen_store_fpr32(fp2
, fd
);
8077 tcg_temp_free_i32(fp2
);
8083 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
8085 TCGv_i64 fp0
= tcg_temp_new_i64();
8086 TCGv_i64 fp1
= tcg_temp_new_i64();
8087 TCGv_i64 fp2
= tcg_temp_new_i64();
8089 gen_load_fpr64(ctx
, fp0
, fs
);
8090 gen_load_fpr64(ctx
, fp1
, ft
);
8091 gen_load_fpr64(ctx
, fp2
, fr
);
8092 gen_helper_float_nmulsub_d(fp2
, cpu_env
, fp0
, fp1
, fp2
);
8093 tcg_temp_free_i64(fp0
);
8094 tcg_temp_free_i64(fp1
);
8095 gen_store_fpr64(ctx
, fp2
, fd
);
8096 tcg_temp_free_i64(fp2
);
8101 check_cp1_64bitmode(ctx
);
8103 TCGv_i64 fp0
= tcg_temp_new_i64();
8104 TCGv_i64 fp1
= tcg_temp_new_i64();
8105 TCGv_i64 fp2
= tcg_temp_new_i64();
8107 gen_load_fpr64(ctx
, fp0
, fs
);
8108 gen_load_fpr64(ctx
, fp1
, ft
);
8109 gen_load_fpr64(ctx
, fp2
, fr
);
8110 gen_helper_float_nmulsub_ps(fp2
, cpu_env
, fp0
, fp1
, fp2
);
8111 tcg_temp_free_i64(fp0
);
8112 tcg_temp_free_i64(fp1
);
8113 gen_store_fpr64(ctx
, fp2
, fd
);
8114 tcg_temp_free_i64(fp2
);
8120 generate_exception (ctx
, EXCP_RI
);
8123 (void)opn
; /* avoid a compiler warning */
8124 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
8125 fregnames
[fs
], fregnames
[ft
]);
8129 gen_rdhwr (CPUMIPSState
*env
, DisasContext
*ctx
, int rt
, int rd
)
8133 #if !defined(CONFIG_USER_ONLY)
8134 /* The Linux kernel will emulate rdhwr if it's not supported natively.
8135 Therefore only check the ISA in system mode. */
8136 check_insn(env
, ctx
, ISA_MIPS32R2
);
8138 t0
= tcg_temp_new();
8142 save_cpu_state(ctx
, 1);
8143 gen_helper_rdhwr_cpunum(t0
, cpu_env
);
8144 gen_store_gpr(t0
, rt
);
8147 save_cpu_state(ctx
, 1);
8148 gen_helper_rdhwr_synci_step(t0
, cpu_env
);
8149 gen_store_gpr(t0
, rt
);
8152 save_cpu_state(ctx
, 1);
8153 gen_helper_rdhwr_cc(t0
, cpu_env
);
8154 gen_store_gpr(t0
, rt
);
8157 save_cpu_state(ctx
, 1);
8158 gen_helper_rdhwr_ccres(t0
, cpu_env
);
8159 gen_store_gpr(t0
, rt
);
8162 #if defined(CONFIG_USER_ONLY)
8163 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUMIPSState
, tls_value
));
8164 gen_store_gpr(t0
, rt
);
8167 /* XXX: Some CPUs implement this in hardware.
8168 Not supported yet. */
8170 default: /* Invalid */
8171 MIPS_INVAL("rdhwr");
8172 generate_exception(ctx
, EXCP_RI
);
8178 static void handle_delay_slot (CPUMIPSState
*env
, DisasContext
*ctx
,
8181 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8182 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8183 /* Branches completion */
8184 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8185 ctx
->bstate
= BS_BRANCH
;
8186 save_cpu_state(ctx
, 0);
8187 /* FIXME: Need to clear can_do_io. */
8188 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
8190 /* unconditional branch */
8191 MIPS_DEBUG("unconditional branch");
8192 if (proc_hflags
& MIPS_HFLAG_BX
) {
8193 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
8195 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8198 /* blikely taken case */
8199 MIPS_DEBUG("blikely branch taken");
8200 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8203 /* Conditional branch */
8204 MIPS_DEBUG("conditional branch");
8206 int l1
= gen_new_label();
8208 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8209 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
8211 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8215 /* unconditional branch to register */
8216 MIPS_DEBUG("branch to register");
8217 if (env
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
8218 TCGv t0
= tcg_temp_new();
8219 TCGv_i32 t1
= tcg_temp_new_i32();
8221 tcg_gen_andi_tl(t0
, btarget
, 0x1);
8222 tcg_gen_trunc_tl_i32(t1
, t0
);
8224 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
8225 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
8226 tcg_gen_or_i32(hflags
, hflags
, t1
);
8227 tcg_temp_free_i32(t1
);
8229 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
8231 tcg_gen_mov_tl(cpu_PC
, btarget
);
8233 if (ctx
->singlestep_enabled
) {
8234 save_cpu_state(ctx
, 0);
8235 gen_helper_0e0i(raise_exception
, EXCP_DEBUG
);
8240 MIPS_DEBUG("unknown branch");
8246 /* ISA extensions (ASEs) */
8247 /* MIPS16 extension to MIPS32 */
8249 /* MIPS16 major opcodes */
8251 M16_OPC_ADDIUSP
= 0x00,
8252 M16_OPC_ADDIUPC
= 0x01,
8255 M16_OPC_BEQZ
= 0x04,
8256 M16_OPC_BNEQZ
= 0x05,
8257 M16_OPC_SHIFT
= 0x06,
8259 M16_OPC_RRIA
= 0x08,
8260 M16_OPC_ADDIU8
= 0x09,
8261 M16_OPC_SLTI
= 0x0a,
8262 M16_OPC_SLTIU
= 0x0b,
8265 M16_OPC_CMPI
= 0x0e,
8269 M16_OPC_LWSP
= 0x12,
8273 M16_OPC_LWPC
= 0x16,
8277 M16_OPC_SWSP
= 0x1a,
8281 M16_OPC_EXTEND
= 0x1e,
8285 /* I8 funct field */
8304 /* RR funct field */
8338 /* I64 funct field */
8350 /* RR ry field for CNVT */
8352 RR_RY_CNVT_ZEB
= 0x0,
8353 RR_RY_CNVT_ZEH
= 0x1,
8354 RR_RY_CNVT_ZEW
= 0x2,
8355 RR_RY_CNVT_SEB
= 0x4,
8356 RR_RY_CNVT_SEH
= 0x5,
8357 RR_RY_CNVT_SEW
= 0x6,
8360 static int xlat (int r
)
8362 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
8367 static void gen_mips16_save (DisasContext
*ctx
,
8368 int xsregs
, int aregs
,
8369 int do_ra
, int do_s0
, int do_s1
,
8372 TCGv t0
= tcg_temp_new();
8373 TCGv t1
= tcg_temp_new();
8403 generate_exception(ctx
, EXCP_RI
);
8409 gen_base_offset_addr(ctx
, t0
, 29, 12);
8410 gen_load_gpr(t1
, 7);
8411 op_st_sw(t1
, t0
, ctx
);
8414 gen_base_offset_addr(ctx
, t0
, 29, 8);
8415 gen_load_gpr(t1
, 6);
8416 op_st_sw(t1
, t0
, ctx
);
8419 gen_base_offset_addr(ctx
, t0
, 29, 4);
8420 gen_load_gpr(t1
, 5);
8421 op_st_sw(t1
, t0
, ctx
);
8424 gen_base_offset_addr(ctx
, t0
, 29, 0);
8425 gen_load_gpr(t1
, 4);
8426 op_st_sw(t1
, t0
, ctx
);
8429 gen_load_gpr(t0
, 29);
8431 #define DECR_AND_STORE(reg) do { \
8432 tcg_gen_subi_tl(t0, t0, 4); \
8433 gen_load_gpr(t1, reg); \
8434 op_st_sw(t1, t0, ctx); \
8498 generate_exception(ctx
, EXCP_RI
);
8514 #undef DECR_AND_STORE
8516 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8521 static void gen_mips16_restore (DisasContext
*ctx
,
8522 int xsregs
, int aregs
,
8523 int do_ra
, int do_s0
, int do_s1
,
8527 TCGv t0
= tcg_temp_new();
8528 TCGv t1
= tcg_temp_new();
8530 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
8532 #define DECR_AND_LOAD(reg) do { \
8533 tcg_gen_subi_tl(t0, t0, 4); \
8534 op_ld_lw(t1, t0, ctx); \
8535 gen_store_gpr(t1, reg); \
8599 generate_exception(ctx
, EXCP_RI
);
8615 #undef DECR_AND_LOAD
8617 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8622 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
8623 int is_64_bit
, int extended
)
8627 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8628 generate_exception(ctx
, EXCP_RI
);
8632 t0
= tcg_temp_new();
8634 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
8635 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
8637 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8643 #if defined(TARGET_MIPS64)
8644 static void decode_i64_mips16 (CPUMIPSState
*env
, DisasContext
*ctx
,
8645 int ry
, int funct
, int16_t offset
,
8651 offset
= extended
? offset
: offset
<< 3;
8652 gen_ld(env
, ctx
, OPC_LD
, ry
, 29, offset
);
8656 offset
= extended
? offset
: offset
<< 3;
8657 gen_st(ctx
, OPC_SD
, ry
, 29, offset
);
8661 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8662 gen_st(ctx
, OPC_SD
, 31, 29, offset
);
8666 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8667 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8670 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8671 generate_exception(ctx
, EXCP_RI
);
8673 offset
= extended
? offset
: offset
<< 3;
8674 gen_ld(env
, ctx
, OPC_LDPC
, ry
, 0, offset
);
8679 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8680 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8684 offset
= extended
? offset
: offset
<< 2;
8685 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8689 offset
= extended
? offset
: offset
<< 2;
8690 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8696 static int decode_extended_mips16_opc (CPUMIPSState
*env
, DisasContext
*ctx
,
8699 int extend
= cpu_lduw_code(env
, ctx
->pc
+ 2);
8700 int op
, rx
, ry
, funct
, sa
;
8701 int16_t imm
, offset
;
8703 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8704 op
= (ctx
->opcode
>> 11) & 0x1f;
8705 sa
= (ctx
->opcode
>> 22) & 0x1f;
8706 funct
= (ctx
->opcode
>> 8) & 0x7;
8707 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8708 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8709 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8710 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8711 | (ctx
->opcode
& 0x1f));
8713 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8716 case M16_OPC_ADDIUSP
:
8717 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8719 case M16_OPC_ADDIUPC
:
8720 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8723 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8724 /* No delay slot, so just process as a normal instruction */
8727 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8728 /* No delay slot, so just process as a normal instruction */
8731 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8732 /* No delay slot, so just process as a normal instruction */
8735 switch (ctx
->opcode
& 0x3) {
8737 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8740 #if defined(TARGET_MIPS64)
8742 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8744 generate_exception(ctx
, EXCP_RI
);
8748 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8751 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8755 #if defined(TARGET_MIPS64)
8758 gen_ld(env
, ctx
, OPC_LD
, ry
, rx
, offset
);
8762 imm
= ctx
->opcode
& 0xf;
8763 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8764 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8765 imm
= (int16_t) (imm
<< 1) >> 1;
8766 if ((ctx
->opcode
>> 4) & 0x1) {
8767 #if defined(TARGET_MIPS64)
8769 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8771 generate_exception(ctx
, EXCP_RI
);
8774 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8777 case M16_OPC_ADDIU8
:
8778 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8781 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8784 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8789 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8792 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8795 gen_st(ctx
, OPC_SW
, 31, 29, imm
);
8798 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8802 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8803 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8804 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8805 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8806 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8807 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8808 | (ctx
->opcode
& 0xf)) << 3;
8810 if (ctx
->opcode
& (1 << 7)) {
8811 gen_mips16_save(ctx
, xsregs
, aregs
,
8812 do_ra
, do_s0
, do_s1
,
8815 gen_mips16_restore(ctx
, xsregs
, aregs
,
8816 do_ra
, do_s0
, do_s1
,
8822 generate_exception(ctx
, EXCP_RI
);
8827 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8830 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8832 #if defined(TARGET_MIPS64)
8834 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
);
8838 gen_ld(env
, ctx
, OPC_LB
, ry
, rx
, offset
);
8841 gen_ld(env
, ctx
, OPC_LH
, ry
, rx
, offset
);
8844 gen_ld(env
, ctx
, OPC_LW
, rx
, 29, offset
);
8847 gen_ld(env
, ctx
, OPC_LW
, ry
, rx
, offset
);
8850 gen_ld(env
, ctx
, OPC_LBU
, ry
, rx
, offset
);
8853 gen_ld(env
, ctx
, OPC_LHU
, ry
, rx
, offset
);
8856 gen_ld(env
, ctx
, OPC_LWPC
, rx
, 0, offset
);
8858 #if defined(TARGET_MIPS64)
8860 gen_ld(env
, ctx
, OPC_LWU
, ry
, rx
, offset
);
8864 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
8867 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
);
8870 gen_st(ctx
, OPC_SW
, rx
, 29, offset
);
8873 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
);
8875 #if defined(TARGET_MIPS64)
8877 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8881 generate_exception(ctx
, EXCP_RI
);
8888 static int decode_mips16_opc (CPUMIPSState
*env
, DisasContext
*ctx
,
8893 int op
, cnvt_op
, op1
, offset
;
8897 op
= (ctx
->opcode
>> 11) & 0x1f;
8898 sa
= (ctx
->opcode
>> 2) & 0x7;
8899 sa
= sa
== 0 ? 8 : sa
;
8900 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8901 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8902 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8903 op1
= offset
= ctx
->opcode
& 0x1f;
8908 case M16_OPC_ADDIUSP
:
8910 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8912 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8915 case M16_OPC_ADDIUPC
:
8916 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8919 offset
= (ctx
->opcode
& 0x7ff) << 1;
8920 offset
= (int16_t)(offset
<< 4) >> 4;
8921 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8922 /* No delay slot, so just process as a normal instruction */
8925 offset
= cpu_lduw_code(env
, ctx
->pc
+ 2);
8926 offset
= (((ctx
->opcode
& 0x1f) << 21)
8927 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8929 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALXS
: OPC_JALS
;
8930 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8935 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8936 /* No delay slot, so just process as a normal instruction */
8939 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8940 /* No delay slot, so just process as a normal instruction */
8943 switch (ctx
->opcode
& 0x3) {
8945 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8948 #if defined(TARGET_MIPS64)
8950 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8952 generate_exception(ctx
, EXCP_RI
);
8956 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8959 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8963 #if defined(TARGET_MIPS64)
8966 gen_ld(env
, ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8971 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8973 if ((ctx
->opcode
>> 4) & 1) {
8974 #if defined(TARGET_MIPS64)
8976 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8978 generate_exception(ctx
, EXCP_RI
);
8981 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8985 case M16_OPC_ADDIU8
:
8987 int16_t imm
= (int8_t) ctx
->opcode
;
8989 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8994 int16_t imm
= (uint8_t) ctx
->opcode
;
8996 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
9001 int16_t imm
= (uint8_t) ctx
->opcode
;
9003 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
9010 funct
= (ctx
->opcode
>> 8) & 0x7;
9013 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
9014 ((int8_t)ctx
->opcode
) << 1);
9017 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
9018 ((int8_t)ctx
->opcode
) << 1);
9021 gen_st(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
9024 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
9025 ((int8_t)ctx
->opcode
) << 3);
9029 int do_ra
= ctx
->opcode
& (1 << 6);
9030 int do_s0
= ctx
->opcode
& (1 << 5);
9031 int do_s1
= ctx
->opcode
& (1 << 4);
9032 int framesize
= ctx
->opcode
& 0xf;
9034 if (framesize
== 0) {
9037 framesize
= framesize
<< 3;
9040 if (ctx
->opcode
& (1 << 7)) {
9041 gen_mips16_save(ctx
, 0, 0,
9042 do_ra
, do_s0
, do_s1
, framesize
);
9044 gen_mips16_restore(ctx
, 0, 0,
9045 do_ra
, do_s0
, do_s1
, framesize
);
9051 int rz
= xlat(ctx
->opcode
& 0x7);
9053 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
9054 ((ctx
->opcode
>> 5) & 0x7);
9055 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
9059 reg32
= ctx
->opcode
& 0x1f;
9060 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
9063 generate_exception(ctx
, EXCP_RI
);
9070 int16_t imm
= (uint8_t) ctx
->opcode
;
9072 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
9077 int16_t imm
= (uint8_t) ctx
->opcode
;
9079 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
9082 #if defined(TARGET_MIPS64)
9085 gen_st(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
9089 gen_ld(env
, ctx
, OPC_LB
, ry
, rx
, offset
);
9092 gen_ld(env
, ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
9095 gen_ld(env
, ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
9098 gen_ld(env
, ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
9101 gen_ld(env
, ctx
, OPC_LBU
, ry
, rx
, offset
);
9104 gen_ld(env
, ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
9107 gen_ld(env
, ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
9109 #if defined (TARGET_MIPS64)
9112 gen_ld(env
, ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
9116 gen_st(ctx
, OPC_SB
, ry
, rx
, offset
);
9119 gen_st(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
9122 gen_st(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
9125 gen_st(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
9129 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
9132 switch (ctx
->opcode
& 0x3) {
9134 mips32_op
= OPC_ADDU
;
9137 mips32_op
= OPC_SUBU
;
9139 #if defined(TARGET_MIPS64)
9141 mips32_op
= OPC_DADDU
;
9145 mips32_op
= OPC_DSUBU
;
9150 generate_exception(ctx
, EXCP_RI
);
9154 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
9163 int nd
= (ctx
->opcode
>> 7) & 0x1;
9164 int link
= (ctx
->opcode
>> 6) & 0x1;
9165 int ra
= (ctx
->opcode
>> 5) & 0x1;
9168 op
= nd
? OPC_JALRC
: OPC_JALRS
;
9173 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
9180 /* XXX: not clear which exception should be raised
9181 * when in debug mode...
9183 check_insn(env
, ctx
, ISA_MIPS32
);
9184 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9185 generate_exception(ctx
, EXCP_DBp
);
9187 generate_exception(ctx
, EXCP_DBp
);
9191 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
9194 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
9197 generate_exception(ctx
, EXCP_BREAK
);
9200 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
9203 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
9206 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
9208 #if defined (TARGET_MIPS64)
9211 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
9215 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
9218 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
9221 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
9224 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
9227 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
9230 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
9233 gen_HILO(ctx
, OPC_MFHI
, rx
);
9237 case RR_RY_CNVT_ZEB
:
9238 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9240 case RR_RY_CNVT_ZEH
:
9241 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9243 case RR_RY_CNVT_SEB
:
9244 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9246 case RR_RY_CNVT_SEH
:
9247 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9249 #if defined (TARGET_MIPS64)
9250 case RR_RY_CNVT_ZEW
:
9252 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9254 case RR_RY_CNVT_SEW
:
9256 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
9260 generate_exception(ctx
, EXCP_RI
);
9265 gen_HILO(ctx
, OPC_MFLO
, rx
);
9267 #if defined (TARGET_MIPS64)
9270 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
9274 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
9278 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
9282 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
9286 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
9289 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
9292 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
9295 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
9297 #if defined (TARGET_MIPS64)
9300 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
9304 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
9308 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
9312 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
9316 generate_exception(ctx
, EXCP_RI
);
9320 case M16_OPC_EXTEND
:
9321 decode_extended_mips16_opc(env
, ctx
, is_branch
);
9324 #if defined(TARGET_MIPS64)
9326 funct
= (ctx
->opcode
>> 8) & 0x7;
9327 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
9331 generate_exception(ctx
, EXCP_RI
);
9338 /* microMIPS extension to MIPS32 */
9340 /* microMIPS32 major opcodes */
9379 /* 0x20 is reserved */
9389 /* 0x28 and 0x29 are reserved */
9399 /* 0x30 and 0x31 are reserved */
9409 /* 0x38 and 0x39 are reserved */
9420 /* POOL32A encoding of minor opcode field */
9423 /* These opcodes are distinguished only by bits 9..6; those bits are
9424 * what are recorded below. */
9450 /* The following can be distinguished by their lower 6 bits. */
9456 /* POOL32AXF encoding of minor opcode field extension */
9470 /* bits 13..12 for 0x01 */
9476 /* bits 13..12 for 0x2a */
9482 /* bits 13..12 for 0x32 */
9486 /* bits 15..12 for 0x2c */
9502 /* bits 15..12 for 0x34 */
9510 /* bits 15..12 for 0x3c */
9512 JR
= 0x0, /* alias */
9517 /* bits 15..12 for 0x05 */
9521 /* bits 15..12 for 0x0d */
9531 /* bits 15..12 for 0x15 */
9537 /* bits 15..12 for 0x1d */
9541 /* bits 15..12 for 0x2d */
9546 /* bits 15..12 for 0x35 */
9553 /* POOL32B encoding of minor opcode field (bits 15..12) */
9569 /* POOL32C encoding of minor opcode field (bits 15..12) */
9577 /* 0xa is reserved */
9584 /* 0x6 is reserved */
9590 /* POOL32F encoding of minor opcode field (bits 5..0) */
9593 /* These are the bit 7..6 values */
9604 /* These are the bit 8..6 values */
9648 CABS_COND_FMT
= 0x1c, /* MIPS3D */
9652 /* POOL32Fxf encoding of minor opcode extension field */
9690 /* POOL32I encoding of minor opcode field (bits 25..21) */
9715 /* These overlap and are distinguished by bit16 of the instruction */
9724 /* POOL16A encoding of minor opcode field */
9731 /* POOL16B encoding of minor opcode field */
9738 /* POOL16C encoding of minor opcode field */
9758 /* POOL16D encoding of minor opcode field */
9765 /* POOL16E encoding of minor opcode field */
9772 static int mmreg (int r
)
9774 static const int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
9779 /* Used for 16-bit store instructions. */
9780 static int mmreg2 (int r
)
9782 static const int map
[] = { 0, 17, 2, 3, 4, 5, 6, 7 };
9787 #define uMIPS_RD(op) ((op >> 7) & 0x7)
9788 #define uMIPS_RS(op) ((op >> 4) & 0x7)
9789 #define uMIPS_RS2(op) uMIPS_RS(op)
9790 #define uMIPS_RS1(op) ((op >> 1) & 0x7)
9791 #define uMIPS_RD5(op) ((op >> 5) & 0x1f)
9792 #define uMIPS_RS5(op) (op & 0x1f)
9794 /* Signed immediate */
9795 #define SIMM(op, start, width) \
9796 ((int32_t)(((op >> start) & ((~0U) >> (32-width))) \
9799 /* Zero-extended immediate */
9800 #define ZIMM(op, start, width) ((op >> start) & ((~0U) >> (32-width)))
9802 static void gen_addiur1sp (CPUMIPSState
*env
, DisasContext
*ctx
)
9804 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9806 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, 29, ((ctx
->opcode
>> 1) & 0x3f) << 2);
9809 static void gen_addiur2 (CPUMIPSState
*env
, DisasContext
*ctx
)
9811 static const int decoded_imm
[] = { 1, 4, 8, 12, 16, 20, 24, -1 };
9812 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9813 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9815 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, decoded_imm
[ZIMM(ctx
->opcode
, 1, 3)]);
9818 static void gen_addiusp (CPUMIPSState
*env
, DisasContext
*ctx
)
9820 int encoded
= ZIMM(ctx
->opcode
, 1, 9);
9824 decoded
= 256 + encoded
;
9825 } else if (encoded
<= 255) {
9827 } else if (encoded
<= 509) {
9828 decoded
= encoded
- 512;
9830 decoded
= encoded
- 768;
9833 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, decoded
<< 2);
9836 static void gen_addius5 (CPUMIPSState
*env
, DisasContext
*ctx
)
9838 int imm
= SIMM(ctx
->opcode
, 1, 4);
9839 int rd
= (ctx
->opcode
>> 5) & 0x1f;
9841 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rd
, imm
);
9844 static void gen_andi16 (CPUMIPSState
*env
, DisasContext
*ctx
)
9846 static const int decoded_imm
[] = { 128, 1, 2, 3, 4, 7, 8, 15, 16,
9847 31, 32, 63, 64, 255, 32768, 65535 };
9848 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
9849 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
9850 int encoded
= ZIMM(ctx
->opcode
, 0, 4);
9852 gen_logic_imm(env
, OPC_ANDI
, rd
, rs
, decoded_imm
[encoded
]);
9855 static void gen_ldst_multiple (DisasContext
*ctx
, uint32_t opc
, int reglist
,
9856 int base
, int16_t offset
)
9861 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
9862 generate_exception(ctx
, EXCP_RI
);
9866 t0
= tcg_temp_new();
9868 gen_base_offset_addr(ctx
, t0
, base
, offset
);
9870 t1
= tcg_const_tl(reglist
);
9871 t2
= tcg_const_i32(ctx
->mem_idx
);
9873 save_cpu_state(ctx
, 1);
9876 gen_helper_lwm(cpu_env
, t0
, t1
, t2
);
9879 gen_helper_swm(cpu_env
, t0
, t1
, t2
);
9881 #ifdef TARGET_MIPS64
9883 gen_helper_ldm(cpu_env
, t0
, t1
, t2
);
9886 gen_helper_sdm(cpu_env
, t0
, t1
, t2
);
9890 MIPS_DEBUG("%s, %x, %d(%s)", opn
, reglist
, offset
, regnames
[base
]);
9893 tcg_temp_free_i32(t2
);
9897 static void gen_pool16c_insn (CPUMIPSState
*env
, DisasContext
*ctx
, int *is_branch
)
9899 int rd
= mmreg((ctx
->opcode
>> 3) & 0x7);
9900 int rs
= mmreg(ctx
->opcode
& 0x7);
9903 switch (((ctx
->opcode
) >> 4) & 0x3f) {
9908 gen_logic(env
, OPC_NOR
, rd
, rs
, 0);
9914 gen_logic(env
, OPC_XOR
, rd
, rd
, rs
);
9920 gen_logic(env
, OPC_AND
, rd
, rd
, rs
);
9926 gen_logic(env
, OPC_OR
, rd
, rd
, rs
);
9933 static const int lwm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9934 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9936 gen_ldst_multiple(ctx
, LWM32
, lwm_convert
[(ctx
->opcode
>> 4) & 0x3],
9945 static const int swm_convert
[] = { 0x11, 0x12, 0x13, 0x14 };
9946 int offset
= ZIMM(ctx
->opcode
, 0, 4);
9948 gen_ldst_multiple(ctx
, SWM32
, swm_convert
[(ctx
->opcode
>> 4) & 0x3],
9955 int reg
= ctx
->opcode
& 0x1f;
9957 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9964 int reg
= ctx
->opcode
& 0x1f;
9966 gen_compute_branch(ctx
, OPC_JR
, 2, reg
, 0, 0);
9967 /* Let normal delay slot handling in our caller take us
9968 to the branch target. */
9980 int reg
= ctx
->opcode
& 0x1f;
9982 gen_compute_branch(ctx
, opc
, 2, reg
, 31, 0);
9988 gen_HILO(ctx
, OPC_MFHI
, uMIPS_RS5(ctx
->opcode
));
9992 gen_HILO(ctx
, OPC_MFLO
, uMIPS_RS5(ctx
->opcode
));
9995 generate_exception(ctx
, EXCP_BREAK
);
9998 /* XXX: not clear which exception should be raised
9999 * when in debug mode...
10001 check_insn(env
, ctx
, ISA_MIPS32
);
10002 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
10003 generate_exception(ctx
, EXCP_DBp
);
10005 generate_exception(ctx
, EXCP_DBp
);
10008 case JRADDIUSP
+ 0:
10009 case JRADDIUSP
+ 1:
10011 int imm
= ZIMM(ctx
->opcode
, 0, 5);
10013 gen_compute_branch(ctx
, OPC_JR
, 2, 31, 0, 0);
10014 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
<< 2);
10015 /* Let normal delay slot handling in our caller take us
10016 to the branch target. */
10020 generate_exception(ctx
, EXCP_RI
);
10025 static void gen_ldxs (DisasContext
*ctx
, int base
, int index
, int rd
)
10027 TCGv t0
= tcg_temp_new();
10028 TCGv t1
= tcg_temp_new();
10030 gen_load_gpr(t0
, base
);
10033 gen_load_gpr(t1
, index
);
10034 tcg_gen_shli_tl(t1
, t1
, 2);
10035 gen_op_addr_add(ctx
, t0
, t1
, t0
);
10038 save_cpu_state(ctx
, 0);
10039 op_ld_lw(t1
, t0
, ctx
);
10040 gen_store_gpr(t1
, rd
);
10046 static void gen_ldst_pair (DisasContext
*ctx
, uint32_t opc
, int rd
,
10047 int base
, int16_t offset
)
10049 const char *opn
= "ldst_pair";
10052 if (ctx
->hflags
& MIPS_HFLAG_BMASK
|| rd
== 31) {
10053 generate_exception(ctx
, EXCP_RI
);
10057 t0
= tcg_temp_new();
10058 t1
= tcg_temp_new();
10060 gen_base_offset_addr(ctx
, t0
, base
, offset
);
10065 generate_exception(ctx
, EXCP_RI
);
10068 save_cpu_state(ctx
, 0);
10069 op_ld_lw(t1
, t0
, ctx
);
10070 gen_store_gpr(t1
, rd
);
10071 tcg_gen_movi_tl(t1
, 4);
10072 gen_op_addr_add(ctx
, t0
, t0
, t1
);
10073 op_ld_lw(t1
, t0
, ctx
);
10074 gen_store_gpr(t1
, rd
+1);
10078 save_cpu_state(ctx
, 0);
10079 gen_load_gpr(t1
, rd
);
10080 op_st_sw(t1
, t0
, ctx
);
10081 tcg_gen_movi_tl(t1
, 4);
10082 gen_op_addr_add(ctx
, t0
, t0
, t1
);
10083 gen_load_gpr(t1
, rd
+1);
10084 op_st_sw(t1
, t0
, ctx
);
10087 #ifdef TARGET_MIPS64
10090 generate_exception(ctx
, EXCP_RI
);
10093 save_cpu_state(ctx
, 0);
10094 op_ld_ld(t1
, t0
, ctx
);
10095 gen_store_gpr(t1
, rd
);
10096 tcg_gen_movi_tl(t1
, 8);
10097 gen_op_addr_add(ctx
, t0
, t0
, t1
);
10098 op_ld_ld(t1
, t0
, ctx
);
10099 gen_store_gpr(t1
, rd
+1);
10103 save_cpu_state(ctx
, 0);
10104 gen_load_gpr(t1
, rd
);
10105 op_st_sd(t1
, t0
, ctx
);
10106 tcg_gen_movi_tl(t1
, 8);
10107 gen_op_addr_add(ctx
, t0
, t0
, t1
);
10108 gen_load_gpr(t1
, rd
+1);
10109 op_st_sd(t1
, t0
, ctx
);
10114 (void)opn
; /* avoid a compiler warning */
10115 MIPS_DEBUG("%s, %s, %d(%s)", opn
, regnames
[rd
], offset
, regnames
[base
]);
10120 static void gen_pool32axf (CPUMIPSState
*env
, DisasContext
*ctx
, int rt
, int rs
,
10123 int extension
= (ctx
->opcode
>> 6) & 0x3f;
10124 int minor
= (ctx
->opcode
>> 12) & 0xf;
10125 uint32_t mips32_op
;
10127 switch (extension
) {
10129 mips32_op
= OPC_TEQ
;
10132 mips32_op
= OPC_TGE
;
10135 mips32_op
= OPC_TGEU
;
10138 mips32_op
= OPC_TLT
;
10141 mips32_op
= OPC_TLTU
;
10144 mips32_op
= OPC_TNE
;
10146 gen_trap(ctx
, mips32_op
, rs
, rt
, -1);
10148 #ifndef CONFIG_USER_ONLY
10151 check_cp0_enabled(ctx
);
10153 /* Treat as NOP. */
10156 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rs
, (ctx
->opcode
>> 11) & 0x7);
10160 check_cp0_enabled(ctx
);
10162 TCGv t0
= tcg_temp_new();
10164 gen_load_gpr(t0
, rt
);
10165 gen_mtc0(env
, ctx
, t0
, rs
, (ctx
->opcode
>> 11) & 0x7);
10173 gen_bshfl(ctx
, OPC_SEB
, rs
, rt
);
10176 gen_bshfl(ctx
, OPC_SEH
, rs
, rt
);
10179 mips32_op
= OPC_CLO
;
10182 mips32_op
= OPC_CLZ
;
10184 check_insn(env
, ctx
, ISA_MIPS32
);
10185 gen_cl(ctx
, mips32_op
, rt
, rs
);
10188 gen_rdhwr(env
, ctx
, rt
, rs
);
10191 gen_bshfl(ctx
, OPC_WSBH
, rs
, rt
);
10194 mips32_op
= OPC_MULT
;
10197 mips32_op
= OPC_MULTU
;
10200 mips32_op
= OPC_DIV
;
10203 mips32_op
= OPC_DIVU
;
10206 mips32_op
= OPC_MADD
;
10209 mips32_op
= OPC_MADDU
;
10212 mips32_op
= OPC_MSUB
;
10215 mips32_op
= OPC_MSUBU
;
10217 check_insn(env
, ctx
, ISA_MIPS32
);
10218 gen_muldiv(ctx
, mips32_op
, rs
, rt
);
10221 goto pool32axf_invalid
;
10232 generate_exception_err(ctx
, EXCP_CpU
, 2);
10235 goto pool32axf_invalid
;
10242 gen_compute_branch (ctx
, OPC_JALR
, 4, rs
, rt
, 0);
10247 gen_compute_branch (ctx
, OPC_JALRS
, 4, rs
, rt
, 0);
10251 goto pool32axf_invalid
;
10257 check_cp0_enabled(ctx
);
10258 check_insn(env
, ctx
, ISA_MIPS32R2
);
10259 gen_load_srsgpr(rt
, rs
);
10262 check_cp0_enabled(ctx
);
10263 check_insn(env
, ctx
, ISA_MIPS32R2
);
10264 gen_store_srsgpr(rt
, rs
);
10267 goto pool32axf_invalid
;
10270 #ifndef CONFIG_USER_ONLY
10274 mips32_op
= OPC_TLBP
;
10277 mips32_op
= OPC_TLBR
;
10280 mips32_op
= OPC_TLBWI
;
10283 mips32_op
= OPC_TLBWR
;
10286 mips32_op
= OPC_WAIT
;
10289 mips32_op
= OPC_DERET
;
10292 mips32_op
= OPC_ERET
;
10294 gen_cp0(env
, ctx
, mips32_op
, rt
, rs
);
10297 goto pool32axf_invalid
;
10303 check_cp0_enabled(ctx
);
10305 TCGv t0
= tcg_temp_new();
10307 save_cpu_state(ctx
, 1);
10308 gen_helper_di(t0
, cpu_env
);
10309 gen_store_gpr(t0
, rs
);
10310 /* Stop translation as we may have switched the execution mode */
10311 ctx
->bstate
= BS_STOP
;
10316 check_cp0_enabled(ctx
);
10318 TCGv t0
= tcg_temp_new();
10320 save_cpu_state(ctx
, 1);
10321 gen_helper_ei(t0
, cpu_env
);
10322 gen_store_gpr(t0
, rs
);
10323 /* Stop translation as we may have switched the execution mode */
10324 ctx
->bstate
= BS_STOP
;
10329 goto pool32axf_invalid
;
10339 generate_exception(ctx
, EXCP_SYSCALL
);
10340 ctx
->bstate
= BS_STOP
;
10343 check_insn(env
, ctx
, ISA_MIPS32
);
10344 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
10345 generate_exception(ctx
, EXCP_DBp
);
10347 generate_exception(ctx
, EXCP_DBp
);
10351 goto pool32axf_invalid
;
10357 gen_HILO(ctx
, OPC_MFHI
, rs
);
10360 gen_HILO(ctx
, OPC_MFLO
, rs
);
10363 gen_HILO(ctx
, OPC_MTHI
, rs
);
10366 gen_HILO(ctx
, OPC_MTLO
, rs
);
10369 goto pool32axf_invalid
;
10374 MIPS_INVAL("pool32axf");
10375 generate_exception(ctx
, EXCP_RI
);
10380 /* Values for microMIPS fmt field. Variable-width, depending on which
10381 formats the instruction supports. */
10400 static void gen_pool32fxf (CPUMIPSState
*env
, DisasContext
*ctx
, int rt
, int rs
)
10402 int extension
= (ctx
->opcode
>> 6) & 0x3ff;
10403 uint32_t mips32_op
;
10405 #define FLOAT_1BIT_FMT(opc, fmt) (fmt << 8) | opc
10406 #define FLOAT_2BIT_FMT(opc, fmt) (fmt << 7) | opc
10407 #define COND_FLOAT_MOV(opc, cond) (cond << 7) | opc
10409 switch (extension
) {
10410 case FLOAT_1BIT_FMT(CFC1
, 0):
10411 mips32_op
= OPC_CFC1
;
10413 case FLOAT_1BIT_FMT(CTC1
, 0):
10414 mips32_op
= OPC_CTC1
;
10416 case FLOAT_1BIT_FMT(MFC1
, 0):
10417 mips32_op
= OPC_MFC1
;
10419 case FLOAT_1BIT_FMT(MTC1
, 0):
10420 mips32_op
= OPC_MTC1
;
10422 case FLOAT_1BIT_FMT(MFHC1
, 0):
10423 mips32_op
= OPC_MFHC1
;
10425 case FLOAT_1BIT_FMT(MTHC1
, 0):
10426 mips32_op
= OPC_MTHC1
;
10428 gen_cp1(ctx
, mips32_op
, rt
, rs
);
10431 /* Reciprocal square root */
10432 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_S
):
10433 mips32_op
= OPC_RSQRT_S
;
10435 case FLOAT_1BIT_FMT(RSQRT_FMT
, FMT_SD_D
):
10436 mips32_op
= OPC_RSQRT_D
;
10440 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_S
):
10441 mips32_op
= OPC_SQRT_S
;
10443 case FLOAT_1BIT_FMT(SQRT_FMT
, FMT_SD_D
):
10444 mips32_op
= OPC_SQRT_D
;
10448 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_S
):
10449 mips32_op
= OPC_RECIP_S
;
10451 case FLOAT_1BIT_FMT(RECIP_FMT
, FMT_SD_D
):
10452 mips32_op
= OPC_RECIP_D
;
10456 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_S
):
10457 mips32_op
= OPC_FLOOR_L_S
;
10459 case FLOAT_1BIT_FMT(FLOOR_L
, FMT_SD_D
):
10460 mips32_op
= OPC_FLOOR_L_D
;
10462 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_S
):
10463 mips32_op
= OPC_FLOOR_W_S
;
10465 case FLOAT_1BIT_FMT(FLOOR_W
, FMT_SD_D
):
10466 mips32_op
= OPC_FLOOR_W_D
;
10470 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_S
):
10471 mips32_op
= OPC_CEIL_L_S
;
10473 case FLOAT_1BIT_FMT(CEIL_L
, FMT_SD_D
):
10474 mips32_op
= OPC_CEIL_L_D
;
10476 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_S
):
10477 mips32_op
= OPC_CEIL_W_S
;
10479 case FLOAT_1BIT_FMT(CEIL_W
, FMT_SD_D
):
10480 mips32_op
= OPC_CEIL_W_D
;
10484 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_S
):
10485 mips32_op
= OPC_TRUNC_L_S
;
10487 case FLOAT_1BIT_FMT(TRUNC_L
, FMT_SD_D
):
10488 mips32_op
= OPC_TRUNC_L_D
;
10490 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_S
):
10491 mips32_op
= OPC_TRUNC_W_S
;
10493 case FLOAT_1BIT_FMT(TRUNC_W
, FMT_SD_D
):
10494 mips32_op
= OPC_TRUNC_W_D
;
10498 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_S
):
10499 mips32_op
= OPC_ROUND_L_S
;
10501 case FLOAT_1BIT_FMT(ROUND_L
, FMT_SD_D
):
10502 mips32_op
= OPC_ROUND_L_D
;
10504 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_S
):
10505 mips32_op
= OPC_ROUND_W_S
;
10507 case FLOAT_1BIT_FMT(ROUND_W
, FMT_SD_D
):
10508 mips32_op
= OPC_ROUND_W_D
;
10511 /* Integer to floating-point conversion */
10512 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_S
):
10513 mips32_op
= OPC_CVT_L_S
;
10515 case FLOAT_1BIT_FMT(CVT_L
, FMT_SD_D
):
10516 mips32_op
= OPC_CVT_L_D
;
10518 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_S
):
10519 mips32_op
= OPC_CVT_W_S
;
10521 case FLOAT_1BIT_FMT(CVT_W
, FMT_SD_D
):
10522 mips32_op
= OPC_CVT_W_D
;
10525 /* Paired-foo conversions */
10526 case FLOAT_1BIT_FMT(CVT_S_PL
, 0):
10527 mips32_op
= OPC_CVT_S_PL
;
10529 case FLOAT_1BIT_FMT(CVT_S_PU
, 0):
10530 mips32_op
= OPC_CVT_S_PU
;
10532 case FLOAT_1BIT_FMT(CVT_PW_PS
, 0):
10533 mips32_op
= OPC_CVT_PW_PS
;
10535 case FLOAT_1BIT_FMT(CVT_PS_PW
, 0):
10536 mips32_op
= OPC_CVT_PS_PW
;
10539 /* Floating-point moves */
10540 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_S
):
10541 mips32_op
= OPC_MOV_S
;
10543 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_D
):
10544 mips32_op
= OPC_MOV_D
;
10546 case FLOAT_2BIT_FMT(MOV_FMT
, FMT_SDPS_PS
):
10547 mips32_op
= OPC_MOV_PS
;
10550 /* Absolute value */
10551 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_S
):
10552 mips32_op
= OPC_ABS_S
;
10554 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_D
):
10555 mips32_op
= OPC_ABS_D
;
10557 case FLOAT_2BIT_FMT(ABS_FMT
, FMT_SDPS_PS
):
10558 mips32_op
= OPC_ABS_PS
;
10562 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_S
):
10563 mips32_op
= OPC_NEG_S
;
10565 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_D
):
10566 mips32_op
= OPC_NEG_D
;
10568 case FLOAT_2BIT_FMT(NEG_FMT
, FMT_SDPS_PS
):
10569 mips32_op
= OPC_NEG_PS
;
10572 /* Reciprocal square root step */
10573 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_S
):
10574 mips32_op
= OPC_RSQRT1_S
;
10576 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_D
):
10577 mips32_op
= OPC_RSQRT1_D
;
10579 case FLOAT_2BIT_FMT(RSQRT1_FMT
, FMT_SDPS_PS
):
10580 mips32_op
= OPC_RSQRT1_PS
;
10583 /* Reciprocal step */
10584 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_S
):
10585 mips32_op
= OPC_RECIP1_S
;
10587 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_D
):
10588 mips32_op
= OPC_RECIP1_S
;
10590 case FLOAT_2BIT_FMT(RECIP1_FMT
, FMT_SDPS_PS
):
10591 mips32_op
= OPC_RECIP1_PS
;
10594 /* Conversions from double */
10595 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_S
):
10596 mips32_op
= OPC_CVT_D_S
;
10598 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_W
):
10599 mips32_op
= OPC_CVT_D_W
;
10601 case FLOAT_2BIT_FMT(CVT_D
, FMT_SWL_L
):
10602 mips32_op
= OPC_CVT_D_L
;
10605 /* Conversions from single */
10606 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_D
):
10607 mips32_op
= OPC_CVT_S_D
;
10609 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_W
):
10610 mips32_op
= OPC_CVT_S_W
;
10612 case FLOAT_2BIT_FMT(CVT_S
, FMT_DWL_L
):
10613 mips32_op
= OPC_CVT_S_L
;
10615 gen_farith(ctx
, mips32_op
, -1, rs
, rt
, 0);
10618 /* Conditional moves on floating-point codes */
10619 case COND_FLOAT_MOV(MOVT
, 0):
10620 case COND_FLOAT_MOV(MOVT
, 1):
10621 case COND_FLOAT_MOV(MOVT
, 2):
10622 case COND_FLOAT_MOV(MOVT
, 3):
10623 case COND_FLOAT_MOV(MOVT
, 4):
10624 case COND_FLOAT_MOV(MOVT
, 5):
10625 case COND_FLOAT_MOV(MOVT
, 6):
10626 case COND_FLOAT_MOV(MOVT
, 7):
10627 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 1);
10629 case COND_FLOAT_MOV(MOVF
, 0):
10630 case COND_FLOAT_MOV(MOVF
, 1):
10631 case COND_FLOAT_MOV(MOVF
, 2):
10632 case COND_FLOAT_MOV(MOVF
, 3):
10633 case COND_FLOAT_MOV(MOVF
, 4):
10634 case COND_FLOAT_MOV(MOVF
, 5):
10635 case COND_FLOAT_MOV(MOVF
, 6):
10636 case COND_FLOAT_MOV(MOVF
, 7):
10637 gen_movci(ctx
, rt
, rs
, (ctx
->opcode
>> 13) & 0x7, 0);
10640 MIPS_INVAL("pool32fxf");
10641 generate_exception(ctx
, EXCP_RI
);
10646 static void decode_micromips32_opc (CPUMIPSState
*env
, DisasContext
*ctx
,
10647 uint16_t insn_hw1
, int *is_branch
)
10651 int rt
, rs
, rd
, rr
;
10653 uint32_t op
, minor
, mips32_op
;
10654 uint32_t cond
, fmt
, cc
;
10656 insn
= cpu_lduw_code(env
, ctx
->pc
+ 2);
10657 ctx
->opcode
= (ctx
->opcode
<< 16) | insn
;
10659 rt
= (ctx
->opcode
>> 21) & 0x1f;
10660 rs
= (ctx
->opcode
>> 16) & 0x1f;
10661 rd
= (ctx
->opcode
>> 11) & 0x1f;
10662 rr
= (ctx
->opcode
>> 6) & 0x1f;
10663 imm
= (int16_t) ctx
->opcode
;
10665 op
= (ctx
->opcode
>> 26) & 0x3f;
10668 minor
= ctx
->opcode
& 0x3f;
10671 minor
= (ctx
->opcode
>> 6) & 0xf;
10674 mips32_op
= OPC_SLL
;
10677 mips32_op
= OPC_SRA
;
10680 mips32_op
= OPC_SRL
;
10683 mips32_op
= OPC_ROTR
;
10685 gen_shift_imm(env
, ctx
, mips32_op
, rt
, rs
, rd
);
10688 goto pool32a_invalid
;
10692 minor
= (ctx
->opcode
>> 6) & 0xf;
10696 mips32_op
= OPC_ADD
;
10699 mips32_op
= OPC_ADDU
;
10702 mips32_op
= OPC_SUB
;
10705 mips32_op
= OPC_SUBU
;
10708 mips32_op
= OPC_MUL
;
10710 gen_arith(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10714 mips32_op
= OPC_SLLV
;
10717 mips32_op
= OPC_SRLV
;
10720 mips32_op
= OPC_SRAV
;
10723 mips32_op
= OPC_ROTRV
;
10725 gen_shift(env
, ctx
, mips32_op
, rd
, rs
, rt
);
10727 /* Logical operations */
10729 mips32_op
= OPC_AND
;
10732 mips32_op
= OPC_OR
;
10735 mips32_op
= OPC_NOR
;
10738 mips32_op
= OPC_XOR
;
10740 gen_logic(env
, mips32_op
, rd
, rs
, rt
);
10742 /* Set less than */
10744 mips32_op
= OPC_SLT
;
10747 mips32_op
= OPC_SLTU
;
10749 gen_slt(env
, mips32_op
, rd
, rs
, rt
);
10752 goto pool32a_invalid
;
10756 minor
= (ctx
->opcode
>> 6) & 0xf;
10758 /* Conditional moves */
10760 mips32_op
= OPC_MOVN
;
10763 mips32_op
= OPC_MOVZ
;
10765 gen_cond_move(env
, mips32_op
, rd
, rs
, rt
);
10768 gen_ldxs(ctx
, rs
, rt
, rd
);
10771 goto pool32a_invalid
;
10775 gen_bitops(ctx
, OPC_INS
, rt
, rs
, rr
, rd
);
10778 gen_bitops(ctx
, OPC_EXT
, rt
, rs
, rr
, rd
);
10781 gen_pool32axf(env
, ctx
, rt
, rs
, is_branch
);
10784 generate_exception(ctx
, EXCP_BREAK
);
10788 MIPS_INVAL("pool32a");
10789 generate_exception(ctx
, EXCP_RI
);
10794 minor
= (ctx
->opcode
>> 12) & 0xf;
10797 check_cp0_enabled(ctx
);
10798 /* Treat as no-op. */
10802 /* COP2: Not implemented. */
10803 generate_exception_err(ctx
, EXCP_CpU
, 2);
10807 #ifdef TARGET_MIPS64
10811 gen_ldst_pair(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10815 #ifdef TARGET_MIPS64
10819 gen_ldst_multiple(ctx
, minor
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
10822 MIPS_INVAL("pool32b");
10823 generate_exception(ctx
, EXCP_RI
);
10828 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
10829 minor
= ctx
->opcode
& 0x3f;
10830 check_cp1_enabled(ctx
);
10833 mips32_op
= OPC_ALNV_PS
;
10836 mips32_op
= OPC_MADD_S
;
10839 mips32_op
= OPC_MADD_D
;
10842 mips32_op
= OPC_MADD_PS
;
10845 mips32_op
= OPC_MSUB_S
;
10848 mips32_op
= OPC_MSUB_D
;
10851 mips32_op
= OPC_MSUB_PS
;
10854 mips32_op
= OPC_NMADD_S
;
10857 mips32_op
= OPC_NMADD_D
;
10860 mips32_op
= OPC_NMADD_PS
;
10863 mips32_op
= OPC_NMSUB_S
;
10866 mips32_op
= OPC_NMSUB_D
;
10869 mips32_op
= OPC_NMSUB_PS
;
10871 gen_flt3_arith(ctx
, mips32_op
, rd
, rr
, rs
, rt
);
10873 case CABS_COND_FMT
:
10874 cond
= (ctx
->opcode
>> 6) & 0xf;
10875 cc
= (ctx
->opcode
>> 13) & 0x7;
10876 fmt
= (ctx
->opcode
>> 10) & 0x3;
10879 gen_cmpabs_s(ctx
, cond
, rt
, rs
, cc
);
10882 gen_cmpabs_d(ctx
, cond
, rt
, rs
, cc
);
10885 gen_cmpabs_ps(ctx
, cond
, rt
, rs
, cc
);
10888 goto pool32f_invalid
;
10892 cond
= (ctx
->opcode
>> 6) & 0xf;
10893 cc
= (ctx
->opcode
>> 13) & 0x7;
10894 fmt
= (ctx
->opcode
>> 10) & 0x3;
10897 gen_cmp_s(ctx
, cond
, rt
, rs
, cc
);
10900 gen_cmp_d(ctx
, cond
, rt
, rs
, cc
);
10903 gen_cmp_ps(ctx
, cond
, rt
, rs
, cc
);
10906 goto pool32f_invalid
;
10910 gen_pool32fxf(env
, ctx
, rt
, rs
);
10914 switch ((ctx
->opcode
>> 6) & 0x7) {
10916 mips32_op
= OPC_PLL_PS
;
10919 mips32_op
= OPC_PLU_PS
;
10922 mips32_op
= OPC_PUL_PS
;
10925 mips32_op
= OPC_PUU_PS
;
10928 mips32_op
= OPC_CVT_PS_S
;
10930 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
10933 goto pool32f_invalid
;
10938 switch ((ctx
->opcode
>> 6) & 0x7) {
10940 mips32_op
= OPC_LWXC1
;
10943 mips32_op
= OPC_SWXC1
;
10946 mips32_op
= OPC_LDXC1
;
10949 mips32_op
= OPC_SDXC1
;
10952 mips32_op
= OPC_LUXC1
;
10955 mips32_op
= OPC_SUXC1
;
10957 gen_flt3_ldst(ctx
, mips32_op
, rd
, rd
, rt
, rs
);
10960 goto pool32f_invalid
;
10965 fmt
= (ctx
->opcode
>> 9) & 0x3;
10966 switch ((ctx
->opcode
>> 6) & 0x7) {
10970 mips32_op
= OPC_RSQRT2_S
;
10973 mips32_op
= OPC_RSQRT2_D
;
10976 mips32_op
= OPC_RSQRT2_PS
;
10979 goto pool32f_invalid
;
10985 mips32_op
= OPC_RECIP2_S
;
10988 mips32_op
= OPC_RECIP2_D
;
10991 mips32_op
= OPC_RECIP2_PS
;
10994 goto pool32f_invalid
;
10998 mips32_op
= OPC_ADDR_PS
;
11001 mips32_op
= OPC_MULR_PS
;
11003 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
11006 goto pool32f_invalid
;
11010 /* MOV[FT].fmt and PREFX */
11011 cc
= (ctx
->opcode
>> 13) & 0x7;
11012 fmt
= (ctx
->opcode
>> 9) & 0x3;
11013 switch ((ctx
->opcode
>> 6) & 0x7) {
11017 gen_movcf_s(rs
, rt
, cc
, 0);
11020 gen_movcf_d(ctx
, rs
, rt
, cc
, 0);
11023 gen_movcf_ps(rs
, rt
, cc
, 0);
11026 goto pool32f_invalid
;
11032 gen_movcf_s(rs
, rt
, cc
, 1);
11035 gen_movcf_d(ctx
, rs
, rt
, cc
, 1);
11038 gen_movcf_ps(rs
, rt
, cc
, 1);
11041 goto pool32f_invalid
;
11047 goto pool32f_invalid
;
11050 #define FINSN_3ARG_SDPS(prfx) \
11051 switch ((ctx->opcode >> 8) & 0x3) { \
11053 mips32_op = OPC_##prfx##_S; \
11056 mips32_op = OPC_##prfx##_D; \
11058 case FMT_SDPS_PS: \
11059 mips32_op = OPC_##prfx##_PS; \
11062 goto pool32f_invalid; \
11065 /* regular FP ops */
11066 switch ((ctx
->opcode
>> 6) & 0x3) {
11068 FINSN_3ARG_SDPS(ADD
);
11071 FINSN_3ARG_SDPS(SUB
);
11074 FINSN_3ARG_SDPS(MUL
);
11077 fmt
= (ctx
->opcode
>> 8) & 0x3;
11079 mips32_op
= OPC_DIV_D
;
11080 } else if (fmt
== 0) {
11081 mips32_op
= OPC_DIV_S
;
11083 goto pool32f_invalid
;
11087 goto pool32f_invalid
;
11092 switch ((ctx
->opcode
>> 6) & 0x3) {
11094 FINSN_3ARG_SDPS(MOVN
);
11097 FINSN_3ARG_SDPS(MOVZ
);
11100 goto pool32f_invalid
;
11104 gen_farith(ctx
, mips32_op
, rt
, rs
, rd
, 0);
11108 MIPS_INVAL("pool32f");
11109 generate_exception(ctx
, EXCP_RI
);
11113 generate_exception_err(ctx
, EXCP_CpU
, 1);
11117 minor
= (ctx
->opcode
>> 21) & 0x1f;
11120 mips32_op
= OPC_BLTZ
;
11123 mips32_op
= OPC_BLTZAL
;
11126 mips32_op
= OPC_BLTZALS
;
11129 mips32_op
= OPC_BGEZ
;
11132 mips32_op
= OPC_BGEZAL
;
11135 mips32_op
= OPC_BGEZALS
;
11138 mips32_op
= OPC_BLEZ
;
11141 mips32_op
= OPC_BGTZ
;
11143 gen_compute_branch(ctx
, mips32_op
, 4, rs
, -1, imm
<< 1);
11149 mips32_op
= OPC_TLTI
;
11152 mips32_op
= OPC_TGEI
;
11155 mips32_op
= OPC_TLTIU
;
11158 mips32_op
= OPC_TGEIU
;
11161 mips32_op
= OPC_TNEI
;
11164 mips32_op
= OPC_TEQI
;
11166 gen_trap(ctx
, mips32_op
, rs
, -1, imm
);
11171 gen_compute_branch(ctx
, minor
== BNEZC
? OPC_BNE
: OPC_BEQ
,
11172 4, rs
, 0, imm
<< 1);
11173 /* Compact branches don't have a delay slot, so just let
11174 the normal delay slot handling take us to the branch
11178 gen_logic_imm(env
, OPC_LUI
, rs
, -1, imm
);
11184 /* COP2: Not implemented. */
11185 generate_exception_err(ctx
, EXCP_CpU
, 2);
11188 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1FANY2
: OPC_BC1F
;
11191 mips32_op
= (ctx
->opcode
& (1 << 16)) ? OPC_BC1TANY2
: OPC_BC1T
;
11194 mips32_op
= OPC_BC1FANY4
;
11197 mips32_op
= OPC_BC1TANY4
;
11200 check_insn(env
, ctx
, ASE_MIPS3D
);
11203 gen_compute_branch1(env
, ctx
, mips32_op
,
11204 (ctx
->opcode
>> 18) & 0x7, imm
<< 1);
11209 /* MIPS DSP: not implemented */
11212 MIPS_INVAL("pool32i");
11213 generate_exception(ctx
, EXCP_RI
);
11218 minor
= (ctx
->opcode
>> 12) & 0xf;
11221 mips32_op
= OPC_LWL
;
11224 mips32_op
= OPC_SWL
;
11227 mips32_op
= OPC_LWR
;
11230 mips32_op
= OPC_SWR
;
11232 #if defined(TARGET_MIPS64)
11234 mips32_op
= OPC_LDL
;
11237 mips32_op
= OPC_SDL
;
11240 mips32_op
= OPC_LDR
;
11243 mips32_op
= OPC_SDR
;
11246 mips32_op
= OPC_LWU
;
11249 mips32_op
= OPC_LLD
;
11253 mips32_op
= OPC_LL
;
11256 gen_ld(env
, ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11259 gen_st(ctx
, mips32_op
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11262 gen_st_cond(ctx
, OPC_SC
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11264 #if defined(TARGET_MIPS64)
11266 gen_st_cond(ctx
, OPC_SCD
, rt
, rs
, SIMM(ctx
->opcode
, 0, 12));
11270 /* Treat as no-op */
11273 MIPS_INVAL("pool32c");
11274 generate_exception(ctx
, EXCP_RI
);
11279 mips32_op
= OPC_ADDI
;
11282 mips32_op
= OPC_ADDIU
;
11284 gen_arith_imm(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11287 /* Logical operations */
11289 mips32_op
= OPC_ORI
;
11292 mips32_op
= OPC_XORI
;
11295 mips32_op
= OPC_ANDI
;
11297 gen_logic_imm(env
, mips32_op
, rt
, rs
, imm
);
11300 /* Set less than immediate */
11302 mips32_op
= OPC_SLTI
;
11305 mips32_op
= OPC_SLTIU
;
11307 gen_slt_imm(env
, mips32_op
, rt
, rs
, imm
);
11310 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
11311 gen_compute_branch(ctx
, OPC_JALX
, 4, rt
, rs
, offset
);
11315 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1;
11316 gen_compute_branch(ctx
, OPC_JALS
, 4, rt
, rs
, offset
);
11320 gen_compute_branch(ctx
, OPC_BEQ
, 4, rt
, rs
, imm
<< 1);
11324 gen_compute_branch(ctx
, OPC_BNE
, 4, rt
, rs
, imm
<< 1);
11328 gen_compute_branch(ctx
, OPC_J
, 4, rt
, rs
,
11329 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
11333 gen_compute_branch(ctx
, OPC_JAL
, 4, rt
, rs
,
11334 (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 1);
11337 /* Floating point (COP1) */
11339 mips32_op
= OPC_LWC1
;
11342 mips32_op
= OPC_LDC1
;
11345 mips32_op
= OPC_SWC1
;
11348 mips32_op
= OPC_SDC1
;
11350 gen_cop1_ldst(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11354 int reg
= mmreg(ZIMM(ctx
->opcode
, 23, 3));
11355 int offset
= SIMM(ctx
->opcode
, 0, 23) << 2;
11357 gen_addiupc(ctx
, reg
, offset
, 0, 0);
11360 /* Loads and stores */
11362 mips32_op
= OPC_LB
;
11365 mips32_op
= OPC_LBU
;
11368 mips32_op
= OPC_LH
;
11371 mips32_op
= OPC_LHU
;
11374 mips32_op
= OPC_LW
;
11376 #ifdef TARGET_MIPS64
11378 mips32_op
= OPC_LD
;
11381 mips32_op
= OPC_SD
;
11385 mips32_op
= OPC_SB
;
11388 mips32_op
= OPC_SH
;
11391 mips32_op
= OPC_SW
;
11394 gen_ld(env
, ctx
, mips32_op
, rt
, rs
, imm
);
11397 gen_st(ctx
, mips32_op
, rt
, rs
, imm
);
11400 generate_exception(ctx
, EXCP_RI
);
11405 static int decode_micromips_opc (CPUMIPSState
*env
, DisasContext
*ctx
, int *is_branch
)
11409 /* make sure instructions are on a halfword boundary */
11410 if (ctx
->pc
& 0x1) {
11411 env
->CP0_BadVAddr
= ctx
->pc
;
11412 generate_exception(ctx
, EXCP_AdEL
);
11413 ctx
->bstate
= BS_STOP
;
11417 op
= (ctx
->opcode
>> 10) & 0x3f;
11418 /* Enforce properly-sized instructions in a delay slot */
11419 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
11420 int bits
= ctx
->hflags
& MIPS_HFLAG_BMASK_EXT
;
11454 case POOL48A
: /* ??? */
11459 if (bits
& MIPS_HFLAG_BDS16
) {
11460 generate_exception(ctx
, EXCP_RI
);
11461 /* Just stop translation; the user is confused. */
11462 ctx
->bstate
= BS_STOP
;
11487 if (bits
& MIPS_HFLAG_BDS32
) {
11488 generate_exception(ctx
, EXCP_RI
);
11489 /* Just stop translation; the user is confused. */
11490 ctx
->bstate
= BS_STOP
;
11501 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11502 int rs1
= mmreg(uMIPS_RS1(ctx
->opcode
));
11503 int rs2
= mmreg(uMIPS_RS2(ctx
->opcode
));
11506 switch (ctx
->opcode
& 0x1) {
11515 gen_arith(env
, ctx
, opc
, rd
, rs1
, rs2
);
11520 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11521 int rs
= mmreg(uMIPS_RS(ctx
->opcode
));
11522 int amount
= (ctx
->opcode
>> 1) & 0x7;
11524 amount
= amount
== 0 ? 8 : amount
;
11526 switch (ctx
->opcode
& 0x1) {
11535 gen_shift_imm(env
, ctx
, opc
, rd
, rs
, amount
);
11539 gen_pool16c_insn(env
, ctx
, is_branch
);
11543 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11544 int rb
= 28; /* GP */
11545 int16_t offset
= SIMM(ctx
->opcode
, 0, 7) << 2;
11547 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11551 if (ctx
->opcode
& 1) {
11552 generate_exception(ctx
, EXCP_RI
);
11555 int enc_dest
= uMIPS_RD(ctx
->opcode
);
11556 int enc_rt
= uMIPS_RS2(ctx
->opcode
);
11557 int enc_rs
= uMIPS_RS1(ctx
->opcode
);
11558 int rd
, rs
, re
, rt
;
11559 static const int rd_enc
[] = { 5, 5, 6, 4, 4, 4, 4, 4 };
11560 static const int re_enc
[] = { 6, 7, 7, 21, 22, 5, 6, 7 };
11561 static const int rs_rt_enc
[] = { 0, 17, 2, 3, 16, 18, 19, 20 };
11563 rd
= rd_enc
[enc_dest
];
11564 re
= re_enc
[enc_dest
];
11565 rs
= rs_rt_enc
[enc_rs
];
11566 rt
= rs_rt_enc
[enc_rt
];
11568 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11569 gen_arith_imm(env
, ctx
, OPC_ADDIU
, re
, rt
, 0);
11574 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11575 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11576 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11577 offset
= (offset
== 0xf ? -1 : offset
);
11579 gen_ld(env
, ctx
, OPC_LBU
, rd
, rb
, offset
);
11584 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11585 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11586 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11588 gen_ld(env
, ctx
, OPC_LHU
, rd
, rb
, offset
);
11593 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11594 int rb
= 29; /* SP */
11595 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11597 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11602 int rd
= mmreg(uMIPS_RD(ctx
->opcode
));
11603 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11604 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11606 gen_ld(env
, ctx
, OPC_LW
, rd
, rb
, offset
);
11611 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11612 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11613 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4);
11615 gen_st(ctx
, OPC_SB
, rd
, rb
, offset
);
11620 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11621 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11622 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 1;
11624 gen_st(ctx
, OPC_SH
, rd
, rb
, offset
);
11629 int rd
= (ctx
->opcode
>> 5) & 0x1f;
11630 int rb
= 29; /* SP */
11631 int16_t offset
= ZIMM(ctx
->opcode
, 0, 5) << 2;
11633 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11638 int rd
= mmreg2(uMIPS_RD(ctx
->opcode
));
11639 int rb
= mmreg(uMIPS_RS(ctx
->opcode
));
11640 int16_t offset
= ZIMM(ctx
->opcode
, 0, 4) << 2;
11642 gen_st(ctx
, OPC_SW
, rd
, rb
, offset
);
11647 int rd
= uMIPS_RD5(ctx
->opcode
);
11648 int rs
= uMIPS_RS5(ctx
->opcode
);
11650 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rd
, rs
, 0);
11654 gen_andi16(env
, ctx
);
11657 switch (ctx
->opcode
& 0x1) {
11659 gen_addius5(env
, ctx
);
11662 gen_addiusp(env
, ctx
);
11667 switch (ctx
->opcode
& 0x1) {
11669 gen_addiur2(env
, ctx
);
11672 gen_addiur1sp(env
, ctx
);
11677 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0,
11678 SIMM(ctx
->opcode
, 0, 10) << 1);
11683 gen_compute_branch(ctx
, op
== BNEZ16
? OPC_BNE
: OPC_BEQ
, 2,
11684 mmreg(uMIPS_RD(ctx
->opcode
)),
11685 0, SIMM(ctx
->opcode
, 0, 7) << 1);
11690 int reg
= mmreg(uMIPS_RD(ctx
->opcode
));
11691 int imm
= ZIMM(ctx
->opcode
, 0, 7);
11693 imm
= (imm
== 0x7f ? -1 : imm
);
11694 tcg_gen_movi_tl(cpu_gpr
[reg
], imm
);
11704 generate_exception(ctx
, EXCP_RI
);
11707 decode_micromips32_opc (env
, ctx
, op
, is_branch
);
11714 /* SmartMIPS extension to MIPS32 */
11716 #if defined(TARGET_MIPS64)
11718 /* MDMX extension to MIPS64 */
11722 static void decode_opc (CPUMIPSState
*env
, DisasContext
*ctx
, int *is_branch
)
11725 int rs
, rt
, rd
, sa
;
11726 uint32_t op
, op1
, op2
;
11729 /* make sure instructions are on a word boundary */
11730 if (ctx
->pc
& 0x3) {
11731 env
->CP0_BadVAddr
= ctx
->pc
;
11732 generate_exception(ctx
, EXCP_AdEL
);
11736 /* Handle blikely not taken case */
11737 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
11738 int l1
= gen_new_label();
11740 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
11741 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
11742 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
11743 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
11747 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
11748 tcg_gen_debug_insn_start(ctx
->pc
);
11750 op
= MASK_OP_MAJOR(ctx
->opcode
);
11751 rs
= (ctx
->opcode
>> 21) & 0x1f;
11752 rt
= (ctx
->opcode
>> 16) & 0x1f;
11753 rd
= (ctx
->opcode
>> 11) & 0x1f;
11754 sa
= (ctx
->opcode
>> 6) & 0x1f;
11755 imm
= (int16_t)ctx
->opcode
;
11758 op1
= MASK_SPECIAL(ctx
->opcode
);
11760 case OPC_SLL
: /* Shift with immediate */
11762 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11765 switch ((ctx
->opcode
>> 21) & 0x1f) {
11767 /* rotr is decoded as srl on non-R2 CPUs */
11768 if (env
->insn_flags
& ISA_MIPS32R2
) {
11773 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11776 generate_exception(ctx
, EXCP_RI
);
11780 case OPC_MOVN
: /* Conditional move */
11782 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
|
11783 INSN_LOONGSON2E
| INSN_LOONGSON2F
);
11784 gen_cond_move(env
, op1
, rd
, rs
, rt
);
11786 case OPC_ADD
... OPC_SUBU
:
11787 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11789 case OPC_SLLV
: /* Shifts */
11791 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11794 switch ((ctx
->opcode
>> 6) & 0x1f) {
11796 /* rotrv is decoded as srlv on non-R2 CPUs */
11797 if (env
->insn_flags
& ISA_MIPS32R2
) {
11802 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11805 generate_exception(ctx
, EXCP_RI
);
11809 case OPC_SLT
: /* Set on less than */
11811 gen_slt(env
, op1
, rd
, rs
, rt
);
11813 case OPC_AND
: /* Logic*/
11817 gen_logic(env
, op1
, rd
, rs
, rt
);
11819 case OPC_MULT
... OPC_DIVU
:
11821 check_insn(env
, ctx
, INSN_VR54XX
);
11822 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
11823 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
11825 gen_muldiv(ctx
, op1
, rs
, rt
);
11827 case OPC_JR
... OPC_JALR
:
11828 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
11831 case OPC_TGE
... OPC_TEQ
: /* Traps */
11833 gen_trap(ctx
, op1
, rs
, rt
, -1);
11835 case OPC_MFHI
: /* Move from HI/LO */
11837 gen_HILO(ctx
, op1
, rd
);
11840 case OPC_MTLO
: /* Move to HI/LO */
11841 gen_HILO(ctx
, op1
, rs
);
11843 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
11844 #ifdef MIPS_STRICT_STANDARD
11845 MIPS_INVAL("PMON / selsl");
11846 generate_exception(ctx
, EXCP_RI
);
11848 gen_helper_0e0i(pmon
, sa
);
11852 generate_exception(ctx
, EXCP_SYSCALL
);
11853 ctx
->bstate
= BS_STOP
;
11856 generate_exception(ctx
, EXCP_BREAK
);
11859 #ifdef MIPS_STRICT_STANDARD
11860 MIPS_INVAL("SPIM");
11861 generate_exception(ctx
, EXCP_RI
);
11863 /* Implemented as RI exception for now. */
11864 MIPS_INVAL("spim (unofficial)");
11865 generate_exception(ctx
, EXCP_RI
);
11869 /* Treat as NOP. */
11873 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
11874 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
11875 check_cp1_enabled(ctx
);
11876 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
11877 (ctx
->opcode
>> 16) & 1);
11879 generate_exception_err(ctx
, EXCP_CpU
, 1);
11883 #if defined(TARGET_MIPS64)
11884 /* MIPS64 specific opcodes */
11889 check_insn(env
, ctx
, ISA_MIPS3
);
11890 check_mips_64(ctx
);
11891 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11894 switch ((ctx
->opcode
>> 21) & 0x1f) {
11896 /* drotr is decoded as dsrl on non-R2 CPUs */
11897 if (env
->insn_flags
& ISA_MIPS32R2
) {
11902 check_insn(env
, ctx
, ISA_MIPS3
);
11903 check_mips_64(ctx
);
11904 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11907 generate_exception(ctx
, EXCP_RI
);
11912 switch ((ctx
->opcode
>> 21) & 0x1f) {
11914 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
11915 if (env
->insn_flags
& ISA_MIPS32R2
) {
11920 check_insn(env
, ctx
, ISA_MIPS3
);
11921 check_mips_64(ctx
);
11922 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
11925 generate_exception(ctx
, EXCP_RI
);
11929 case OPC_DADD
... OPC_DSUBU
:
11930 check_insn(env
, ctx
, ISA_MIPS3
);
11931 check_mips_64(ctx
);
11932 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11936 check_insn(env
, ctx
, ISA_MIPS3
);
11937 check_mips_64(ctx
);
11938 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11941 switch ((ctx
->opcode
>> 6) & 0x1f) {
11943 /* drotrv is decoded as dsrlv on non-R2 CPUs */
11944 if (env
->insn_flags
& ISA_MIPS32R2
) {
11949 check_insn(env
, ctx
, ISA_MIPS3
);
11950 check_mips_64(ctx
);
11951 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
11954 generate_exception(ctx
, EXCP_RI
);
11958 case OPC_DMULT
... OPC_DDIVU
:
11959 check_insn(env
, ctx
, ISA_MIPS3
);
11960 check_mips_64(ctx
);
11961 gen_muldiv(ctx
, op1
, rs
, rt
);
11964 default: /* Invalid */
11965 MIPS_INVAL("special");
11966 generate_exception(ctx
, EXCP_RI
);
11971 op1
= MASK_SPECIAL2(ctx
->opcode
);
11973 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
11974 case OPC_MSUB
... OPC_MSUBU
:
11975 check_insn(env
, ctx
, ISA_MIPS32
);
11976 gen_muldiv(ctx
, op1
, rs
, rt
);
11979 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
11983 check_insn(env
, ctx
, ISA_MIPS32
);
11984 gen_cl(ctx
, op1
, rd
, rs
);
11987 /* XXX: not clear which exception should be raised
11988 * when in debug mode...
11990 check_insn(env
, ctx
, ISA_MIPS32
);
11991 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
11992 generate_exception(ctx
, EXCP_DBp
);
11994 generate_exception(ctx
, EXCP_DBp
);
11996 /* Treat as NOP. */
11999 case OPC_DIVU_G_2F
:
12000 case OPC_MULT_G_2F
:
12001 case OPC_MULTU_G_2F
:
12003 case OPC_MODU_G_2F
:
12004 check_insn(env
, ctx
, INSN_LOONGSON2F
);
12005 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
12007 #if defined(TARGET_MIPS64)
12010 check_insn(env
, ctx
, ISA_MIPS64
);
12011 check_mips_64(ctx
);
12012 gen_cl(ctx
, op1
, rd
, rs
);
12014 case OPC_DMULT_G_2F
:
12015 case OPC_DMULTU_G_2F
:
12016 case OPC_DDIV_G_2F
:
12017 case OPC_DDIVU_G_2F
:
12018 case OPC_DMOD_G_2F
:
12019 case OPC_DMODU_G_2F
:
12020 check_insn(env
, ctx
, INSN_LOONGSON2F
);
12021 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
12024 default: /* Invalid */
12025 MIPS_INVAL("special2");
12026 generate_exception(ctx
, EXCP_RI
);
12031 op1
= MASK_SPECIAL3(ctx
->opcode
);
12035 check_insn(env
, ctx
, ISA_MIPS32R2
);
12036 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
12039 check_insn(env
, ctx
, ISA_MIPS32R2
);
12040 op2
= MASK_BSHFL(ctx
->opcode
);
12041 gen_bshfl(ctx
, op2
, rt
, rd
);
12044 gen_rdhwr(env
, ctx
, rt
, rd
);
12047 check_insn(env
, ctx
, ASE_MT
);
12049 TCGv t0
= tcg_temp_new();
12050 TCGv t1
= tcg_temp_new();
12052 gen_load_gpr(t0
, rt
);
12053 gen_load_gpr(t1
, rs
);
12054 gen_helper_fork(t0
, t1
);
12060 check_insn(env
, ctx
, ASE_MT
);
12062 TCGv t0
= tcg_temp_new();
12064 save_cpu_state(ctx
, 1);
12065 gen_load_gpr(t0
, rs
);
12066 gen_helper_yield(t0
, cpu_env
, t0
);
12067 gen_store_gpr(t0
, rd
);
12071 case OPC_DIV_G_2E
... OPC_DIVU_G_2E
:
12072 case OPC_MULT_G_2E
... OPC_MULTU_G_2E
:
12073 case OPC_MOD_G_2E
... OPC_MODU_G_2E
:
12074 check_insn(env
, ctx
, INSN_LOONGSON2E
);
12075 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
12077 #if defined(TARGET_MIPS64)
12078 case OPC_DEXTM
... OPC_DEXT
:
12079 case OPC_DINSM
... OPC_DINS
:
12080 check_insn(env
, ctx
, ISA_MIPS64R2
);
12081 check_mips_64(ctx
);
12082 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
12085 check_insn(env
, ctx
, ISA_MIPS64R2
);
12086 check_mips_64(ctx
);
12087 op2
= MASK_DBSHFL(ctx
->opcode
);
12088 gen_bshfl(ctx
, op2
, rt
, rd
);
12090 case OPC_DDIV_G_2E
... OPC_DDIVU_G_2E
:
12091 case OPC_DMULT_G_2E
... OPC_DMULTU_G_2E
:
12092 case OPC_DMOD_G_2E
... OPC_DMODU_G_2E
:
12093 check_insn(env
, ctx
, INSN_LOONGSON2E
);
12094 gen_loongson_integer(ctx
, op1
, rd
, rs
, rt
);
12097 default: /* Invalid */
12098 MIPS_INVAL("special3");
12099 generate_exception(ctx
, EXCP_RI
);
12104 op1
= MASK_REGIMM(ctx
->opcode
);
12106 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
12107 case OPC_BLTZAL
... OPC_BGEZALL
:
12108 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
12111 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
12113 gen_trap(ctx
, op1
, rs
, -1, imm
);
12116 check_insn(env
, ctx
, ISA_MIPS32R2
);
12117 /* Treat as NOP. */
12119 default: /* Invalid */
12120 MIPS_INVAL("regimm");
12121 generate_exception(ctx
, EXCP_RI
);
12126 check_cp0_enabled(ctx
);
12127 op1
= MASK_CP0(ctx
->opcode
);
12133 #if defined(TARGET_MIPS64)
12137 #ifndef CONFIG_USER_ONLY
12138 gen_cp0(env
, ctx
, op1
, rt
, rd
);
12139 #endif /* !CONFIG_USER_ONLY */
12141 case OPC_C0_FIRST
... OPC_C0_LAST
:
12142 #ifndef CONFIG_USER_ONLY
12143 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
12144 #endif /* !CONFIG_USER_ONLY */
12147 #ifndef CONFIG_USER_ONLY
12149 TCGv t0
= tcg_temp_new();
12151 op2
= MASK_MFMC0(ctx
->opcode
);
12154 check_insn(env
, ctx
, ASE_MT
);
12155 gen_helper_dmt(t0
);
12156 gen_store_gpr(t0
, rt
);
12159 check_insn(env
, ctx
, ASE_MT
);
12160 gen_helper_emt(t0
);
12161 gen_store_gpr(t0
, rt
);
12164 check_insn(env
, ctx
, ASE_MT
);
12165 gen_helper_dvpe(t0
, cpu_env
);
12166 gen_store_gpr(t0
, rt
);
12169 check_insn(env
, ctx
, ASE_MT
);
12170 gen_helper_evpe(t0
, cpu_env
);
12171 gen_store_gpr(t0
, rt
);
12174 check_insn(env
, ctx
, ISA_MIPS32R2
);
12175 save_cpu_state(ctx
, 1);
12176 gen_helper_di(t0
, cpu_env
);
12177 gen_store_gpr(t0
, rt
);
12178 /* Stop translation as we may have switched the execution mode */
12179 ctx
->bstate
= BS_STOP
;
12182 check_insn(env
, ctx
, ISA_MIPS32R2
);
12183 save_cpu_state(ctx
, 1);
12184 gen_helper_ei(t0
, cpu_env
);
12185 gen_store_gpr(t0
, rt
);
12186 /* Stop translation as we may have switched the execution mode */
12187 ctx
->bstate
= BS_STOP
;
12189 default: /* Invalid */
12190 MIPS_INVAL("mfmc0");
12191 generate_exception(ctx
, EXCP_RI
);
12196 #endif /* !CONFIG_USER_ONLY */
12199 check_insn(env
, ctx
, ISA_MIPS32R2
);
12200 gen_load_srsgpr(rt
, rd
);
12203 check_insn(env
, ctx
, ISA_MIPS32R2
);
12204 gen_store_srsgpr(rt
, rd
);
12208 generate_exception(ctx
, EXCP_RI
);
12212 case OPC_ADDI
: /* Arithmetic with immediate opcode */
12214 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
12216 case OPC_SLTI
: /* Set on less than with immediate opcode */
12218 gen_slt_imm(env
, op
, rt
, rs
, imm
);
12220 case OPC_ANDI
: /* Arithmetic with immediate opcode */
12224 gen_logic_imm(env
, op
, rt
, rs
, imm
);
12226 case OPC_J
... OPC_JAL
: /* Jump */
12227 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
12228 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
12231 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
12232 case OPC_BEQL
... OPC_BGTZL
:
12233 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
12236 case OPC_LB
... OPC_LWR
: /* Load and stores */
12238 gen_ld(env
, ctx
, op
, rt
, rs
, imm
);
12240 case OPC_SB
... OPC_SW
:
12242 gen_st(ctx
, op
, rt
, rs
, imm
);
12245 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
12248 check_cp0_enabled(ctx
);
12249 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
12250 /* Treat as NOP. */
12253 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
12254 /* Treat as NOP. */
12257 /* Floating point (COP1). */
12262 gen_cop1_ldst(env
, ctx
, op
, rt
, rs
, imm
);
12266 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12267 check_cp1_enabled(ctx
);
12268 op1
= MASK_CP1(ctx
->opcode
);
12272 check_insn(env
, ctx
, ISA_MIPS32R2
);
12277 gen_cp1(ctx
, op1
, rt
, rd
);
12279 #if defined(TARGET_MIPS64)
12282 check_insn(env
, ctx
, ISA_MIPS3
);
12283 gen_cp1(ctx
, op1
, rt
, rd
);
12289 check_insn(env
, ctx
, ASE_MIPS3D
);
12292 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
12293 (rt
>> 2) & 0x7, imm
<< 2);
12301 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
12306 generate_exception (ctx
, EXCP_RI
);
12310 generate_exception_err(ctx
, EXCP_CpU
, 1);
12320 /* COP2: Not implemented. */
12321 generate_exception_err(ctx
, EXCP_CpU
, 2);
12325 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12326 check_cp1_enabled(ctx
);
12327 op1
= MASK_CP3(ctx
->opcode
);
12335 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
12338 /* Treat as NOP. */
12353 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
12357 generate_exception (ctx
, EXCP_RI
);
12361 generate_exception_err(ctx
, EXCP_CpU
, 1);
12365 #if defined(TARGET_MIPS64)
12366 /* MIPS64 opcodes */
12368 case OPC_LDL
... OPC_LDR
:
12371 check_insn(env
, ctx
, ISA_MIPS3
);
12372 check_mips_64(ctx
);
12373 gen_ld(env
, ctx
, op
, rt
, rs
, imm
);
12375 case OPC_SDL
... OPC_SDR
:
12377 check_insn(env
, ctx
, ISA_MIPS3
);
12378 check_mips_64(ctx
);
12379 gen_st(ctx
, op
, rt
, rs
, imm
);
12382 check_insn(env
, ctx
, ISA_MIPS3
);
12383 check_mips_64(ctx
);
12384 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
12388 check_insn(env
, ctx
, ISA_MIPS3
);
12389 check_mips_64(ctx
);
12390 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
12394 check_insn(env
, ctx
, ASE_MIPS16
| ASE_MICROMIPS
);
12395 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
12396 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
12400 check_insn(env
, ctx
, ASE_MDMX
);
12401 /* MDMX: Not implemented. */
12402 default: /* Invalid */
12403 MIPS_INVAL("major opcode");
12404 generate_exception(ctx
, EXCP_RI
);
12410 gen_intermediate_code_internal (CPUMIPSState
*env
, TranslationBlock
*tb
,
12414 target_ulong pc_start
;
12415 uint16_t *gen_opc_end
;
12424 qemu_log("search pc %d\n", search_pc
);
12427 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
12430 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
12432 ctx
.bstate
= BS_NONE
;
12433 /* Restore delay slot state from the tb context. */
12434 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
12435 restore_cpu_state(env
, &ctx
);
12436 #ifdef CONFIG_USER_ONLY
12437 ctx
.mem_idx
= MIPS_HFLAG_UM
;
12439 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
12442 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
12443 if (max_insns
== 0)
12444 max_insns
= CF_COUNT_MASK
;
12445 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
12446 gen_icount_start();
12447 while (ctx
.bstate
== BS_NONE
) {
12448 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
12449 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
12450 if (bp
->pc
== ctx
.pc
) {
12451 save_cpu_state(&ctx
, 1);
12452 ctx
.bstate
= BS_BRANCH
;
12453 gen_helper_0e0i(raise_exception
, EXCP_DEBUG
);
12454 /* Include the breakpoint location or the tb won't
12455 * be flushed when it must be. */
12457 goto done_generating
;
12463 j
= gen_opc_ptr
- gen_opc_buf
;
12467 gen_opc_instr_start
[lj
++] = 0;
12469 gen_opc_pc
[lj
] = ctx
.pc
;
12470 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
12471 gen_opc_instr_start
[lj
] = 1;
12472 gen_opc_icount
[lj
] = num_insns
;
12474 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
12478 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
12479 ctx
.opcode
= cpu_ldl_code(env
, ctx
.pc
);
12481 decode_opc(env
, &ctx
, &is_branch
);
12482 } else if (env
->insn_flags
& ASE_MICROMIPS
) {
12483 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
12484 insn_bytes
= decode_micromips_opc(env
, &ctx
, &is_branch
);
12485 } else if (env
->insn_flags
& ASE_MIPS16
) {
12486 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
12487 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
12489 generate_exception(&ctx
, EXCP_RI
);
12490 ctx
.bstate
= BS_STOP
;
12494 handle_delay_slot(env
, &ctx
, insn_bytes
);
12496 ctx
.pc
+= insn_bytes
;
12500 /* Execute a branch and its delay slot as a single instruction.
12501 This is what GDB expects and is consistent with what the
12502 hardware does (e.g. if a delay slot instruction faults, the
12503 reported PC is the PC of the branch). */
12504 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
12507 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
12510 if (gen_opc_ptr
>= gen_opc_end
)
12513 if (num_insns
>= max_insns
)
12519 if (tb
->cflags
& CF_LAST_IO
)
12521 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
12522 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
12523 gen_helper_0e0i(raise_exception
, EXCP_DEBUG
);
12525 switch (ctx
.bstate
) {
12527 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12530 save_cpu_state(&ctx
, 0);
12531 gen_goto_tb(&ctx
, 0, ctx
.pc
);
12534 tcg_gen_exit_tb(0);
12542 gen_icount_end(tb
, num_insns
);
12543 *gen_opc_ptr
= INDEX_op_end
;
12545 j
= gen_opc_ptr
- gen_opc_buf
;
12548 gen_opc_instr_start
[lj
++] = 0;
12550 tb
->size
= ctx
.pc
- pc_start
;
12551 tb
->icount
= num_insns
;
12555 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
12556 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
12557 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
12563 void gen_intermediate_code (CPUMIPSState
*env
, struct TranslationBlock
*tb
)
12565 gen_intermediate_code_internal(env
, tb
, 0);
12568 void gen_intermediate_code_pc (CPUMIPSState
*env
, struct TranslationBlock
*tb
)
12570 gen_intermediate_code_internal(env
, tb
, 1);
12573 static void fpu_dump_state(CPUMIPSState
*env
, FILE *f
, fprintf_function fpu_fprintf
,
12577 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
12579 #define printfpr(fp) \
12582 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12583 " fd:%13g fs:%13g psu: %13g\n", \
12584 (fp)->w[FP_ENDIAN_IDX], (fp)->d, \
12585 (double)(fp)->fd, \
12586 (double)(fp)->fs[FP_ENDIAN_IDX], \
12587 (double)(fp)->fs[!FP_ENDIAN_IDX]); \
12590 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
12591 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
12592 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
12593 " fd:%13g fs:%13g psu:%13g\n", \
12594 tmp.w[FP_ENDIAN_IDX], tmp.d, \
12596 (double)tmp.fs[FP_ENDIAN_IDX], \
12597 (double)tmp.fs[!FP_ENDIAN_IDX]); \
12602 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%02x\n",
12603 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
,
12604 get_float_exception_flags(&env
->active_fpu
.fp_status
));
12605 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
12606 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
12607 printfpr(&env
->active_fpu
.fpr
[i
]);
12613 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12614 /* Debug help: The architecture requires 32bit code to maintain proper
12615 sign-extended values on 64bit machines. */
12617 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
12620 cpu_mips_check_sign_extensions (CPUMIPSState
*env
, FILE *f
,
12621 fprintf_function cpu_fprintf
,
12626 if (!SIGN_EXT_P(env
->active_tc
.PC
))
12627 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
12628 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
12629 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
12630 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
12631 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
12632 if (!SIGN_EXT_P(env
->btarget
))
12633 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
12635 for (i
= 0; i
< 32; i
++) {
12636 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
12637 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
12640 if (!SIGN_EXT_P(env
->CP0_EPC
))
12641 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
12642 if (!SIGN_EXT_P(env
->lladdr
))
12643 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
12647 void cpu_dump_state (CPUMIPSState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
12652 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
12653 " LO=0x" TARGET_FMT_lx
" ds %04x "
12654 TARGET_FMT_lx
" " TARGET_FMT_ld
"\n",
12655 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
12656 env
->hflags
, env
->btarget
, env
->bcond
);
12657 for (i
= 0; i
< 32; i
++) {
12659 cpu_fprintf(f
, "GPR%02d:", i
);
12660 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
12662 cpu_fprintf(f
, "\n");
12665 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
12666 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
12667 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
12668 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
12669 if (env
->hflags
& MIPS_HFLAG_FPU
)
12670 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
12671 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
12672 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
12676 static void mips_tcg_init(void)
12681 /* Initialize various static tables. */
12685 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
12686 TCGV_UNUSED(cpu_gpr
[0]);
12687 for (i
= 1; i
< 32; i
++)
12688 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
12689 offsetof(CPUMIPSState
, active_tc
.gpr
[i
]),
12691 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
12692 offsetof(CPUMIPSState
, active_tc
.PC
), "PC");
12693 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
12694 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
12695 offsetof(CPUMIPSState
, active_tc
.HI
[i
]),
12697 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
12698 offsetof(CPUMIPSState
, active_tc
.LO
[i
]),
12700 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
12701 offsetof(CPUMIPSState
, active_tc
.ACX
[i
]),
12704 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
12705 offsetof(CPUMIPSState
, active_tc
.DSPControl
),
12707 bcond
= tcg_global_mem_new(TCG_AREG0
,
12708 offsetof(CPUMIPSState
, bcond
), "bcond");
12709 btarget
= tcg_global_mem_new(TCG_AREG0
,
12710 offsetof(CPUMIPSState
, btarget
), "btarget");
12711 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
12712 offsetof(CPUMIPSState
, hflags
), "hflags");
12714 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
12715 offsetof(CPUMIPSState
, active_fpu
.fcr0
),
12717 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
12718 offsetof(CPUMIPSState
, active_fpu
.fcr31
),
12721 /* register helpers */
12722 #define GEN_HELPER 2
12723 #include "helper.h"
12728 #include "translate_init.c"
12730 MIPSCPU
*cpu_mips_init(const char *cpu_model
)
12734 const mips_def_t
*def
;
12736 def
= cpu_mips_find_by_name(cpu_model
);
12739 cpu
= MIPS_CPU(object_new(TYPE_MIPS_CPU
));
12741 env
->cpu_model
= def
;
12742 env
->cpu_model_str
= cpu_model
;
12744 #ifndef CONFIG_USER_ONLY
12745 mmu_init(env
, def
);
12747 fpu_init(env
, def
);
12748 mvp_init(env
, def
);
12750 cpu_reset(CPU(cpu
));
12751 qemu_init_vcpu(env
);
12755 void cpu_state_reset(CPUMIPSState
*env
)
12757 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
12758 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
12759 log_cpu_state(env
, 0);
12762 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
12765 /* Reset registers to their default values */
12766 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
12767 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
12768 #ifdef TARGET_WORDS_BIGENDIAN
12769 env
->CP0_Config0
|= (1 << CP0C0_BE
);
12771 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
12772 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
12773 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
12774 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
12775 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
12776 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
12777 << env
->cpu_model
->CP0_LLAddr_shift
;
12778 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
12779 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
12780 env
->CCRes
= env
->cpu_model
->CCRes
;
12781 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
12782 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
12783 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
12784 env
->current_tc
= 0;
12785 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
12786 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
12787 #if defined(TARGET_MIPS64)
12788 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
12789 env
->SEGMask
|= 3ULL << 62;
12792 env
->PABITS
= env
->cpu_model
->PABITS
;
12793 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
12794 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
12795 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
12796 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
12797 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
12798 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
12799 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
12800 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
12801 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
12802 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
12803 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
12804 env
->active_fpu
.fcr0
= env
->cpu_model
->CP1_fcr0
;
12805 env
->insn_flags
= env
->cpu_model
->insn_flags
;
12807 #if defined(CONFIG_USER_ONLY)
12808 env
->CP0_Status
= (MIPS_HFLAG_UM
<< CP0St_KSU
);
12809 /* Enable access to the CPUNum, SYNCI_Step, CC, and CCRes RDHWR
12810 hardware registers. */
12811 env
->CP0_HWREna
|= 0x0000000F;
12812 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
12813 env
->CP0_Status
|= (1 << CP0St_CU1
);
12816 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
12817 /* If the exception was raised from a delay slot,
12818 come back to the jump. */
12819 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
12821 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
12823 env
->active_tc
.PC
= (int32_t)0xBFC00000;
12824 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
12825 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
12826 env
->CP0_Wired
= 0;
12827 env
->CP0_EBase
= 0x80000000 | (env
->cpu_index
& 0x3FF);
12828 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
12829 /* vectored interrupts not implemented, timer on int 7,
12830 no performance counters. */
12831 env
->CP0_IntCtl
= 0xe0000000;
12835 for (i
= 0; i
< 7; i
++) {
12836 env
->CP0_WatchLo
[i
] = 0;
12837 env
->CP0_WatchHi
[i
] = 0x80000000;
12839 env
->CP0_WatchLo
[7] = 0;
12840 env
->CP0_WatchHi
[7] = 0;
12842 /* Count register increments in debug mode, EJTAG version 1 */
12843 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
12845 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
12848 /* Only TC0 on VPE 0 starts as active. */
12849 for (i
= 0; i
< ARRAY_SIZE(env
->tcs
); i
++) {
12850 env
->tcs
[i
].CP0_TCBind
= env
->cpu_index
<< CP0TCBd_CurVPE
;
12851 env
->tcs
[i
].CP0_TCHalt
= 1;
12853 env
->active_tc
.CP0_TCHalt
= 1;
12856 if (!env
->cpu_index
) {
12857 /* VPE0 starts up enabled. */
12858 env
->mvp
->CP0_MVPControl
|= (1 << CP0MVPCo_EVP
);
12859 env
->CP0_VPEConf0
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
12861 /* TC0 starts up unhalted. */
12863 env
->active_tc
.CP0_TCHalt
= 0;
12864 env
->tcs
[0].CP0_TCHalt
= 0;
12865 /* With thread 0 active. */
12866 env
->active_tc
.CP0_TCStatus
= (1 << CP0TCSt_A
);
12867 env
->tcs
[0].CP0_TCStatus
= (1 << CP0TCSt_A
);
12871 compute_hflags(env
);
12872 env
->exception_index
= EXCP_NONE
;
12875 void restore_state_to_opc(CPUMIPSState
*env
, TranslationBlock
*tb
, int pc_pos
)
12877 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
12878 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
12879 env
->hflags
|= gen_opc_hflags
[pc_pos
];