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 support)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
33 #include "qemu-common.h"
39 //#define MIPS_DEBUG_DISAS
40 //#define MIPS_DEBUG_SIGN_EXTENSIONS
42 /* MIPS major opcodes */
43 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
46 /* indirect opcode tables */
47 OPC_SPECIAL
= (0x00 << 26),
48 OPC_REGIMM
= (0x01 << 26),
49 OPC_CP0
= (0x10 << 26),
50 OPC_CP1
= (0x11 << 26),
51 OPC_CP2
= (0x12 << 26),
52 OPC_CP3
= (0x13 << 26),
53 OPC_SPECIAL2
= (0x1C << 26),
54 OPC_SPECIAL3
= (0x1F << 26),
55 /* arithmetic with immediate */
56 OPC_ADDI
= (0x08 << 26),
57 OPC_ADDIU
= (0x09 << 26),
58 OPC_SLTI
= (0x0A << 26),
59 OPC_SLTIU
= (0x0B << 26),
60 /* logic with immediate */
61 OPC_ANDI
= (0x0C << 26),
62 OPC_ORI
= (0x0D << 26),
63 OPC_XORI
= (0x0E << 26),
64 OPC_LUI
= (0x0F << 26),
65 /* arithmetic with immediate */
66 OPC_DADDI
= (0x18 << 26),
67 OPC_DADDIU
= (0x19 << 26),
68 /* Jump and branches */
70 OPC_JAL
= (0x03 << 26),
71 OPC_JALS
= OPC_JAL
| 0x5,
72 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
73 OPC_BEQL
= (0x14 << 26),
74 OPC_BNE
= (0x05 << 26),
75 OPC_BNEL
= (0x15 << 26),
76 OPC_BLEZ
= (0x06 << 26),
77 OPC_BLEZL
= (0x16 << 26),
78 OPC_BGTZ
= (0x07 << 26),
79 OPC_BGTZL
= (0x17 << 26),
80 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
81 OPC_JALXS
= OPC_JALX
| 0x5,
83 OPC_LDL
= (0x1A << 26),
84 OPC_LDR
= (0x1B << 26),
85 OPC_LB
= (0x20 << 26),
86 OPC_LH
= (0x21 << 26),
87 OPC_LWL
= (0x22 << 26),
88 OPC_LW
= (0x23 << 26),
89 OPC_LWPC
= OPC_LW
| 0x5,
90 OPC_LBU
= (0x24 << 26),
91 OPC_LHU
= (0x25 << 26),
92 OPC_LWR
= (0x26 << 26),
93 OPC_LWU
= (0x27 << 26),
94 OPC_SB
= (0x28 << 26),
95 OPC_SH
= (0x29 << 26),
96 OPC_SWL
= (0x2A << 26),
97 OPC_SW
= (0x2B << 26),
98 OPC_SDL
= (0x2C << 26),
99 OPC_SDR
= (0x2D << 26),
100 OPC_SWR
= (0x2E << 26),
101 OPC_LL
= (0x30 << 26),
102 OPC_LLD
= (0x34 << 26),
103 OPC_LD
= (0x37 << 26),
104 OPC_LDPC
= OPC_LD
| 0x5,
105 OPC_SC
= (0x38 << 26),
106 OPC_SCD
= (0x3C << 26),
107 OPC_SD
= (0x3F << 26),
108 /* Floating point load/store */
109 OPC_LWC1
= (0x31 << 26),
110 OPC_LWC2
= (0x32 << 26),
111 OPC_LDC1
= (0x35 << 26),
112 OPC_LDC2
= (0x36 << 26),
113 OPC_SWC1
= (0x39 << 26),
114 OPC_SWC2
= (0x3A << 26),
115 OPC_SDC1
= (0x3D << 26),
116 OPC_SDC2
= (0x3E << 26),
117 /* MDMX ASE specific */
118 OPC_MDMX
= (0x1E << 26),
119 /* Cache and prefetch */
120 OPC_CACHE
= (0x2F << 26),
121 OPC_PREF
= (0x33 << 26),
122 /* Reserved major opcode */
123 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
126 /* MIPS special opcodes */
127 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
131 OPC_SLL
= 0x00 | OPC_SPECIAL
,
132 /* NOP is SLL r0, r0, 0 */
133 /* SSNOP is SLL r0, r0, 1 */
134 /* EHB is SLL r0, r0, 3 */
135 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
136 OPC_ROTR
= OPC_SRL
| (1 << 21),
137 OPC_SRA
= 0x03 | OPC_SPECIAL
,
138 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
139 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
140 OPC_ROTRV
= OPC_SRLV
| (1 << 6),
141 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
142 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
143 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
144 OPC_DROTRV
= OPC_DSRLV
| (1 << 6),
145 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
146 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
147 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
148 OPC_DROTR
= OPC_DSRL
| (1 << 21),
149 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
150 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
151 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
152 OPC_DROTR32
= OPC_DSRL32
| (1 << 21),
153 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
154 /* Multiplication / division */
155 OPC_MULT
= 0x18 | OPC_SPECIAL
,
156 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
157 OPC_DIV
= 0x1A | OPC_SPECIAL
,
158 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
159 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
160 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
161 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
162 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
163 /* 2 registers arithmetic / logic */
164 OPC_ADD
= 0x20 | OPC_SPECIAL
,
165 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
166 OPC_SUB
= 0x22 | OPC_SPECIAL
,
167 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
168 OPC_AND
= 0x24 | OPC_SPECIAL
,
169 OPC_OR
= 0x25 | OPC_SPECIAL
,
170 OPC_XOR
= 0x26 | OPC_SPECIAL
,
171 OPC_NOR
= 0x27 | OPC_SPECIAL
,
172 OPC_SLT
= 0x2A | OPC_SPECIAL
,
173 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
174 OPC_DADD
= 0x2C | OPC_SPECIAL
,
175 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
176 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
177 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
179 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
180 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
181 OPC_JALRC
= OPC_JALR
| (0x5 << 6),
182 OPC_JALRS
= 0x10 | OPC_SPECIAL
| (0x5 << 6),
184 OPC_TGE
= 0x30 | OPC_SPECIAL
,
185 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
186 OPC_TLT
= 0x32 | OPC_SPECIAL
,
187 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
188 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
189 OPC_TNE
= 0x36 | OPC_SPECIAL
,
190 /* HI / LO registers load & stores */
191 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
192 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
193 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
194 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
195 /* Conditional moves */
196 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
197 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
199 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
202 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* unofficial */
203 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
204 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
205 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
206 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
208 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
209 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
210 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
211 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
212 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
213 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
214 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
217 /* Multiplication variants of the vr54xx. */
218 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
221 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
222 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
223 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
224 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
225 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
226 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
227 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
228 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
229 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
230 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
231 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
232 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
233 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
234 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
237 /* REGIMM (rt field) opcodes */
238 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
241 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
242 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
243 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
244 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
245 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
246 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
247 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
248 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
249 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
250 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
251 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
252 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
253 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
254 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
255 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
258 /* Special2 opcodes */
259 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
262 /* Multiply & xxx operations */
263 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
264 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
265 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
266 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
267 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
269 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
270 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
271 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
272 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
274 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
277 /* Special3 opcodes */
278 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
281 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
282 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
283 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
284 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
285 OPC_INS
= 0x04 | OPC_SPECIAL3
,
286 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
287 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
288 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
289 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
290 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
291 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
292 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
293 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
297 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
300 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
301 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
302 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
306 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
309 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
310 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
313 /* Coprocessor 0 (rs field) */
314 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
317 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
318 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
319 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
320 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
321 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
322 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
323 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
324 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
325 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
326 OPC_C0
= (0x10 << 21) | OPC_CP0
,
327 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
328 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
332 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
335 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
336 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
337 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
338 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
339 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
340 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
343 /* Coprocessor 0 (with rs == C0) */
344 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
347 OPC_TLBR
= 0x01 | OPC_C0
,
348 OPC_TLBWI
= 0x02 | OPC_C0
,
349 OPC_TLBWR
= 0x06 | OPC_C0
,
350 OPC_TLBP
= 0x08 | OPC_C0
,
351 OPC_RFE
= 0x10 | OPC_C0
,
352 OPC_ERET
= 0x18 | OPC_C0
,
353 OPC_DERET
= 0x1F | OPC_C0
,
354 OPC_WAIT
= 0x20 | OPC_C0
,
357 /* Coprocessor 1 (rs field) */
358 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
360 /* Values for the fmt field in FP instructions */
362 /* 0 - 15 are reserved */
363 FMT_S
= 16, /* single fp */
364 FMT_D
= 17, /* double fp */
365 FMT_E
= 18, /* extended fp */
366 FMT_Q
= 19, /* quad fp */
367 FMT_W
= 20, /* 32-bit fixed */
368 FMT_L
= 21, /* 64-bit fixed */
369 FMT_PS
= 22, /* paired single fp */
370 /* 23 - 31 are reserved */
374 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
375 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
376 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
377 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
378 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
379 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
380 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
381 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
382 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
383 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
384 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
385 OPC_S_FMT
= (FMT_S
<< 21) | OPC_CP1
,
386 OPC_D_FMT
= (FMT_D
<< 21) | OPC_CP1
,
387 OPC_E_FMT
= (FMT_E
<< 21) | OPC_CP1
,
388 OPC_Q_FMT
= (FMT_Q
<< 21) | OPC_CP1
,
389 OPC_W_FMT
= (FMT_W
<< 21) | OPC_CP1
,
390 OPC_L_FMT
= (FMT_L
<< 21) | OPC_CP1
,
391 OPC_PS_FMT
= (FMT_PS
<< 21) | OPC_CP1
,
394 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
395 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
398 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
399 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
400 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
401 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
405 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
406 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
410 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
411 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
414 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
417 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
418 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
419 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
420 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
421 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
422 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
423 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
424 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
425 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
428 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
431 OPC_LWXC1
= 0x00 | OPC_CP3
,
432 OPC_LDXC1
= 0x01 | OPC_CP3
,
433 OPC_LUXC1
= 0x05 | OPC_CP3
,
434 OPC_SWXC1
= 0x08 | OPC_CP3
,
435 OPC_SDXC1
= 0x09 | OPC_CP3
,
436 OPC_SUXC1
= 0x0D | OPC_CP3
,
437 OPC_PREFX
= 0x0F | OPC_CP3
,
438 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
439 OPC_MADD_S
= 0x20 | OPC_CP3
,
440 OPC_MADD_D
= 0x21 | OPC_CP3
,
441 OPC_MADD_PS
= 0x26 | OPC_CP3
,
442 OPC_MSUB_S
= 0x28 | OPC_CP3
,
443 OPC_MSUB_D
= 0x29 | OPC_CP3
,
444 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
445 OPC_NMADD_S
= 0x30 | OPC_CP3
,
446 OPC_NMADD_D
= 0x31 | OPC_CP3
,
447 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
448 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
449 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
450 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
453 /* global register indices */
454 static TCGv_ptr cpu_env
;
455 static TCGv cpu_gpr
[32], cpu_PC
;
456 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
457 static TCGv cpu_dspctrl
, btarget
, bcond
;
458 static TCGv_i32 hflags
;
459 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
461 static uint32_t gen_opc_hflags
[OPC_BUF_SIZE
];
463 #include "gen-icount.h"
465 #define gen_helper_0i(name, arg) do { \
466 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
467 gen_helper_##name(helper_tmp); \
468 tcg_temp_free_i32(helper_tmp); \
471 #define gen_helper_1i(name, arg1, arg2) do { \
472 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
473 gen_helper_##name(arg1, helper_tmp); \
474 tcg_temp_free_i32(helper_tmp); \
477 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
478 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
479 gen_helper_##name(arg1, arg2, helper_tmp); \
480 tcg_temp_free_i32(helper_tmp); \
483 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
484 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
485 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
486 tcg_temp_free_i32(helper_tmp); \
489 typedef struct DisasContext
{
490 struct TranslationBlock
*tb
;
491 target_ulong pc
, saved_pc
;
493 int singlestep_enabled
;
494 /* Routine used to access memory */
496 uint32_t hflags
, saved_hflags
;
498 target_ulong btarget
;
502 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
503 * exception condition */
504 BS_STOP
= 1, /* We want to stop translation for any reason */
505 BS_BRANCH
= 2, /* We reached a branch condition */
506 BS_EXCP
= 3, /* We reached an exception condition */
509 static const char *regnames
[] =
510 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
511 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
512 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
513 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
515 static const char *regnames_HI
[] =
516 { "HI0", "HI1", "HI2", "HI3", };
518 static const char *regnames_LO
[] =
519 { "LO0", "LO1", "LO2", "LO3", };
521 static const char *regnames_ACX
[] =
522 { "ACX0", "ACX1", "ACX2", "ACX3", };
524 static const char *fregnames
[] =
525 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
526 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
527 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
528 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
530 #ifdef MIPS_DEBUG_DISAS
531 #define MIPS_DEBUG(fmt, ...) \
532 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
533 TARGET_FMT_lx ": %08x " fmt "\n", \
534 ctx->pc, ctx->opcode , ## __VA_ARGS__)
535 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
537 #define MIPS_DEBUG(fmt, ...) do { } while(0)
538 #define LOG_DISAS(...) do { } while (0)
541 #define MIPS_INVAL(op) \
543 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
544 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
547 /* General purpose registers moves. */
548 static inline void gen_load_gpr (TCGv t
, int reg
)
551 tcg_gen_movi_tl(t
, 0);
553 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
556 static inline void gen_store_gpr (TCGv t
, int reg
)
559 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
562 /* Moves to/from ACX register. */
563 static inline void gen_load_ACX (TCGv t
, int reg
)
565 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
568 static inline void gen_store_ACX (TCGv t
, int reg
)
570 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
573 /* Moves to/from shadow registers. */
574 static inline void gen_load_srsgpr (int from
, int to
)
576 TCGv t0
= tcg_temp_new();
579 tcg_gen_movi_tl(t0
, 0);
581 TCGv_i32 t2
= tcg_temp_new_i32();
582 TCGv_ptr addr
= tcg_temp_new_ptr();
584 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
585 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
586 tcg_gen_andi_i32(t2
, t2
, 0xf);
587 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
588 tcg_gen_ext_i32_ptr(addr
, t2
);
589 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
591 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
592 tcg_temp_free_ptr(addr
);
593 tcg_temp_free_i32(t2
);
595 gen_store_gpr(t0
, to
);
599 static inline void gen_store_srsgpr (int from
, int to
)
602 TCGv t0
= tcg_temp_new();
603 TCGv_i32 t2
= tcg_temp_new_i32();
604 TCGv_ptr addr
= tcg_temp_new_ptr();
606 gen_load_gpr(t0
, from
);
607 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
608 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
609 tcg_gen_andi_i32(t2
, t2
, 0xf);
610 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
611 tcg_gen_ext_i32_ptr(addr
, t2
);
612 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
614 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
615 tcg_temp_free_ptr(addr
);
616 tcg_temp_free_i32(t2
);
621 /* Floating point register moves. */
622 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
624 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
627 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
629 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
632 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
634 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
637 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
639 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
642 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
644 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
645 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
647 TCGv_i32 t0
= tcg_temp_new_i32();
648 TCGv_i32 t1
= tcg_temp_new_i32();
649 gen_load_fpr32(t0
, reg
& ~1);
650 gen_load_fpr32(t1
, reg
| 1);
651 tcg_gen_concat_i32_i64(t
, t0
, t1
);
652 tcg_temp_free_i32(t0
);
653 tcg_temp_free_i32(t1
);
657 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
659 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
660 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
662 TCGv_i64 t0
= tcg_temp_new_i64();
663 TCGv_i32 t1
= tcg_temp_new_i32();
664 tcg_gen_trunc_i64_i32(t1
, t
);
665 gen_store_fpr32(t1
, reg
& ~1);
666 tcg_gen_shri_i64(t0
, t
, 32);
667 tcg_gen_trunc_i64_i32(t1
, t0
);
668 gen_store_fpr32(t1
, reg
| 1);
669 tcg_temp_free_i32(t1
);
670 tcg_temp_free_i64(t0
);
674 static inline int get_fp_bit (int cc
)
683 static inline void gen_save_pc(target_ulong pc
)
685 tcg_gen_movi_tl(cpu_PC
, pc
);
688 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
690 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
691 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
692 gen_save_pc(ctx
->pc
);
693 ctx
->saved_pc
= ctx
->pc
;
695 if (ctx
->hflags
!= ctx
->saved_hflags
) {
696 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
697 ctx
->saved_hflags
= ctx
->hflags
;
698 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
704 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
710 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
712 ctx
->saved_hflags
= ctx
->hflags
;
713 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
719 ctx
->btarget
= env
->btarget
;
725 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
727 TCGv_i32 texcp
= tcg_const_i32(excp
);
728 TCGv_i32 terr
= tcg_const_i32(err
);
729 save_cpu_state(ctx
, 1);
730 gen_helper_raise_exception_err(texcp
, terr
);
731 tcg_temp_free_i32(terr
);
732 tcg_temp_free_i32(texcp
);
736 generate_exception (DisasContext
*ctx
, int excp
)
738 save_cpu_state(ctx
, 1);
739 gen_helper_0i(raise_exception
, excp
);
742 /* Addresses computation */
743 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
745 tcg_gen_add_tl(ret
, arg0
, arg1
);
747 #if defined(TARGET_MIPS64)
748 /* For compatibility with 32-bit code, data reference in user mode
749 with Status_UX = 0 should be casted to 32-bit and sign extended.
750 See the MIPS64 PRA manual, section 4.10. */
751 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
752 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
753 tcg_gen_ext32s_i64(ret
, ret
);
758 static inline void check_cp0_enabled(DisasContext
*ctx
)
760 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
761 generate_exception_err(ctx
, EXCP_CpU
, 0);
764 static inline void check_cp1_enabled(DisasContext
*ctx
)
766 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
767 generate_exception_err(ctx
, EXCP_CpU
, 1);
770 /* Verify that the processor is running with COP1X instructions enabled.
771 This is associated with the nabla symbol in the MIPS32 and MIPS64
774 static inline void check_cop1x(DisasContext
*ctx
)
776 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
777 generate_exception(ctx
, EXCP_RI
);
780 /* Verify that the processor is running with 64-bit floating-point
781 operations enabled. */
783 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
785 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
786 generate_exception(ctx
, EXCP_RI
);
790 * Verify if floating point register is valid; an operation is not defined
791 * if bit 0 of any register specification is set and the FR bit in the
792 * Status register equals zero, since the register numbers specify an
793 * even-odd pair of adjacent coprocessor general registers. When the FR bit
794 * in the Status register equals one, both even and odd register numbers
795 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
797 * Multiple 64 bit wide registers can be checked by calling
798 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
800 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
802 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
803 generate_exception(ctx
, EXCP_RI
);
806 /* This code generates a "reserved instruction" exception if the
807 CPU does not support the instruction set corresponding to flags. */
808 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
810 if (unlikely(!(env
->insn_flags
& flags
)))
811 generate_exception(ctx
, EXCP_RI
);
814 /* This code generates a "reserved instruction" exception if 64-bit
815 instructions are not enabled. */
816 static inline void check_mips_64(DisasContext
*ctx
)
818 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
819 generate_exception(ctx
, EXCP_RI
);
822 /* Define small wrappers for gen_load_fpr* so that we have a uniform
823 calling interface for 32 and 64-bit FPRs. No sense in changing
824 all callers for gen_load_fpr32 when we need the CTX parameter for
826 #define gen_ldcmp_fpr32(ctx, x, y) gen_load_fpr32(x, y)
827 #define gen_ldcmp_fpr64(ctx, x, y) gen_load_fpr64(ctx, x, y)
828 #define FOP_CONDS(type, abs, fmt, ifmt, bits) \
829 static inline void gen_cmp ## type ## _ ## fmt(DisasContext *ctx, int n, \
830 int ft, int fs, int cc) \
832 TCGv_i##bits fp0 = tcg_temp_new_i##bits (); \
833 TCGv_i##bits fp1 = tcg_temp_new_i##bits (); \
836 check_cp1_64bitmode(ctx); \
842 check_cp1_registers(ctx, fs | ft); \
850 gen_ldcmp_fpr##bits (ctx, fp0, fs); \
851 gen_ldcmp_fpr##bits (ctx, fp1, ft); \
853 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, fp0, fp1, cc); break;\
854 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, fp0, fp1, cc); break;\
855 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, fp0, fp1, cc); break;\
856 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, fp0, fp1, cc); break;\
857 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, fp0, fp1, cc); break;\
858 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, fp0, fp1, cc); break;\
859 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, fp0, fp1, cc); break;\
860 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, fp0, fp1, cc); break;\
861 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, fp0, fp1, cc); break;\
862 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, fp0, fp1, cc); break;\
863 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, fp0, fp1, cc); break;\
864 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, fp0, fp1, cc); break;\
865 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, fp0, fp1, cc); break;\
866 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, fp0, fp1, cc); break;\
867 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, fp0, fp1, cc); break;\
868 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, fp0, fp1, cc); break;\
871 tcg_temp_free_i##bits (fp0); \
872 tcg_temp_free_i##bits (fp1); \
875 FOP_CONDS(, 0, d
, FMT_D
, 64)
876 FOP_CONDS(abs
, 1, d
, FMT_D
, 64)
877 FOP_CONDS(, 0, s
, FMT_S
, 32)
878 FOP_CONDS(abs
, 1, s
, FMT_S
, 32)
879 FOP_CONDS(, 0, ps
, FMT_PS
, 64)
880 FOP_CONDS(abs
, 1, ps
, FMT_PS
, 64)
882 #undef gen_ldcmp_fpr32
883 #undef gen_ldcmp_fpr64
885 /* load/store instructions. */
886 #define OP_LD(insn,fname) \
887 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
889 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
896 #if defined(TARGET_MIPS64)
902 #define OP_ST(insn,fname) \
903 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
905 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
910 #if defined(TARGET_MIPS64)
915 #ifdef CONFIG_USER_ONLY
916 #define OP_LD_ATOMIC(insn,fname) \
917 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
919 TCGv t0 = tcg_temp_new(); \
920 tcg_gen_mov_tl(t0, arg1); \
921 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
922 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
923 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
927 #define OP_LD_ATOMIC(insn,fname) \
928 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
930 gen_helper_2i(insn, ret, arg1, ctx->mem_idx); \
933 OP_LD_ATOMIC(ll
,ld32s
);
934 #if defined(TARGET_MIPS64)
935 OP_LD_ATOMIC(lld
,ld64
);
939 #ifdef CONFIG_USER_ONLY
940 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
941 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
943 TCGv t0 = tcg_temp_new(); \
944 int l1 = gen_new_label(); \
945 int l2 = gen_new_label(); \
947 tcg_gen_andi_tl(t0, arg2, almask); \
948 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
949 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
950 generate_exception(ctx, EXCP_AdES); \
952 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
953 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
954 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
955 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
956 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
957 gen_helper_0i(raise_exception, EXCP_SC); \
959 tcg_gen_movi_tl(t0, 0); \
960 gen_store_gpr(t0, rt); \
964 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
965 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
967 TCGv t0 = tcg_temp_new(); \
968 gen_helper_3i(insn, t0, arg1, arg2, ctx->mem_idx); \
969 gen_store_gpr(t0, rt); \
973 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
974 #if defined(TARGET_MIPS64)
975 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
979 static void gen_base_offset_addr (DisasContext
*ctx
, TCGv addr
,
980 int base
, int16_t offset
)
983 tcg_gen_movi_tl(addr
, offset
);
984 } else if (offset
== 0) {
985 gen_load_gpr(addr
, base
);
987 tcg_gen_movi_tl(addr
, offset
);
988 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
992 static target_ulong
pc_relative_pc (DisasContext
*ctx
)
994 target_ulong pc
= ctx
->pc
;
996 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
997 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
1002 pc
&= ~(target_ulong
)3;
1006 /* Load and store */
1007 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
1008 int base
, int16_t offset
)
1010 const char *opn
= "ldst";
1011 TCGv t0
= tcg_temp_new();
1012 TCGv t1
= tcg_temp_new();
1014 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1015 /* Don't do NOP if destination is zero: we must perform the actual
1018 #if defined(TARGET_MIPS64)
1020 save_cpu_state(ctx
, 0);
1021 op_ldst_lwu(t0
, t0
, ctx
);
1022 gen_store_gpr(t0
, rt
);
1026 save_cpu_state(ctx
, 0);
1027 op_ldst_ld(t0
, t0
, ctx
);
1028 gen_store_gpr(t0
, rt
);
1032 save_cpu_state(ctx
, 0);
1033 op_ldst_lld(t0
, t0
, ctx
);
1034 gen_store_gpr(t0
, rt
);
1038 save_cpu_state(ctx
, 0);
1039 gen_load_gpr(t1
, rt
);
1040 op_ldst_sd(t1
, t0
, ctx
);
1044 save_cpu_state(ctx
, 1);
1045 gen_load_gpr(t1
, rt
);
1046 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1047 gen_store_gpr(t1
, rt
);
1051 save_cpu_state(ctx
, 1);
1052 gen_load_gpr(t1
, rt
);
1053 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1057 save_cpu_state(ctx
, 1);
1058 gen_load_gpr(t1
, rt
);
1059 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1060 gen_store_gpr(t1
, rt
);
1064 save_cpu_state(ctx
, 1);
1065 gen_load_gpr(t1
, rt
);
1066 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1070 save_cpu_state(ctx
, 1);
1071 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1072 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1073 op_ldst_ld(t0
, t0
, ctx
);
1074 gen_store_gpr(t0
, rt
);
1078 save_cpu_state(ctx
, 1);
1079 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1080 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1081 op_ldst_lw(t0
, t0
, ctx
);
1082 gen_store_gpr(t0
, rt
);
1085 save_cpu_state(ctx
, 0);
1086 op_ldst_lw(t0
, t0
, ctx
);
1087 gen_store_gpr(t0
, rt
);
1091 save_cpu_state(ctx
, 0);
1092 gen_load_gpr(t1
, rt
);
1093 op_ldst_sw(t1
, t0
, ctx
);
1097 save_cpu_state(ctx
, 0);
1098 op_ldst_lh(t0
, t0
, ctx
);
1099 gen_store_gpr(t0
, rt
);
1103 save_cpu_state(ctx
, 0);
1104 gen_load_gpr(t1
, rt
);
1105 op_ldst_sh(t1
, t0
, ctx
);
1109 save_cpu_state(ctx
, 0);
1110 op_ldst_lhu(t0
, t0
, ctx
);
1111 gen_store_gpr(t0
, rt
);
1115 save_cpu_state(ctx
, 0);
1116 op_ldst_lb(t0
, t0
, ctx
);
1117 gen_store_gpr(t0
, rt
);
1121 save_cpu_state(ctx
, 0);
1122 gen_load_gpr(t1
, rt
);
1123 op_ldst_sb(t1
, t0
, ctx
);
1127 save_cpu_state(ctx
, 0);
1128 op_ldst_lbu(t0
, t0
, ctx
);
1129 gen_store_gpr(t0
, rt
);
1133 save_cpu_state(ctx
, 1);
1134 gen_load_gpr(t1
, rt
);
1135 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1136 gen_store_gpr(t1
, rt
);
1140 save_cpu_state(ctx
, 1);
1141 gen_load_gpr(t1
, rt
);
1142 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1146 save_cpu_state(ctx
, 1);
1147 gen_load_gpr(t1
, rt
);
1148 gen_helper_3i(lwr
, 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_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1159 save_cpu_state(ctx
, 1);
1160 op_ldst_ll(t0
, t0
, ctx
);
1161 gen_store_gpr(t0
, rt
);
1165 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1170 /* Store conditional */
1171 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1172 int base
, int16_t offset
)
1174 const char *opn
= "st_cond";
1177 t0
= tcg_temp_local_new();
1179 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1180 /* Don't do NOP if destination is zero: we must perform the actual
1183 t1
= tcg_temp_local_new();
1184 gen_load_gpr(t1
, rt
);
1186 #if defined(TARGET_MIPS64)
1188 save_cpu_state(ctx
, 0);
1189 op_ldst_scd(t1
, t0
, rt
, ctx
);
1194 save_cpu_state(ctx
, 1);
1195 op_ldst_sc(t1
, t0
, rt
, ctx
);
1199 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1204 /* Load and store */
1205 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1206 int base
, int16_t offset
)
1208 const char *opn
= "flt_ldst";
1209 TCGv t0
= tcg_temp_new();
1211 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1212 /* Don't do NOP if destination is zero: we must perform the actual
1217 TCGv_i32 fp0
= tcg_temp_new_i32();
1219 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1220 tcg_gen_trunc_tl_i32(fp0
, t0
);
1221 gen_store_fpr32(fp0
, ft
);
1222 tcg_temp_free_i32(fp0
);
1228 TCGv_i32 fp0
= tcg_temp_new_i32();
1229 TCGv t1
= tcg_temp_new();
1231 gen_load_fpr32(fp0
, ft
);
1232 tcg_gen_extu_i32_tl(t1
, fp0
);
1233 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1235 tcg_temp_free_i32(fp0
);
1241 TCGv_i64 fp0
= tcg_temp_new_i64();
1243 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1244 gen_store_fpr64(ctx
, fp0
, ft
);
1245 tcg_temp_free_i64(fp0
);
1251 TCGv_i64 fp0
= tcg_temp_new_i64();
1253 gen_load_fpr64(ctx
, fp0
, ft
);
1254 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1255 tcg_temp_free_i64(fp0
);
1261 generate_exception(ctx
, EXCP_RI
);
1264 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1269 static void gen_cop1_ldst(CPUState
*env
, DisasContext
*ctx
,
1270 uint32_t op
, int rt
, int rs
, int16_t imm
)
1272 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
1273 check_cp1_enabled(ctx
);
1274 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
1276 generate_exception_err(ctx
, EXCP_CpU
, 1);
1280 /* Arithmetic with immediate operand */
1281 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1282 int rt
, int rs
, int16_t imm
)
1284 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1285 const char *opn
= "imm arith";
1287 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1288 /* If no destination, treat it as a NOP.
1289 For addi, we must generate the overflow exception when needed. */
1296 TCGv t0
= tcg_temp_local_new();
1297 TCGv t1
= tcg_temp_new();
1298 TCGv t2
= tcg_temp_new();
1299 int l1
= gen_new_label();
1301 gen_load_gpr(t1
, rs
);
1302 tcg_gen_addi_tl(t0
, t1
, uimm
);
1303 tcg_gen_ext32s_tl(t0
, t0
);
1305 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1306 tcg_gen_xori_tl(t2
, t0
, uimm
);
1307 tcg_gen_and_tl(t1
, t1
, t2
);
1309 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1311 /* operands of same sign, result different sign */
1312 generate_exception(ctx
, EXCP_OVERFLOW
);
1314 tcg_gen_ext32s_tl(t0
, t0
);
1315 gen_store_gpr(t0
, rt
);
1322 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1323 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1325 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1329 #if defined(TARGET_MIPS64)
1332 TCGv t0
= tcg_temp_local_new();
1333 TCGv t1
= tcg_temp_new();
1334 TCGv t2
= tcg_temp_new();
1335 int l1
= gen_new_label();
1337 gen_load_gpr(t1
, rs
);
1338 tcg_gen_addi_tl(t0
, t1
, uimm
);
1340 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1341 tcg_gen_xori_tl(t2
, t0
, uimm
);
1342 tcg_gen_and_tl(t1
, t1
, t2
);
1344 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1346 /* operands of same sign, result different sign */
1347 generate_exception(ctx
, EXCP_OVERFLOW
);
1349 gen_store_gpr(t0
, rt
);
1356 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1358 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1364 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1367 /* Logic with immediate operand */
1368 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1371 const char *opn
= "imm logic";
1374 /* If no destination, treat it as a NOP. */
1378 uimm
= (uint16_t)imm
;
1381 if (likely(rs
!= 0))
1382 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1384 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1389 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1391 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1395 if (likely(rs
!= 0))
1396 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1398 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1402 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1406 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1409 /* Set on less than with immediate operand */
1410 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1412 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1413 const char *opn
= "imm arith";
1417 /* If no destination, treat it as a NOP. */
1421 t0
= tcg_temp_new();
1422 gen_load_gpr(t0
, rs
);
1425 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
1429 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
1433 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1437 /* Shifts with immediate operand */
1438 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1439 int rt
, int rs
, int16_t imm
)
1441 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1442 const char *opn
= "imm shift";
1446 /* If no destination, treat it as a NOP. */
1451 t0
= tcg_temp_new();
1452 gen_load_gpr(t0
, rs
);
1455 tcg_gen_shli_tl(t0
, t0
, uimm
);
1456 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1460 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1465 tcg_gen_ext32u_tl(t0
, t0
);
1466 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1468 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1474 TCGv_i32 t1
= tcg_temp_new_i32();
1476 tcg_gen_trunc_tl_i32(t1
, t0
);
1477 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1478 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1479 tcg_temp_free_i32(t1
);
1481 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1485 #if defined(TARGET_MIPS64)
1487 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1491 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1495 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1500 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1502 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
1507 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1511 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1515 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1519 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1524 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1529 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1530 int rd
, int rs
, int rt
)
1532 const char *opn
= "arith";
1534 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1535 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1536 /* If no destination, treat it as a NOP.
1537 For add & sub, we must generate the overflow exception when needed. */
1545 TCGv t0
= tcg_temp_local_new();
1546 TCGv t1
= tcg_temp_new();
1547 TCGv t2
= tcg_temp_new();
1548 int l1
= gen_new_label();
1550 gen_load_gpr(t1
, rs
);
1551 gen_load_gpr(t2
, rt
);
1552 tcg_gen_add_tl(t0
, t1
, t2
);
1553 tcg_gen_ext32s_tl(t0
, t0
);
1554 tcg_gen_xor_tl(t1
, t1
, t2
);
1555 tcg_gen_xor_tl(t2
, t0
, t2
);
1556 tcg_gen_andc_tl(t1
, t2
, t1
);
1558 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1560 /* operands of same sign, result different sign */
1561 generate_exception(ctx
, EXCP_OVERFLOW
);
1563 gen_store_gpr(t0
, rd
);
1569 if (rs
!= 0 && rt
!= 0) {
1570 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1571 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1572 } else if (rs
== 0 && rt
!= 0) {
1573 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1574 } else if (rs
!= 0 && rt
== 0) {
1575 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1577 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1583 TCGv t0
= tcg_temp_local_new();
1584 TCGv t1
= tcg_temp_new();
1585 TCGv t2
= tcg_temp_new();
1586 int l1
= gen_new_label();
1588 gen_load_gpr(t1
, rs
);
1589 gen_load_gpr(t2
, rt
);
1590 tcg_gen_sub_tl(t0
, t1
, t2
);
1591 tcg_gen_ext32s_tl(t0
, t0
);
1592 tcg_gen_xor_tl(t2
, t1
, t2
);
1593 tcg_gen_xor_tl(t1
, t0
, t1
);
1594 tcg_gen_and_tl(t1
, t1
, t2
);
1596 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1598 /* operands of different sign, first operand and result different sign */
1599 generate_exception(ctx
, EXCP_OVERFLOW
);
1601 gen_store_gpr(t0
, rd
);
1607 if (rs
!= 0 && rt
!= 0) {
1608 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1609 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1610 } else if (rs
== 0 && rt
!= 0) {
1611 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1612 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1613 } else if (rs
!= 0 && rt
== 0) {
1614 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1616 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1620 #if defined(TARGET_MIPS64)
1623 TCGv t0
= tcg_temp_local_new();
1624 TCGv t1
= tcg_temp_new();
1625 TCGv t2
= tcg_temp_new();
1626 int l1
= gen_new_label();
1628 gen_load_gpr(t1
, rs
);
1629 gen_load_gpr(t2
, rt
);
1630 tcg_gen_add_tl(t0
, t1
, t2
);
1631 tcg_gen_xor_tl(t1
, t1
, t2
);
1632 tcg_gen_xor_tl(t2
, t0
, t2
);
1633 tcg_gen_andc_tl(t1
, t2
, t1
);
1635 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1637 /* operands of same sign, result different sign */
1638 generate_exception(ctx
, EXCP_OVERFLOW
);
1640 gen_store_gpr(t0
, rd
);
1646 if (rs
!= 0 && rt
!= 0) {
1647 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1648 } else if (rs
== 0 && rt
!= 0) {
1649 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1650 } else if (rs
!= 0 && rt
== 0) {
1651 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1653 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1659 TCGv t0
= tcg_temp_local_new();
1660 TCGv t1
= tcg_temp_new();
1661 TCGv t2
= tcg_temp_new();
1662 int l1
= gen_new_label();
1664 gen_load_gpr(t1
, rs
);
1665 gen_load_gpr(t2
, rt
);
1666 tcg_gen_sub_tl(t0
, t1
, t2
);
1667 tcg_gen_xor_tl(t2
, t1
, t2
);
1668 tcg_gen_xor_tl(t1
, t0
, t1
);
1669 tcg_gen_and_tl(t1
, t1
, t2
);
1671 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1673 /* operands of different sign, first operand and result different sign */
1674 generate_exception(ctx
, EXCP_OVERFLOW
);
1676 gen_store_gpr(t0
, rd
);
1682 if (rs
!= 0 && rt
!= 0) {
1683 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1684 } else if (rs
== 0 && rt
!= 0) {
1685 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1686 } else if (rs
!= 0 && rt
== 0) {
1687 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1689 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1695 if (likely(rs
!= 0 && rt
!= 0)) {
1696 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1697 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1699 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1704 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1707 /* Conditional move */
1708 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1710 const char *opn
= "cond move";
1714 /* If no destination, treat it as a NOP.
1715 For add & sub, we must generate the overflow exception when needed. */
1720 l1
= gen_new_label();
1723 if (likely(rt
!= 0))
1724 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1730 if (likely(rt
!= 0))
1731 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1736 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1738 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1741 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1745 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1747 const char *opn
= "logic";
1750 /* If no destination, treat it as a NOP. */
1757 if (likely(rs
!= 0 && rt
!= 0)) {
1758 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1760 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1765 if (rs
!= 0 && rt
!= 0) {
1766 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1767 } else if (rs
== 0 && rt
!= 0) {
1768 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1769 } else if (rs
!= 0 && rt
== 0) {
1770 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1772 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1777 if (likely(rs
!= 0 && rt
!= 0)) {
1778 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1779 } else if (rs
== 0 && rt
!= 0) {
1780 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1781 } else if (rs
!= 0 && rt
== 0) {
1782 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1784 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1789 if (likely(rs
!= 0 && rt
!= 0)) {
1790 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1791 } else if (rs
== 0 && rt
!= 0) {
1792 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1793 } else if (rs
!= 0 && rt
== 0) {
1794 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1796 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1801 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1804 /* Set on lower than */
1805 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1807 const char *opn
= "slt";
1811 /* If no destination, treat it as a NOP. */
1816 t0
= tcg_temp_new();
1817 t1
= tcg_temp_new();
1818 gen_load_gpr(t0
, rs
);
1819 gen_load_gpr(t1
, rt
);
1822 tcg_gen_setcond_tl(TCG_COND_LT
, cpu_gpr
[rd
], t0
, t1
);
1826 tcg_gen_setcond_tl(TCG_COND_LTU
, cpu_gpr
[rd
], t0
, t1
);
1830 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1836 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1837 int rd
, int rs
, int rt
)
1839 const char *opn
= "shifts";
1843 /* If no destination, treat it as a NOP.
1844 For add & sub, we must generate the overflow exception when needed. */
1849 t0
= tcg_temp_new();
1850 t1
= tcg_temp_new();
1851 gen_load_gpr(t0
, rs
);
1852 gen_load_gpr(t1
, rt
);
1855 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1856 tcg_gen_shl_tl(t0
, t1
, t0
);
1857 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1861 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1862 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1866 tcg_gen_ext32u_tl(t1
, t1
);
1867 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1868 tcg_gen_shr_tl(t0
, t1
, t0
);
1869 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1874 TCGv_i32 t2
= tcg_temp_new_i32();
1875 TCGv_i32 t3
= tcg_temp_new_i32();
1877 tcg_gen_trunc_tl_i32(t2
, t0
);
1878 tcg_gen_trunc_tl_i32(t3
, t1
);
1879 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1880 tcg_gen_rotr_i32(t2
, t3
, t2
);
1881 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1882 tcg_temp_free_i32(t2
);
1883 tcg_temp_free_i32(t3
);
1887 #if defined(TARGET_MIPS64)
1889 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1890 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1894 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1895 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1899 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1900 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1904 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1905 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1910 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1915 /* Arithmetic on HI/LO registers */
1916 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1918 const char *opn
= "hilo";
1920 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1927 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1931 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1936 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1938 tcg_gen_movi_tl(cpu_HI
[0], 0);
1943 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
1945 tcg_gen_movi_tl(cpu_LO
[0], 0);
1949 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1952 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1955 const char *opn
= "mul/div";
1961 #if defined(TARGET_MIPS64)
1965 t0
= tcg_temp_local_new();
1966 t1
= tcg_temp_local_new();
1969 t0
= tcg_temp_new();
1970 t1
= tcg_temp_new();
1974 gen_load_gpr(t0
, rs
);
1975 gen_load_gpr(t1
, rt
);
1979 int l1
= gen_new_label();
1980 int l2
= gen_new_label();
1982 tcg_gen_ext32s_tl(t0
, t0
);
1983 tcg_gen_ext32s_tl(t1
, t1
);
1984 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1985 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
1986 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
1988 tcg_gen_mov_tl(cpu_LO
[0], t0
);
1989 tcg_gen_movi_tl(cpu_HI
[0], 0);
1992 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
1993 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
1994 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
1995 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2002 int l1
= gen_new_label();
2004 tcg_gen_ext32u_tl(t0
, t0
);
2005 tcg_gen_ext32u_tl(t1
, t1
);
2006 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2007 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2008 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2009 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2010 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2017 TCGv_i64 t2
= tcg_temp_new_i64();
2018 TCGv_i64 t3
= tcg_temp_new_i64();
2020 tcg_gen_ext_tl_i64(t2
, t0
);
2021 tcg_gen_ext_tl_i64(t3
, t1
);
2022 tcg_gen_mul_i64(t2
, t2
, t3
);
2023 tcg_temp_free_i64(t3
);
2024 tcg_gen_trunc_i64_tl(t0
, t2
);
2025 tcg_gen_shri_i64(t2
, t2
, 32);
2026 tcg_gen_trunc_i64_tl(t1
, t2
);
2027 tcg_temp_free_i64(t2
);
2028 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2029 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2035 TCGv_i64 t2
= tcg_temp_new_i64();
2036 TCGv_i64 t3
= tcg_temp_new_i64();
2038 tcg_gen_ext32u_tl(t0
, t0
);
2039 tcg_gen_ext32u_tl(t1
, t1
);
2040 tcg_gen_extu_tl_i64(t2
, t0
);
2041 tcg_gen_extu_tl_i64(t3
, t1
);
2042 tcg_gen_mul_i64(t2
, t2
, t3
);
2043 tcg_temp_free_i64(t3
);
2044 tcg_gen_trunc_i64_tl(t0
, t2
);
2045 tcg_gen_shri_i64(t2
, t2
, 32);
2046 tcg_gen_trunc_i64_tl(t1
, t2
);
2047 tcg_temp_free_i64(t2
);
2048 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2049 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2053 #if defined(TARGET_MIPS64)
2056 int l1
= gen_new_label();
2057 int l2
= gen_new_label();
2059 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2060 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2061 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2062 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2063 tcg_gen_movi_tl(cpu_HI
[0], 0);
2066 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2067 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2074 int l1
= gen_new_label();
2076 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2077 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2078 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2084 gen_helper_dmult(t0
, t1
);
2088 gen_helper_dmultu(t0
, t1
);
2094 TCGv_i64 t2
= tcg_temp_new_i64();
2095 TCGv_i64 t3
= tcg_temp_new_i64();
2097 tcg_gen_ext_tl_i64(t2
, t0
);
2098 tcg_gen_ext_tl_i64(t3
, t1
);
2099 tcg_gen_mul_i64(t2
, t2
, t3
);
2100 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2101 tcg_gen_add_i64(t2
, t2
, t3
);
2102 tcg_temp_free_i64(t3
);
2103 tcg_gen_trunc_i64_tl(t0
, t2
);
2104 tcg_gen_shri_i64(t2
, t2
, 32);
2105 tcg_gen_trunc_i64_tl(t1
, t2
);
2106 tcg_temp_free_i64(t2
);
2107 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2108 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2114 TCGv_i64 t2
= tcg_temp_new_i64();
2115 TCGv_i64 t3
= tcg_temp_new_i64();
2117 tcg_gen_ext32u_tl(t0
, t0
);
2118 tcg_gen_ext32u_tl(t1
, t1
);
2119 tcg_gen_extu_tl_i64(t2
, t0
);
2120 tcg_gen_extu_tl_i64(t3
, t1
);
2121 tcg_gen_mul_i64(t2
, t2
, t3
);
2122 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2123 tcg_gen_add_i64(t2
, t2
, t3
);
2124 tcg_temp_free_i64(t3
);
2125 tcg_gen_trunc_i64_tl(t0
, t2
);
2126 tcg_gen_shri_i64(t2
, t2
, 32);
2127 tcg_gen_trunc_i64_tl(t1
, t2
);
2128 tcg_temp_free_i64(t2
);
2129 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2130 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2136 TCGv_i64 t2
= tcg_temp_new_i64();
2137 TCGv_i64 t3
= tcg_temp_new_i64();
2139 tcg_gen_ext_tl_i64(t2
, t0
);
2140 tcg_gen_ext_tl_i64(t3
, t1
);
2141 tcg_gen_mul_i64(t2
, t2
, t3
);
2142 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2143 tcg_gen_sub_i64(t2
, t3
, t2
);
2144 tcg_temp_free_i64(t3
);
2145 tcg_gen_trunc_i64_tl(t0
, t2
);
2146 tcg_gen_shri_i64(t2
, t2
, 32);
2147 tcg_gen_trunc_i64_tl(t1
, t2
);
2148 tcg_temp_free_i64(t2
);
2149 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2150 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2156 TCGv_i64 t2
= tcg_temp_new_i64();
2157 TCGv_i64 t3
= tcg_temp_new_i64();
2159 tcg_gen_ext32u_tl(t0
, t0
);
2160 tcg_gen_ext32u_tl(t1
, t1
);
2161 tcg_gen_extu_tl_i64(t2
, t0
);
2162 tcg_gen_extu_tl_i64(t3
, t1
);
2163 tcg_gen_mul_i64(t2
, t2
, t3
);
2164 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2165 tcg_gen_sub_i64(t2
, t3
, t2
);
2166 tcg_temp_free_i64(t3
);
2167 tcg_gen_trunc_i64_tl(t0
, t2
);
2168 tcg_gen_shri_i64(t2
, t2
, 32);
2169 tcg_gen_trunc_i64_tl(t1
, t2
);
2170 tcg_temp_free_i64(t2
);
2171 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2172 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2178 generate_exception(ctx
, EXCP_RI
);
2181 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2187 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2188 int rd
, int rs
, int rt
)
2190 const char *opn
= "mul vr54xx";
2191 TCGv t0
= tcg_temp_new();
2192 TCGv t1
= tcg_temp_new();
2194 gen_load_gpr(t0
, rs
);
2195 gen_load_gpr(t1
, rt
);
2198 case OPC_VR54XX_MULS
:
2199 gen_helper_muls(t0
, t0
, t1
);
2202 case OPC_VR54XX_MULSU
:
2203 gen_helper_mulsu(t0
, t0
, t1
);
2206 case OPC_VR54XX_MACC
:
2207 gen_helper_macc(t0
, t0
, t1
);
2210 case OPC_VR54XX_MACCU
:
2211 gen_helper_maccu(t0
, t0
, t1
);
2214 case OPC_VR54XX_MSAC
:
2215 gen_helper_msac(t0
, t0
, t1
);
2218 case OPC_VR54XX_MSACU
:
2219 gen_helper_msacu(t0
, t0
, t1
);
2222 case OPC_VR54XX_MULHI
:
2223 gen_helper_mulhi(t0
, t0
, t1
);
2226 case OPC_VR54XX_MULHIU
:
2227 gen_helper_mulhiu(t0
, t0
, t1
);
2230 case OPC_VR54XX_MULSHI
:
2231 gen_helper_mulshi(t0
, t0
, t1
);
2234 case OPC_VR54XX_MULSHIU
:
2235 gen_helper_mulshiu(t0
, t0
, t1
);
2238 case OPC_VR54XX_MACCHI
:
2239 gen_helper_macchi(t0
, t0
, t1
);
2242 case OPC_VR54XX_MACCHIU
:
2243 gen_helper_macchiu(t0
, t0
, t1
);
2246 case OPC_VR54XX_MSACHI
:
2247 gen_helper_msachi(t0
, t0
, t1
);
2250 case OPC_VR54XX_MSACHIU
:
2251 gen_helper_msachiu(t0
, t0
, t1
);
2255 MIPS_INVAL("mul vr54xx");
2256 generate_exception(ctx
, EXCP_RI
);
2259 gen_store_gpr(t0
, rd
);
2260 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2267 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2270 const char *opn
= "CLx";
2278 t0
= tcg_temp_new();
2279 gen_load_gpr(t0
, rs
);
2282 gen_helper_clo(cpu_gpr
[rd
], t0
);
2286 gen_helper_clz(cpu_gpr
[rd
], t0
);
2289 #if defined(TARGET_MIPS64)
2291 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2295 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2300 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2305 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2306 int rs
, int rt
, int16_t imm
)
2309 TCGv t0
= tcg_temp_new();
2310 TCGv t1
= tcg_temp_new();
2313 /* Load needed operands */
2321 /* Compare two registers */
2323 gen_load_gpr(t0
, rs
);
2324 gen_load_gpr(t1
, rt
);
2334 /* Compare register to immediate */
2335 if (rs
!= 0 || imm
!= 0) {
2336 gen_load_gpr(t0
, rs
);
2337 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2344 case OPC_TEQ
: /* rs == rs */
2345 case OPC_TEQI
: /* r0 == 0 */
2346 case OPC_TGE
: /* rs >= rs */
2347 case OPC_TGEI
: /* r0 >= 0 */
2348 case OPC_TGEU
: /* rs >= rs unsigned */
2349 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2351 generate_exception(ctx
, EXCP_TRAP
);
2353 case OPC_TLT
: /* rs < rs */
2354 case OPC_TLTI
: /* r0 < 0 */
2355 case OPC_TLTU
: /* rs < rs unsigned */
2356 case OPC_TLTIU
: /* r0 < 0 unsigned */
2357 case OPC_TNE
: /* rs != rs */
2358 case OPC_TNEI
: /* r0 != 0 */
2359 /* Never trap: treat as NOP. */
2363 int l1
= gen_new_label();
2368 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2372 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2376 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2380 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2384 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2388 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2391 generate_exception(ctx
, EXCP_TRAP
);
2398 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2400 TranslationBlock
*tb
;
2402 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2403 likely(!ctx
->singlestep_enabled
)) {
2406 tcg_gen_exit_tb((long)tb
+ n
);
2409 if (ctx
->singlestep_enabled
) {
2410 save_cpu_state(ctx
, 0);
2411 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
2417 /* Branches (before delay slot) */
2418 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2420 int rs
, int rt
, int32_t offset
)
2422 target_ulong btgt
= -1;
2424 int bcond_compute
= 0;
2425 TCGv t0
= tcg_temp_new();
2426 TCGv t1
= tcg_temp_new();
2428 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2429 #ifdef MIPS_DEBUG_DISAS
2430 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2432 generate_exception(ctx
, EXCP_RI
);
2436 /* Load needed operands */
2442 /* Compare two registers */
2444 gen_load_gpr(t0
, rs
);
2445 gen_load_gpr(t1
, rt
);
2448 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2462 /* Compare to zero */
2464 gen_load_gpr(t0
, rs
);
2467 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2474 /* Jump to immediate */
2475 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
2481 /* Jump to register */
2482 if (offset
!= 0 && offset
!= 16) {
2483 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2484 others are reserved. */
2485 MIPS_INVAL("jump hint");
2486 generate_exception(ctx
, EXCP_RI
);
2489 gen_load_gpr(btarget
, rs
);
2492 MIPS_INVAL("branch/jump");
2493 generate_exception(ctx
, EXCP_RI
);
2496 if (bcond_compute
== 0) {
2497 /* No condition to be computed */
2499 case OPC_BEQ
: /* rx == rx */
2500 case OPC_BEQL
: /* rx == rx likely */
2501 case OPC_BGEZ
: /* 0 >= 0 */
2502 case OPC_BGEZL
: /* 0 >= 0 likely */
2503 case OPC_BLEZ
: /* 0 <= 0 */
2504 case OPC_BLEZL
: /* 0 <= 0 likely */
2506 ctx
->hflags
|= MIPS_HFLAG_B
;
2507 MIPS_DEBUG("balways");
2509 case OPC_BGEZAL
: /* 0 >= 0 */
2510 case OPC_BGEZALL
: /* 0 >= 0 likely */
2511 /* Always take and link */
2513 ctx
->hflags
|= MIPS_HFLAG_B
;
2514 MIPS_DEBUG("balways and link");
2516 case OPC_BNE
: /* rx != rx */
2517 case OPC_BGTZ
: /* 0 > 0 */
2518 case OPC_BLTZ
: /* 0 < 0 */
2520 MIPS_DEBUG("bnever (NOP)");
2522 case OPC_BLTZAL
: /* 0 < 0 */
2523 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2524 MIPS_DEBUG("bnever and link");
2526 case OPC_BLTZALL
: /* 0 < 0 likely */
2527 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2528 /* Skip the instruction in the delay slot */
2529 MIPS_DEBUG("bnever, link and skip");
2532 case OPC_BNEL
: /* rx != rx likely */
2533 case OPC_BGTZL
: /* 0 > 0 likely */
2534 case OPC_BLTZL
: /* 0 < 0 likely */
2535 /* Skip the instruction in the delay slot */
2536 MIPS_DEBUG("bnever and skip");
2540 ctx
->hflags
|= MIPS_HFLAG_B
;
2541 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2545 ctx
->hflags
|= MIPS_HFLAG_BX
;
2550 ctx
->hflags
|= MIPS_HFLAG_B
;
2551 ctx
->hflags
|= ((opc
== OPC_JALS
|| opc
== OPC_JALXS
)
2553 : MIPS_HFLAG_BDS32
);
2554 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2557 ctx
->hflags
|= MIPS_HFLAG_BR
;
2558 if (insn_bytes
== 4)
2559 ctx
->hflags
|= MIPS_HFLAG_BDS32
;
2560 MIPS_DEBUG("jr %s", regnames
[rs
]);
2566 ctx
->hflags
|= MIPS_HFLAG_BR
;
2567 ctx
->hflags
|= (opc
== OPC_JALRS
2569 : MIPS_HFLAG_BDS32
);
2570 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2573 MIPS_INVAL("branch/jump");
2574 generate_exception(ctx
, EXCP_RI
);
2580 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2581 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2582 regnames
[rs
], regnames
[rt
], btgt
);
2585 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2586 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2587 regnames
[rs
], regnames
[rt
], btgt
);
2590 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2591 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2592 regnames
[rs
], regnames
[rt
], btgt
);
2595 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2596 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2597 regnames
[rs
], regnames
[rt
], btgt
);
2600 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2601 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2604 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2605 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2608 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2609 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2613 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2615 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2618 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2619 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2622 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2623 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2626 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2627 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2630 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2631 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2634 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2635 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2638 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2639 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2642 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2644 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2646 ctx
->hflags
|= MIPS_HFLAG_BC
;
2649 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2651 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2653 ctx
->hflags
|= MIPS_HFLAG_BL
;
2656 MIPS_INVAL("conditional branch/jump");
2657 generate_exception(ctx
, EXCP_RI
);
2661 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2662 blink
, ctx
->hflags
, btgt
);
2664 ctx
->btarget
= btgt
;
2666 int post_delay
= insn_bytes
;
2667 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
2669 if (opc
!= OPC_JALRC
)
2670 post_delay
+= ((ctx
->hflags
& MIPS_HFLAG_BDS16
) ? 2 : 4);
2672 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ post_delay
+ lowbit
);
2676 if (insn_bytes
== 2)
2677 ctx
->hflags
|= MIPS_HFLAG_B16
;
2682 /* special3 bitfield operations */
2683 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2684 int rs
, int lsb
, int msb
)
2686 TCGv t0
= tcg_temp_new();
2687 TCGv t1
= tcg_temp_new();
2690 gen_load_gpr(t1
, rs
);
2695 tcg_gen_shri_tl(t0
, t1
, lsb
);
2697 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2699 tcg_gen_ext32s_tl(t0
, t0
);
2702 #if defined(TARGET_MIPS64)
2704 tcg_gen_shri_tl(t0
, t1
, lsb
);
2706 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2710 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2711 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2714 tcg_gen_shri_tl(t0
, t1
, lsb
);
2715 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2721 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2722 gen_load_gpr(t0
, rt
);
2723 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2724 tcg_gen_shli_tl(t1
, t1
, lsb
);
2725 tcg_gen_andi_tl(t1
, t1
, mask
);
2726 tcg_gen_or_tl(t0
, t0
, t1
);
2727 tcg_gen_ext32s_tl(t0
, t0
);
2729 #if defined(TARGET_MIPS64)
2733 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2734 gen_load_gpr(t0
, rt
);
2735 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2736 tcg_gen_shli_tl(t1
, t1
, lsb
);
2737 tcg_gen_andi_tl(t1
, t1
, mask
);
2738 tcg_gen_or_tl(t0
, t0
, t1
);
2743 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2744 gen_load_gpr(t0
, rt
);
2745 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2746 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2747 tcg_gen_andi_tl(t1
, t1
, mask
);
2748 tcg_gen_or_tl(t0
, t0
, t1
);
2753 gen_load_gpr(t0
, rt
);
2754 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2755 gen_load_gpr(t0
, rt
);
2756 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2757 tcg_gen_shli_tl(t1
, t1
, lsb
);
2758 tcg_gen_andi_tl(t1
, t1
, mask
);
2759 tcg_gen_or_tl(t0
, t0
, t1
);
2764 MIPS_INVAL("bitops");
2765 generate_exception(ctx
, EXCP_RI
);
2770 gen_store_gpr(t0
, rt
);
2775 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2780 /* If no destination, treat it as a NOP. */
2785 t0
= tcg_temp_new();
2786 gen_load_gpr(t0
, rt
);
2790 TCGv t1
= tcg_temp_new();
2792 tcg_gen_shri_tl(t1
, t0
, 8);
2793 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2794 tcg_gen_shli_tl(t0
, t0
, 8);
2795 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2796 tcg_gen_or_tl(t0
, t0
, t1
);
2798 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2802 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2805 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2807 #if defined(TARGET_MIPS64)
2810 TCGv t1
= tcg_temp_new();
2812 tcg_gen_shri_tl(t1
, t0
, 8);
2813 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2814 tcg_gen_shli_tl(t0
, t0
, 8);
2815 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2816 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2822 TCGv t1
= tcg_temp_new();
2824 tcg_gen_shri_tl(t1
, t0
, 16);
2825 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2826 tcg_gen_shli_tl(t0
, t0
, 16);
2827 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2828 tcg_gen_or_tl(t0
, t0
, t1
);
2829 tcg_gen_shri_tl(t1
, t0
, 32);
2830 tcg_gen_shli_tl(t0
, t0
, 32);
2831 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2837 MIPS_INVAL("bsfhl");
2838 generate_exception(ctx
, EXCP_RI
);
2845 #ifndef CONFIG_USER_ONLY
2846 /* CP0 (MMU and control) */
2847 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
2849 TCGv_i32 t0
= tcg_temp_new_i32();
2851 tcg_gen_ld_i32(t0
, cpu_env
, off
);
2852 tcg_gen_ext_i32_tl(arg
, t0
);
2853 tcg_temp_free_i32(t0
);
2856 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
2858 tcg_gen_ld_tl(arg
, cpu_env
, off
);
2859 tcg_gen_ext32s_tl(arg
, arg
);
2862 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
2864 TCGv_i32 t0
= tcg_temp_new_i32();
2866 tcg_gen_trunc_tl_i32(t0
, arg
);
2867 tcg_gen_st_i32(t0
, cpu_env
, off
);
2868 tcg_temp_free_i32(t0
);
2871 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
2873 tcg_gen_ext32s_tl(arg
, arg
);
2874 tcg_gen_st_tl(arg
, cpu_env
, off
);
2877 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
2879 const char *rn
= "invalid";
2882 check_insn(env
, ctx
, ISA_MIPS32
);
2888 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
2892 check_insn(env
, ctx
, ASE_MT
);
2893 gen_helper_mfc0_mvpcontrol(arg
);
2897 check_insn(env
, ctx
, ASE_MT
);
2898 gen_helper_mfc0_mvpconf0(arg
);
2902 check_insn(env
, ctx
, ASE_MT
);
2903 gen_helper_mfc0_mvpconf1(arg
);
2913 gen_helper_mfc0_random(arg
);
2917 check_insn(env
, ctx
, ASE_MT
);
2918 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
2922 check_insn(env
, ctx
, ASE_MT
);
2923 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
2927 check_insn(env
, ctx
, ASE_MT
);
2928 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
2932 check_insn(env
, ctx
, ASE_MT
);
2933 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
2937 check_insn(env
, ctx
, ASE_MT
);
2938 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
2942 check_insn(env
, ctx
, ASE_MT
);
2943 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
2944 rn
= "VPEScheFBack";
2947 check_insn(env
, ctx
, ASE_MT
);
2948 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
2958 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2959 tcg_gen_ext32s_tl(arg
, arg
);
2963 check_insn(env
, ctx
, ASE_MT
);
2964 gen_helper_mfc0_tcstatus(arg
);
2968 check_insn(env
, ctx
, ASE_MT
);
2969 gen_helper_mfc0_tcbind(arg
);
2973 check_insn(env
, ctx
, ASE_MT
);
2974 gen_helper_mfc0_tcrestart(arg
);
2978 check_insn(env
, ctx
, ASE_MT
);
2979 gen_helper_mfc0_tchalt(arg
);
2983 check_insn(env
, ctx
, ASE_MT
);
2984 gen_helper_mfc0_tccontext(arg
);
2988 check_insn(env
, ctx
, ASE_MT
);
2989 gen_helper_mfc0_tcschedule(arg
);
2993 check_insn(env
, ctx
, ASE_MT
);
2994 gen_helper_mfc0_tcschefback(arg
);
3004 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
3005 tcg_gen_ext32s_tl(arg
, arg
);
3015 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
3016 tcg_gen_ext32s_tl(arg
, arg
);
3020 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3021 rn
= "ContextConfig";
3030 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
3034 check_insn(env
, ctx
, ISA_MIPS32R2
);
3035 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
3045 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
3049 check_insn(env
, ctx
, ISA_MIPS32R2
);
3050 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3054 check_insn(env
, ctx
, ISA_MIPS32R2
);
3055 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3059 check_insn(env
, ctx
, ISA_MIPS32R2
);
3060 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3064 check_insn(env
, ctx
, ISA_MIPS32R2
);
3065 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3069 check_insn(env
, ctx
, ISA_MIPS32R2
);
3070 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3080 check_insn(env
, ctx
, ISA_MIPS32R2
);
3081 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3091 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3092 tcg_gen_ext32s_tl(arg
, arg
);
3102 /* Mark as an IO operation because we read the time. */
3105 gen_helper_mfc0_count(arg
);
3108 ctx
->bstate
= BS_STOP
;
3112 /* 6,7 are implementation dependent */
3120 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3121 tcg_gen_ext32s_tl(arg
, arg
);
3131 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3134 /* 6,7 are implementation dependent */
3142 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3146 check_insn(env
, ctx
, ISA_MIPS32R2
);
3147 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3151 check_insn(env
, ctx
, ISA_MIPS32R2
);
3152 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3156 check_insn(env
, ctx
, ISA_MIPS32R2
);
3157 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3167 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3177 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3178 tcg_gen_ext32s_tl(arg
, arg
);
3188 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3192 check_insn(env
, ctx
, ISA_MIPS32R2
);
3193 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3203 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3207 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3211 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3215 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3218 /* 4,5 are reserved */
3219 /* 6,7 are implementation dependent */
3221 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3225 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3235 gen_helper_mfc0_lladdr(arg
);
3245 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3255 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3265 #if defined(TARGET_MIPS64)
3266 check_insn(env
, ctx
, ISA_MIPS3
);
3267 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3268 tcg_gen_ext32s_tl(arg
, arg
);
3277 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3280 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3288 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3289 rn
= "'Diagnostic"; /* implementation dependent */
3294 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3298 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3299 rn
= "TraceControl";
3302 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3303 rn
= "TraceControl2";
3306 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3307 rn
= "UserTraceData";
3310 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3321 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3322 tcg_gen_ext32s_tl(arg
, arg
);
3332 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3333 rn
= "Performance0";
3336 // gen_helper_mfc0_performance1(arg);
3337 rn
= "Performance1";
3340 // gen_helper_mfc0_performance2(arg);
3341 rn
= "Performance2";
3344 // gen_helper_mfc0_performance3(arg);
3345 rn
= "Performance3";
3348 // gen_helper_mfc0_performance4(arg);
3349 rn
= "Performance4";
3352 // gen_helper_mfc0_performance5(arg);
3353 rn
= "Performance5";
3356 // gen_helper_mfc0_performance6(arg);
3357 rn
= "Performance6";
3360 // gen_helper_mfc0_performance7(arg);
3361 rn
= "Performance7";
3368 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3374 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3387 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3394 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3407 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3414 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3424 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3425 tcg_gen_ext32s_tl(arg
, arg
);
3436 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3446 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3450 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3451 generate_exception(ctx
, EXCP_RI
);
3454 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3456 const char *rn
= "invalid";
3459 check_insn(env
, ctx
, ISA_MIPS32
);
3468 gen_helper_mtc0_index(arg
);
3472 check_insn(env
, ctx
, ASE_MT
);
3473 gen_helper_mtc0_mvpcontrol(arg
);
3477 check_insn(env
, ctx
, ASE_MT
);
3482 check_insn(env
, ctx
, ASE_MT
);
3497 check_insn(env
, ctx
, ASE_MT
);
3498 gen_helper_mtc0_vpecontrol(arg
);
3502 check_insn(env
, ctx
, ASE_MT
);
3503 gen_helper_mtc0_vpeconf0(arg
);
3507 check_insn(env
, ctx
, ASE_MT
);
3508 gen_helper_mtc0_vpeconf1(arg
);
3512 check_insn(env
, ctx
, ASE_MT
);
3513 gen_helper_mtc0_yqmask(arg
);
3517 check_insn(env
, ctx
, ASE_MT
);
3518 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3522 check_insn(env
, ctx
, ASE_MT
);
3523 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3524 rn
= "VPEScheFBack";
3527 check_insn(env
, ctx
, ASE_MT
);
3528 gen_helper_mtc0_vpeopt(arg
);
3538 gen_helper_mtc0_entrylo0(arg
);
3542 check_insn(env
, ctx
, ASE_MT
);
3543 gen_helper_mtc0_tcstatus(arg
);
3547 check_insn(env
, ctx
, ASE_MT
);
3548 gen_helper_mtc0_tcbind(arg
);
3552 check_insn(env
, ctx
, ASE_MT
);
3553 gen_helper_mtc0_tcrestart(arg
);
3557 check_insn(env
, ctx
, ASE_MT
);
3558 gen_helper_mtc0_tchalt(arg
);
3562 check_insn(env
, ctx
, ASE_MT
);
3563 gen_helper_mtc0_tccontext(arg
);
3567 check_insn(env
, ctx
, ASE_MT
);
3568 gen_helper_mtc0_tcschedule(arg
);
3572 check_insn(env
, ctx
, ASE_MT
);
3573 gen_helper_mtc0_tcschefback(arg
);
3583 gen_helper_mtc0_entrylo1(arg
);
3593 gen_helper_mtc0_context(arg
);
3597 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3598 rn
= "ContextConfig";
3607 gen_helper_mtc0_pagemask(arg
);
3611 check_insn(env
, ctx
, ISA_MIPS32R2
);
3612 gen_helper_mtc0_pagegrain(arg
);
3622 gen_helper_mtc0_wired(arg
);
3626 check_insn(env
, ctx
, ISA_MIPS32R2
);
3627 gen_helper_mtc0_srsconf0(arg
);
3631 check_insn(env
, ctx
, ISA_MIPS32R2
);
3632 gen_helper_mtc0_srsconf1(arg
);
3636 check_insn(env
, ctx
, ISA_MIPS32R2
);
3637 gen_helper_mtc0_srsconf2(arg
);
3641 check_insn(env
, ctx
, ISA_MIPS32R2
);
3642 gen_helper_mtc0_srsconf3(arg
);
3646 check_insn(env
, ctx
, ISA_MIPS32R2
);
3647 gen_helper_mtc0_srsconf4(arg
);
3657 check_insn(env
, ctx
, ISA_MIPS32R2
);
3658 gen_helper_mtc0_hwrena(arg
);
3672 gen_helper_mtc0_count(arg
);
3675 /* 6,7 are implementation dependent */
3683 gen_helper_mtc0_entryhi(arg
);
3693 gen_helper_mtc0_compare(arg
);
3696 /* 6,7 are implementation dependent */
3704 save_cpu_state(ctx
, 1);
3705 gen_helper_mtc0_status(arg
);
3706 /* BS_STOP isn't good enough here, hflags may have changed. */
3707 gen_save_pc(ctx
->pc
+ 4);
3708 ctx
->bstate
= BS_EXCP
;
3712 check_insn(env
, ctx
, ISA_MIPS32R2
);
3713 gen_helper_mtc0_intctl(arg
);
3714 /* Stop translation as we may have switched the execution mode */
3715 ctx
->bstate
= BS_STOP
;
3719 check_insn(env
, ctx
, ISA_MIPS32R2
);
3720 gen_helper_mtc0_srsctl(arg
);
3721 /* Stop translation as we may have switched the execution mode */
3722 ctx
->bstate
= BS_STOP
;
3726 check_insn(env
, ctx
, ISA_MIPS32R2
);
3727 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3728 /* Stop translation as we may have switched the execution mode */
3729 ctx
->bstate
= BS_STOP
;
3739 save_cpu_state(ctx
, 1);
3740 gen_helper_mtc0_cause(arg
);
3750 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
3764 check_insn(env
, ctx
, ISA_MIPS32R2
);
3765 gen_helper_mtc0_ebase(arg
);
3775 gen_helper_mtc0_config0(arg
);
3777 /* Stop translation as we may have switched the execution mode */
3778 ctx
->bstate
= BS_STOP
;
3781 /* ignored, read only */
3785 gen_helper_mtc0_config2(arg
);
3787 /* Stop translation as we may have switched the execution mode */
3788 ctx
->bstate
= BS_STOP
;
3791 /* ignored, read only */
3794 /* 4,5 are reserved */
3795 /* 6,7 are implementation dependent */
3805 rn
= "Invalid config selector";
3812 gen_helper_mtc0_lladdr(arg
);
3822 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
3832 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
3842 #if defined(TARGET_MIPS64)
3843 check_insn(env
, ctx
, ISA_MIPS3
);
3844 gen_helper_mtc0_xcontext(arg
);
3853 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3856 gen_helper_mtc0_framemask(arg
);
3865 rn
= "Diagnostic"; /* implementation dependent */
3870 gen_helper_mtc0_debug(arg
); /* EJTAG support */
3871 /* BS_STOP isn't good enough here, hflags may have changed. */
3872 gen_save_pc(ctx
->pc
+ 4);
3873 ctx
->bstate
= BS_EXCP
;
3877 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
3878 rn
= "TraceControl";
3879 /* Stop translation as we may have switched the execution mode */
3880 ctx
->bstate
= BS_STOP
;
3883 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
3884 rn
= "TraceControl2";
3885 /* Stop translation as we may have switched the execution mode */
3886 ctx
->bstate
= BS_STOP
;
3889 /* Stop translation as we may have switched the execution mode */
3890 ctx
->bstate
= BS_STOP
;
3891 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
3892 rn
= "UserTraceData";
3893 /* Stop translation as we may have switched the execution mode */
3894 ctx
->bstate
= BS_STOP
;
3897 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
3898 /* Stop translation as we may have switched the execution mode */
3899 ctx
->bstate
= BS_STOP
;
3910 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
3920 gen_helper_mtc0_performance0(arg
);
3921 rn
= "Performance0";
3924 // gen_helper_mtc0_performance1(arg);
3925 rn
= "Performance1";
3928 // gen_helper_mtc0_performance2(arg);
3929 rn
= "Performance2";
3932 // gen_helper_mtc0_performance3(arg);
3933 rn
= "Performance3";
3936 // gen_helper_mtc0_performance4(arg);
3937 rn
= "Performance4";
3940 // gen_helper_mtc0_performance5(arg);
3941 rn
= "Performance5";
3944 // gen_helper_mtc0_performance6(arg);
3945 rn
= "Performance6";
3948 // gen_helper_mtc0_performance7(arg);
3949 rn
= "Performance7";
3975 gen_helper_mtc0_taglo(arg
);
3982 gen_helper_mtc0_datalo(arg
);
3995 gen_helper_mtc0_taghi(arg
);
4002 gen_helper_mtc0_datahi(arg
);
4013 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
4024 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4030 /* Stop translation as we may have switched the execution mode */
4031 ctx
->bstate
= BS_STOP
;
4036 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4037 /* For simplicity assume that all writes can cause interrupts. */
4040 ctx
->bstate
= BS_STOP
;
4045 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4046 generate_exception(ctx
, EXCP_RI
);
4049 #if defined(TARGET_MIPS64)
4050 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4052 const char *rn
= "invalid";
4055 check_insn(env
, ctx
, ISA_MIPS64
);
4061 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4065 check_insn(env
, ctx
, ASE_MT
);
4066 gen_helper_mfc0_mvpcontrol(arg
);
4070 check_insn(env
, ctx
, ASE_MT
);
4071 gen_helper_mfc0_mvpconf0(arg
);
4075 check_insn(env
, ctx
, ASE_MT
);
4076 gen_helper_mfc0_mvpconf1(arg
);
4086 gen_helper_mfc0_random(arg
);
4090 check_insn(env
, ctx
, ASE_MT
);
4091 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4095 check_insn(env
, ctx
, ASE_MT
);
4096 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4100 check_insn(env
, ctx
, ASE_MT
);
4101 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4105 check_insn(env
, ctx
, ASE_MT
);
4106 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4110 check_insn(env
, ctx
, ASE_MT
);
4111 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4115 check_insn(env
, ctx
, ASE_MT
);
4116 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4117 rn
= "VPEScheFBack";
4120 check_insn(env
, ctx
, ASE_MT
);
4121 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4131 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4135 check_insn(env
, ctx
, ASE_MT
);
4136 gen_helper_mfc0_tcstatus(arg
);
4140 check_insn(env
, ctx
, ASE_MT
);
4141 gen_helper_mfc0_tcbind(arg
);
4145 check_insn(env
, ctx
, ASE_MT
);
4146 gen_helper_dmfc0_tcrestart(arg
);
4150 check_insn(env
, ctx
, ASE_MT
);
4151 gen_helper_dmfc0_tchalt(arg
);
4155 check_insn(env
, ctx
, ASE_MT
);
4156 gen_helper_dmfc0_tccontext(arg
);
4160 check_insn(env
, ctx
, ASE_MT
);
4161 gen_helper_dmfc0_tcschedule(arg
);
4165 check_insn(env
, ctx
, ASE_MT
);
4166 gen_helper_dmfc0_tcschefback(arg
);
4176 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4186 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4190 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4191 rn
= "ContextConfig";
4200 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4204 check_insn(env
, ctx
, ISA_MIPS32R2
);
4205 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4215 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4219 check_insn(env
, ctx
, ISA_MIPS32R2
);
4220 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4224 check_insn(env
, ctx
, ISA_MIPS32R2
);
4225 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4229 check_insn(env
, ctx
, ISA_MIPS32R2
);
4230 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4234 check_insn(env
, ctx
, ISA_MIPS32R2
);
4235 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4239 check_insn(env
, ctx
, ISA_MIPS32R2
);
4240 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4250 check_insn(env
, ctx
, ISA_MIPS32R2
);
4251 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4261 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4271 /* Mark as an IO operation because we read the time. */
4274 gen_helper_mfc0_count(arg
);
4277 ctx
->bstate
= BS_STOP
;
4281 /* 6,7 are implementation dependent */
4289 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4299 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4302 /* 6,7 are implementation dependent */
4310 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4314 check_insn(env
, ctx
, ISA_MIPS32R2
);
4315 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4319 check_insn(env
, ctx
, ISA_MIPS32R2
);
4320 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4324 check_insn(env
, ctx
, ISA_MIPS32R2
);
4325 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4335 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4345 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4355 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4359 check_insn(env
, ctx
, ISA_MIPS32R2
);
4360 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4370 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4374 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4378 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4382 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4385 /* 6,7 are implementation dependent */
4387 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4391 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4401 gen_helper_dmfc0_lladdr(arg
);
4411 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4421 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4431 check_insn(env
, ctx
, ISA_MIPS3
);
4432 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4440 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4443 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4451 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4452 rn
= "'Diagnostic"; /* implementation dependent */
4457 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4461 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4462 rn
= "TraceControl";
4465 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4466 rn
= "TraceControl2";
4469 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4470 rn
= "UserTraceData";
4473 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4484 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4494 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4495 rn
= "Performance0";
4498 // gen_helper_dmfc0_performance1(arg);
4499 rn
= "Performance1";
4502 // gen_helper_dmfc0_performance2(arg);
4503 rn
= "Performance2";
4506 // gen_helper_dmfc0_performance3(arg);
4507 rn
= "Performance3";
4510 // gen_helper_dmfc0_performance4(arg);
4511 rn
= "Performance4";
4514 // gen_helper_dmfc0_performance5(arg);
4515 rn
= "Performance5";
4518 // gen_helper_dmfc0_performance6(arg);
4519 rn
= "Performance6";
4522 // gen_helper_dmfc0_performance7(arg);
4523 rn
= "Performance7";
4530 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4537 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4550 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4557 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4570 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4577 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4587 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4598 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4608 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4612 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4613 generate_exception(ctx
, EXCP_RI
);
4616 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4618 const char *rn
= "invalid";
4621 check_insn(env
, ctx
, ISA_MIPS64
);
4630 gen_helper_mtc0_index(arg
);
4634 check_insn(env
, ctx
, ASE_MT
);
4635 gen_helper_mtc0_mvpcontrol(arg
);
4639 check_insn(env
, ctx
, ASE_MT
);
4644 check_insn(env
, ctx
, ASE_MT
);
4659 check_insn(env
, ctx
, ASE_MT
);
4660 gen_helper_mtc0_vpecontrol(arg
);
4664 check_insn(env
, ctx
, ASE_MT
);
4665 gen_helper_mtc0_vpeconf0(arg
);
4669 check_insn(env
, ctx
, ASE_MT
);
4670 gen_helper_mtc0_vpeconf1(arg
);
4674 check_insn(env
, ctx
, ASE_MT
);
4675 gen_helper_mtc0_yqmask(arg
);
4679 check_insn(env
, ctx
, ASE_MT
);
4680 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4684 check_insn(env
, ctx
, ASE_MT
);
4685 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4686 rn
= "VPEScheFBack";
4689 check_insn(env
, ctx
, ASE_MT
);
4690 gen_helper_mtc0_vpeopt(arg
);
4700 gen_helper_mtc0_entrylo0(arg
);
4704 check_insn(env
, ctx
, ASE_MT
);
4705 gen_helper_mtc0_tcstatus(arg
);
4709 check_insn(env
, ctx
, ASE_MT
);
4710 gen_helper_mtc0_tcbind(arg
);
4714 check_insn(env
, ctx
, ASE_MT
);
4715 gen_helper_mtc0_tcrestart(arg
);
4719 check_insn(env
, ctx
, ASE_MT
);
4720 gen_helper_mtc0_tchalt(arg
);
4724 check_insn(env
, ctx
, ASE_MT
);
4725 gen_helper_mtc0_tccontext(arg
);
4729 check_insn(env
, ctx
, ASE_MT
);
4730 gen_helper_mtc0_tcschedule(arg
);
4734 check_insn(env
, ctx
, ASE_MT
);
4735 gen_helper_mtc0_tcschefback(arg
);
4745 gen_helper_mtc0_entrylo1(arg
);
4755 gen_helper_mtc0_context(arg
);
4759 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
4760 rn
= "ContextConfig";
4769 gen_helper_mtc0_pagemask(arg
);
4773 check_insn(env
, ctx
, ISA_MIPS32R2
);
4774 gen_helper_mtc0_pagegrain(arg
);
4784 gen_helper_mtc0_wired(arg
);
4788 check_insn(env
, ctx
, ISA_MIPS32R2
);
4789 gen_helper_mtc0_srsconf0(arg
);
4793 check_insn(env
, ctx
, ISA_MIPS32R2
);
4794 gen_helper_mtc0_srsconf1(arg
);
4798 check_insn(env
, ctx
, ISA_MIPS32R2
);
4799 gen_helper_mtc0_srsconf2(arg
);
4803 check_insn(env
, ctx
, ISA_MIPS32R2
);
4804 gen_helper_mtc0_srsconf3(arg
);
4808 check_insn(env
, ctx
, ISA_MIPS32R2
);
4809 gen_helper_mtc0_srsconf4(arg
);
4819 check_insn(env
, ctx
, ISA_MIPS32R2
);
4820 gen_helper_mtc0_hwrena(arg
);
4834 gen_helper_mtc0_count(arg
);
4837 /* 6,7 are implementation dependent */
4841 /* Stop translation as we may have switched the execution mode */
4842 ctx
->bstate
= BS_STOP
;
4847 gen_helper_mtc0_entryhi(arg
);
4857 gen_helper_mtc0_compare(arg
);
4860 /* 6,7 are implementation dependent */
4864 /* Stop translation as we may have switched the execution mode */
4865 ctx
->bstate
= BS_STOP
;
4870 save_cpu_state(ctx
, 1);
4871 gen_helper_mtc0_status(arg
);
4872 /* BS_STOP isn't good enough here, hflags may have changed. */
4873 gen_save_pc(ctx
->pc
+ 4);
4874 ctx
->bstate
= BS_EXCP
;
4878 check_insn(env
, ctx
, ISA_MIPS32R2
);
4879 gen_helper_mtc0_intctl(arg
);
4880 /* Stop translation as we may have switched the execution mode */
4881 ctx
->bstate
= BS_STOP
;
4885 check_insn(env
, ctx
, ISA_MIPS32R2
);
4886 gen_helper_mtc0_srsctl(arg
);
4887 /* Stop translation as we may have switched the execution mode */
4888 ctx
->bstate
= BS_STOP
;
4892 check_insn(env
, ctx
, ISA_MIPS32R2
);
4893 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4894 /* Stop translation as we may have switched the execution mode */
4895 ctx
->bstate
= BS_STOP
;
4905 save_cpu_state(ctx
, 1);
4906 gen_helper_mtc0_cause(arg
);
4916 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4930 check_insn(env
, ctx
, ISA_MIPS32R2
);
4931 gen_helper_mtc0_ebase(arg
);
4941 gen_helper_mtc0_config0(arg
);
4943 /* Stop translation as we may have switched the execution mode */
4944 ctx
->bstate
= BS_STOP
;
4947 /* ignored, read only */
4951 gen_helper_mtc0_config2(arg
);
4953 /* Stop translation as we may have switched the execution mode */
4954 ctx
->bstate
= BS_STOP
;
4960 /* 6,7 are implementation dependent */
4962 rn
= "Invalid config selector";
4969 gen_helper_mtc0_lladdr(arg
);
4979 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
4989 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
4999 check_insn(env
, ctx
, ISA_MIPS3
);
5000 gen_helper_mtc0_xcontext(arg
);
5008 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5011 gen_helper_mtc0_framemask(arg
);
5020 rn
= "Diagnostic"; /* implementation dependent */
5025 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5026 /* BS_STOP isn't good enough here, hflags may have changed. */
5027 gen_save_pc(ctx
->pc
+ 4);
5028 ctx
->bstate
= BS_EXCP
;
5032 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5033 /* Stop translation as we may have switched the execution mode */
5034 ctx
->bstate
= BS_STOP
;
5035 rn
= "TraceControl";
5038 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5039 /* Stop translation as we may have switched the execution mode */
5040 ctx
->bstate
= BS_STOP
;
5041 rn
= "TraceControl2";
5044 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5045 /* Stop translation as we may have switched the execution mode */
5046 ctx
->bstate
= BS_STOP
;
5047 rn
= "UserTraceData";
5050 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5051 /* Stop translation as we may have switched the execution mode */
5052 ctx
->bstate
= BS_STOP
;
5063 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5073 gen_helper_mtc0_performance0(arg
);
5074 rn
= "Performance0";
5077 // gen_helper_mtc0_performance1(arg);
5078 rn
= "Performance1";
5081 // gen_helper_mtc0_performance2(arg);
5082 rn
= "Performance2";
5085 // gen_helper_mtc0_performance3(arg);
5086 rn
= "Performance3";
5089 // gen_helper_mtc0_performance4(arg);
5090 rn
= "Performance4";
5093 // gen_helper_mtc0_performance5(arg);
5094 rn
= "Performance5";
5097 // gen_helper_mtc0_performance6(arg);
5098 rn
= "Performance6";
5101 // gen_helper_mtc0_performance7(arg);
5102 rn
= "Performance7";
5128 gen_helper_mtc0_taglo(arg
);
5135 gen_helper_mtc0_datalo(arg
);
5148 gen_helper_mtc0_taghi(arg
);
5155 gen_helper_mtc0_datahi(arg
);
5166 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5177 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5183 /* Stop translation as we may have switched the execution mode */
5184 ctx
->bstate
= BS_STOP
;
5189 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5190 /* For simplicity assume that all writes can cause interrupts. */
5193 ctx
->bstate
= BS_STOP
;
5198 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5199 generate_exception(ctx
, EXCP_RI
);
5201 #endif /* TARGET_MIPS64 */
5203 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5204 int u
, int sel
, int h
)
5206 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5207 TCGv t0
= tcg_temp_local_new();
5209 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5210 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5211 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5212 tcg_gen_movi_tl(t0
, -1);
5213 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5214 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5215 tcg_gen_movi_tl(t0
, -1);
5221 gen_helper_mftc0_tcstatus(t0
);
5224 gen_helper_mftc0_tcbind(t0
);
5227 gen_helper_mftc0_tcrestart(t0
);
5230 gen_helper_mftc0_tchalt(t0
);
5233 gen_helper_mftc0_tccontext(t0
);
5236 gen_helper_mftc0_tcschedule(t0
);
5239 gen_helper_mftc0_tcschefback(t0
);
5242 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5249 gen_helper_mftc0_entryhi(t0
);
5252 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5258 gen_helper_mftc0_status(t0
);
5261 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5267 gen_helper_mftc0_debug(t0
);
5270 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5275 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5277 } else switch (sel
) {
5278 /* GPR registers. */
5280 gen_helper_1i(mftgpr
, t0
, rt
);
5282 /* Auxiliary CPU registers */
5286 gen_helper_1i(mftlo
, t0
, 0);
5289 gen_helper_1i(mfthi
, t0
, 0);
5292 gen_helper_1i(mftacx
, t0
, 0);
5295 gen_helper_1i(mftlo
, t0
, 1);
5298 gen_helper_1i(mfthi
, t0
, 1);
5301 gen_helper_1i(mftacx
, t0
, 1);
5304 gen_helper_1i(mftlo
, t0
, 2);
5307 gen_helper_1i(mfthi
, t0
, 2);
5310 gen_helper_1i(mftacx
, t0
, 2);
5313 gen_helper_1i(mftlo
, t0
, 3);
5316 gen_helper_1i(mfthi
, t0
, 3);
5319 gen_helper_1i(mftacx
, t0
, 3);
5322 gen_helper_mftdsp(t0
);
5328 /* Floating point (COP1). */
5330 /* XXX: For now we support only a single FPU context. */
5332 TCGv_i32 fp0
= tcg_temp_new_i32();
5334 gen_load_fpr32(fp0
, rt
);
5335 tcg_gen_ext_i32_tl(t0
, fp0
);
5336 tcg_temp_free_i32(fp0
);
5338 TCGv_i32 fp0
= tcg_temp_new_i32();
5340 gen_load_fpr32h(fp0
, rt
);
5341 tcg_gen_ext_i32_tl(t0
, fp0
);
5342 tcg_temp_free_i32(fp0
);
5346 /* XXX: For now we support only a single FPU context. */
5347 gen_helper_1i(cfc1
, t0
, rt
);
5349 /* COP2: Not implemented. */
5356 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5357 gen_store_gpr(t0
, rd
);
5363 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5364 generate_exception(ctx
, EXCP_RI
);
5367 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5368 int u
, int sel
, int h
)
5370 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5371 TCGv t0
= tcg_temp_local_new();
5373 gen_load_gpr(t0
, rt
);
5374 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5375 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5376 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5378 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5379 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5386 gen_helper_mttc0_tcstatus(t0
);
5389 gen_helper_mttc0_tcbind(t0
);
5392 gen_helper_mttc0_tcrestart(t0
);
5395 gen_helper_mttc0_tchalt(t0
);
5398 gen_helper_mttc0_tccontext(t0
);
5401 gen_helper_mttc0_tcschedule(t0
);
5404 gen_helper_mttc0_tcschefback(t0
);
5407 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5414 gen_helper_mttc0_entryhi(t0
);
5417 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5423 gen_helper_mttc0_status(t0
);
5426 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5432 gen_helper_mttc0_debug(t0
);
5435 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5440 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5442 } else switch (sel
) {
5443 /* GPR registers. */
5445 gen_helper_1i(mttgpr
, t0
, rd
);
5447 /* Auxiliary CPU registers */
5451 gen_helper_1i(mttlo
, t0
, 0);
5454 gen_helper_1i(mtthi
, t0
, 0);
5457 gen_helper_1i(mttacx
, t0
, 0);
5460 gen_helper_1i(mttlo
, t0
, 1);
5463 gen_helper_1i(mtthi
, t0
, 1);
5466 gen_helper_1i(mttacx
, t0
, 1);
5469 gen_helper_1i(mttlo
, t0
, 2);
5472 gen_helper_1i(mtthi
, t0
, 2);
5475 gen_helper_1i(mttacx
, t0
, 2);
5478 gen_helper_1i(mttlo
, t0
, 3);
5481 gen_helper_1i(mtthi
, t0
, 3);
5484 gen_helper_1i(mttacx
, t0
, 3);
5487 gen_helper_mttdsp(t0
);
5493 /* Floating point (COP1). */
5495 /* XXX: For now we support only a single FPU context. */
5497 TCGv_i32 fp0
= tcg_temp_new_i32();
5499 tcg_gen_trunc_tl_i32(fp0
, t0
);
5500 gen_store_fpr32(fp0
, rd
);
5501 tcg_temp_free_i32(fp0
);
5503 TCGv_i32 fp0
= tcg_temp_new_i32();
5505 tcg_gen_trunc_tl_i32(fp0
, t0
);
5506 gen_store_fpr32h(fp0
, rd
);
5507 tcg_temp_free_i32(fp0
);
5511 /* XXX: For now we support only a single FPU context. */
5512 gen_helper_1i(ctc1
, t0
, rd
);
5514 /* COP2: Not implemented. */
5521 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5527 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5528 generate_exception(ctx
, EXCP_RI
);
5531 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5533 const char *opn
= "ldst";
5541 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5546 TCGv t0
= tcg_temp_new();
5548 gen_load_gpr(t0
, rt
);
5549 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5554 #if defined(TARGET_MIPS64)
5556 check_insn(env
, ctx
, ISA_MIPS3
);
5561 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5565 check_insn(env
, ctx
, ISA_MIPS3
);
5567 TCGv t0
= tcg_temp_new();
5569 gen_load_gpr(t0
, rt
);
5570 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5577 check_insn(env
, ctx
, ASE_MT
);
5582 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5583 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5587 check_insn(env
, ctx
, ASE_MT
);
5588 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5589 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5594 if (!env
->tlb
->helper_tlbwi
)
5600 if (!env
->tlb
->helper_tlbwr
)
5606 if (!env
->tlb
->helper_tlbp
)
5612 if (!env
->tlb
->helper_tlbr
)
5618 check_insn(env
, ctx
, ISA_MIPS2
);
5620 ctx
->bstate
= BS_EXCP
;
5624 check_insn(env
, ctx
, ISA_MIPS32
);
5625 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5627 generate_exception(ctx
, EXCP_RI
);
5630 ctx
->bstate
= BS_EXCP
;
5635 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5636 /* If we get an exception, we want to restart at next instruction */
5638 save_cpu_state(ctx
, 1);
5641 ctx
->bstate
= BS_EXCP
;
5646 generate_exception(ctx
, EXCP_RI
);
5649 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5651 #endif /* !CONFIG_USER_ONLY */
5653 /* CP1 Branches (before delay slot) */
5654 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5655 int32_t cc
, int32_t offset
)
5657 target_ulong btarget
;
5658 const char *opn
= "cp1 cond branch";
5659 TCGv_i32 t0
= tcg_temp_new_i32();
5662 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5664 btarget
= ctx
->pc
+ 4 + offset
;
5668 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5669 tcg_gen_not_i32(t0
, t0
);
5670 tcg_gen_andi_i32(t0
, t0
, 1);
5671 tcg_gen_extu_i32_tl(bcond
, t0
);
5675 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5676 tcg_gen_not_i32(t0
, t0
);
5677 tcg_gen_andi_i32(t0
, t0
, 1);
5678 tcg_gen_extu_i32_tl(bcond
, t0
);
5682 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5683 tcg_gen_andi_i32(t0
, t0
, 1);
5684 tcg_gen_extu_i32_tl(bcond
, t0
);
5688 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5689 tcg_gen_andi_i32(t0
, t0
, 1);
5690 tcg_gen_extu_i32_tl(bcond
, t0
);
5693 ctx
->hflags
|= MIPS_HFLAG_BL
;
5697 TCGv_i32 t1
= tcg_temp_new_i32();
5698 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5699 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5700 tcg_gen_nor_i32(t0
, t0
, t1
);
5701 tcg_temp_free_i32(t1
);
5702 tcg_gen_andi_i32(t0
, t0
, 1);
5703 tcg_gen_extu_i32_tl(bcond
, t0
);
5709 TCGv_i32 t1
= tcg_temp_new_i32();
5710 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5711 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5712 tcg_gen_or_i32(t0
, t0
, t1
);
5713 tcg_temp_free_i32(t1
);
5714 tcg_gen_andi_i32(t0
, t0
, 1);
5715 tcg_gen_extu_i32_tl(bcond
, t0
);
5721 TCGv_i32 t1
= tcg_temp_new_i32();
5722 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5723 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5724 tcg_gen_or_i32(t0
, t0
, t1
);
5725 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5726 tcg_gen_or_i32(t0
, t0
, t1
);
5727 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5728 tcg_gen_nor_i32(t0
, t0
, t1
);
5729 tcg_temp_free_i32(t1
);
5730 tcg_gen_andi_i32(t0
, t0
, 1);
5731 tcg_gen_extu_i32_tl(bcond
, t0
);
5737 TCGv_i32 t1
= tcg_temp_new_i32();
5738 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5739 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5740 tcg_gen_or_i32(t0
, t0
, t1
);
5741 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5742 tcg_gen_or_i32(t0
, t0
, t1
);
5743 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5744 tcg_gen_or_i32(t0
, t0
, t1
);
5745 tcg_temp_free_i32(t1
);
5746 tcg_gen_andi_i32(t0
, t0
, 1);
5747 tcg_gen_extu_i32_tl(bcond
, t0
);
5751 ctx
->hflags
|= MIPS_HFLAG_BC
;
5755 generate_exception (ctx
, EXCP_RI
);
5758 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5759 ctx
->hflags
, btarget
);
5760 ctx
->btarget
= btarget
;
5763 tcg_temp_free_i32(t0
);
5766 /* Coprocessor 1 (FPU) */
5768 #define FOP(func, fmt) (((fmt) << 21) | (func))
5771 OPC_ADD_S
= FOP(0, FMT_S
),
5772 OPC_SUB_S
= FOP(1, FMT_S
),
5773 OPC_MUL_S
= FOP(2, FMT_S
),
5774 OPC_DIV_S
= FOP(3, FMT_S
),
5775 OPC_SQRT_S
= FOP(4, FMT_S
),
5776 OPC_ABS_S
= FOP(5, FMT_S
),
5777 OPC_MOV_S
= FOP(6, FMT_S
),
5778 OPC_NEG_S
= FOP(7, FMT_S
),
5779 OPC_ROUND_L_S
= FOP(8, FMT_S
),
5780 OPC_TRUNC_L_S
= FOP(9, FMT_S
),
5781 OPC_CEIL_L_S
= FOP(10, FMT_S
),
5782 OPC_FLOOR_L_S
= FOP(11, FMT_S
),
5783 OPC_ROUND_W_S
= FOP(12, FMT_S
),
5784 OPC_TRUNC_W_S
= FOP(13, FMT_S
),
5785 OPC_CEIL_W_S
= FOP(14, FMT_S
),
5786 OPC_FLOOR_W_S
= FOP(15, FMT_S
),
5787 OPC_MOVCF_S
= FOP(17, FMT_S
),
5788 OPC_MOVZ_S
= FOP(18, FMT_S
),
5789 OPC_MOVN_S
= FOP(19, FMT_S
),
5790 OPC_RECIP_S
= FOP(21, FMT_S
),
5791 OPC_RSQRT_S
= FOP(22, FMT_S
),
5792 OPC_RECIP2_S
= FOP(28, FMT_S
),
5793 OPC_RECIP1_S
= FOP(29, FMT_S
),
5794 OPC_RSQRT1_S
= FOP(30, FMT_S
),
5795 OPC_RSQRT2_S
= FOP(31, FMT_S
),
5796 OPC_CVT_D_S
= FOP(33, FMT_S
),
5797 OPC_CVT_W_S
= FOP(36, FMT_S
),
5798 OPC_CVT_L_S
= FOP(37, FMT_S
),
5799 OPC_CVT_PS_S
= FOP(38, FMT_S
),
5800 OPC_CMP_F_S
= FOP (48, FMT_S
),
5801 OPC_CMP_UN_S
= FOP (49, FMT_S
),
5802 OPC_CMP_EQ_S
= FOP (50, FMT_S
),
5803 OPC_CMP_UEQ_S
= FOP (51, FMT_S
),
5804 OPC_CMP_OLT_S
= FOP (52, FMT_S
),
5805 OPC_CMP_ULT_S
= FOP (53, FMT_S
),
5806 OPC_CMP_OLE_S
= FOP (54, FMT_S
),
5807 OPC_CMP_ULE_S
= FOP (55, FMT_S
),
5808 OPC_CMP_SF_S
= FOP (56, FMT_S
),
5809 OPC_CMP_NGLE_S
= FOP (57, FMT_S
),
5810 OPC_CMP_SEQ_S
= FOP (58, FMT_S
),
5811 OPC_CMP_NGL_S
= FOP (59, FMT_S
),
5812 OPC_CMP_LT_S
= FOP (60, FMT_S
),
5813 OPC_CMP_NGE_S
= FOP (61, FMT_S
),
5814 OPC_CMP_LE_S
= FOP (62, FMT_S
),
5815 OPC_CMP_NGT_S
= FOP (63, FMT_S
),
5817 OPC_ADD_D
= FOP(0, FMT_D
),
5818 OPC_SUB_D
= FOP(1, FMT_D
),
5819 OPC_MUL_D
= FOP(2, FMT_D
),
5820 OPC_DIV_D
= FOP(3, FMT_D
),
5821 OPC_SQRT_D
= FOP(4, FMT_D
),
5822 OPC_ABS_D
= FOP(5, FMT_D
),
5823 OPC_MOV_D
= FOP(6, FMT_D
),
5824 OPC_NEG_D
= FOP(7, FMT_D
),
5825 OPC_ROUND_L_D
= FOP(8, FMT_D
),
5826 OPC_TRUNC_L_D
= FOP(9, FMT_D
),
5827 OPC_CEIL_L_D
= FOP(10, FMT_D
),
5828 OPC_FLOOR_L_D
= FOP(11, FMT_D
),
5829 OPC_ROUND_W_D
= FOP(12, FMT_D
),
5830 OPC_TRUNC_W_D
= FOP(13, FMT_D
),
5831 OPC_CEIL_W_D
= FOP(14, FMT_D
),
5832 OPC_FLOOR_W_D
= FOP(15, FMT_D
),
5833 OPC_MOVCF_D
= FOP(17, FMT_D
),
5834 OPC_MOVZ_D
= FOP(18, FMT_D
),
5835 OPC_MOVN_D
= FOP(19, FMT_D
),
5836 OPC_RECIP_D
= FOP(21, FMT_D
),
5837 OPC_RSQRT_D
= FOP(22, FMT_D
),
5838 OPC_RECIP2_D
= FOP(28, FMT_D
),
5839 OPC_RECIP1_D
= FOP(29, FMT_D
),
5840 OPC_RSQRT1_D
= FOP(30, FMT_D
),
5841 OPC_RSQRT2_D
= FOP(31, FMT_D
),
5842 OPC_CVT_S_D
= FOP(32, FMT_D
),
5843 OPC_CVT_W_D
= FOP(36, FMT_D
),
5844 OPC_CVT_L_D
= FOP(37, FMT_D
),
5845 OPC_CMP_F_D
= FOP (48, FMT_D
),
5846 OPC_CMP_UN_D
= FOP (49, FMT_D
),
5847 OPC_CMP_EQ_D
= FOP (50, FMT_D
),
5848 OPC_CMP_UEQ_D
= FOP (51, FMT_D
),
5849 OPC_CMP_OLT_D
= FOP (52, FMT_D
),
5850 OPC_CMP_ULT_D
= FOP (53, FMT_D
),
5851 OPC_CMP_OLE_D
= FOP (54, FMT_D
),
5852 OPC_CMP_ULE_D
= FOP (55, FMT_D
),
5853 OPC_CMP_SF_D
= FOP (56, FMT_D
),
5854 OPC_CMP_NGLE_D
= FOP (57, FMT_D
),
5855 OPC_CMP_SEQ_D
= FOP (58, FMT_D
),
5856 OPC_CMP_NGL_D
= FOP (59, FMT_D
),
5857 OPC_CMP_LT_D
= FOP (60, FMT_D
),
5858 OPC_CMP_NGE_D
= FOP (61, FMT_D
),
5859 OPC_CMP_LE_D
= FOP (62, FMT_D
),
5860 OPC_CMP_NGT_D
= FOP (63, FMT_D
),
5862 OPC_CVT_S_W
= FOP(32, FMT_W
),
5863 OPC_CVT_D_W
= FOP(33, FMT_W
),
5864 OPC_CVT_S_L
= FOP(32, FMT_L
),
5865 OPC_CVT_D_L
= FOP(33, FMT_L
),
5866 OPC_CVT_PS_PW
= FOP(38, FMT_W
),
5868 OPC_ADD_PS
= FOP(0, FMT_PS
),
5869 OPC_SUB_PS
= FOP(1, FMT_PS
),
5870 OPC_MUL_PS
= FOP(2, FMT_PS
),
5871 OPC_DIV_PS
= FOP(3, FMT_PS
),
5872 OPC_ABS_PS
= FOP(5, FMT_PS
),
5873 OPC_MOV_PS
= FOP(6, FMT_PS
),
5874 OPC_NEG_PS
= FOP(7, FMT_PS
),
5875 OPC_MOVCF_PS
= FOP(17, FMT_PS
),
5876 OPC_MOVZ_PS
= FOP(18, FMT_PS
),
5877 OPC_MOVN_PS
= FOP(19, FMT_PS
),
5878 OPC_ADDR_PS
= FOP(24, FMT_PS
),
5879 OPC_MULR_PS
= FOP(26, FMT_PS
),
5880 OPC_RECIP2_PS
= FOP(28, FMT_PS
),
5881 OPC_RECIP1_PS
= FOP(29, FMT_PS
),
5882 OPC_RSQRT1_PS
= FOP(30, FMT_PS
),
5883 OPC_RSQRT2_PS
= FOP(31, FMT_PS
),
5885 OPC_CVT_S_PU
= FOP(32, FMT_PS
),
5886 OPC_CVT_PW_PS
= FOP(36, FMT_PS
),
5887 OPC_CVT_S_PL
= FOP(40, FMT_PS
),
5888 OPC_PLL_PS
= FOP(44, FMT_PS
),
5889 OPC_PLU_PS
= FOP(45, FMT_PS
),
5890 OPC_PUL_PS
= FOP(46, FMT_PS
),
5891 OPC_PUU_PS
= FOP(47, FMT_PS
),
5892 OPC_CMP_F_PS
= FOP (48, FMT_PS
),
5893 OPC_CMP_UN_PS
= FOP (49, FMT_PS
),
5894 OPC_CMP_EQ_PS
= FOP (50, FMT_PS
),
5895 OPC_CMP_UEQ_PS
= FOP (51, FMT_PS
),
5896 OPC_CMP_OLT_PS
= FOP (52, FMT_PS
),
5897 OPC_CMP_ULT_PS
= FOP (53, FMT_PS
),
5898 OPC_CMP_OLE_PS
= FOP (54, FMT_PS
),
5899 OPC_CMP_ULE_PS
= FOP (55, FMT_PS
),
5900 OPC_CMP_SF_PS
= FOP (56, FMT_PS
),
5901 OPC_CMP_NGLE_PS
= FOP (57, FMT_PS
),
5902 OPC_CMP_SEQ_PS
= FOP (58, FMT_PS
),
5903 OPC_CMP_NGL_PS
= FOP (59, FMT_PS
),
5904 OPC_CMP_LT_PS
= FOP (60, FMT_PS
),
5905 OPC_CMP_NGE_PS
= FOP (61, FMT_PS
),
5906 OPC_CMP_LE_PS
= FOP (62, FMT_PS
),
5907 OPC_CMP_NGT_PS
= FOP (63, FMT_PS
),
5910 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5912 const char *opn
= "cp1 move";
5913 TCGv t0
= tcg_temp_new();
5918 TCGv_i32 fp0
= tcg_temp_new_i32();
5920 gen_load_fpr32(fp0
, fs
);
5921 tcg_gen_ext_i32_tl(t0
, fp0
);
5922 tcg_temp_free_i32(fp0
);
5924 gen_store_gpr(t0
, rt
);
5928 gen_load_gpr(t0
, rt
);
5930 TCGv_i32 fp0
= tcg_temp_new_i32();
5932 tcg_gen_trunc_tl_i32(fp0
, t0
);
5933 gen_store_fpr32(fp0
, fs
);
5934 tcg_temp_free_i32(fp0
);
5939 gen_helper_1i(cfc1
, t0
, fs
);
5940 gen_store_gpr(t0
, rt
);
5944 gen_load_gpr(t0
, rt
);
5945 gen_helper_1i(ctc1
, t0
, fs
);
5948 #if defined(TARGET_MIPS64)
5950 gen_load_fpr64(ctx
, t0
, fs
);
5951 gen_store_gpr(t0
, rt
);
5955 gen_load_gpr(t0
, rt
);
5956 gen_store_fpr64(ctx
, t0
, fs
);
5962 TCGv_i32 fp0
= tcg_temp_new_i32();
5964 gen_load_fpr32h(fp0
, fs
);
5965 tcg_gen_ext_i32_tl(t0
, fp0
);
5966 tcg_temp_free_i32(fp0
);
5968 gen_store_gpr(t0
, rt
);
5972 gen_load_gpr(t0
, rt
);
5974 TCGv_i32 fp0
= tcg_temp_new_i32();
5976 tcg_gen_trunc_tl_i32(fp0
, t0
);
5977 gen_store_fpr32h(fp0
, fs
);
5978 tcg_temp_free_i32(fp0
);
5984 generate_exception (ctx
, EXCP_RI
);
5987 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5993 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
6009 l1
= gen_new_label();
6010 t0
= tcg_temp_new_i32();
6011 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6012 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6013 tcg_temp_free_i32(t0
);
6015 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
6017 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
6022 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
6025 TCGv_i32 t0
= tcg_temp_new_i32();
6026 int l1
= gen_new_label();
6033 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6034 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6035 gen_load_fpr32(t0
, fs
);
6036 gen_store_fpr32(t0
, fd
);
6038 tcg_temp_free_i32(t0
);
6041 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
6044 TCGv_i32 t0
= tcg_temp_new_i32();
6046 int l1
= gen_new_label();
6053 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6054 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6055 tcg_temp_free_i32(t0
);
6056 fp0
= tcg_temp_new_i64();
6057 gen_load_fpr64(ctx
, fp0
, fs
);
6058 gen_store_fpr64(ctx
, fp0
, fd
);
6059 tcg_temp_free_i64(fp0
);
6063 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
6066 TCGv_i32 t0
= tcg_temp_new_i32();
6067 int l1
= gen_new_label();
6068 int l2
= gen_new_label();
6075 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
6076 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
6077 gen_load_fpr32(t0
, fs
);
6078 gen_store_fpr32(t0
, fd
);
6081 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
6082 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
6083 gen_load_fpr32h(t0
, fs
);
6084 gen_store_fpr32h(t0
, fd
);
6085 tcg_temp_free_i32(t0
);
6090 static void gen_farith (DisasContext
*ctx
, enum fopcode op1
,
6091 int ft
, int fs
, int fd
, int cc
)
6093 const char *opn
= "farith";
6094 const char *condnames
[] = {
6112 const char *condnames_abs
[] = {
6130 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6131 uint32_t func
= ctx
->opcode
& 0x3f;
6136 TCGv_i32 fp0
= tcg_temp_new_i32();
6137 TCGv_i32 fp1
= tcg_temp_new_i32();
6139 gen_load_fpr32(fp0
, fs
);
6140 gen_load_fpr32(fp1
, ft
);
6141 gen_helper_float_add_s(fp0
, fp0
, fp1
);
6142 tcg_temp_free_i32(fp1
);
6143 gen_store_fpr32(fp0
, fd
);
6144 tcg_temp_free_i32(fp0
);
6151 TCGv_i32 fp0
= tcg_temp_new_i32();
6152 TCGv_i32 fp1
= tcg_temp_new_i32();
6154 gen_load_fpr32(fp0
, fs
);
6155 gen_load_fpr32(fp1
, ft
);
6156 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6157 tcg_temp_free_i32(fp1
);
6158 gen_store_fpr32(fp0
, fd
);
6159 tcg_temp_free_i32(fp0
);
6166 TCGv_i32 fp0
= tcg_temp_new_i32();
6167 TCGv_i32 fp1
= tcg_temp_new_i32();
6169 gen_load_fpr32(fp0
, fs
);
6170 gen_load_fpr32(fp1
, ft
);
6171 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6172 tcg_temp_free_i32(fp1
);
6173 gen_store_fpr32(fp0
, fd
);
6174 tcg_temp_free_i32(fp0
);
6181 TCGv_i32 fp0
= tcg_temp_new_i32();
6182 TCGv_i32 fp1
= tcg_temp_new_i32();
6184 gen_load_fpr32(fp0
, fs
);
6185 gen_load_fpr32(fp1
, ft
);
6186 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6187 tcg_temp_free_i32(fp1
);
6188 gen_store_fpr32(fp0
, fd
);
6189 tcg_temp_free_i32(fp0
);
6196 TCGv_i32 fp0
= tcg_temp_new_i32();
6198 gen_load_fpr32(fp0
, fs
);
6199 gen_helper_float_sqrt_s(fp0
, fp0
);
6200 gen_store_fpr32(fp0
, fd
);
6201 tcg_temp_free_i32(fp0
);
6207 TCGv_i32 fp0
= tcg_temp_new_i32();
6209 gen_load_fpr32(fp0
, fs
);
6210 gen_helper_float_abs_s(fp0
, fp0
);
6211 gen_store_fpr32(fp0
, fd
);
6212 tcg_temp_free_i32(fp0
);
6218 TCGv_i32 fp0
= tcg_temp_new_i32();
6220 gen_load_fpr32(fp0
, fs
);
6221 gen_store_fpr32(fp0
, fd
);
6222 tcg_temp_free_i32(fp0
);
6228 TCGv_i32 fp0
= tcg_temp_new_i32();
6230 gen_load_fpr32(fp0
, fs
);
6231 gen_helper_float_chs_s(fp0
, fp0
);
6232 gen_store_fpr32(fp0
, fd
);
6233 tcg_temp_free_i32(fp0
);
6238 check_cp1_64bitmode(ctx
);
6240 TCGv_i32 fp32
= tcg_temp_new_i32();
6241 TCGv_i64 fp64
= tcg_temp_new_i64();
6243 gen_load_fpr32(fp32
, fs
);
6244 gen_helper_float_roundl_s(fp64
, fp32
);
6245 tcg_temp_free_i32(fp32
);
6246 gen_store_fpr64(ctx
, fp64
, fd
);
6247 tcg_temp_free_i64(fp64
);
6252 check_cp1_64bitmode(ctx
);
6254 TCGv_i32 fp32
= tcg_temp_new_i32();
6255 TCGv_i64 fp64
= tcg_temp_new_i64();
6257 gen_load_fpr32(fp32
, fs
);
6258 gen_helper_float_truncl_s(fp64
, fp32
);
6259 tcg_temp_free_i32(fp32
);
6260 gen_store_fpr64(ctx
, fp64
, fd
);
6261 tcg_temp_free_i64(fp64
);
6266 check_cp1_64bitmode(ctx
);
6268 TCGv_i32 fp32
= tcg_temp_new_i32();
6269 TCGv_i64 fp64
= tcg_temp_new_i64();
6271 gen_load_fpr32(fp32
, fs
);
6272 gen_helper_float_ceill_s(fp64
, fp32
);
6273 tcg_temp_free_i32(fp32
);
6274 gen_store_fpr64(ctx
, fp64
, fd
);
6275 tcg_temp_free_i64(fp64
);
6280 check_cp1_64bitmode(ctx
);
6282 TCGv_i32 fp32
= tcg_temp_new_i32();
6283 TCGv_i64 fp64
= tcg_temp_new_i64();
6285 gen_load_fpr32(fp32
, fs
);
6286 gen_helper_float_floorl_s(fp64
, fp32
);
6287 tcg_temp_free_i32(fp32
);
6288 gen_store_fpr64(ctx
, fp64
, fd
);
6289 tcg_temp_free_i64(fp64
);
6295 TCGv_i32 fp0
= tcg_temp_new_i32();
6297 gen_load_fpr32(fp0
, fs
);
6298 gen_helper_float_roundw_s(fp0
, fp0
);
6299 gen_store_fpr32(fp0
, fd
);
6300 tcg_temp_free_i32(fp0
);
6306 TCGv_i32 fp0
= tcg_temp_new_i32();
6308 gen_load_fpr32(fp0
, fs
);
6309 gen_helper_float_truncw_s(fp0
, fp0
);
6310 gen_store_fpr32(fp0
, fd
);
6311 tcg_temp_free_i32(fp0
);
6317 TCGv_i32 fp0
= tcg_temp_new_i32();
6319 gen_load_fpr32(fp0
, fs
);
6320 gen_helper_float_ceilw_s(fp0
, fp0
);
6321 gen_store_fpr32(fp0
, fd
);
6322 tcg_temp_free_i32(fp0
);
6328 TCGv_i32 fp0
= tcg_temp_new_i32();
6330 gen_load_fpr32(fp0
, fs
);
6331 gen_helper_float_floorw_s(fp0
, fp0
);
6332 gen_store_fpr32(fp0
, fd
);
6333 tcg_temp_free_i32(fp0
);
6338 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6343 int l1
= gen_new_label();
6347 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6349 fp0
= tcg_temp_new_i32();
6350 gen_load_fpr32(fp0
, fs
);
6351 gen_store_fpr32(fp0
, fd
);
6352 tcg_temp_free_i32(fp0
);
6359 int l1
= gen_new_label();
6363 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6364 fp0
= tcg_temp_new_i32();
6365 gen_load_fpr32(fp0
, fs
);
6366 gen_store_fpr32(fp0
, fd
);
6367 tcg_temp_free_i32(fp0
);
6376 TCGv_i32 fp0
= tcg_temp_new_i32();
6378 gen_load_fpr32(fp0
, fs
);
6379 gen_helper_float_recip_s(fp0
, fp0
);
6380 gen_store_fpr32(fp0
, fd
);
6381 tcg_temp_free_i32(fp0
);
6388 TCGv_i32 fp0
= tcg_temp_new_i32();
6390 gen_load_fpr32(fp0
, fs
);
6391 gen_helper_float_rsqrt_s(fp0
, fp0
);
6392 gen_store_fpr32(fp0
, fd
);
6393 tcg_temp_free_i32(fp0
);
6398 check_cp1_64bitmode(ctx
);
6400 TCGv_i32 fp0
= tcg_temp_new_i32();
6401 TCGv_i32 fp1
= tcg_temp_new_i32();
6403 gen_load_fpr32(fp0
, fs
);
6404 gen_load_fpr32(fp1
, fd
);
6405 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6406 tcg_temp_free_i32(fp1
);
6407 gen_store_fpr32(fp0
, fd
);
6408 tcg_temp_free_i32(fp0
);
6413 check_cp1_64bitmode(ctx
);
6415 TCGv_i32 fp0
= tcg_temp_new_i32();
6417 gen_load_fpr32(fp0
, fs
);
6418 gen_helper_float_recip1_s(fp0
, fp0
);
6419 gen_store_fpr32(fp0
, fd
);
6420 tcg_temp_free_i32(fp0
);
6425 check_cp1_64bitmode(ctx
);
6427 TCGv_i32 fp0
= tcg_temp_new_i32();
6429 gen_load_fpr32(fp0
, fs
);
6430 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6431 gen_store_fpr32(fp0
, fd
);
6432 tcg_temp_free_i32(fp0
);
6437 check_cp1_64bitmode(ctx
);
6439 TCGv_i32 fp0
= tcg_temp_new_i32();
6440 TCGv_i32 fp1
= tcg_temp_new_i32();
6442 gen_load_fpr32(fp0
, fs
);
6443 gen_load_fpr32(fp1
, ft
);
6444 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6445 tcg_temp_free_i32(fp1
);
6446 gen_store_fpr32(fp0
, fd
);
6447 tcg_temp_free_i32(fp0
);
6452 check_cp1_registers(ctx
, fd
);
6454 TCGv_i32 fp32
= tcg_temp_new_i32();
6455 TCGv_i64 fp64
= tcg_temp_new_i64();
6457 gen_load_fpr32(fp32
, fs
);
6458 gen_helper_float_cvtd_s(fp64
, fp32
);
6459 tcg_temp_free_i32(fp32
);
6460 gen_store_fpr64(ctx
, fp64
, fd
);
6461 tcg_temp_free_i64(fp64
);
6467 TCGv_i32 fp0
= tcg_temp_new_i32();
6469 gen_load_fpr32(fp0
, fs
);
6470 gen_helper_float_cvtw_s(fp0
, fp0
);
6471 gen_store_fpr32(fp0
, fd
);
6472 tcg_temp_free_i32(fp0
);
6477 check_cp1_64bitmode(ctx
);
6479 TCGv_i32 fp32
= tcg_temp_new_i32();
6480 TCGv_i64 fp64
= tcg_temp_new_i64();
6482 gen_load_fpr32(fp32
, fs
);
6483 gen_helper_float_cvtl_s(fp64
, fp32
);
6484 tcg_temp_free_i32(fp32
);
6485 gen_store_fpr64(ctx
, fp64
, fd
);
6486 tcg_temp_free_i64(fp64
);
6491 check_cp1_64bitmode(ctx
);
6493 TCGv_i64 fp64
= tcg_temp_new_i64();
6494 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6495 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6497 gen_load_fpr32(fp32_0
, fs
);
6498 gen_load_fpr32(fp32_1
, ft
);
6499 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6500 tcg_temp_free_i32(fp32_1
);
6501 tcg_temp_free_i32(fp32_0
);
6502 gen_store_fpr64(ctx
, fp64
, fd
);
6503 tcg_temp_free_i64(fp64
);
6516 case OPC_CMP_NGLE_S
:
6523 if (ctx
->opcode
& (1 << 6)) {
6524 gen_cmpabs_s(ctx
, func
-48, ft
, fs
, cc
);
6525 opn
= condnames_abs
[func
-48];
6527 gen_cmp_s(ctx
, func
-48, ft
, fs
, cc
);
6528 opn
= condnames
[func
-48];
6532 check_cp1_registers(ctx
, fs
| ft
| fd
);
6534 TCGv_i64 fp0
= tcg_temp_new_i64();
6535 TCGv_i64 fp1
= tcg_temp_new_i64();
6537 gen_load_fpr64(ctx
, fp0
, fs
);
6538 gen_load_fpr64(ctx
, fp1
, ft
);
6539 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6540 tcg_temp_free_i64(fp1
);
6541 gen_store_fpr64(ctx
, fp0
, fd
);
6542 tcg_temp_free_i64(fp0
);
6548 check_cp1_registers(ctx
, fs
| ft
| fd
);
6550 TCGv_i64 fp0
= tcg_temp_new_i64();
6551 TCGv_i64 fp1
= tcg_temp_new_i64();
6553 gen_load_fpr64(ctx
, fp0
, fs
);
6554 gen_load_fpr64(ctx
, fp1
, ft
);
6555 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6556 tcg_temp_free_i64(fp1
);
6557 gen_store_fpr64(ctx
, fp0
, fd
);
6558 tcg_temp_free_i64(fp0
);
6564 check_cp1_registers(ctx
, fs
| ft
| fd
);
6566 TCGv_i64 fp0
= tcg_temp_new_i64();
6567 TCGv_i64 fp1
= tcg_temp_new_i64();
6569 gen_load_fpr64(ctx
, fp0
, fs
);
6570 gen_load_fpr64(ctx
, fp1
, ft
);
6571 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6572 tcg_temp_free_i64(fp1
);
6573 gen_store_fpr64(ctx
, fp0
, fd
);
6574 tcg_temp_free_i64(fp0
);
6580 check_cp1_registers(ctx
, fs
| ft
| fd
);
6582 TCGv_i64 fp0
= tcg_temp_new_i64();
6583 TCGv_i64 fp1
= tcg_temp_new_i64();
6585 gen_load_fpr64(ctx
, fp0
, fs
);
6586 gen_load_fpr64(ctx
, fp1
, ft
);
6587 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6588 tcg_temp_free_i64(fp1
);
6589 gen_store_fpr64(ctx
, fp0
, fd
);
6590 tcg_temp_free_i64(fp0
);
6596 check_cp1_registers(ctx
, fs
| fd
);
6598 TCGv_i64 fp0
= tcg_temp_new_i64();
6600 gen_load_fpr64(ctx
, fp0
, fs
);
6601 gen_helper_float_sqrt_d(fp0
, fp0
);
6602 gen_store_fpr64(ctx
, fp0
, fd
);
6603 tcg_temp_free_i64(fp0
);
6608 check_cp1_registers(ctx
, fs
| fd
);
6610 TCGv_i64 fp0
= tcg_temp_new_i64();
6612 gen_load_fpr64(ctx
, fp0
, fs
);
6613 gen_helper_float_abs_d(fp0
, fp0
);
6614 gen_store_fpr64(ctx
, fp0
, fd
);
6615 tcg_temp_free_i64(fp0
);
6620 check_cp1_registers(ctx
, fs
| fd
);
6622 TCGv_i64 fp0
= tcg_temp_new_i64();
6624 gen_load_fpr64(ctx
, fp0
, fs
);
6625 gen_store_fpr64(ctx
, fp0
, fd
);
6626 tcg_temp_free_i64(fp0
);
6631 check_cp1_registers(ctx
, fs
| fd
);
6633 TCGv_i64 fp0
= tcg_temp_new_i64();
6635 gen_load_fpr64(ctx
, fp0
, fs
);
6636 gen_helper_float_chs_d(fp0
, fp0
);
6637 gen_store_fpr64(ctx
, fp0
, fd
);
6638 tcg_temp_free_i64(fp0
);
6643 check_cp1_64bitmode(ctx
);
6645 TCGv_i64 fp0
= tcg_temp_new_i64();
6647 gen_load_fpr64(ctx
, fp0
, fs
);
6648 gen_helper_float_roundl_d(fp0
, fp0
);
6649 gen_store_fpr64(ctx
, fp0
, fd
);
6650 tcg_temp_free_i64(fp0
);
6655 check_cp1_64bitmode(ctx
);
6657 TCGv_i64 fp0
= tcg_temp_new_i64();
6659 gen_load_fpr64(ctx
, fp0
, fs
);
6660 gen_helper_float_truncl_d(fp0
, fp0
);
6661 gen_store_fpr64(ctx
, fp0
, fd
);
6662 tcg_temp_free_i64(fp0
);
6667 check_cp1_64bitmode(ctx
);
6669 TCGv_i64 fp0
= tcg_temp_new_i64();
6671 gen_load_fpr64(ctx
, fp0
, fs
);
6672 gen_helper_float_ceill_d(fp0
, fp0
);
6673 gen_store_fpr64(ctx
, fp0
, fd
);
6674 tcg_temp_free_i64(fp0
);
6679 check_cp1_64bitmode(ctx
);
6681 TCGv_i64 fp0
= tcg_temp_new_i64();
6683 gen_load_fpr64(ctx
, fp0
, fs
);
6684 gen_helper_float_floorl_d(fp0
, fp0
);
6685 gen_store_fpr64(ctx
, fp0
, fd
);
6686 tcg_temp_free_i64(fp0
);
6691 check_cp1_registers(ctx
, fs
);
6693 TCGv_i32 fp32
= tcg_temp_new_i32();
6694 TCGv_i64 fp64
= tcg_temp_new_i64();
6696 gen_load_fpr64(ctx
, fp64
, fs
);
6697 gen_helper_float_roundw_d(fp32
, fp64
);
6698 tcg_temp_free_i64(fp64
);
6699 gen_store_fpr32(fp32
, fd
);
6700 tcg_temp_free_i32(fp32
);
6705 check_cp1_registers(ctx
, fs
);
6707 TCGv_i32 fp32
= tcg_temp_new_i32();
6708 TCGv_i64 fp64
= tcg_temp_new_i64();
6710 gen_load_fpr64(ctx
, fp64
, fs
);
6711 gen_helper_float_truncw_d(fp32
, fp64
);
6712 tcg_temp_free_i64(fp64
);
6713 gen_store_fpr32(fp32
, fd
);
6714 tcg_temp_free_i32(fp32
);
6719 check_cp1_registers(ctx
, fs
);
6721 TCGv_i32 fp32
= tcg_temp_new_i32();
6722 TCGv_i64 fp64
= tcg_temp_new_i64();
6724 gen_load_fpr64(ctx
, fp64
, fs
);
6725 gen_helper_float_ceilw_d(fp32
, fp64
);
6726 tcg_temp_free_i64(fp64
);
6727 gen_store_fpr32(fp32
, fd
);
6728 tcg_temp_free_i32(fp32
);
6733 check_cp1_registers(ctx
, fs
);
6735 TCGv_i32 fp32
= tcg_temp_new_i32();
6736 TCGv_i64 fp64
= tcg_temp_new_i64();
6738 gen_load_fpr64(ctx
, fp64
, fs
);
6739 gen_helper_float_floorw_d(fp32
, fp64
);
6740 tcg_temp_free_i64(fp64
);
6741 gen_store_fpr32(fp32
, fd
);
6742 tcg_temp_free_i32(fp32
);
6747 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6752 int l1
= gen_new_label();
6756 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6758 fp0
= tcg_temp_new_i64();
6759 gen_load_fpr64(ctx
, fp0
, fs
);
6760 gen_store_fpr64(ctx
, fp0
, fd
);
6761 tcg_temp_free_i64(fp0
);
6768 int l1
= gen_new_label();
6772 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6773 fp0
= tcg_temp_new_i64();
6774 gen_load_fpr64(ctx
, fp0
, fs
);
6775 gen_store_fpr64(ctx
, fp0
, fd
);
6776 tcg_temp_free_i64(fp0
);
6783 check_cp1_64bitmode(ctx
);
6785 TCGv_i64 fp0
= tcg_temp_new_i64();
6787 gen_load_fpr64(ctx
, fp0
, fs
);
6788 gen_helper_float_recip_d(fp0
, fp0
);
6789 gen_store_fpr64(ctx
, fp0
, fd
);
6790 tcg_temp_free_i64(fp0
);
6795 check_cp1_64bitmode(ctx
);
6797 TCGv_i64 fp0
= tcg_temp_new_i64();
6799 gen_load_fpr64(ctx
, fp0
, fs
);
6800 gen_helper_float_rsqrt_d(fp0
, fp0
);
6801 gen_store_fpr64(ctx
, fp0
, fd
);
6802 tcg_temp_free_i64(fp0
);
6807 check_cp1_64bitmode(ctx
);
6809 TCGv_i64 fp0
= tcg_temp_new_i64();
6810 TCGv_i64 fp1
= tcg_temp_new_i64();
6812 gen_load_fpr64(ctx
, fp0
, fs
);
6813 gen_load_fpr64(ctx
, fp1
, ft
);
6814 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6815 tcg_temp_free_i64(fp1
);
6816 gen_store_fpr64(ctx
, fp0
, fd
);
6817 tcg_temp_free_i64(fp0
);
6822 check_cp1_64bitmode(ctx
);
6824 TCGv_i64 fp0
= tcg_temp_new_i64();
6826 gen_load_fpr64(ctx
, fp0
, fs
);
6827 gen_helper_float_recip1_d(fp0
, fp0
);
6828 gen_store_fpr64(ctx
, fp0
, fd
);
6829 tcg_temp_free_i64(fp0
);
6834 check_cp1_64bitmode(ctx
);
6836 TCGv_i64 fp0
= tcg_temp_new_i64();
6838 gen_load_fpr64(ctx
, fp0
, fs
);
6839 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6840 gen_store_fpr64(ctx
, fp0
, fd
);
6841 tcg_temp_free_i64(fp0
);
6846 check_cp1_64bitmode(ctx
);
6848 TCGv_i64 fp0
= tcg_temp_new_i64();
6849 TCGv_i64 fp1
= tcg_temp_new_i64();
6851 gen_load_fpr64(ctx
, fp0
, fs
);
6852 gen_load_fpr64(ctx
, fp1
, ft
);
6853 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6854 tcg_temp_free_i64(fp1
);
6855 gen_store_fpr64(ctx
, fp0
, fd
);
6856 tcg_temp_free_i64(fp0
);
6869 case OPC_CMP_NGLE_D
:
6876 if (ctx
->opcode
& (1 << 6)) {
6877 gen_cmpabs_d(ctx
, func
-48, ft
, fs
, cc
);
6878 opn
= condnames_abs
[func
-48];
6880 gen_cmp_d(ctx
, func
-48, ft
, fs
, cc
);
6881 opn
= condnames
[func
-48];
6885 check_cp1_registers(ctx
, fs
);
6887 TCGv_i32 fp32
= tcg_temp_new_i32();
6888 TCGv_i64 fp64
= tcg_temp_new_i64();
6890 gen_load_fpr64(ctx
, fp64
, fs
);
6891 gen_helper_float_cvts_d(fp32
, fp64
);
6892 tcg_temp_free_i64(fp64
);
6893 gen_store_fpr32(fp32
, fd
);
6894 tcg_temp_free_i32(fp32
);
6899 check_cp1_registers(ctx
, fs
);
6901 TCGv_i32 fp32
= tcg_temp_new_i32();
6902 TCGv_i64 fp64
= tcg_temp_new_i64();
6904 gen_load_fpr64(ctx
, fp64
, fs
);
6905 gen_helper_float_cvtw_d(fp32
, fp64
);
6906 tcg_temp_free_i64(fp64
);
6907 gen_store_fpr32(fp32
, fd
);
6908 tcg_temp_free_i32(fp32
);
6913 check_cp1_64bitmode(ctx
);
6915 TCGv_i64 fp0
= tcg_temp_new_i64();
6917 gen_load_fpr64(ctx
, fp0
, fs
);
6918 gen_helper_float_cvtl_d(fp0
, fp0
);
6919 gen_store_fpr64(ctx
, fp0
, fd
);
6920 tcg_temp_free_i64(fp0
);
6926 TCGv_i32 fp0
= tcg_temp_new_i32();
6928 gen_load_fpr32(fp0
, fs
);
6929 gen_helper_float_cvts_w(fp0
, fp0
);
6930 gen_store_fpr32(fp0
, fd
);
6931 tcg_temp_free_i32(fp0
);
6936 check_cp1_registers(ctx
, fd
);
6938 TCGv_i32 fp32
= tcg_temp_new_i32();
6939 TCGv_i64 fp64
= tcg_temp_new_i64();
6941 gen_load_fpr32(fp32
, fs
);
6942 gen_helper_float_cvtd_w(fp64
, fp32
);
6943 tcg_temp_free_i32(fp32
);
6944 gen_store_fpr64(ctx
, fp64
, fd
);
6945 tcg_temp_free_i64(fp64
);
6950 check_cp1_64bitmode(ctx
);
6952 TCGv_i32 fp32
= tcg_temp_new_i32();
6953 TCGv_i64 fp64
= tcg_temp_new_i64();
6955 gen_load_fpr64(ctx
, fp64
, fs
);
6956 gen_helper_float_cvts_l(fp32
, fp64
);
6957 tcg_temp_free_i64(fp64
);
6958 gen_store_fpr32(fp32
, fd
);
6959 tcg_temp_free_i32(fp32
);
6964 check_cp1_64bitmode(ctx
);
6966 TCGv_i64 fp0
= tcg_temp_new_i64();
6968 gen_load_fpr64(ctx
, fp0
, fs
);
6969 gen_helper_float_cvtd_l(fp0
, fp0
);
6970 gen_store_fpr64(ctx
, fp0
, fd
);
6971 tcg_temp_free_i64(fp0
);
6976 check_cp1_64bitmode(ctx
);
6978 TCGv_i64 fp0
= tcg_temp_new_i64();
6980 gen_load_fpr64(ctx
, fp0
, fs
);
6981 gen_helper_float_cvtps_pw(fp0
, fp0
);
6982 gen_store_fpr64(ctx
, fp0
, fd
);
6983 tcg_temp_free_i64(fp0
);
6988 check_cp1_64bitmode(ctx
);
6990 TCGv_i64 fp0
= tcg_temp_new_i64();
6991 TCGv_i64 fp1
= tcg_temp_new_i64();
6993 gen_load_fpr64(ctx
, fp0
, fs
);
6994 gen_load_fpr64(ctx
, fp1
, ft
);
6995 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6996 tcg_temp_free_i64(fp1
);
6997 gen_store_fpr64(ctx
, fp0
, fd
);
6998 tcg_temp_free_i64(fp0
);
7003 check_cp1_64bitmode(ctx
);
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_sub_ps(fp0
, fp0
, fp1
);
7011 tcg_temp_free_i64(fp1
);
7012 gen_store_fpr64(ctx
, fp0
, fd
);
7013 tcg_temp_free_i64(fp0
);
7018 check_cp1_64bitmode(ctx
);
7020 TCGv_i64 fp0
= tcg_temp_new_i64();
7021 TCGv_i64 fp1
= tcg_temp_new_i64();
7023 gen_load_fpr64(ctx
, fp0
, fs
);
7024 gen_load_fpr64(ctx
, fp1
, ft
);
7025 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
7026 tcg_temp_free_i64(fp1
);
7027 gen_store_fpr64(ctx
, fp0
, fd
);
7028 tcg_temp_free_i64(fp0
);
7033 check_cp1_64bitmode(ctx
);
7035 TCGv_i64 fp0
= tcg_temp_new_i64();
7037 gen_load_fpr64(ctx
, fp0
, fs
);
7038 gen_helper_float_abs_ps(fp0
, fp0
);
7039 gen_store_fpr64(ctx
, fp0
, fd
);
7040 tcg_temp_free_i64(fp0
);
7045 check_cp1_64bitmode(ctx
);
7047 TCGv_i64 fp0
= tcg_temp_new_i64();
7049 gen_load_fpr64(ctx
, fp0
, fs
);
7050 gen_store_fpr64(ctx
, fp0
, fd
);
7051 tcg_temp_free_i64(fp0
);
7056 check_cp1_64bitmode(ctx
);
7058 TCGv_i64 fp0
= tcg_temp_new_i64();
7060 gen_load_fpr64(ctx
, fp0
, fs
);
7061 gen_helper_float_chs_ps(fp0
, fp0
);
7062 gen_store_fpr64(ctx
, fp0
, fd
);
7063 tcg_temp_free_i64(fp0
);
7068 check_cp1_64bitmode(ctx
);
7069 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7073 check_cp1_64bitmode(ctx
);
7075 int l1
= gen_new_label();
7079 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
7080 fp0
= tcg_temp_new_i64();
7081 gen_load_fpr64(ctx
, fp0
, fs
);
7082 gen_store_fpr64(ctx
, fp0
, fd
);
7083 tcg_temp_free_i64(fp0
);
7089 check_cp1_64bitmode(ctx
);
7091 int l1
= gen_new_label();
7095 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7096 fp0
= tcg_temp_new_i64();
7097 gen_load_fpr64(ctx
, fp0
, fs
);
7098 gen_store_fpr64(ctx
, fp0
, fd
);
7099 tcg_temp_free_i64(fp0
);
7106 check_cp1_64bitmode(ctx
);
7108 TCGv_i64 fp0
= tcg_temp_new_i64();
7109 TCGv_i64 fp1
= tcg_temp_new_i64();
7111 gen_load_fpr64(ctx
, fp0
, ft
);
7112 gen_load_fpr64(ctx
, fp1
, fs
);
7113 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
7114 tcg_temp_free_i64(fp1
);
7115 gen_store_fpr64(ctx
, fp0
, fd
);
7116 tcg_temp_free_i64(fp0
);
7121 check_cp1_64bitmode(ctx
);
7123 TCGv_i64 fp0
= tcg_temp_new_i64();
7124 TCGv_i64 fp1
= tcg_temp_new_i64();
7126 gen_load_fpr64(ctx
, fp0
, ft
);
7127 gen_load_fpr64(ctx
, fp1
, fs
);
7128 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7129 tcg_temp_free_i64(fp1
);
7130 gen_store_fpr64(ctx
, fp0
, fd
);
7131 tcg_temp_free_i64(fp0
);
7136 check_cp1_64bitmode(ctx
);
7138 TCGv_i64 fp0
= tcg_temp_new_i64();
7139 TCGv_i64 fp1
= tcg_temp_new_i64();
7141 gen_load_fpr64(ctx
, fp0
, fs
);
7142 gen_load_fpr64(ctx
, fp1
, fd
);
7143 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7144 tcg_temp_free_i64(fp1
);
7145 gen_store_fpr64(ctx
, fp0
, fd
);
7146 tcg_temp_free_i64(fp0
);
7151 check_cp1_64bitmode(ctx
);
7153 TCGv_i64 fp0
= tcg_temp_new_i64();
7155 gen_load_fpr64(ctx
, fp0
, fs
);
7156 gen_helper_float_recip1_ps(fp0
, fp0
);
7157 gen_store_fpr64(ctx
, fp0
, fd
);
7158 tcg_temp_free_i64(fp0
);
7163 check_cp1_64bitmode(ctx
);
7165 TCGv_i64 fp0
= tcg_temp_new_i64();
7167 gen_load_fpr64(ctx
, fp0
, fs
);
7168 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7169 gen_store_fpr64(ctx
, fp0
, fd
);
7170 tcg_temp_free_i64(fp0
);
7175 check_cp1_64bitmode(ctx
);
7177 TCGv_i64 fp0
= tcg_temp_new_i64();
7178 TCGv_i64 fp1
= tcg_temp_new_i64();
7180 gen_load_fpr64(ctx
, fp0
, fs
);
7181 gen_load_fpr64(ctx
, fp1
, ft
);
7182 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7183 tcg_temp_free_i64(fp1
);
7184 gen_store_fpr64(ctx
, fp0
, fd
);
7185 tcg_temp_free_i64(fp0
);
7190 check_cp1_64bitmode(ctx
);
7192 TCGv_i32 fp0
= tcg_temp_new_i32();
7194 gen_load_fpr32h(fp0
, fs
);
7195 gen_helper_float_cvts_pu(fp0
, fp0
);
7196 gen_store_fpr32(fp0
, fd
);
7197 tcg_temp_free_i32(fp0
);
7202 check_cp1_64bitmode(ctx
);
7204 TCGv_i64 fp0
= tcg_temp_new_i64();
7206 gen_load_fpr64(ctx
, fp0
, fs
);
7207 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7208 gen_store_fpr64(ctx
, fp0
, fd
);
7209 tcg_temp_free_i64(fp0
);
7214 check_cp1_64bitmode(ctx
);
7216 TCGv_i32 fp0
= tcg_temp_new_i32();
7218 gen_load_fpr32(fp0
, fs
);
7219 gen_helper_float_cvts_pl(fp0
, fp0
);
7220 gen_store_fpr32(fp0
, fd
);
7221 tcg_temp_free_i32(fp0
);
7226 check_cp1_64bitmode(ctx
);
7228 TCGv_i32 fp0
= tcg_temp_new_i32();
7229 TCGv_i32 fp1
= tcg_temp_new_i32();
7231 gen_load_fpr32(fp0
, fs
);
7232 gen_load_fpr32(fp1
, ft
);
7233 gen_store_fpr32h(fp0
, fd
);
7234 gen_store_fpr32(fp1
, fd
);
7235 tcg_temp_free_i32(fp0
);
7236 tcg_temp_free_i32(fp1
);
7241 check_cp1_64bitmode(ctx
);
7243 TCGv_i32 fp0
= tcg_temp_new_i32();
7244 TCGv_i32 fp1
= tcg_temp_new_i32();
7246 gen_load_fpr32(fp0
, fs
);
7247 gen_load_fpr32h(fp1
, ft
);
7248 gen_store_fpr32(fp1
, fd
);
7249 gen_store_fpr32h(fp0
, fd
);
7250 tcg_temp_free_i32(fp0
);
7251 tcg_temp_free_i32(fp1
);
7256 check_cp1_64bitmode(ctx
);
7258 TCGv_i32 fp0
= tcg_temp_new_i32();
7259 TCGv_i32 fp1
= tcg_temp_new_i32();
7261 gen_load_fpr32h(fp0
, fs
);
7262 gen_load_fpr32(fp1
, ft
);
7263 gen_store_fpr32(fp1
, fd
);
7264 gen_store_fpr32h(fp0
, fd
);
7265 tcg_temp_free_i32(fp0
);
7266 tcg_temp_free_i32(fp1
);
7271 check_cp1_64bitmode(ctx
);
7273 TCGv_i32 fp0
= tcg_temp_new_i32();
7274 TCGv_i32 fp1
= tcg_temp_new_i32();
7276 gen_load_fpr32h(fp0
, fs
);
7277 gen_load_fpr32h(fp1
, ft
);
7278 gen_store_fpr32(fp1
, fd
);
7279 gen_store_fpr32h(fp0
, fd
);
7280 tcg_temp_free_i32(fp0
);
7281 tcg_temp_free_i32(fp1
);
7288 case OPC_CMP_UEQ_PS
:
7289 case OPC_CMP_OLT_PS
:
7290 case OPC_CMP_ULT_PS
:
7291 case OPC_CMP_OLE_PS
:
7292 case OPC_CMP_ULE_PS
:
7294 case OPC_CMP_NGLE_PS
:
7295 case OPC_CMP_SEQ_PS
:
7296 case OPC_CMP_NGL_PS
:
7298 case OPC_CMP_NGE_PS
:
7300 case OPC_CMP_NGT_PS
:
7301 if (ctx
->opcode
& (1 << 6)) {
7302 gen_cmpabs_ps(ctx
, func
-48, ft
, fs
, cc
);
7303 opn
= condnames_abs
[func
-48];
7305 gen_cmp_ps(ctx
, func
-48, ft
, fs
, cc
);
7306 opn
= condnames
[func
-48];
7311 generate_exception (ctx
, EXCP_RI
);
7316 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7319 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7322 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7327 /* Coprocessor 3 (FPU) */
7328 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7329 int fd
, int fs
, int base
, int index
)
7331 const char *opn
= "extended float load/store";
7333 TCGv t0
= tcg_temp_new();
7336 gen_load_gpr(t0
, index
);
7337 } else if (index
== 0) {
7338 gen_load_gpr(t0
, base
);
7340 gen_load_gpr(t0
, index
);
7341 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7343 /* Don't do NOP if destination is zero: we must perform the actual
7345 save_cpu_state(ctx
, 0);
7350 TCGv_i32 fp0
= tcg_temp_new_i32();
7352 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7353 tcg_gen_trunc_tl_i32(fp0
, t0
);
7354 gen_store_fpr32(fp0
, fd
);
7355 tcg_temp_free_i32(fp0
);
7361 check_cp1_registers(ctx
, fd
);
7363 TCGv_i64 fp0
= tcg_temp_new_i64();
7365 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7366 gen_store_fpr64(ctx
, fp0
, fd
);
7367 tcg_temp_free_i64(fp0
);
7372 check_cp1_64bitmode(ctx
);
7373 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7375 TCGv_i64 fp0
= tcg_temp_new_i64();
7377 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7378 gen_store_fpr64(ctx
, fp0
, fd
);
7379 tcg_temp_free_i64(fp0
);
7386 TCGv_i32 fp0
= tcg_temp_new_i32();
7387 TCGv t1
= tcg_temp_new();
7389 gen_load_fpr32(fp0
, fs
);
7390 tcg_gen_extu_i32_tl(t1
, fp0
);
7391 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7392 tcg_temp_free_i32(fp0
);
7400 check_cp1_registers(ctx
, fs
);
7402 TCGv_i64 fp0
= tcg_temp_new_i64();
7404 gen_load_fpr64(ctx
, fp0
, fs
);
7405 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7406 tcg_temp_free_i64(fp0
);
7412 check_cp1_64bitmode(ctx
);
7413 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7415 TCGv_i64 fp0
= tcg_temp_new_i64();
7417 gen_load_fpr64(ctx
, fp0
, fs
);
7418 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7419 tcg_temp_free_i64(fp0
);
7426 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7427 regnames
[index
], regnames
[base
]);
7430 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7431 int fd
, int fr
, int fs
, int ft
)
7433 const char *opn
= "flt3_arith";
7437 check_cp1_64bitmode(ctx
);
7439 TCGv t0
= tcg_temp_local_new();
7440 TCGv_i32 fp
= tcg_temp_new_i32();
7441 TCGv_i32 fph
= tcg_temp_new_i32();
7442 int l1
= gen_new_label();
7443 int l2
= gen_new_label();
7445 gen_load_gpr(t0
, fr
);
7446 tcg_gen_andi_tl(t0
, t0
, 0x7);
7448 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7449 gen_load_fpr32(fp
, fs
);
7450 gen_load_fpr32h(fph
, fs
);
7451 gen_store_fpr32(fp
, fd
);
7452 gen_store_fpr32h(fph
, fd
);
7455 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7457 #ifdef TARGET_WORDS_BIGENDIAN
7458 gen_load_fpr32(fp
, fs
);
7459 gen_load_fpr32h(fph
, ft
);
7460 gen_store_fpr32h(fp
, fd
);
7461 gen_store_fpr32(fph
, fd
);
7463 gen_load_fpr32h(fph
, fs
);
7464 gen_load_fpr32(fp
, ft
);
7465 gen_store_fpr32(fph
, fd
);
7466 gen_store_fpr32h(fp
, fd
);
7469 tcg_temp_free_i32(fp
);
7470 tcg_temp_free_i32(fph
);
7477 TCGv_i32 fp0
= tcg_temp_new_i32();
7478 TCGv_i32 fp1
= tcg_temp_new_i32();
7479 TCGv_i32 fp2
= tcg_temp_new_i32();
7481 gen_load_fpr32(fp0
, fs
);
7482 gen_load_fpr32(fp1
, ft
);
7483 gen_load_fpr32(fp2
, fr
);
7484 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7485 tcg_temp_free_i32(fp0
);
7486 tcg_temp_free_i32(fp1
);
7487 gen_store_fpr32(fp2
, fd
);
7488 tcg_temp_free_i32(fp2
);
7494 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7496 TCGv_i64 fp0
= tcg_temp_new_i64();
7497 TCGv_i64 fp1
= tcg_temp_new_i64();
7498 TCGv_i64 fp2
= tcg_temp_new_i64();
7500 gen_load_fpr64(ctx
, fp0
, fs
);
7501 gen_load_fpr64(ctx
, fp1
, ft
);
7502 gen_load_fpr64(ctx
, fp2
, fr
);
7503 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7504 tcg_temp_free_i64(fp0
);
7505 tcg_temp_free_i64(fp1
);
7506 gen_store_fpr64(ctx
, fp2
, fd
);
7507 tcg_temp_free_i64(fp2
);
7512 check_cp1_64bitmode(ctx
);
7514 TCGv_i64 fp0
= tcg_temp_new_i64();
7515 TCGv_i64 fp1
= tcg_temp_new_i64();
7516 TCGv_i64 fp2
= tcg_temp_new_i64();
7518 gen_load_fpr64(ctx
, fp0
, fs
);
7519 gen_load_fpr64(ctx
, fp1
, ft
);
7520 gen_load_fpr64(ctx
, fp2
, fr
);
7521 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7522 tcg_temp_free_i64(fp0
);
7523 tcg_temp_free_i64(fp1
);
7524 gen_store_fpr64(ctx
, fp2
, fd
);
7525 tcg_temp_free_i64(fp2
);
7532 TCGv_i32 fp0
= tcg_temp_new_i32();
7533 TCGv_i32 fp1
= tcg_temp_new_i32();
7534 TCGv_i32 fp2
= tcg_temp_new_i32();
7536 gen_load_fpr32(fp0
, fs
);
7537 gen_load_fpr32(fp1
, ft
);
7538 gen_load_fpr32(fp2
, fr
);
7539 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7540 tcg_temp_free_i32(fp0
);
7541 tcg_temp_free_i32(fp1
);
7542 gen_store_fpr32(fp2
, fd
);
7543 tcg_temp_free_i32(fp2
);
7549 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7551 TCGv_i64 fp0
= tcg_temp_new_i64();
7552 TCGv_i64 fp1
= tcg_temp_new_i64();
7553 TCGv_i64 fp2
= tcg_temp_new_i64();
7555 gen_load_fpr64(ctx
, fp0
, fs
);
7556 gen_load_fpr64(ctx
, fp1
, ft
);
7557 gen_load_fpr64(ctx
, fp2
, fr
);
7558 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7559 tcg_temp_free_i64(fp0
);
7560 tcg_temp_free_i64(fp1
);
7561 gen_store_fpr64(ctx
, fp2
, fd
);
7562 tcg_temp_free_i64(fp2
);
7567 check_cp1_64bitmode(ctx
);
7569 TCGv_i64 fp0
= tcg_temp_new_i64();
7570 TCGv_i64 fp1
= tcg_temp_new_i64();
7571 TCGv_i64 fp2
= tcg_temp_new_i64();
7573 gen_load_fpr64(ctx
, fp0
, fs
);
7574 gen_load_fpr64(ctx
, fp1
, ft
);
7575 gen_load_fpr64(ctx
, fp2
, fr
);
7576 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7577 tcg_temp_free_i64(fp0
);
7578 tcg_temp_free_i64(fp1
);
7579 gen_store_fpr64(ctx
, fp2
, fd
);
7580 tcg_temp_free_i64(fp2
);
7587 TCGv_i32 fp0
= tcg_temp_new_i32();
7588 TCGv_i32 fp1
= tcg_temp_new_i32();
7589 TCGv_i32 fp2
= tcg_temp_new_i32();
7591 gen_load_fpr32(fp0
, fs
);
7592 gen_load_fpr32(fp1
, ft
);
7593 gen_load_fpr32(fp2
, fr
);
7594 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7595 tcg_temp_free_i32(fp0
);
7596 tcg_temp_free_i32(fp1
);
7597 gen_store_fpr32(fp2
, fd
);
7598 tcg_temp_free_i32(fp2
);
7604 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7606 TCGv_i64 fp0
= tcg_temp_new_i64();
7607 TCGv_i64 fp1
= tcg_temp_new_i64();
7608 TCGv_i64 fp2
= tcg_temp_new_i64();
7610 gen_load_fpr64(ctx
, fp0
, fs
);
7611 gen_load_fpr64(ctx
, fp1
, ft
);
7612 gen_load_fpr64(ctx
, fp2
, fr
);
7613 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7614 tcg_temp_free_i64(fp0
);
7615 tcg_temp_free_i64(fp1
);
7616 gen_store_fpr64(ctx
, fp2
, fd
);
7617 tcg_temp_free_i64(fp2
);
7622 check_cp1_64bitmode(ctx
);
7624 TCGv_i64 fp0
= tcg_temp_new_i64();
7625 TCGv_i64 fp1
= tcg_temp_new_i64();
7626 TCGv_i64 fp2
= tcg_temp_new_i64();
7628 gen_load_fpr64(ctx
, fp0
, fs
);
7629 gen_load_fpr64(ctx
, fp1
, ft
);
7630 gen_load_fpr64(ctx
, fp2
, fr
);
7631 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7632 tcg_temp_free_i64(fp0
);
7633 tcg_temp_free_i64(fp1
);
7634 gen_store_fpr64(ctx
, fp2
, fd
);
7635 tcg_temp_free_i64(fp2
);
7642 TCGv_i32 fp0
= tcg_temp_new_i32();
7643 TCGv_i32 fp1
= tcg_temp_new_i32();
7644 TCGv_i32 fp2
= tcg_temp_new_i32();
7646 gen_load_fpr32(fp0
, fs
);
7647 gen_load_fpr32(fp1
, ft
);
7648 gen_load_fpr32(fp2
, fr
);
7649 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7650 tcg_temp_free_i32(fp0
);
7651 tcg_temp_free_i32(fp1
);
7652 gen_store_fpr32(fp2
, fd
);
7653 tcg_temp_free_i32(fp2
);
7659 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7661 TCGv_i64 fp0
= tcg_temp_new_i64();
7662 TCGv_i64 fp1
= tcg_temp_new_i64();
7663 TCGv_i64 fp2
= tcg_temp_new_i64();
7665 gen_load_fpr64(ctx
, fp0
, fs
);
7666 gen_load_fpr64(ctx
, fp1
, ft
);
7667 gen_load_fpr64(ctx
, fp2
, fr
);
7668 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7669 tcg_temp_free_i64(fp0
);
7670 tcg_temp_free_i64(fp1
);
7671 gen_store_fpr64(ctx
, fp2
, fd
);
7672 tcg_temp_free_i64(fp2
);
7677 check_cp1_64bitmode(ctx
);
7679 TCGv_i64 fp0
= tcg_temp_new_i64();
7680 TCGv_i64 fp1
= tcg_temp_new_i64();
7681 TCGv_i64 fp2
= tcg_temp_new_i64();
7683 gen_load_fpr64(ctx
, fp0
, fs
);
7684 gen_load_fpr64(ctx
, fp1
, ft
);
7685 gen_load_fpr64(ctx
, fp2
, fr
);
7686 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7687 tcg_temp_free_i64(fp0
);
7688 tcg_temp_free_i64(fp1
);
7689 gen_store_fpr64(ctx
, fp2
, fd
);
7690 tcg_temp_free_i64(fp2
);
7696 generate_exception (ctx
, EXCP_RI
);
7699 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7700 fregnames
[fs
], fregnames
[ft
]);
7704 gen_rdhwr (CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
)
7708 check_insn(env
, ctx
, ISA_MIPS32R2
);
7709 t0
= tcg_temp_new();
7713 save_cpu_state(ctx
, 1);
7714 gen_helper_rdhwr_cpunum(t0
);
7715 gen_store_gpr(t0
, rt
);
7718 save_cpu_state(ctx
, 1);
7719 gen_helper_rdhwr_synci_step(t0
);
7720 gen_store_gpr(t0
, rt
);
7723 save_cpu_state(ctx
, 1);
7724 gen_helper_rdhwr_cc(t0
);
7725 gen_store_gpr(t0
, rt
);
7728 save_cpu_state(ctx
, 1);
7729 gen_helper_rdhwr_ccres(t0
);
7730 gen_store_gpr(t0
, rt
);
7733 #if defined(CONFIG_USER_ONLY)
7734 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7735 gen_store_gpr(t0
, rt
);
7738 /* XXX: Some CPUs implement this in hardware.
7739 Not supported yet. */
7741 default: /* Invalid */
7742 MIPS_INVAL("rdhwr");
7743 generate_exception(ctx
, EXCP_RI
);
7749 static void handle_delay_slot (CPUState
*env
, DisasContext
*ctx
,
7752 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7753 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7754 /* Branches completion */
7755 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7756 ctx
->bstate
= BS_BRANCH
;
7757 save_cpu_state(ctx
, 0);
7758 /* FIXME: Need to clear can_do_io. */
7759 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
7761 /* unconditional branch */
7762 MIPS_DEBUG("unconditional branch");
7763 if (proc_hflags
& MIPS_HFLAG_BX
) {
7764 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
7766 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7769 /* blikely taken case */
7770 MIPS_DEBUG("blikely branch taken");
7771 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7774 /* Conditional branch */
7775 MIPS_DEBUG("conditional branch");
7777 int l1
= gen_new_label();
7779 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7780 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
7782 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7786 /* unconditional branch to register */
7787 MIPS_DEBUG("branch to register");
7788 if (env
->insn_flags
& ASE_MIPS16
) {
7789 TCGv t0
= tcg_temp_new();
7790 TCGv_i32 t1
= tcg_temp_new_i32();
7792 tcg_gen_andi_tl(t0
, btarget
, 0x1);
7793 tcg_gen_trunc_tl_i32(t1
, t0
);
7795 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
7796 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
7797 tcg_gen_or_i32(hflags
, hflags
, t1
);
7798 tcg_temp_free_i32(t1
);
7800 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
7802 tcg_gen_mov_tl(cpu_PC
, btarget
);
7804 if (ctx
->singlestep_enabled
) {
7805 save_cpu_state(ctx
, 0);
7806 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
7811 MIPS_DEBUG("unknown branch");
7817 /* ISA extensions (ASEs) */
7818 /* MIPS16 extension to MIPS32 */
7820 /* MIPS16 major opcodes */
7822 M16_OPC_ADDIUSP
= 0x00,
7823 M16_OPC_ADDIUPC
= 0x01,
7826 M16_OPC_BEQZ
= 0x04,
7827 M16_OPC_BNEQZ
= 0x05,
7828 M16_OPC_SHIFT
= 0x06,
7830 M16_OPC_RRIA
= 0x08,
7831 M16_OPC_ADDIU8
= 0x09,
7832 M16_OPC_SLTI
= 0x0a,
7833 M16_OPC_SLTIU
= 0x0b,
7836 M16_OPC_CMPI
= 0x0e,
7840 M16_OPC_LWSP
= 0x12,
7844 M16_OPC_LWPC
= 0x16,
7848 M16_OPC_SWSP
= 0x1a,
7852 M16_OPC_EXTEND
= 0x1e,
7856 /* I8 funct field */
7875 /* RR funct field */
7909 /* I64 funct field */
7921 /* RR ry field for CNVT */
7923 RR_RY_CNVT_ZEB
= 0x0,
7924 RR_RY_CNVT_ZEH
= 0x1,
7925 RR_RY_CNVT_ZEW
= 0x2,
7926 RR_RY_CNVT_SEB
= 0x4,
7927 RR_RY_CNVT_SEH
= 0x5,
7928 RR_RY_CNVT_SEW
= 0x6,
7931 static int xlat (int r
)
7933 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
7938 static void gen_mips16_save (DisasContext
*ctx
,
7939 int xsregs
, int aregs
,
7940 int do_ra
, int do_s0
, int do_s1
,
7943 TCGv t0
= tcg_temp_new();
7944 TCGv t1
= tcg_temp_new();
7974 generate_exception(ctx
, EXCP_RI
);
7980 gen_base_offset_addr(ctx
, t0
, 29, 12);
7981 gen_load_gpr(t1
, 7);
7982 op_ldst_sw(t1
, t0
, ctx
);
7985 gen_base_offset_addr(ctx
, t0
, 29, 8);
7986 gen_load_gpr(t1
, 6);
7987 op_ldst_sw(t1
, t0
, ctx
);
7990 gen_base_offset_addr(ctx
, t0
, 29, 4);
7991 gen_load_gpr(t1
, 5);
7992 op_ldst_sw(t1
, t0
, ctx
);
7995 gen_base_offset_addr(ctx
, t0
, 29, 0);
7996 gen_load_gpr(t1
, 4);
7997 op_ldst_sw(t1
, t0
, ctx
);
8000 gen_load_gpr(t0
, 29);
8002 #define DECR_AND_STORE(reg) do { \
8003 tcg_gen_subi_tl(t0, t0, 4); \
8004 gen_load_gpr(t1, reg); \
8005 op_ldst_sw(t1, t0, ctx); \
8069 generate_exception(ctx
, EXCP_RI
);
8085 #undef DECR_AND_STORE
8087 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8092 static void gen_mips16_restore (DisasContext
*ctx
,
8093 int xsregs
, int aregs
,
8094 int do_ra
, int do_s0
, int do_s1
,
8098 TCGv t0
= tcg_temp_new();
8099 TCGv t1
= tcg_temp_new();
8101 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
8103 #define DECR_AND_LOAD(reg) do { \
8104 tcg_gen_subi_tl(t0, t0, 4); \
8105 op_ldst_lw(t1, t0, ctx); \
8106 gen_store_gpr(t1, reg); \
8170 generate_exception(ctx
, EXCP_RI
);
8186 #undef DECR_AND_LOAD
8188 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8193 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
8194 int is_64_bit
, int extended
)
8198 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8199 generate_exception(ctx
, EXCP_RI
);
8203 t0
= tcg_temp_new();
8205 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
8206 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
8208 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8214 #if defined(TARGET_MIPS64)
8215 static void decode_i64_mips16 (CPUState
*env
, DisasContext
*ctx
,
8216 int ry
, int funct
, int16_t offset
,
8222 offset
= extended
? offset
: offset
<< 3;
8223 gen_ldst(ctx
, OPC_LD
, ry
, 29, offset
);
8227 offset
= extended
? offset
: offset
<< 3;
8228 gen_ldst(ctx
, OPC_SD
, ry
, 29, offset
);
8232 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8233 gen_ldst(ctx
, OPC_SD
, 31, 29, offset
);
8237 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8238 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8241 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8242 generate_exception(ctx
, EXCP_RI
);
8244 offset
= extended
? offset
: offset
<< 3;
8245 gen_ldst(ctx
, OPC_LDPC
, ry
, 0, offset
);
8250 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8251 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8255 offset
= extended
? offset
: offset
<< 2;
8256 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8260 offset
= extended
? offset
: offset
<< 2;
8261 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8267 static int decode_extended_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8270 int extend
= lduw_code(ctx
->pc
+ 2);
8271 int op
, rx
, ry
, funct
, sa
;
8272 int16_t imm
, offset
;
8274 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8275 op
= (ctx
->opcode
>> 11) & 0x1f;
8276 sa
= (ctx
->opcode
>> 22) & 0x1f;
8277 funct
= (ctx
->opcode
>> 8) & 0x7;
8278 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8279 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8280 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8281 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8282 | (ctx
->opcode
& 0x1f));
8284 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8287 case M16_OPC_ADDIUSP
:
8288 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8290 case M16_OPC_ADDIUPC
:
8291 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8294 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8295 /* No delay slot, so just process as a normal instruction */
8298 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8299 /* No delay slot, so just process as a normal instruction */
8302 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8303 /* No delay slot, so just process as a normal instruction */
8306 switch (ctx
->opcode
& 0x3) {
8308 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8311 #if defined(TARGET_MIPS64)
8313 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8315 generate_exception(ctx
, EXCP_RI
);
8319 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8322 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8326 #if defined(TARGET_MIPS64)
8329 gen_ldst(ctx
, OPC_LD
, ry
, rx
, offset
);
8333 imm
= ctx
->opcode
& 0xf;
8334 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8335 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8336 imm
= (int16_t) (imm
<< 1) >> 1;
8337 if ((ctx
->opcode
>> 4) & 0x1) {
8338 #if defined(TARGET_MIPS64)
8340 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8342 generate_exception(ctx
, EXCP_RI
);
8345 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8348 case M16_OPC_ADDIU8
:
8349 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8352 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8355 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8360 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8363 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8366 gen_ldst(ctx
, OPC_SW
, 31, 29, imm
);
8369 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8373 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8374 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8375 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8376 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8377 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8378 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8379 | (ctx
->opcode
& 0xf)) << 3;
8381 if (ctx
->opcode
& (1 << 7)) {
8382 gen_mips16_save(ctx
, xsregs
, aregs
,
8383 do_ra
, do_s0
, do_s1
,
8386 gen_mips16_restore(ctx
, xsregs
, aregs
,
8387 do_ra
, do_s0
, do_s1
,
8393 generate_exception(ctx
, EXCP_RI
);
8398 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8401 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8403 #if defined(TARGET_MIPS64)
8405 gen_ldst(ctx
, OPC_SD
, ry
, rx
, offset
);
8409 gen_ldst(ctx
, OPC_LB
, ry
, rx
, offset
);
8412 gen_ldst(ctx
, OPC_LH
, ry
, rx
, offset
);
8415 gen_ldst(ctx
, OPC_LW
, rx
, 29, offset
);
8418 gen_ldst(ctx
, OPC_LW
, ry
, rx
, offset
);
8421 gen_ldst(ctx
, OPC_LBU
, ry
, rx
, offset
);
8424 gen_ldst(ctx
, OPC_LHU
, ry
, rx
, offset
);
8427 gen_ldst(ctx
, OPC_LWPC
, rx
, 0, offset
);
8429 #if defined(TARGET_MIPS64)
8431 gen_ldst(ctx
, OPC_LWU
, ry
, rx
, offset
);
8435 gen_ldst(ctx
, OPC_SB
, ry
, rx
, offset
);
8438 gen_ldst(ctx
, OPC_SH
, ry
, rx
, offset
);
8441 gen_ldst(ctx
, OPC_SW
, rx
, 29, offset
);
8444 gen_ldst(ctx
, OPC_SW
, ry
, rx
, offset
);
8446 #if defined(TARGET_MIPS64)
8448 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8452 generate_exception(ctx
, EXCP_RI
);
8459 static int decode_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8464 int op
, cnvt_op
, op1
, offset
;
8468 op
= (ctx
->opcode
>> 11) & 0x1f;
8469 sa
= (ctx
->opcode
>> 2) & 0x7;
8470 sa
= sa
== 0 ? 8 : sa
;
8471 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8472 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8473 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8474 op1
= offset
= ctx
->opcode
& 0x1f;
8479 case M16_OPC_ADDIUSP
:
8481 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8483 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8486 case M16_OPC_ADDIUPC
:
8487 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8490 offset
= (ctx
->opcode
& 0x7ff) << 1;
8491 offset
= (int16_t)(offset
<< 4) >> 4;
8492 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8493 /* No delay slot, so just process as a normal instruction */
8496 offset
= lduw_code(ctx
->pc
+ 2);
8497 offset
= (((ctx
->opcode
& 0x1f) << 21)
8498 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8500 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALXS
: OPC_JALS
;
8501 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8506 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8507 /* No delay slot, so just process as a normal instruction */
8510 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8511 /* No delay slot, so just process as a normal instruction */
8514 switch (ctx
->opcode
& 0x3) {
8516 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8519 #if defined(TARGET_MIPS64)
8521 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8523 generate_exception(ctx
, EXCP_RI
);
8527 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8530 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8534 #if defined(TARGET_MIPS64)
8537 gen_ldst(ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8542 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8544 if ((ctx
->opcode
>> 4) & 1) {
8545 #if defined(TARGET_MIPS64)
8547 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8549 generate_exception(ctx
, EXCP_RI
);
8552 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8556 case M16_OPC_ADDIU8
:
8558 int16_t imm
= (int8_t) ctx
->opcode
;
8560 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8565 int16_t imm
= (uint8_t) ctx
->opcode
;
8567 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8572 int16_t imm
= (uint8_t) ctx
->opcode
;
8574 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8581 funct
= (ctx
->opcode
>> 8) & 0x7;
8584 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
8585 ((int8_t)ctx
->opcode
) << 1);
8588 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
8589 ((int8_t)ctx
->opcode
) << 1);
8592 gen_ldst(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
8595 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
8596 ((int8_t)ctx
->opcode
) << 3);
8600 int do_ra
= ctx
->opcode
& (1 << 6);
8601 int do_s0
= ctx
->opcode
& (1 << 5);
8602 int do_s1
= ctx
->opcode
& (1 << 4);
8603 int framesize
= ctx
->opcode
& 0xf;
8605 if (framesize
== 0) {
8608 framesize
= framesize
<< 3;
8611 if (ctx
->opcode
& (1 << 7)) {
8612 gen_mips16_save(ctx
, 0, 0,
8613 do_ra
, do_s0
, do_s1
, framesize
);
8615 gen_mips16_restore(ctx
, 0, 0,
8616 do_ra
, do_s0
, do_s1
, framesize
);
8622 int rz
= xlat(ctx
->opcode
& 0x7);
8624 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
8625 ((ctx
->opcode
>> 5) & 0x7);
8626 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
8630 reg32
= ctx
->opcode
& 0x1f;
8631 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
8634 generate_exception(ctx
, EXCP_RI
);
8641 int16_t imm
= (uint8_t) ctx
->opcode
;
8643 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
8648 int16_t imm
= (uint8_t) ctx
->opcode
;
8650 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
8653 #if defined(TARGET_MIPS64)
8656 gen_ldst(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
8660 gen_ldst(ctx
, OPC_LB
, ry
, rx
, offset
);
8663 gen_ldst(ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
8666 gen_ldst(ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8669 gen_ldst(ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
8672 gen_ldst(ctx
, OPC_LBU
, ry
, rx
, offset
);
8675 gen_ldst(ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
8678 gen_ldst(ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
8680 #if defined (TARGET_MIPS64)
8683 gen_ldst(ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
8687 gen_ldst(ctx
, OPC_SB
, ry
, rx
, offset
);
8690 gen_ldst(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
8693 gen_ldst(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8696 gen_ldst(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
8700 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
8703 switch (ctx
->opcode
& 0x3) {
8705 mips32_op
= OPC_ADDU
;
8708 mips32_op
= OPC_SUBU
;
8710 #if defined(TARGET_MIPS64)
8712 mips32_op
= OPC_DADDU
;
8716 mips32_op
= OPC_DSUBU
;
8721 generate_exception(ctx
, EXCP_RI
);
8725 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
8734 int nd
= (ctx
->opcode
>> 7) & 0x1;
8735 int link
= (ctx
->opcode
>> 6) & 0x1;
8736 int ra
= (ctx
->opcode
>> 5) & 0x1;
8739 op
= nd
? OPC_JALRC
: OPC_JALRS
;
8744 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
8751 /* XXX: not clear which exception should be raised
8752 * when in debug mode...
8754 check_insn(env
, ctx
, ISA_MIPS32
);
8755 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8756 generate_exception(ctx
, EXCP_DBp
);
8758 generate_exception(ctx
, EXCP_DBp
);
8762 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
8765 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
8768 generate_exception(ctx
, EXCP_BREAK
);
8771 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
8774 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
8777 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
8779 #if defined (TARGET_MIPS64)
8782 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
8786 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
8789 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
8792 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
8795 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
8798 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
8801 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
8804 gen_HILO(ctx
, OPC_MFHI
, rx
);
8808 case RR_RY_CNVT_ZEB
:
8809 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8811 case RR_RY_CNVT_ZEH
:
8812 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8814 case RR_RY_CNVT_SEB
:
8815 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8817 case RR_RY_CNVT_SEH
:
8818 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8820 #if defined (TARGET_MIPS64)
8821 case RR_RY_CNVT_ZEW
:
8823 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8825 case RR_RY_CNVT_SEW
:
8827 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8831 generate_exception(ctx
, EXCP_RI
);
8836 gen_HILO(ctx
, OPC_MFLO
, rx
);
8838 #if defined (TARGET_MIPS64)
8841 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
8845 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
8849 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
8853 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
8857 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
8860 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
8863 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
8866 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
8868 #if defined (TARGET_MIPS64)
8871 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
8875 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
8879 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
8883 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
8887 generate_exception(ctx
, EXCP_RI
);
8891 case M16_OPC_EXTEND
:
8892 decode_extended_mips16_opc(env
, ctx
, is_branch
);
8895 #if defined(TARGET_MIPS64)
8897 funct
= (ctx
->opcode
>> 8) & 0x7;
8898 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
8902 generate_exception(ctx
, EXCP_RI
);
8909 /* SmartMIPS extension to MIPS32 */
8911 #if defined(TARGET_MIPS64)
8913 /* MDMX extension to MIPS64 */
8917 static void decode_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
8921 uint32_t op
, op1
, op2
;
8924 /* make sure instructions are on a word boundary */
8925 if (ctx
->pc
& 0x3) {
8926 env
->CP0_BadVAddr
= ctx
->pc
;
8927 generate_exception(ctx
, EXCP_AdEL
);
8931 /* Handle blikely not taken case */
8932 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
8933 int l1
= gen_new_label();
8935 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
8936 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8937 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
8938 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8942 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
8943 tcg_gen_debug_insn_start(ctx
->pc
);
8945 op
= MASK_OP_MAJOR(ctx
->opcode
);
8946 rs
= (ctx
->opcode
>> 21) & 0x1f;
8947 rt
= (ctx
->opcode
>> 16) & 0x1f;
8948 rd
= (ctx
->opcode
>> 11) & 0x1f;
8949 sa
= (ctx
->opcode
>> 6) & 0x1f;
8950 imm
= (int16_t)ctx
->opcode
;
8953 op1
= MASK_SPECIAL(ctx
->opcode
);
8955 case OPC_SLL
: /* Shift with immediate */
8957 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8960 switch ((ctx
->opcode
>> 21) & 0x1f) {
8962 /* rotr is decoded as srl on non-R2 CPUs */
8963 if (env
->insn_flags
& ISA_MIPS32R2
) {
8968 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8971 generate_exception(ctx
, EXCP_RI
);
8975 case OPC_MOVN
: /* Conditional move */
8977 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8978 gen_cond_move(env
, op1
, rd
, rs
, rt
);
8980 case OPC_ADD
... OPC_SUBU
:
8981 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8983 case OPC_SLLV
: /* Shifts */
8985 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8988 switch ((ctx
->opcode
>> 6) & 0x1f) {
8990 /* rotrv is decoded as srlv on non-R2 CPUs */
8991 if (env
->insn_flags
& ISA_MIPS32R2
) {
8996 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8999 generate_exception(ctx
, EXCP_RI
);
9003 case OPC_SLT
: /* Set on less than */
9005 gen_slt(env
, op1
, rd
, rs
, rt
);
9007 case OPC_AND
: /* Logic*/
9011 gen_logic(env
, op1
, rd
, rs
, rt
);
9013 case OPC_MULT
... OPC_DIVU
:
9015 check_insn(env
, ctx
, INSN_VR54XX
);
9016 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
9017 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
9019 gen_muldiv(ctx
, op1
, rs
, rt
);
9021 case OPC_JR
... OPC_JALR
:
9022 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
9025 case OPC_TGE
... OPC_TEQ
: /* Traps */
9027 gen_trap(ctx
, op1
, rs
, rt
, -1);
9029 case OPC_MFHI
: /* Move from HI/LO */
9031 gen_HILO(ctx
, op1
, rd
);
9034 case OPC_MTLO
: /* Move to HI/LO */
9035 gen_HILO(ctx
, op1
, rs
);
9037 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
9038 #ifdef MIPS_STRICT_STANDARD
9039 MIPS_INVAL("PMON / selsl");
9040 generate_exception(ctx
, EXCP_RI
);
9042 gen_helper_0i(pmon
, sa
);
9046 generate_exception(ctx
, EXCP_SYSCALL
);
9047 ctx
->bstate
= BS_STOP
;
9050 generate_exception(ctx
, EXCP_BREAK
);
9053 #ifdef MIPS_STRICT_STANDARD
9055 generate_exception(ctx
, EXCP_RI
);
9057 /* Implemented as RI exception for now. */
9058 MIPS_INVAL("spim (unofficial)");
9059 generate_exception(ctx
, EXCP_RI
);
9067 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
9068 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9069 check_cp1_enabled(ctx
);
9070 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
9071 (ctx
->opcode
>> 16) & 1);
9073 generate_exception_err(ctx
, EXCP_CpU
, 1);
9077 #if defined(TARGET_MIPS64)
9078 /* MIPS64 specific opcodes */
9083 check_insn(env
, ctx
, ISA_MIPS3
);
9085 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
9088 switch ((ctx
->opcode
>> 21) & 0x1f) {
9090 /* drotr is decoded as dsrl on non-R2 CPUs */
9091 if (env
->insn_flags
& ISA_MIPS32R2
) {
9096 check_insn(env
, ctx
, ISA_MIPS3
);
9098 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
9101 generate_exception(ctx
, EXCP_RI
);
9106 switch ((ctx
->opcode
>> 21) & 0x1f) {
9108 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
9109 if (env
->insn_flags
& ISA_MIPS32R2
) {
9114 check_insn(env
, ctx
, ISA_MIPS3
);
9116 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
9119 generate_exception(ctx
, EXCP_RI
);
9123 case OPC_DADD
... OPC_DSUBU
:
9124 check_insn(env
, ctx
, ISA_MIPS3
);
9126 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
9130 check_insn(env
, ctx
, ISA_MIPS3
);
9132 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
9135 switch ((ctx
->opcode
>> 6) & 0x1f) {
9137 /* drotrv is decoded as dsrlv on non-R2 CPUs */
9138 if (env
->insn_flags
& ISA_MIPS32R2
) {
9143 check_insn(env
, ctx
, ISA_MIPS3
);
9145 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
9148 generate_exception(ctx
, EXCP_RI
);
9152 case OPC_DMULT
... OPC_DDIVU
:
9153 check_insn(env
, ctx
, ISA_MIPS3
);
9155 gen_muldiv(ctx
, op1
, rs
, rt
);
9158 default: /* Invalid */
9159 MIPS_INVAL("special");
9160 generate_exception(ctx
, EXCP_RI
);
9165 op1
= MASK_SPECIAL2(ctx
->opcode
);
9167 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
9168 case OPC_MSUB
... OPC_MSUBU
:
9169 check_insn(env
, ctx
, ISA_MIPS32
);
9170 gen_muldiv(ctx
, op1
, rs
, rt
);
9173 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
9177 check_insn(env
, ctx
, ISA_MIPS32
);
9178 gen_cl(ctx
, op1
, rd
, rs
);
9181 /* XXX: not clear which exception should be raised
9182 * when in debug mode...
9184 check_insn(env
, ctx
, ISA_MIPS32
);
9185 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9186 generate_exception(ctx
, EXCP_DBp
);
9188 generate_exception(ctx
, EXCP_DBp
);
9192 #if defined(TARGET_MIPS64)
9195 check_insn(env
, ctx
, ISA_MIPS64
);
9197 gen_cl(ctx
, op1
, rd
, rs
);
9200 default: /* Invalid */
9201 MIPS_INVAL("special2");
9202 generate_exception(ctx
, EXCP_RI
);
9207 op1
= MASK_SPECIAL3(ctx
->opcode
);
9211 check_insn(env
, ctx
, ISA_MIPS32R2
);
9212 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
9215 check_insn(env
, ctx
, ISA_MIPS32R2
);
9216 op2
= MASK_BSHFL(ctx
->opcode
);
9217 gen_bshfl(ctx
, op2
, rt
, rd
);
9220 gen_rdhwr(env
, ctx
, rt
, rd
);
9223 check_insn(env
, ctx
, ASE_MT
);
9225 TCGv t0
= tcg_temp_new();
9226 TCGv t1
= tcg_temp_new();
9228 gen_load_gpr(t0
, rt
);
9229 gen_load_gpr(t1
, rs
);
9230 gen_helper_fork(t0
, t1
);
9236 check_insn(env
, ctx
, ASE_MT
);
9238 TCGv t0
= tcg_temp_new();
9240 save_cpu_state(ctx
, 1);
9241 gen_load_gpr(t0
, rs
);
9242 gen_helper_yield(t0
, t0
);
9243 gen_store_gpr(t0
, rd
);
9247 #if defined(TARGET_MIPS64)
9248 case OPC_DEXTM
... OPC_DEXT
:
9249 case OPC_DINSM
... OPC_DINS
:
9250 check_insn(env
, ctx
, ISA_MIPS64R2
);
9252 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
9255 check_insn(env
, ctx
, ISA_MIPS64R2
);
9257 op2
= MASK_DBSHFL(ctx
->opcode
);
9258 gen_bshfl(ctx
, op2
, rt
, rd
);
9261 default: /* Invalid */
9262 MIPS_INVAL("special3");
9263 generate_exception(ctx
, EXCP_RI
);
9268 op1
= MASK_REGIMM(ctx
->opcode
);
9270 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
9271 case OPC_BLTZAL
... OPC_BGEZALL
:
9272 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
9275 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
9277 gen_trap(ctx
, op1
, rs
, -1, imm
);
9280 check_insn(env
, ctx
, ISA_MIPS32R2
);
9283 default: /* Invalid */
9284 MIPS_INVAL("regimm");
9285 generate_exception(ctx
, EXCP_RI
);
9290 check_cp0_enabled(ctx
);
9291 op1
= MASK_CP0(ctx
->opcode
);
9297 #if defined(TARGET_MIPS64)
9301 #ifndef CONFIG_USER_ONLY
9302 gen_cp0(env
, ctx
, op1
, rt
, rd
);
9303 #endif /* !CONFIG_USER_ONLY */
9305 case OPC_C0_FIRST
... OPC_C0_LAST
:
9306 #ifndef CONFIG_USER_ONLY
9307 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
9308 #endif /* !CONFIG_USER_ONLY */
9311 #ifndef CONFIG_USER_ONLY
9313 TCGv t0
= tcg_temp_new();
9315 op2
= MASK_MFMC0(ctx
->opcode
);
9318 check_insn(env
, ctx
, ASE_MT
);
9319 gen_helper_dmt(t0
, t0
);
9320 gen_store_gpr(t0
, rt
);
9323 check_insn(env
, ctx
, ASE_MT
);
9324 gen_helper_emt(t0
, t0
);
9325 gen_store_gpr(t0
, rt
);
9328 check_insn(env
, ctx
, ASE_MT
);
9329 gen_helper_dvpe(t0
, t0
);
9330 gen_store_gpr(t0
, rt
);
9333 check_insn(env
, ctx
, ASE_MT
);
9334 gen_helper_evpe(t0
, t0
);
9335 gen_store_gpr(t0
, rt
);
9338 check_insn(env
, ctx
, ISA_MIPS32R2
);
9339 save_cpu_state(ctx
, 1);
9341 gen_store_gpr(t0
, rt
);
9342 /* Stop translation as we may have switched the execution mode */
9343 ctx
->bstate
= BS_STOP
;
9346 check_insn(env
, ctx
, ISA_MIPS32R2
);
9347 save_cpu_state(ctx
, 1);
9349 gen_store_gpr(t0
, rt
);
9350 /* Stop translation as we may have switched the execution mode */
9351 ctx
->bstate
= BS_STOP
;
9353 default: /* Invalid */
9354 MIPS_INVAL("mfmc0");
9355 generate_exception(ctx
, EXCP_RI
);
9360 #endif /* !CONFIG_USER_ONLY */
9363 check_insn(env
, ctx
, ISA_MIPS32R2
);
9364 gen_load_srsgpr(rt
, rd
);
9367 check_insn(env
, ctx
, ISA_MIPS32R2
);
9368 gen_store_srsgpr(rt
, rd
);
9372 generate_exception(ctx
, EXCP_RI
);
9376 case OPC_ADDI
: /* Arithmetic with immediate opcode */
9378 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
9380 case OPC_SLTI
: /* Set on less than with immediate opcode */
9382 gen_slt_imm(env
, op
, rt
, rs
, imm
);
9384 case OPC_ANDI
: /* Arithmetic with immediate opcode */
9388 gen_logic_imm(env
, op
, rt
, rs
, imm
);
9390 case OPC_J
... OPC_JAL
: /* Jump */
9391 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
9392 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
9395 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
9396 case OPC_BEQL
... OPC_BGTZL
:
9397 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
9400 case OPC_LB
... OPC_LWR
: /* Load and stores */
9401 case OPC_SB
... OPC_SW
:
9404 gen_ldst(ctx
, op
, rt
, rs
, imm
);
9407 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
9410 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
9414 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
9418 /* Floating point (COP1). */
9423 gen_cop1_ldst(env
, ctx
, op
, rt
, rs
, imm
);
9427 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9428 check_cp1_enabled(ctx
);
9429 op1
= MASK_CP1(ctx
->opcode
);
9433 check_insn(env
, ctx
, ISA_MIPS32R2
);
9438 gen_cp1(ctx
, op1
, rt
, rd
);
9440 #if defined(TARGET_MIPS64)
9443 check_insn(env
, ctx
, ISA_MIPS3
);
9444 gen_cp1(ctx
, op1
, rt
, rd
);
9450 check_insn(env
, ctx
, ASE_MIPS3D
);
9453 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
9454 (rt
>> 2) & 0x7, imm
<< 2);
9462 gen_farith(ctx
, ctx
->opcode
& FOP(0x3f, 0x1f), rt
, rd
, sa
,
9467 generate_exception (ctx
, EXCP_RI
);
9471 generate_exception_err(ctx
, EXCP_CpU
, 1);
9481 /* COP2: Not implemented. */
9482 generate_exception_err(ctx
, EXCP_CpU
, 2);
9486 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9487 check_cp1_enabled(ctx
);
9488 op1
= MASK_CP3(ctx
->opcode
);
9496 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
9514 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
9518 generate_exception (ctx
, EXCP_RI
);
9522 generate_exception_err(ctx
, EXCP_CpU
, 1);
9526 #if defined(TARGET_MIPS64)
9527 /* MIPS64 opcodes */
9529 case OPC_LDL
... OPC_LDR
:
9530 case OPC_SDL
... OPC_SDR
:
9534 check_insn(env
, ctx
, ISA_MIPS3
);
9536 gen_ldst(ctx
, op
, rt
, rs
, imm
);
9539 check_insn(env
, ctx
, ISA_MIPS3
);
9541 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
9545 check_insn(env
, ctx
, ISA_MIPS3
);
9547 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
9551 check_insn(env
, ctx
, ASE_MIPS16
);
9552 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
9553 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
9557 check_insn(env
, ctx
, ASE_MDMX
);
9558 /* MDMX: Not implemented. */
9559 default: /* Invalid */
9560 MIPS_INVAL("major opcode");
9561 generate_exception(ctx
, EXCP_RI
);
9567 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
9571 target_ulong pc_start
;
9572 uint16_t *gen_opc_end
;
9581 qemu_log("search pc %d\n", search_pc
);
9584 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
9587 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
9589 ctx
.bstate
= BS_NONE
;
9590 /* Restore delay slot state from the tb context. */
9591 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
9592 restore_cpu_state(env
, &ctx
);
9593 #ifdef CONFIG_USER_ONLY
9594 ctx
.mem_idx
= MIPS_HFLAG_UM
;
9596 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
9599 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9601 max_insns
= CF_COUNT_MASK
;
9602 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
9604 while (ctx
.bstate
== BS_NONE
) {
9605 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9606 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9607 if (bp
->pc
== ctx
.pc
) {
9608 save_cpu_state(&ctx
, 1);
9609 ctx
.bstate
= BS_BRANCH
;
9610 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
9611 /* Include the breakpoint location or the tb won't
9612 * be flushed when it must be. */
9614 goto done_generating
;
9620 j
= gen_opc_ptr
- gen_opc_buf
;
9624 gen_opc_instr_start
[lj
++] = 0;
9626 gen_opc_pc
[lj
] = ctx
.pc
;
9627 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
9628 gen_opc_instr_start
[lj
] = 1;
9629 gen_opc_icount
[lj
] = num_insns
;
9631 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9635 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
9636 ctx
.opcode
= ldl_code(ctx
.pc
);
9638 decode_opc(env
, &ctx
, &is_branch
);
9639 } else if (env
->insn_flags
& ASE_MIPS16
) {
9640 ctx
.opcode
= lduw_code(ctx
.pc
);
9641 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
9643 generate_exception(&ctx
, EXCP_RI
);
9647 handle_delay_slot(env
, &ctx
, insn_bytes
);
9649 ctx
.pc
+= insn_bytes
;
9653 /* Execute a branch and its delay slot as a single instruction.
9654 This is what GDB expects and is consistent with what the
9655 hardware does (e.g. if a delay slot instruction faults, the
9656 reported PC is the PC of the branch). */
9657 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
9660 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
9663 if (gen_opc_ptr
>= gen_opc_end
)
9666 if (num_insns
>= max_insns
)
9672 if (tb
->cflags
& CF_LAST_IO
)
9674 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
9675 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
9676 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
9678 switch (ctx
.bstate
) {
9680 gen_helper_interrupt_restart();
9681 gen_goto_tb(&ctx
, 0, ctx
.pc
);
9684 save_cpu_state(&ctx
, 0);
9685 gen_goto_tb(&ctx
, 0, ctx
.pc
);
9688 gen_helper_interrupt_restart();
9697 gen_icount_end(tb
, num_insns
);
9698 *gen_opc_ptr
= INDEX_op_end
;
9700 j
= gen_opc_ptr
- gen_opc_buf
;
9703 gen_opc_instr_start
[lj
++] = 0;
9705 tb
->size
= ctx
.pc
- pc_start
;
9706 tb
->icount
= num_insns
;
9710 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9711 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9712 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
9718 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
9720 gen_intermediate_code_internal(env
, tb
, 0);
9723 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
9725 gen_intermediate_code_internal(env
, tb
, 1);
9728 static void fpu_dump_state(CPUState
*env
, FILE *f
,
9729 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9733 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
9735 #define printfpr(fp) \
9738 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
9739 " fd:%13g fs:%13g psu: %13g\n", \
9740 (fp)->w[FP_ENDIAN_IDX], (fp)->d, \
9742 (double)(fp)->fs[FP_ENDIAN_IDX], \
9743 (double)(fp)->fs[!FP_ENDIAN_IDX]); \
9746 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
9747 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
9748 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
9749 " fd:%13g fs:%13g psu:%13g\n", \
9750 tmp.w[FP_ENDIAN_IDX], tmp.d, \
9752 (double)tmp.fs[FP_ENDIAN_IDX], \
9753 (double)tmp.fs[!FP_ENDIAN_IDX]); \
9758 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
9759 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
9760 get_float_exception_flags(&env
->active_fpu
.fp_status
));
9761 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
9762 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
9763 printfpr(&env
->active_fpu
.fpr
[i
]);
9769 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
9770 /* Debug help: The architecture requires 32bit code to maintain proper
9771 sign-extended values on 64bit machines. */
9773 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
9776 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
9777 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9782 if (!SIGN_EXT_P(env
->active_tc
.PC
))
9783 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
9784 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
9785 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
9786 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
9787 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
9788 if (!SIGN_EXT_P(env
->btarget
))
9789 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
9791 for (i
= 0; i
< 32; i
++) {
9792 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
9793 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
9796 if (!SIGN_EXT_P(env
->CP0_EPC
))
9797 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
9798 if (!SIGN_EXT_P(env
->lladdr
))
9799 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
9803 void cpu_dump_state (CPUState
*env
, FILE *f
,
9804 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9809 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
9810 " LO=0x" TARGET_FMT_lx
" ds %04x "
9811 TARGET_FMT_lx
" " TARGET_FMT_ld
"\n",
9812 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
9813 env
->hflags
, env
->btarget
, env
->bcond
);
9814 for (i
= 0; i
< 32; i
++) {
9816 cpu_fprintf(f
, "GPR%02d:", i
);
9817 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
9819 cpu_fprintf(f
, "\n");
9822 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
9823 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
9824 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
9825 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
9826 if (env
->hflags
& MIPS_HFLAG_FPU
)
9827 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
9828 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
9829 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
9833 static void mips_tcg_init(void)
9838 /* Initialize various static tables. */
9842 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
9843 TCGV_UNUSED(cpu_gpr
[0]);
9844 for (i
= 1; i
< 32; i
++)
9845 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
9846 offsetof(CPUState
, active_tc
.gpr
[i
]),
9848 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
9849 offsetof(CPUState
, active_tc
.PC
), "PC");
9850 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
9851 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
9852 offsetof(CPUState
, active_tc
.HI
[i
]),
9854 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
9855 offsetof(CPUState
, active_tc
.LO
[i
]),
9857 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
9858 offsetof(CPUState
, active_tc
.ACX
[i
]),
9861 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
9862 offsetof(CPUState
, active_tc
.DSPControl
),
9864 bcond
= tcg_global_mem_new(TCG_AREG0
,
9865 offsetof(CPUState
, bcond
), "bcond");
9866 btarget
= tcg_global_mem_new(TCG_AREG0
,
9867 offsetof(CPUState
, btarget
), "btarget");
9868 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
9869 offsetof(CPUState
, hflags
), "hflags");
9871 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
9872 offsetof(CPUState
, active_fpu
.fcr0
),
9874 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
9875 offsetof(CPUState
, active_fpu
.fcr31
),
9878 /* register helpers */
9879 #define GEN_HELPER 2
9885 #include "translate_init.c"
9887 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
9890 const mips_def_t
*def
;
9892 def
= cpu_mips_find_by_name(cpu_model
);
9895 env
= qemu_mallocz(sizeof(CPUMIPSState
));
9896 env
->cpu_model
= def
;
9897 env
->cpu_model_str
= cpu_model
;
9900 #ifndef CONFIG_USER_ONLY
9907 qemu_init_vcpu(env
);
9911 void cpu_reset (CPUMIPSState
*env
)
9913 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
9914 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
9915 log_cpu_state(env
, 0);
9918 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
9921 /* Reset registers to their default values */
9922 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
9923 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
9924 #ifdef TARGET_WORDS_BIGENDIAN
9925 env
->CP0_Config0
|= (1 << CP0C0_BE
);
9927 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
9928 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
9929 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
9930 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
9931 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
9932 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
9933 << env
->cpu_model
->CP0_LLAddr_shift
;
9934 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
9935 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
9936 env
->CCRes
= env
->cpu_model
->CCRes
;
9937 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
9938 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
9939 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
9940 env
->current_tc
= 0;
9941 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
9942 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
9943 #if defined(TARGET_MIPS64)
9944 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
9945 env
->SEGMask
|= 3ULL << 62;
9948 env
->PABITS
= env
->cpu_model
->PABITS
;
9949 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
9950 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
9951 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
9952 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
9953 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
9954 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
9955 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
9956 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
9957 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
9958 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
9959 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
9960 env
->insn_flags
= env
->cpu_model
->insn_flags
;
9962 #if defined(CONFIG_USER_ONLY)
9963 env
->hflags
= MIPS_HFLAG_UM
;
9964 /* Enable access to the SYNCI_Step register. */
9965 env
->CP0_HWREna
|= (1 << 1);
9966 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9967 env
->hflags
|= MIPS_HFLAG_FPU
;
9969 #ifdef TARGET_MIPS64
9970 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
9971 env
->hflags
|= MIPS_HFLAG_F64
;
9975 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
9976 /* If the exception was raised from a delay slot,
9977 come back to the jump. */
9978 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
9980 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
9982 env
->active_tc
.PC
= (int32_t)0xBFC00000;
9983 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
9984 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
9986 /* SMP not implemented */
9987 env
->CP0_EBase
= 0x80000000;
9988 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
9989 /* vectored interrupts not implemented, timer on int 7,
9990 no performance counters. */
9991 env
->CP0_IntCtl
= 0xe0000000;
9995 for (i
= 0; i
< 7; i
++) {
9996 env
->CP0_WatchLo
[i
] = 0;
9997 env
->CP0_WatchHi
[i
] = 0x80000000;
9999 env
->CP0_WatchLo
[7] = 0;
10000 env
->CP0_WatchHi
[7] = 0;
10002 /* Count register increments in debug mode, EJTAG version 1 */
10003 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
10004 env
->hflags
= MIPS_HFLAG_CP0
;
10006 #if defined(TARGET_MIPS64)
10007 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
10008 env
->hflags
|= MIPS_HFLAG_64
;
10011 env
->exception_index
= EXCP_NONE
;
10014 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
10015 unsigned long searched_pc
, int pc_pos
, void *puc
)
10017 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
10018 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
10019 env
->hflags
|= gen_opc_hflags
[pc_pos
];