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_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
72 OPC_BEQL
= (0x14 << 26),
73 OPC_BNE
= (0x05 << 26),
74 OPC_BNEL
= (0x15 << 26),
75 OPC_BLEZ
= (0x06 << 26),
76 OPC_BLEZL
= (0x16 << 26),
77 OPC_BGTZ
= (0x07 << 26),
78 OPC_BGTZL
= (0x17 << 26),
79 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
81 OPC_LDL
= (0x1A << 26),
82 OPC_LDR
= (0x1B << 26),
83 OPC_LB
= (0x20 << 26),
84 OPC_LH
= (0x21 << 26),
85 OPC_LWL
= (0x22 << 26),
86 OPC_LW
= (0x23 << 26),
87 OPC_LWPC
= OPC_LW
| 0x5,
88 OPC_LBU
= (0x24 << 26),
89 OPC_LHU
= (0x25 << 26),
90 OPC_LWR
= (0x26 << 26),
91 OPC_LWU
= (0x27 << 26),
92 OPC_SB
= (0x28 << 26),
93 OPC_SH
= (0x29 << 26),
94 OPC_SWL
= (0x2A << 26),
95 OPC_SW
= (0x2B << 26),
96 OPC_SDL
= (0x2C << 26),
97 OPC_SDR
= (0x2D << 26),
98 OPC_SWR
= (0x2E << 26),
99 OPC_LL
= (0x30 << 26),
100 OPC_LLD
= (0x34 << 26),
101 OPC_LD
= (0x37 << 26),
102 OPC_LDPC
= OPC_LD
| 0x5,
103 OPC_SC
= (0x38 << 26),
104 OPC_SCD
= (0x3C << 26),
105 OPC_SD
= (0x3F << 26),
106 /* Floating point load/store */
107 OPC_LWC1
= (0x31 << 26),
108 OPC_LWC2
= (0x32 << 26),
109 OPC_LDC1
= (0x35 << 26),
110 OPC_LDC2
= (0x36 << 26),
111 OPC_SWC1
= (0x39 << 26),
112 OPC_SWC2
= (0x3A << 26),
113 OPC_SDC1
= (0x3D << 26),
114 OPC_SDC2
= (0x3E << 26),
115 /* MDMX ASE specific */
116 OPC_MDMX
= (0x1E << 26),
117 /* Cache and prefetch */
118 OPC_CACHE
= (0x2F << 26),
119 OPC_PREF
= (0x33 << 26),
120 /* Reserved major opcode */
121 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
124 /* MIPS special opcodes */
125 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
129 OPC_SLL
= 0x00 | OPC_SPECIAL
,
130 /* NOP is SLL r0, r0, 0 */
131 /* SSNOP is SLL r0, r0, 1 */
132 /* EHB is SLL r0, r0, 3 */
133 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
134 OPC_ROTR
= OPC_SRL
| (1 << 21),
135 OPC_SRA
= 0x03 | OPC_SPECIAL
,
136 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
137 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
138 OPC_ROTRV
= OPC_SRLV
| (1 << 6),
139 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
140 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
141 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
142 OPC_DROTRV
= OPC_DSRLV
| (1 << 6),
143 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
144 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
145 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
146 OPC_DROTR
= OPC_DSRL
| (1 << 21),
147 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
148 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
149 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
150 OPC_DROTR32
= OPC_DSRL32
| (1 << 21),
151 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
152 /* Multiplication / division */
153 OPC_MULT
= 0x18 | OPC_SPECIAL
,
154 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
155 OPC_DIV
= 0x1A | OPC_SPECIAL
,
156 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
157 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
158 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
159 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
160 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
161 /* 2 registers arithmetic / logic */
162 OPC_ADD
= 0x20 | OPC_SPECIAL
,
163 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
164 OPC_SUB
= 0x22 | OPC_SPECIAL
,
165 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
166 OPC_AND
= 0x24 | OPC_SPECIAL
,
167 OPC_OR
= 0x25 | OPC_SPECIAL
,
168 OPC_XOR
= 0x26 | OPC_SPECIAL
,
169 OPC_NOR
= 0x27 | OPC_SPECIAL
,
170 OPC_SLT
= 0x2A | OPC_SPECIAL
,
171 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
172 OPC_DADD
= 0x2C | OPC_SPECIAL
,
173 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
174 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
175 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
177 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
178 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
179 OPC_JALRC
= OPC_JALR
| (0x5 << 6),
181 OPC_TGE
= 0x30 | OPC_SPECIAL
,
182 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
183 OPC_TLT
= 0x32 | OPC_SPECIAL
,
184 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
185 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
186 OPC_TNE
= 0x36 | OPC_SPECIAL
,
187 /* HI / LO registers load & stores */
188 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
189 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
190 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
191 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
192 /* Conditional moves */
193 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
194 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
196 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
199 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* unofficial */
200 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
201 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
202 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
203 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
205 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
206 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
207 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
208 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
209 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
210 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
211 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
214 /* Multiplication variants of the vr54xx. */
215 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
218 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
219 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
220 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
221 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
222 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
223 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
224 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
225 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
226 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
227 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
228 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
229 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
230 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
231 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
234 /* REGIMM (rt field) opcodes */
235 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
238 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
239 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
240 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
241 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
242 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
243 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
244 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
245 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
246 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
247 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
248 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
249 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
250 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
251 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
252 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
255 /* Special2 opcodes */
256 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
259 /* Multiply & xxx operations */
260 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
261 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
262 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
263 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
264 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
266 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
267 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
268 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
269 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
271 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
274 /* Special3 opcodes */
275 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
278 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
279 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
280 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
281 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
282 OPC_INS
= 0x04 | OPC_SPECIAL3
,
283 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
284 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
285 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
286 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
287 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
288 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
289 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
290 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
294 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
297 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
298 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
299 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
303 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
306 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
307 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
310 /* Coprocessor 0 (rs field) */
311 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
314 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
315 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
316 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
317 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
318 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
319 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
320 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
321 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
322 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
323 OPC_C0
= (0x10 << 21) | OPC_CP0
,
324 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
325 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
329 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
332 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
333 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
334 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
335 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
336 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
337 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
340 /* Coprocessor 0 (with rs == C0) */
341 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
344 OPC_TLBR
= 0x01 | OPC_C0
,
345 OPC_TLBWI
= 0x02 | OPC_C0
,
346 OPC_TLBWR
= 0x06 | OPC_C0
,
347 OPC_TLBP
= 0x08 | OPC_C0
,
348 OPC_RFE
= 0x10 | OPC_C0
,
349 OPC_ERET
= 0x18 | OPC_C0
,
350 OPC_DERET
= 0x1F | OPC_C0
,
351 OPC_WAIT
= 0x20 | OPC_C0
,
354 /* Coprocessor 1 (rs field) */
355 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
358 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
359 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
360 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
361 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
362 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
363 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
364 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
365 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
366 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
367 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
368 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
369 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
370 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
371 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
372 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
373 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
374 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
375 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
378 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
379 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
382 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
383 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
384 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
385 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
389 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
390 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
394 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
395 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
398 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
401 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
402 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
403 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
404 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
405 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
406 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
407 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
408 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
409 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
412 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
415 OPC_LWXC1
= 0x00 | OPC_CP3
,
416 OPC_LDXC1
= 0x01 | OPC_CP3
,
417 OPC_LUXC1
= 0x05 | OPC_CP3
,
418 OPC_SWXC1
= 0x08 | OPC_CP3
,
419 OPC_SDXC1
= 0x09 | OPC_CP3
,
420 OPC_SUXC1
= 0x0D | OPC_CP3
,
421 OPC_PREFX
= 0x0F | OPC_CP3
,
422 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
423 OPC_MADD_S
= 0x20 | OPC_CP3
,
424 OPC_MADD_D
= 0x21 | OPC_CP3
,
425 OPC_MADD_PS
= 0x26 | OPC_CP3
,
426 OPC_MSUB_S
= 0x28 | OPC_CP3
,
427 OPC_MSUB_D
= 0x29 | OPC_CP3
,
428 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
429 OPC_NMADD_S
= 0x30 | OPC_CP3
,
430 OPC_NMADD_D
= 0x31 | OPC_CP3
,
431 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
432 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
433 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
434 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
437 /* global register indices */
438 static TCGv_ptr cpu_env
;
439 static TCGv cpu_gpr
[32], cpu_PC
;
440 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
441 static TCGv cpu_dspctrl
, btarget
, bcond
;
442 static TCGv_i32 hflags
;
443 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
445 #include "gen-icount.h"
447 #define gen_helper_0i(name, arg) do { \
448 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
449 gen_helper_##name(helper_tmp); \
450 tcg_temp_free_i32(helper_tmp); \
453 #define gen_helper_1i(name, arg1, arg2) do { \
454 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
455 gen_helper_##name(arg1, helper_tmp); \
456 tcg_temp_free_i32(helper_tmp); \
459 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
460 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
461 gen_helper_##name(arg1, arg2, helper_tmp); \
462 tcg_temp_free_i32(helper_tmp); \
465 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
466 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
467 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
468 tcg_temp_free_i32(helper_tmp); \
471 typedef struct DisasContext
{
472 struct TranslationBlock
*tb
;
473 target_ulong pc
, saved_pc
;
475 int singlestep_enabled
;
476 /* Routine used to access memory */
478 uint32_t hflags
, saved_hflags
;
480 target_ulong btarget
;
484 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
485 * exception condition */
486 BS_STOP
= 1, /* We want to stop translation for any reason */
487 BS_BRANCH
= 2, /* We reached a branch condition */
488 BS_EXCP
= 3, /* We reached an exception condition */
491 static const char *regnames
[] =
492 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
493 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
494 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
495 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
497 static const char *regnames_HI
[] =
498 { "HI0", "HI1", "HI2", "HI3", };
500 static const char *regnames_LO
[] =
501 { "LO0", "LO1", "LO2", "LO3", };
503 static const char *regnames_ACX
[] =
504 { "ACX0", "ACX1", "ACX2", "ACX3", };
506 static const char *fregnames
[] =
507 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
508 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
509 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
510 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
512 #ifdef MIPS_DEBUG_DISAS
513 #define MIPS_DEBUG(fmt, ...) \
514 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
515 TARGET_FMT_lx ": %08x " fmt "\n", \
516 ctx->pc, ctx->opcode , ## __VA_ARGS__)
517 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
519 #define MIPS_DEBUG(fmt, ...) do { } while(0)
520 #define LOG_DISAS(...) do { } while (0)
523 #define MIPS_INVAL(op) \
525 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
526 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
529 /* General purpose registers moves. */
530 static inline void gen_load_gpr (TCGv t
, int reg
)
533 tcg_gen_movi_tl(t
, 0);
535 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
538 static inline void gen_store_gpr (TCGv t
, int reg
)
541 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
544 /* Moves to/from ACX register. */
545 static inline void gen_load_ACX (TCGv t
, int reg
)
547 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
550 static inline void gen_store_ACX (TCGv t
, int reg
)
552 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
555 /* Moves to/from shadow registers. */
556 static inline void gen_load_srsgpr (int from
, int to
)
558 TCGv t0
= tcg_temp_new();
561 tcg_gen_movi_tl(t0
, 0);
563 TCGv_i32 t2
= tcg_temp_new_i32();
564 TCGv_ptr addr
= tcg_temp_new_ptr();
566 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
567 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
568 tcg_gen_andi_i32(t2
, t2
, 0xf);
569 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
570 tcg_gen_ext_i32_ptr(addr
, t2
);
571 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
573 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
574 tcg_temp_free_ptr(addr
);
575 tcg_temp_free_i32(t2
);
577 gen_store_gpr(t0
, to
);
581 static inline void gen_store_srsgpr (int from
, int to
)
584 TCGv t0
= tcg_temp_new();
585 TCGv_i32 t2
= tcg_temp_new_i32();
586 TCGv_ptr addr
= tcg_temp_new_ptr();
588 gen_load_gpr(t0
, from
);
589 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
590 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
591 tcg_gen_andi_i32(t2
, t2
, 0xf);
592 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
593 tcg_gen_ext_i32_ptr(addr
, t2
);
594 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
596 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
597 tcg_temp_free_ptr(addr
);
598 tcg_temp_free_i32(t2
);
603 /* Floating point register moves. */
604 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
606 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
609 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
611 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
614 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
616 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
619 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
621 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
624 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
626 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
627 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
629 TCGv_i32 t0
= tcg_temp_new_i32();
630 TCGv_i32 t1
= tcg_temp_new_i32();
631 gen_load_fpr32(t0
, reg
& ~1);
632 gen_load_fpr32(t1
, reg
| 1);
633 tcg_gen_concat_i32_i64(t
, t0
, t1
);
634 tcg_temp_free_i32(t0
);
635 tcg_temp_free_i32(t1
);
639 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
641 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
642 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
644 TCGv_i64 t0
= tcg_temp_new_i64();
645 TCGv_i32 t1
= tcg_temp_new_i32();
646 tcg_gen_trunc_i64_i32(t1
, t
);
647 gen_store_fpr32(t1
, reg
& ~1);
648 tcg_gen_shri_i64(t0
, t
, 32);
649 tcg_gen_trunc_i64_i32(t1
, t0
);
650 gen_store_fpr32(t1
, reg
| 1);
651 tcg_temp_free_i32(t1
);
652 tcg_temp_free_i64(t0
);
656 static inline int get_fp_bit (int cc
)
664 #define FOP_CONDS(type, fmt, bits) \
665 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
666 TCGv_i##bits b, int cc) \
669 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
670 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
671 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
672 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
673 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
674 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
675 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
676 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
677 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
678 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
679 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
680 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
681 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
682 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
683 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
684 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
690 FOP_CONDS(abs
, d
, 64)
692 FOP_CONDS(abs
, s
, 32)
694 FOP_CONDS(abs
, ps
, 64)
698 static inline void gen_save_pc(target_ulong pc
)
700 tcg_gen_movi_tl(cpu_PC
, pc
);
703 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
705 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
706 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
707 gen_save_pc(ctx
->pc
);
708 ctx
->saved_pc
= ctx
->pc
;
710 if (ctx
->hflags
!= ctx
->saved_hflags
) {
711 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
712 ctx
->saved_hflags
= ctx
->hflags
;
713 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
719 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
725 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
727 ctx
->saved_hflags
= ctx
->hflags
;
728 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
734 ctx
->btarget
= env
->btarget
;
740 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
742 TCGv_i32 texcp
= tcg_const_i32(excp
);
743 TCGv_i32 terr
= tcg_const_i32(err
);
744 save_cpu_state(ctx
, 1);
745 gen_helper_raise_exception_err(texcp
, terr
);
746 tcg_temp_free_i32(terr
);
747 tcg_temp_free_i32(texcp
);
751 generate_exception (DisasContext
*ctx
, int excp
)
753 save_cpu_state(ctx
, 1);
754 gen_helper_0i(raise_exception
, excp
);
757 /* Addresses computation */
758 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
760 tcg_gen_add_tl(ret
, arg0
, arg1
);
762 #if defined(TARGET_MIPS64)
763 /* For compatibility with 32-bit code, data reference in user mode
764 with Status_UX = 0 should be casted to 32-bit and sign extended.
765 See the MIPS64 PRA manual, section 4.10. */
766 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
767 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
768 tcg_gen_ext32s_i64(ret
, ret
);
773 static inline void check_cp0_enabled(DisasContext
*ctx
)
775 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
776 generate_exception_err(ctx
, EXCP_CpU
, 0);
779 static inline void check_cp1_enabled(DisasContext
*ctx
)
781 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
782 generate_exception_err(ctx
, EXCP_CpU
, 1);
785 /* Verify that the processor is running with COP1X instructions enabled.
786 This is associated with the nabla symbol in the MIPS32 and MIPS64
789 static inline void check_cop1x(DisasContext
*ctx
)
791 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
792 generate_exception(ctx
, EXCP_RI
);
795 /* Verify that the processor is running with 64-bit floating-point
796 operations enabled. */
798 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
800 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
801 generate_exception(ctx
, EXCP_RI
);
805 * Verify if floating point register is valid; an operation is not defined
806 * if bit 0 of any register specification is set and the FR bit in the
807 * Status register equals zero, since the register numbers specify an
808 * even-odd pair of adjacent coprocessor general registers. When the FR bit
809 * in the Status register equals one, both even and odd register numbers
810 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
812 * Multiple 64 bit wide registers can be checked by calling
813 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
815 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
817 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
818 generate_exception(ctx
, EXCP_RI
);
821 /* This code generates a "reserved instruction" exception if the
822 CPU does not support the instruction set corresponding to flags. */
823 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
825 if (unlikely(!(env
->insn_flags
& flags
)))
826 generate_exception(ctx
, EXCP_RI
);
829 /* This code generates a "reserved instruction" exception if 64-bit
830 instructions are not enabled. */
831 static inline void check_mips_64(DisasContext
*ctx
)
833 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
834 generate_exception(ctx
, EXCP_RI
);
837 /* load/store instructions. */
838 #define OP_LD(insn,fname) \
839 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
841 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
848 #if defined(TARGET_MIPS64)
854 #define OP_ST(insn,fname) \
855 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
857 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
862 #if defined(TARGET_MIPS64)
867 #ifdef CONFIG_USER_ONLY
868 #define OP_LD_ATOMIC(insn,fname) \
869 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
871 TCGv t0 = tcg_temp_new(); \
872 tcg_gen_mov_tl(t0, arg1); \
873 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
874 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
875 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
879 #define OP_LD_ATOMIC(insn,fname) \
880 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
882 gen_helper_2i(insn, ret, arg1, ctx->mem_idx); \
885 OP_LD_ATOMIC(ll
,ld32s
);
886 #if defined(TARGET_MIPS64)
887 OP_LD_ATOMIC(lld
,ld64
);
891 #ifdef CONFIG_USER_ONLY
892 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
893 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
895 TCGv t0 = tcg_temp_new(); \
896 int l1 = gen_new_label(); \
897 int l2 = gen_new_label(); \
899 tcg_gen_andi_tl(t0, arg2, almask); \
900 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
901 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
902 generate_exception(ctx, EXCP_AdES); \
904 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
905 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
906 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
907 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
908 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
909 gen_helper_0i(raise_exception, EXCP_SC); \
911 tcg_gen_movi_tl(t0, 0); \
912 gen_store_gpr(t0, rt); \
916 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
917 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
919 TCGv t0 = tcg_temp_new(); \
920 gen_helper_3i(insn, t0, arg1, arg2, ctx->mem_idx); \
921 gen_store_gpr(t0, rt); \
925 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
926 #if defined(TARGET_MIPS64)
927 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
931 static void gen_base_offset_addr (DisasContext
*ctx
, TCGv addr
,
932 int base
, int16_t offset
)
935 tcg_gen_movi_tl(addr
, offset
);
936 } else if (offset
== 0) {
937 gen_load_gpr(addr
, base
);
939 tcg_gen_movi_tl(addr
, offset
);
940 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
944 static target_ulong
pc_relative_pc (DisasContext
*ctx
)
946 target_ulong pc
= ctx
->pc
;
948 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
949 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
954 pc
&= ~(target_ulong
)3;
959 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
960 int base
, int16_t offset
)
962 const char *opn
= "ldst";
963 TCGv t0
= tcg_temp_new();
964 TCGv t1
= tcg_temp_new();
966 gen_base_offset_addr(ctx
, t0
, base
, offset
);
967 /* Don't do NOP if destination is zero: we must perform the actual
970 #if defined(TARGET_MIPS64)
972 save_cpu_state(ctx
, 0);
973 op_ldst_lwu(t0
, t0
, ctx
);
974 gen_store_gpr(t0
, rt
);
978 save_cpu_state(ctx
, 0);
979 op_ldst_ld(t0
, t0
, ctx
);
980 gen_store_gpr(t0
, rt
);
984 save_cpu_state(ctx
, 0);
985 op_ldst_lld(t0
, t0
, ctx
);
986 gen_store_gpr(t0
, rt
);
990 save_cpu_state(ctx
, 0);
991 gen_load_gpr(t1
, rt
);
992 op_ldst_sd(t1
, t0
, ctx
);
996 save_cpu_state(ctx
, 1);
997 gen_load_gpr(t1
, rt
);
998 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
999 gen_store_gpr(t1
, rt
);
1003 save_cpu_state(ctx
, 1);
1004 gen_load_gpr(t1
, rt
);
1005 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1009 save_cpu_state(ctx
, 1);
1010 gen_load_gpr(t1
, rt
);
1011 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1012 gen_store_gpr(t1
, rt
);
1016 save_cpu_state(ctx
, 1);
1017 gen_load_gpr(t1
, rt
);
1018 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1022 save_cpu_state(ctx
, 1);
1023 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1024 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1025 op_ldst_ld(t0
, t0
, ctx
);
1026 gen_store_gpr(t0
, rt
);
1030 save_cpu_state(ctx
, 1);
1031 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1032 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1033 op_ldst_lw(t0
, t0
, ctx
);
1034 gen_store_gpr(t0
, rt
);
1037 save_cpu_state(ctx
, 0);
1038 op_ldst_lw(t0
, t0
, ctx
);
1039 gen_store_gpr(t0
, rt
);
1043 save_cpu_state(ctx
, 0);
1044 gen_load_gpr(t1
, rt
);
1045 op_ldst_sw(t1
, t0
, ctx
);
1049 save_cpu_state(ctx
, 0);
1050 op_ldst_lh(t0
, t0
, ctx
);
1051 gen_store_gpr(t0
, rt
);
1055 save_cpu_state(ctx
, 0);
1056 gen_load_gpr(t1
, rt
);
1057 op_ldst_sh(t1
, t0
, ctx
);
1061 save_cpu_state(ctx
, 0);
1062 op_ldst_lhu(t0
, t0
, ctx
);
1063 gen_store_gpr(t0
, rt
);
1067 save_cpu_state(ctx
, 0);
1068 op_ldst_lb(t0
, t0
, ctx
);
1069 gen_store_gpr(t0
, rt
);
1073 save_cpu_state(ctx
, 0);
1074 gen_load_gpr(t1
, rt
);
1075 op_ldst_sb(t1
, t0
, ctx
);
1079 save_cpu_state(ctx
, 0);
1080 op_ldst_lbu(t0
, t0
, ctx
);
1081 gen_store_gpr(t0
, rt
);
1085 save_cpu_state(ctx
, 1);
1086 gen_load_gpr(t1
, rt
);
1087 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1088 gen_store_gpr(t1
, rt
);
1092 save_cpu_state(ctx
, 1);
1093 gen_load_gpr(t1
, rt
);
1094 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1098 save_cpu_state(ctx
, 1);
1099 gen_load_gpr(t1
, rt
);
1100 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1101 gen_store_gpr(t1
, rt
);
1105 save_cpu_state(ctx
, 1);
1106 gen_load_gpr(t1
, rt
);
1107 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1111 save_cpu_state(ctx
, 1);
1112 op_ldst_ll(t0
, t0
, ctx
);
1113 gen_store_gpr(t0
, rt
);
1117 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1122 /* Store conditional */
1123 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1124 int base
, int16_t offset
)
1126 const char *opn
= "st_cond";
1129 t0
= tcg_temp_local_new();
1131 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1132 /* Don't do NOP if destination is zero: we must perform the actual
1135 t1
= tcg_temp_local_new();
1136 gen_load_gpr(t1
, rt
);
1138 #if defined(TARGET_MIPS64)
1140 save_cpu_state(ctx
, 0);
1141 op_ldst_scd(t1
, t0
, rt
, ctx
);
1146 save_cpu_state(ctx
, 1);
1147 op_ldst_sc(t1
, t0
, rt
, ctx
);
1151 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1156 /* Load and store */
1157 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1158 int base
, int16_t offset
)
1160 const char *opn
= "flt_ldst";
1161 TCGv t0
= tcg_temp_new();
1163 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1164 /* Don't do NOP if destination is zero: we must perform the actual
1169 TCGv_i32 fp0
= tcg_temp_new_i32();
1171 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1172 tcg_gen_trunc_tl_i32(fp0
, t0
);
1173 gen_store_fpr32(fp0
, ft
);
1174 tcg_temp_free_i32(fp0
);
1180 TCGv_i32 fp0
= tcg_temp_new_i32();
1181 TCGv t1
= tcg_temp_new();
1183 gen_load_fpr32(fp0
, ft
);
1184 tcg_gen_extu_i32_tl(t1
, fp0
);
1185 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1187 tcg_temp_free_i32(fp0
);
1193 TCGv_i64 fp0
= tcg_temp_new_i64();
1195 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1196 gen_store_fpr64(ctx
, fp0
, ft
);
1197 tcg_temp_free_i64(fp0
);
1203 TCGv_i64 fp0
= tcg_temp_new_i64();
1205 gen_load_fpr64(ctx
, fp0
, ft
);
1206 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1207 tcg_temp_free_i64(fp0
);
1213 generate_exception(ctx
, EXCP_RI
);
1216 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1221 /* Arithmetic with immediate operand */
1222 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1223 int rt
, int rs
, int16_t imm
)
1225 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1226 const char *opn
= "imm arith";
1228 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1229 /* If no destination, treat it as a NOP.
1230 For addi, we must generate the overflow exception when needed. */
1237 TCGv t0
= tcg_temp_local_new();
1238 TCGv t1
= tcg_temp_new();
1239 TCGv t2
= tcg_temp_new();
1240 int l1
= gen_new_label();
1242 gen_load_gpr(t1
, rs
);
1243 tcg_gen_addi_tl(t0
, t1
, uimm
);
1244 tcg_gen_ext32s_tl(t0
, t0
);
1246 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1247 tcg_gen_xori_tl(t2
, t0
, uimm
);
1248 tcg_gen_and_tl(t1
, t1
, t2
);
1250 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1252 /* operands of same sign, result different sign */
1253 generate_exception(ctx
, EXCP_OVERFLOW
);
1255 tcg_gen_ext32s_tl(t0
, t0
);
1256 gen_store_gpr(t0
, rt
);
1263 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1264 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1266 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1270 #if defined(TARGET_MIPS64)
1273 TCGv t0
= tcg_temp_local_new();
1274 TCGv t1
= tcg_temp_new();
1275 TCGv t2
= tcg_temp_new();
1276 int l1
= gen_new_label();
1278 gen_load_gpr(t1
, rs
);
1279 tcg_gen_addi_tl(t0
, t1
, uimm
);
1281 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1282 tcg_gen_xori_tl(t2
, t0
, uimm
);
1283 tcg_gen_and_tl(t1
, t1
, t2
);
1285 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1287 /* operands of same sign, result different sign */
1288 generate_exception(ctx
, EXCP_OVERFLOW
);
1290 gen_store_gpr(t0
, rt
);
1297 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1299 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1305 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1308 /* Logic with immediate operand */
1309 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1312 const char *opn
= "imm logic";
1315 /* If no destination, treat it as a NOP. */
1319 uimm
= (uint16_t)imm
;
1322 if (likely(rs
!= 0))
1323 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1325 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1330 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1332 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1336 if (likely(rs
!= 0))
1337 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1339 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1343 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1347 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1350 /* Set on less than with immediate operand */
1351 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1353 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1354 const char *opn
= "imm arith";
1358 /* If no destination, treat it as a NOP. */
1362 t0
= tcg_temp_new();
1363 gen_load_gpr(t0
, rs
);
1366 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
1370 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
1374 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1378 /* Shifts with immediate operand */
1379 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1380 int rt
, int rs
, int16_t imm
)
1382 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1383 const char *opn
= "imm shift";
1387 /* If no destination, treat it as a NOP. */
1392 t0
= tcg_temp_new();
1393 gen_load_gpr(t0
, rs
);
1396 tcg_gen_shli_tl(t0
, t0
, uimm
);
1397 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1401 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1406 tcg_gen_ext32u_tl(t0
, t0
);
1407 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1409 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1415 TCGv_i32 t1
= tcg_temp_new_i32();
1417 tcg_gen_trunc_tl_i32(t1
, t0
);
1418 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1419 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1420 tcg_temp_free_i32(t1
);
1422 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1426 #if defined(TARGET_MIPS64)
1428 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1432 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1436 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1441 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1443 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
1448 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1452 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1456 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1460 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1465 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1470 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1471 int rd
, int rs
, int rt
)
1473 const char *opn
= "arith";
1475 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1476 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1477 /* If no destination, treat it as a NOP.
1478 For add & sub, we must generate the overflow exception when needed. */
1486 TCGv t0
= tcg_temp_local_new();
1487 TCGv t1
= tcg_temp_new();
1488 TCGv t2
= tcg_temp_new();
1489 int l1
= gen_new_label();
1491 gen_load_gpr(t1
, rs
);
1492 gen_load_gpr(t2
, rt
);
1493 tcg_gen_add_tl(t0
, t1
, t2
);
1494 tcg_gen_ext32s_tl(t0
, t0
);
1495 tcg_gen_xor_tl(t1
, t1
, t2
);
1496 tcg_gen_not_tl(t1
, t1
);
1497 tcg_gen_xor_tl(t2
, t0
, t2
);
1498 tcg_gen_and_tl(t1
, t1
, t2
);
1500 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1502 /* operands of same sign, result different sign */
1503 generate_exception(ctx
, EXCP_OVERFLOW
);
1505 gen_store_gpr(t0
, rd
);
1511 if (rs
!= 0 && rt
!= 0) {
1512 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1513 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1514 } else if (rs
== 0 && rt
!= 0) {
1515 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1516 } else if (rs
!= 0 && rt
== 0) {
1517 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1519 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1525 TCGv t0
= tcg_temp_local_new();
1526 TCGv t1
= tcg_temp_new();
1527 TCGv t2
= tcg_temp_new();
1528 int l1
= gen_new_label();
1530 gen_load_gpr(t1
, rs
);
1531 gen_load_gpr(t2
, rt
);
1532 tcg_gen_sub_tl(t0
, t1
, t2
);
1533 tcg_gen_ext32s_tl(t0
, t0
);
1534 tcg_gen_xor_tl(t2
, t1
, t2
);
1535 tcg_gen_xor_tl(t1
, t0
, t1
);
1536 tcg_gen_and_tl(t1
, t1
, t2
);
1538 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1540 /* operands of different sign, first operand and result different sign */
1541 generate_exception(ctx
, EXCP_OVERFLOW
);
1543 gen_store_gpr(t0
, rd
);
1549 if (rs
!= 0 && rt
!= 0) {
1550 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1551 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1552 } else if (rs
== 0 && rt
!= 0) {
1553 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1554 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1555 } else if (rs
!= 0 && rt
== 0) {
1556 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1558 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1562 #if defined(TARGET_MIPS64)
1565 TCGv t0
= tcg_temp_local_new();
1566 TCGv t1
= tcg_temp_new();
1567 TCGv t2
= tcg_temp_new();
1568 int l1
= gen_new_label();
1570 gen_load_gpr(t1
, rs
);
1571 gen_load_gpr(t2
, rt
);
1572 tcg_gen_add_tl(t0
, t1
, t2
);
1573 tcg_gen_xor_tl(t1
, t1
, t2
);
1574 tcg_gen_not_tl(t1
, t1
);
1575 tcg_gen_xor_tl(t2
, t0
, t2
);
1576 tcg_gen_and_tl(t1
, t1
, t2
);
1578 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1580 /* operands of same sign, result different sign */
1581 generate_exception(ctx
, EXCP_OVERFLOW
);
1583 gen_store_gpr(t0
, rd
);
1589 if (rs
!= 0 && rt
!= 0) {
1590 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1591 } else if (rs
== 0 && rt
!= 0) {
1592 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1593 } else if (rs
!= 0 && rt
== 0) {
1594 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1596 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1602 TCGv t0
= tcg_temp_local_new();
1603 TCGv t1
= tcg_temp_new();
1604 TCGv t2
= tcg_temp_new();
1605 int l1
= gen_new_label();
1607 gen_load_gpr(t1
, rs
);
1608 gen_load_gpr(t2
, rt
);
1609 tcg_gen_sub_tl(t0
, t1
, t2
);
1610 tcg_gen_xor_tl(t2
, t1
, t2
);
1611 tcg_gen_xor_tl(t1
, t0
, t1
);
1612 tcg_gen_and_tl(t1
, t1
, t2
);
1614 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1616 /* operands of different sign, first operand and result different sign */
1617 generate_exception(ctx
, EXCP_OVERFLOW
);
1619 gen_store_gpr(t0
, rd
);
1625 if (rs
!= 0 && rt
!= 0) {
1626 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1627 } else if (rs
== 0 && rt
!= 0) {
1628 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1629 } else if (rs
!= 0 && rt
== 0) {
1630 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1632 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1638 if (likely(rs
!= 0 && rt
!= 0)) {
1639 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1640 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1642 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1647 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1650 /* Conditional move */
1651 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1653 const char *opn
= "cond move";
1657 /* If no destination, treat it as a NOP.
1658 For add & sub, we must generate the overflow exception when needed. */
1663 l1
= gen_new_label();
1666 if (likely(rt
!= 0))
1667 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1673 if (likely(rt
!= 0))
1674 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1679 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1681 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1684 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1688 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1690 const char *opn
= "logic";
1693 /* If no destination, treat it as a NOP. */
1700 if (likely(rs
!= 0 && rt
!= 0)) {
1701 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1703 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1708 if (rs
!= 0 && rt
!= 0) {
1709 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1710 } else if (rs
== 0 && rt
!= 0) {
1711 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1712 } else if (rs
!= 0 && rt
== 0) {
1713 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1715 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1720 if (likely(rs
!= 0 && rt
!= 0)) {
1721 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1722 } else if (rs
== 0 && rt
!= 0) {
1723 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1724 } else if (rs
!= 0 && rt
== 0) {
1725 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1727 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1732 if (likely(rs
!= 0 && rt
!= 0)) {
1733 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1734 } else if (rs
== 0 && rt
!= 0) {
1735 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1736 } else if (rs
!= 0 && rt
== 0) {
1737 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1739 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1744 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1747 /* Set on lower than */
1748 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1750 const char *opn
= "slt";
1754 /* If no destination, treat it as a NOP. */
1759 t0
= tcg_temp_new();
1760 t1
= tcg_temp_new();
1761 gen_load_gpr(t0
, rs
);
1762 gen_load_gpr(t1
, rt
);
1765 tcg_gen_setcond_tl(TCG_COND_LT
, cpu_gpr
[rd
], t0
, t1
);
1769 tcg_gen_setcond_tl(TCG_COND_LTU
, cpu_gpr
[rd
], t0
, t1
);
1773 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1779 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1780 int rd
, int rs
, int rt
)
1782 const char *opn
= "shifts";
1786 /* If no destination, treat it as a NOP.
1787 For add & sub, we must generate the overflow exception when needed. */
1792 t0
= tcg_temp_new();
1793 t1
= tcg_temp_new();
1794 gen_load_gpr(t0
, rs
);
1795 gen_load_gpr(t1
, rt
);
1798 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1799 tcg_gen_shl_tl(t0
, t1
, t0
);
1800 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1804 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1805 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1809 tcg_gen_ext32u_tl(t1
, t1
);
1810 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1811 tcg_gen_shr_tl(t0
, t1
, t0
);
1812 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1817 TCGv_i32 t2
= tcg_temp_new_i32();
1818 TCGv_i32 t3
= tcg_temp_new_i32();
1820 tcg_gen_trunc_tl_i32(t2
, t0
);
1821 tcg_gen_trunc_tl_i32(t3
, t1
);
1822 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1823 tcg_gen_rotr_i32(t2
, t3
, t2
);
1824 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1825 tcg_temp_free_i32(t2
);
1826 tcg_temp_free_i32(t3
);
1830 #if defined(TARGET_MIPS64)
1832 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1833 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1837 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1838 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1842 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1843 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1847 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1848 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1853 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1858 /* Arithmetic on HI/LO registers */
1859 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1861 const char *opn
= "hilo";
1863 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1870 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1874 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1879 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1881 tcg_gen_movi_tl(cpu_HI
[0], 0);
1886 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
1888 tcg_gen_movi_tl(cpu_LO
[0], 0);
1892 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1895 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1898 const char *opn
= "mul/div";
1904 #if defined(TARGET_MIPS64)
1908 t0
= tcg_temp_local_new();
1909 t1
= tcg_temp_local_new();
1912 t0
= tcg_temp_new();
1913 t1
= tcg_temp_new();
1917 gen_load_gpr(t0
, rs
);
1918 gen_load_gpr(t1
, rt
);
1922 int l1
= gen_new_label();
1923 int l2
= gen_new_label();
1925 tcg_gen_ext32s_tl(t0
, t0
);
1926 tcg_gen_ext32s_tl(t1
, t1
);
1927 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1928 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
1929 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
1931 tcg_gen_mov_tl(cpu_LO
[0], t0
);
1932 tcg_gen_movi_tl(cpu_HI
[0], 0);
1935 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
1936 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
1937 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
1938 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
1945 int l1
= gen_new_label();
1947 tcg_gen_ext32u_tl(t0
, t0
);
1948 tcg_gen_ext32u_tl(t1
, t1
);
1949 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1950 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
1951 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
1952 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
1953 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
1960 TCGv_i64 t2
= tcg_temp_new_i64();
1961 TCGv_i64 t3
= tcg_temp_new_i64();
1963 tcg_gen_ext_tl_i64(t2
, t0
);
1964 tcg_gen_ext_tl_i64(t3
, t1
);
1965 tcg_gen_mul_i64(t2
, t2
, t3
);
1966 tcg_temp_free_i64(t3
);
1967 tcg_gen_trunc_i64_tl(t0
, t2
);
1968 tcg_gen_shri_i64(t2
, t2
, 32);
1969 tcg_gen_trunc_i64_tl(t1
, t2
);
1970 tcg_temp_free_i64(t2
);
1971 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1972 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
1978 TCGv_i64 t2
= tcg_temp_new_i64();
1979 TCGv_i64 t3
= tcg_temp_new_i64();
1981 tcg_gen_ext32u_tl(t0
, t0
);
1982 tcg_gen_ext32u_tl(t1
, t1
);
1983 tcg_gen_extu_tl_i64(t2
, t0
);
1984 tcg_gen_extu_tl_i64(t3
, t1
);
1985 tcg_gen_mul_i64(t2
, t2
, t3
);
1986 tcg_temp_free_i64(t3
);
1987 tcg_gen_trunc_i64_tl(t0
, t2
);
1988 tcg_gen_shri_i64(t2
, t2
, 32);
1989 tcg_gen_trunc_i64_tl(t1
, t2
);
1990 tcg_temp_free_i64(t2
);
1991 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1992 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
1996 #if defined(TARGET_MIPS64)
1999 int l1
= gen_new_label();
2000 int l2
= gen_new_label();
2002 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2003 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2004 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2005 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2006 tcg_gen_movi_tl(cpu_HI
[0], 0);
2009 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2010 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2017 int l1
= gen_new_label();
2019 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2020 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2021 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2027 gen_helper_dmult(t0
, t1
);
2031 gen_helper_dmultu(t0
, t1
);
2037 TCGv_i64 t2
= tcg_temp_new_i64();
2038 TCGv_i64 t3
= tcg_temp_new_i64();
2040 tcg_gen_ext_tl_i64(t2
, t0
);
2041 tcg_gen_ext_tl_i64(t3
, t1
);
2042 tcg_gen_mul_i64(t2
, t2
, t3
);
2043 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2044 tcg_gen_add_i64(t2
, t2
, t3
);
2045 tcg_temp_free_i64(t3
);
2046 tcg_gen_trunc_i64_tl(t0
, t2
);
2047 tcg_gen_shri_i64(t2
, t2
, 32);
2048 tcg_gen_trunc_i64_tl(t1
, t2
);
2049 tcg_temp_free_i64(t2
);
2050 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2051 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2057 TCGv_i64 t2
= tcg_temp_new_i64();
2058 TCGv_i64 t3
= tcg_temp_new_i64();
2060 tcg_gen_ext32u_tl(t0
, t0
);
2061 tcg_gen_ext32u_tl(t1
, t1
);
2062 tcg_gen_extu_tl_i64(t2
, t0
);
2063 tcg_gen_extu_tl_i64(t3
, t1
);
2064 tcg_gen_mul_i64(t2
, t2
, t3
);
2065 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2066 tcg_gen_add_i64(t2
, t2
, t3
);
2067 tcg_temp_free_i64(t3
);
2068 tcg_gen_trunc_i64_tl(t0
, t2
);
2069 tcg_gen_shri_i64(t2
, t2
, 32);
2070 tcg_gen_trunc_i64_tl(t1
, t2
);
2071 tcg_temp_free_i64(t2
);
2072 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2073 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2079 TCGv_i64 t2
= tcg_temp_new_i64();
2080 TCGv_i64 t3
= tcg_temp_new_i64();
2082 tcg_gen_ext_tl_i64(t2
, t0
);
2083 tcg_gen_ext_tl_i64(t3
, t1
);
2084 tcg_gen_mul_i64(t2
, t2
, t3
);
2085 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2086 tcg_gen_sub_i64(t2
, t3
, t2
);
2087 tcg_temp_free_i64(t3
);
2088 tcg_gen_trunc_i64_tl(t0
, t2
);
2089 tcg_gen_shri_i64(t2
, t2
, 32);
2090 tcg_gen_trunc_i64_tl(t1
, t2
);
2091 tcg_temp_free_i64(t2
);
2092 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2093 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2099 TCGv_i64 t2
= tcg_temp_new_i64();
2100 TCGv_i64 t3
= tcg_temp_new_i64();
2102 tcg_gen_ext32u_tl(t0
, t0
);
2103 tcg_gen_ext32u_tl(t1
, t1
);
2104 tcg_gen_extu_tl_i64(t2
, t0
);
2105 tcg_gen_extu_tl_i64(t3
, t1
);
2106 tcg_gen_mul_i64(t2
, t2
, t3
);
2107 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2108 tcg_gen_sub_i64(t2
, t3
, t2
);
2109 tcg_temp_free_i64(t3
);
2110 tcg_gen_trunc_i64_tl(t0
, t2
);
2111 tcg_gen_shri_i64(t2
, t2
, 32);
2112 tcg_gen_trunc_i64_tl(t1
, t2
);
2113 tcg_temp_free_i64(t2
);
2114 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2115 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2121 generate_exception(ctx
, EXCP_RI
);
2124 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2130 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2131 int rd
, int rs
, int rt
)
2133 const char *opn
= "mul vr54xx";
2134 TCGv t0
= tcg_temp_new();
2135 TCGv t1
= tcg_temp_new();
2137 gen_load_gpr(t0
, rs
);
2138 gen_load_gpr(t1
, rt
);
2141 case OPC_VR54XX_MULS
:
2142 gen_helper_muls(t0
, t0
, t1
);
2145 case OPC_VR54XX_MULSU
:
2146 gen_helper_mulsu(t0
, t0
, t1
);
2149 case OPC_VR54XX_MACC
:
2150 gen_helper_macc(t0
, t0
, t1
);
2153 case OPC_VR54XX_MACCU
:
2154 gen_helper_maccu(t0
, t0
, t1
);
2157 case OPC_VR54XX_MSAC
:
2158 gen_helper_msac(t0
, t0
, t1
);
2161 case OPC_VR54XX_MSACU
:
2162 gen_helper_msacu(t0
, t0
, t1
);
2165 case OPC_VR54XX_MULHI
:
2166 gen_helper_mulhi(t0
, t0
, t1
);
2169 case OPC_VR54XX_MULHIU
:
2170 gen_helper_mulhiu(t0
, t0
, t1
);
2173 case OPC_VR54XX_MULSHI
:
2174 gen_helper_mulshi(t0
, t0
, t1
);
2177 case OPC_VR54XX_MULSHIU
:
2178 gen_helper_mulshiu(t0
, t0
, t1
);
2181 case OPC_VR54XX_MACCHI
:
2182 gen_helper_macchi(t0
, t0
, t1
);
2185 case OPC_VR54XX_MACCHIU
:
2186 gen_helper_macchiu(t0
, t0
, t1
);
2189 case OPC_VR54XX_MSACHI
:
2190 gen_helper_msachi(t0
, t0
, t1
);
2193 case OPC_VR54XX_MSACHIU
:
2194 gen_helper_msachiu(t0
, t0
, t1
);
2198 MIPS_INVAL("mul vr54xx");
2199 generate_exception(ctx
, EXCP_RI
);
2202 gen_store_gpr(t0
, rd
);
2203 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2210 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2213 const char *opn
= "CLx";
2221 t0
= tcg_temp_new();
2222 gen_load_gpr(t0
, rs
);
2225 gen_helper_clo(cpu_gpr
[rd
], t0
);
2229 gen_helper_clz(cpu_gpr
[rd
], t0
);
2232 #if defined(TARGET_MIPS64)
2234 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2238 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2243 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2248 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2249 int rs
, int rt
, int16_t imm
)
2252 TCGv t0
= tcg_temp_new();
2253 TCGv t1
= tcg_temp_new();
2256 /* Load needed operands */
2264 /* Compare two registers */
2266 gen_load_gpr(t0
, rs
);
2267 gen_load_gpr(t1
, rt
);
2277 /* Compare register to immediate */
2278 if (rs
!= 0 || imm
!= 0) {
2279 gen_load_gpr(t0
, rs
);
2280 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2287 case OPC_TEQ
: /* rs == rs */
2288 case OPC_TEQI
: /* r0 == 0 */
2289 case OPC_TGE
: /* rs >= rs */
2290 case OPC_TGEI
: /* r0 >= 0 */
2291 case OPC_TGEU
: /* rs >= rs unsigned */
2292 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2294 generate_exception(ctx
, EXCP_TRAP
);
2296 case OPC_TLT
: /* rs < rs */
2297 case OPC_TLTI
: /* r0 < 0 */
2298 case OPC_TLTU
: /* rs < rs unsigned */
2299 case OPC_TLTIU
: /* r0 < 0 unsigned */
2300 case OPC_TNE
: /* rs != rs */
2301 case OPC_TNEI
: /* r0 != 0 */
2302 /* Never trap: treat as NOP. */
2306 int l1
= gen_new_label();
2311 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2315 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2319 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2323 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2327 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2331 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2334 generate_exception(ctx
, EXCP_TRAP
);
2341 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2343 TranslationBlock
*tb
;
2345 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2346 likely(!ctx
->singlestep_enabled
)) {
2349 tcg_gen_exit_tb((long)tb
+ n
);
2352 if (ctx
->singlestep_enabled
) {
2353 save_cpu_state(ctx
, 0);
2354 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
2360 /* Branches (before delay slot) */
2361 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2363 int rs
, int rt
, int32_t offset
)
2365 target_ulong btgt
= -1;
2367 int bcond_compute
= 0;
2368 TCGv t0
= tcg_temp_new();
2369 TCGv t1
= tcg_temp_new();
2371 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2372 #ifdef MIPS_DEBUG_DISAS
2373 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2375 generate_exception(ctx
, EXCP_RI
);
2379 /* Load needed operands */
2385 /* Compare two registers */
2387 gen_load_gpr(t0
, rs
);
2388 gen_load_gpr(t1
, rt
);
2391 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2405 /* Compare to zero */
2407 gen_load_gpr(t0
, rs
);
2410 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2415 /* Jump to immediate */
2416 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
2421 /* Jump to register */
2422 if (offset
!= 0 && offset
!= 16) {
2423 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2424 others are reserved. */
2425 MIPS_INVAL("jump hint");
2426 generate_exception(ctx
, EXCP_RI
);
2429 gen_load_gpr(btarget
, rs
);
2432 MIPS_INVAL("branch/jump");
2433 generate_exception(ctx
, EXCP_RI
);
2436 if (bcond_compute
== 0) {
2437 /* No condition to be computed */
2439 case OPC_BEQ
: /* rx == rx */
2440 case OPC_BEQL
: /* rx == rx likely */
2441 case OPC_BGEZ
: /* 0 >= 0 */
2442 case OPC_BGEZL
: /* 0 >= 0 likely */
2443 case OPC_BLEZ
: /* 0 <= 0 */
2444 case OPC_BLEZL
: /* 0 <= 0 likely */
2446 ctx
->hflags
|= MIPS_HFLAG_B
;
2447 MIPS_DEBUG("balways");
2449 case OPC_BGEZAL
: /* 0 >= 0 */
2450 case OPC_BGEZALL
: /* 0 >= 0 likely */
2451 /* Always take and link */
2453 ctx
->hflags
|= MIPS_HFLAG_B
;
2454 MIPS_DEBUG("balways and link");
2456 case OPC_BNE
: /* rx != rx */
2457 case OPC_BGTZ
: /* 0 > 0 */
2458 case OPC_BLTZ
: /* 0 < 0 */
2460 MIPS_DEBUG("bnever (NOP)");
2462 case OPC_BLTZAL
: /* 0 < 0 */
2463 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2464 MIPS_DEBUG("bnever and link");
2466 case OPC_BLTZALL
: /* 0 < 0 likely */
2467 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2468 /* Skip the instruction in the delay slot */
2469 MIPS_DEBUG("bnever, link and skip");
2472 case OPC_BNEL
: /* rx != rx likely */
2473 case OPC_BGTZL
: /* 0 > 0 likely */
2474 case OPC_BLTZL
: /* 0 < 0 likely */
2475 /* Skip the instruction in the delay slot */
2476 MIPS_DEBUG("bnever and skip");
2480 ctx
->hflags
|= MIPS_HFLAG_B
;
2481 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2484 ctx
->hflags
|= MIPS_HFLAG_BX
;
2488 ctx
->hflags
|= MIPS_HFLAG_B
;
2489 ctx
->hflags
|= (ctx
->hflags
& MIPS_HFLAG_M16
2491 : MIPS_HFLAG_BDS32
);
2492 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2495 ctx
->hflags
|= MIPS_HFLAG_BR
;
2496 if (ctx
->hflags
& MIPS_HFLAG_M16
)
2497 ctx
->hflags
|= MIPS_HFLAG_BDS16
;
2498 MIPS_DEBUG("jr %s", regnames
[rs
]);
2503 ctx
->hflags
|= MIPS_HFLAG_BR
;
2504 if (ctx
->hflags
& MIPS_HFLAG_M16
)
2505 ctx
->hflags
|= MIPS_HFLAG_BDS16
;
2506 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2509 MIPS_INVAL("branch/jump");
2510 generate_exception(ctx
, EXCP_RI
);
2516 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2517 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2518 regnames
[rs
], regnames
[rt
], btgt
);
2521 tcg_gen_setcond_tl(TCG_COND_EQ
, bcond
, t0
, t1
);
2522 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2523 regnames
[rs
], regnames
[rt
], btgt
);
2526 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2527 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2528 regnames
[rs
], regnames
[rt
], btgt
);
2531 tcg_gen_setcond_tl(TCG_COND_NE
, bcond
, t0
, t1
);
2532 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2533 regnames
[rs
], regnames
[rt
], btgt
);
2536 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2537 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2540 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2541 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2544 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2545 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2549 tcg_gen_setcondi_tl(TCG_COND_GE
, bcond
, t0
, 0);
2551 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2554 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2555 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2558 tcg_gen_setcondi_tl(TCG_COND_GT
, bcond
, t0
, 0);
2559 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2562 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2563 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2566 tcg_gen_setcondi_tl(TCG_COND_LE
, bcond
, t0
, 0);
2567 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2570 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2571 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2574 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2575 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2578 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2580 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2582 ctx
->hflags
|= MIPS_HFLAG_BC
;
2585 tcg_gen_setcondi_tl(TCG_COND_LT
, bcond
, t0
, 0);
2587 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2589 ctx
->hflags
|= MIPS_HFLAG_BL
;
2592 MIPS_INVAL("conditional branch/jump");
2593 generate_exception(ctx
, EXCP_RI
);
2597 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2598 blink
, ctx
->hflags
, btgt
);
2600 ctx
->btarget
= btgt
;
2602 int post_delay
= insn_bytes
;
2603 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
2605 if (opc
!= OPC_JALRC
)
2606 post_delay
+= ((ctx
->hflags
& MIPS_HFLAG_BDS16
) ? 2 : 4);
2608 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ post_delay
+ lowbit
);
2612 if (insn_bytes
== 2)
2613 ctx
->hflags
|= MIPS_HFLAG_B16
;
2618 /* special3 bitfield operations */
2619 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2620 int rs
, int lsb
, int msb
)
2622 TCGv t0
= tcg_temp_new();
2623 TCGv t1
= tcg_temp_new();
2626 gen_load_gpr(t1
, rs
);
2631 tcg_gen_shri_tl(t0
, t1
, lsb
);
2633 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2635 tcg_gen_ext32s_tl(t0
, t0
);
2638 #if defined(TARGET_MIPS64)
2640 tcg_gen_shri_tl(t0
, t1
, lsb
);
2642 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2646 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2647 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2650 tcg_gen_shri_tl(t0
, t1
, lsb
);
2651 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2657 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2658 gen_load_gpr(t0
, rt
);
2659 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2660 tcg_gen_shli_tl(t1
, t1
, lsb
);
2661 tcg_gen_andi_tl(t1
, t1
, mask
);
2662 tcg_gen_or_tl(t0
, t0
, t1
);
2663 tcg_gen_ext32s_tl(t0
, t0
);
2665 #if defined(TARGET_MIPS64)
2669 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2670 gen_load_gpr(t0
, rt
);
2671 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2672 tcg_gen_shli_tl(t1
, t1
, lsb
);
2673 tcg_gen_andi_tl(t1
, t1
, mask
);
2674 tcg_gen_or_tl(t0
, t0
, t1
);
2679 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2680 gen_load_gpr(t0
, rt
);
2681 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2682 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2683 tcg_gen_andi_tl(t1
, t1
, mask
);
2684 tcg_gen_or_tl(t0
, t0
, t1
);
2689 gen_load_gpr(t0
, rt
);
2690 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2691 gen_load_gpr(t0
, rt
);
2692 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2693 tcg_gen_shli_tl(t1
, t1
, lsb
);
2694 tcg_gen_andi_tl(t1
, t1
, mask
);
2695 tcg_gen_or_tl(t0
, t0
, t1
);
2700 MIPS_INVAL("bitops");
2701 generate_exception(ctx
, EXCP_RI
);
2706 gen_store_gpr(t0
, rt
);
2711 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2716 /* If no destination, treat it as a NOP. */
2721 t0
= tcg_temp_new();
2722 gen_load_gpr(t0
, rt
);
2726 TCGv t1
= tcg_temp_new();
2728 tcg_gen_shri_tl(t1
, t0
, 8);
2729 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2730 tcg_gen_shli_tl(t0
, t0
, 8);
2731 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2732 tcg_gen_or_tl(t0
, t0
, t1
);
2734 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2738 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2741 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2743 #if defined(TARGET_MIPS64)
2746 TCGv t1
= tcg_temp_new();
2748 tcg_gen_shri_tl(t1
, t0
, 8);
2749 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2750 tcg_gen_shli_tl(t0
, t0
, 8);
2751 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2752 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2758 TCGv t1
= tcg_temp_new();
2760 tcg_gen_shri_tl(t1
, t0
, 16);
2761 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2762 tcg_gen_shli_tl(t0
, t0
, 16);
2763 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2764 tcg_gen_or_tl(t0
, t0
, t1
);
2765 tcg_gen_shri_tl(t1
, t0
, 32);
2766 tcg_gen_shli_tl(t0
, t0
, 32);
2767 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2773 MIPS_INVAL("bsfhl");
2774 generate_exception(ctx
, EXCP_RI
);
2781 #ifndef CONFIG_USER_ONLY
2782 /* CP0 (MMU and control) */
2783 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
2785 TCGv_i32 t0
= tcg_temp_new_i32();
2787 tcg_gen_ld_i32(t0
, cpu_env
, off
);
2788 tcg_gen_ext_i32_tl(arg
, t0
);
2789 tcg_temp_free_i32(t0
);
2792 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
2794 tcg_gen_ld_tl(arg
, cpu_env
, off
);
2795 tcg_gen_ext32s_tl(arg
, arg
);
2798 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
2800 TCGv_i32 t0
= tcg_temp_new_i32();
2802 tcg_gen_trunc_tl_i32(t0
, arg
);
2803 tcg_gen_st_i32(t0
, cpu_env
, off
);
2804 tcg_temp_free_i32(t0
);
2807 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
2809 tcg_gen_ext32s_tl(arg
, arg
);
2810 tcg_gen_st_tl(arg
, cpu_env
, off
);
2813 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
2815 const char *rn
= "invalid";
2818 check_insn(env
, ctx
, ISA_MIPS32
);
2824 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
2828 check_insn(env
, ctx
, ASE_MT
);
2829 gen_helper_mfc0_mvpcontrol(arg
);
2833 check_insn(env
, ctx
, ASE_MT
);
2834 gen_helper_mfc0_mvpconf0(arg
);
2838 check_insn(env
, ctx
, ASE_MT
);
2839 gen_helper_mfc0_mvpconf1(arg
);
2849 gen_helper_mfc0_random(arg
);
2853 check_insn(env
, ctx
, ASE_MT
);
2854 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
2858 check_insn(env
, ctx
, ASE_MT
);
2859 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
2863 check_insn(env
, ctx
, ASE_MT
);
2864 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
2868 check_insn(env
, ctx
, ASE_MT
);
2869 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
2873 check_insn(env
, ctx
, ASE_MT
);
2874 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
2878 check_insn(env
, ctx
, ASE_MT
);
2879 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
2880 rn
= "VPEScheFBack";
2883 check_insn(env
, ctx
, ASE_MT
);
2884 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
2894 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2895 tcg_gen_ext32s_tl(arg
, arg
);
2899 check_insn(env
, ctx
, ASE_MT
);
2900 gen_helper_mfc0_tcstatus(arg
);
2904 check_insn(env
, ctx
, ASE_MT
);
2905 gen_helper_mfc0_tcbind(arg
);
2909 check_insn(env
, ctx
, ASE_MT
);
2910 gen_helper_mfc0_tcrestart(arg
);
2914 check_insn(env
, ctx
, ASE_MT
);
2915 gen_helper_mfc0_tchalt(arg
);
2919 check_insn(env
, ctx
, ASE_MT
);
2920 gen_helper_mfc0_tccontext(arg
);
2924 check_insn(env
, ctx
, ASE_MT
);
2925 gen_helper_mfc0_tcschedule(arg
);
2929 check_insn(env
, ctx
, ASE_MT
);
2930 gen_helper_mfc0_tcschefback(arg
);
2940 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2941 tcg_gen_ext32s_tl(arg
, arg
);
2951 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
2952 tcg_gen_ext32s_tl(arg
, arg
);
2956 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
2957 rn
= "ContextConfig";
2966 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
2970 check_insn(env
, ctx
, ISA_MIPS32R2
);
2971 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
2981 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
2985 check_insn(env
, ctx
, ISA_MIPS32R2
);
2986 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
2990 check_insn(env
, ctx
, ISA_MIPS32R2
);
2991 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
2995 check_insn(env
, ctx
, ISA_MIPS32R2
);
2996 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3000 check_insn(env
, ctx
, ISA_MIPS32R2
);
3001 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3005 check_insn(env
, ctx
, ISA_MIPS32R2
);
3006 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3016 check_insn(env
, ctx
, ISA_MIPS32R2
);
3017 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3027 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3028 tcg_gen_ext32s_tl(arg
, arg
);
3038 /* Mark as an IO operation because we read the time. */
3041 gen_helper_mfc0_count(arg
);
3044 ctx
->bstate
= BS_STOP
;
3048 /* 6,7 are implementation dependent */
3056 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3057 tcg_gen_ext32s_tl(arg
, arg
);
3067 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3070 /* 6,7 are implementation dependent */
3078 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3082 check_insn(env
, ctx
, ISA_MIPS32R2
);
3083 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3087 check_insn(env
, ctx
, ISA_MIPS32R2
);
3088 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3092 check_insn(env
, ctx
, ISA_MIPS32R2
);
3093 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3103 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3113 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3114 tcg_gen_ext32s_tl(arg
, arg
);
3124 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3128 check_insn(env
, ctx
, ISA_MIPS32R2
);
3129 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3139 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3143 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3147 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3151 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3154 /* 4,5 are reserved */
3155 /* 6,7 are implementation dependent */
3157 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3161 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3171 gen_helper_mfc0_lladdr(arg
);
3181 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3191 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3201 #if defined(TARGET_MIPS64)
3202 check_insn(env
, ctx
, ISA_MIPS3
);
3203 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3204 tcg_gen_ext32s_tl(arg
, arg
);
3213 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3216 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3224 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3225 rn
= "'Diagnostic"; /* implementation dependent */
3230 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3234 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3235 rn
= "TraceControl";
3238 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3239 rn
= "TraceControl2";
3242 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3243 rn
= "UserTraceData";
3246 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3257 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3258 tcg_gen_ext32s_tl(arg
, arg
);
3268 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3269 rn
= "Performance0";
3272 // gen_helper_mfc0_performance1(arg);
3273 rn
= "Performance1";
3276 // gen_helper_mfc0_performance2(arg);
3277 rn
= "Performance2";
3280 // gen_helper_mfc0_performance3(arg);
3281 rn
= "Performance3";
3284 // gen_helper_mfc0_performance4(arg);
3285 rn
= "Performance4";
3288 // gen_helper_mfc0_performance5(arg);
3289 rn
= "Performance5";
3292 // gen_helper_mfc0_performance6(arg);
3293 rn
= "Performance6";
3296 // gen_helper_mfc0_performance7(arg);
3297 rn
= "Performance7";
3304 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3310 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3323 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3330 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3343 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3350 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3360 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3361 tcg_gen_ext32s_tl(arg
, arg
);
3372 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3382 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3386 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3387 generate_exception(ctx
, EXCP_RI
);
3390 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3392 const char *rn
= "invalid";
3395 check_insn(env
, ctx
, ISA_MIPS32
);
3404 gen_helper_mtc0_index(arg
);
3408 check_insn(env
, ctx
, ASE_MT
);
3409 gen_helper_mtc0_mvpcontrol(arg
);
3413 check_insn(env
, ctx
, ASE_MT
);
3418 check_insn(env
, ctx
, ASE_MT
);
3433 check_insn(env
, ctx
, ASE_MT
);
3434 gen_helper_mtc0_vpecontrol(arg
);
3438 check_insn(env
, ctx
, ASE_MT
);
3439 gen_helper_mtc0_vpeconf0(arg
);
3443 check_insn(env
, ctx
, ASE_MT
);
3444 gen_helper_mtc0_vpeconf1(arg
);
3448 check_insn(env
, ctx
, ASE_MT
);
3449 gen_helper_mtc0_yqmask(arg
);
3453 check_insn(env
, ctx
, ASE_MT
);
3454 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3458 check_insn(env
, ctx
, ASE_MT
);
3459 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3460 rn
= "VPEScheFBack";
3463 check_insn(env
, ctx
, ASE_MT
);
3464 gen_helper_mtc0_vpeopt(arg
);
3474 gen_helper_mtc0_entrylo0(arg
);
3478 check_insn(env
, ctx
, ASE_MT
);
3479 gen_helper_mtc0_tcstatus(arg
);
3483 check_insn(env
, ctx
, ASE_MT
);
3484 gen_helper_mtc0_tcbind(arg
);
3488 check_insn(env
, ctx
, ASE_MT
);
3489 gen_helper_mtc0_tcrestart(arg
);
3493 check_insn(env
, ctx
, ASE_MT
);
3494 gen_helper_mtc0_tchalt(arg
);
3498 check_insn(env
, ctx
, ASE_MT
);
3499 gen_helper_mtc0_tccontext(arg
);
3503 check_insn(env
, ctx
, ASE_MT
);
3504 gen_helper_mtc0_tcschedule(arg
);
3508 check_insn(env
, ctx
, ASE_MT
);
3509 gen_helper_mtc0_tcschefback(arg
);
3519 gen_helper_mtc0_entrylo1(arg
);
3529 gen_helper_mtc0_context(arg
);
3533 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3534 rn
= "ContextConfig";
3543 gen_helper_mtc0_pagemask(arg
);
3547 check_insn(env
, ctx
, ISA_MIPS32R2
);
3548 gen_helper_mtc0_pagegrain(arg
);
3558 gen_helper_mtc0_wired(arg
);
3562 check_insn(env
, ctx
, ISA_MIPS32R2
);
3563 gen_helper_mtc0_srsconf0(arg
);
3567 check_insn(env
, ctx
, ISA_MIPS32R2
);
3568 gen_helper_mtc0_srsconf1(arg
);
3572 check_insn(env
, ctx
, ISA_MIPS32R2
);
3573 gen_helper_mtc0_srsconf2(arg
);
3577 check_insn(env
, ctx
, ISA_MIPS32R2
);
3578 gen_helper_mtc0_srsconf3(arg
);
3582 check_insn(env
, ctx
, ISA_MIPS32R2
);
3583 gen_helper_mtc0_srsconf4(arg
);
3593 check_insn(env
, ctx
, ISA_MIPS32R2
);
3594 gen_helper_mtc0_hwrena(arg
);
3608 gen_helper_mtc0_count(arg
);
3611 /* 6,7 are implementation dependent */
3619 gen_helper_mtc0_entryhi(arg
);
3629 gen_helper_mtc0_compare(arg
);
3632 /* 6,7 are implementation dependent */
3640 save_cpu_state(ctx
, 1);
3641 gen_helper_mtc0_status(arg
);
3642 /* BS_STOP isn't good enough here, hflags may have changed. */
3643 gen_save_pc(ctx
->pc
+ 4);
3644 ctx
->bstate
= BS_EXCP
;
3648 check_insn(env
, ctx
, ISA_MIPS32R2
);
3649 gen_helper_mtc0_intctl(arg
);
3650 /* Stop translation as we may have switched the execution mode */
3651 ctx
->bstate
= BS_STOP
;
3655 check_insn(env
, ctx
, ISA_MIPS32R2
);
3656 gen_helper_mtc0_srsctl(arg
);
3657 /* Stop translation as we may have switched the execution mode */
3658 ctx
->bstate
= BS_STOP
;
3662 check_insn(env
, ctx
, ISA_MIPS32R2
);
3663 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3664 /* Stop translation as we may have switched the execution mode */
3665 ctx
->bstate
= BS_STOP
;
3675 save_cpu_state(ctx
, 1);
3676 gen_helper_mtc0_cause(arg
);
3686 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
3700 check_insn(env
, ctx
, ISA_MIPS32R2
);
3701 gen_helper_mtc0_ebase(arg
);
3711 gen_helper_mtc0_config0(arg
);
3713 /* Stop translation as we may have switched the execution mode */
3714 ctx
->bstate
= BS_STOP
;
3717 /* ignored, read only */
3721 gen_helper_mtc0_config2(arg
);
3723 /* Stop translation as we may have switched the execution mode */
3724 ctx
->bstate
= BS_STOP
;
3727 /* ignored, read only */
3730 /* 4,5 are reserved */
3731 /* 6,7 are implementation dependent */
3741 rn
= "Invalid config selector";
3748 gen_helper_mtc0_lladdr(arg
);
3758 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
3768 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
3778 #if defined(TARGET_MIPS64)
3779 check_insn(env
, ctx
, ISA_MIPS3
);
3780 gen_helper_mtc0_xcontext(arg
);
3789 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3792 gen_helper_mtc0_framemask(arg
);
3801 rn
= "Diagnostic"; /* implementation dependent */
3806 gen_helper_mtc0_debug(arg
); /* EJTAG support */
3807 /* BS_STOP isn't good enough here, hflags may have changed. */
3808 gen_save_pc(ctx
->pc
+ 4);
3809 ctx
->bstate
= BS_EXCP
;
3813 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
3814 rn
= "TraceControl";
3815 /* Stop translation as we may have switched the execution mode */
3816 ctx
->bstate
= BS_STOP
;
3819 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
3820 rn
= "TraceControl2";
3821 /* Stop translation as we may have switched the execution mode */
3822 ctx
->bstate
= BS_STOP
;
3825 /* Stop translation as we may have switched the execution mode */
3826 ctx
->bstate
= BS_STOP
;
3827 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
3828 rn
= "UserTraceData";
3829 /* Stop translation as we may have switched the execution mode */
3830 ctx
->bstate
= BS_STOP
;
3833 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
3834 /* Stop translation as we may have switched the execution mode */
3835 ctx
->bstate
= BS_STOP
;
3846 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
3856 gen_helper_mtc0_performance0(arg
);
3857 rn
= "Performance0";
3860 // gen_helper_mtc0_performance1(arg);
3861 rn
= "Performance1";
3864 // gen_helper_mtc0_performance2(arg);
3865 rn
= "Performance2";
3868 // gen_helper_mtc0_performance3(arg);
3869 rn
= "Performance3";
3872 // gen_helper_mtc0_performance4(arg);
3873 rn
= "Performance4";
3876 // gen_helper_mtc0_performance5(arg);
3877 rn
= "Performance5";
3880 // gen_helper_mtc0_performance6(arg);
3881 rn
= "Performance6";
3884 // gen_helper_mtc0_performance7(arg);
3885 rn
= "Performance7";
3911 gen_helper_mtc0_taglo(arg
);
3918 gen_helper_mtc0_datalo(arg
);
3931 gen_helper_mtc0_taghi(arg
);
3938 gen_helper_mtc0_datahi(arg
);
3949 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
3960 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3966 /* Stop translation as we may have switched the execution mode */
3967 ctx
->bstate
= BS_STOP
;
3972 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3973 /* For simplicity assume that all writes can cause interrupts. */
3976 ctx
->bstate
= BS_STOP
;
3981 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3982 generate_exception(ctx
, EXCP_RI
);
3985 #if defined(TARGET_MIPS64)
3986 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3988 const char *rn
= "invalid";
3991 check_insn(env
, ctx
, ISA_MIPS64
);
3997 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4001 check_insn(env
, ctx
, ASE_MT
);
4002 gen_helper_mfc0_mvpcontrol(arg
);
4006 check_insn(env
, ctx
, ASE_MT
);
4007 gen_helper_mfc0_mvpconf0(arg
);
4011 check_insn(env
, ctx
, ASE_MT
);
4012 gen_helper_mfc0_mvpconf1(arg
);
4022 gen_helper_mfc0_random(arg
);
4026 check_insn(env
, ctx
, ASE_MT
);
4027 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4031 check_insn(env
, ctx
, ASE_MT
);
4032 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4036 check_insn(env
, ctx
, ASE_MT
);
4037 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4041 check_insn(env
, ctx
, ASE_MT
);
4042 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4046 check_insn(env
, ctx
, ASE_MT
);
4047 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4051 check_insn(env
, ctx
, ASE_MT
);
4052 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4053 rn
= "VPEScheFBack";
4056 check_insn(env
, ctx
, ASE_MT
);
4057 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4067 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4071 check_insn(env
, ctx
, ASE_MT
);
4072 gen_helper_mfc0_tcstatus(arg
);
4076 check_insn(env
, ctx
, ASE_MT
);
4077 gen_helper_mfc0_tcbind(arg
);
4081 check_insn(env
, ctx
, ASE_MT
);
4082 gen_helper_dmfc0_tcrestart(arg
);
4086 check_insn(env
, ctx
, ASE_MT
);
4087 gen_helper_dmfc0_tchalt(arg
);
4091 check_insn(env
, ctx
, ASE_MT
);
4092 gen_helper_dmfc0_tccontext(arg
);
4096 check_insn(env
, ctx
, ASE_MT
);
4097 gen_helper_dmfc0_tcschedule(arg
);
4101 check_insn(env
, ctx
, ASE_MT
);
4102 gen_helper_dmfc0_tcschefback(arg
);
4112 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4122 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4126 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4127 rn
= "ContextConfig";
4136 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4140 check_insn(env
, ctx
, ISA_MIPS32R2
);
4141 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4151 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4155 check_insn(env
, ctx
, ISA_MIPS32R2
);
4156 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4160 check_insn(env
, ctx
, ISA_MIPS32R2
);
4161 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4165 check_insn(env
, ctx
, ISA_MIPS32R2
);
4166 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4170 check_insn(env
, ctx
, ISA_MIPS32R2
);
4171 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4175 check_insn(env
, ctx
, ISA_MIPS32R2
);
4176 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4186 check_insn(env
, ctx
, ISA_MIPS32R2
);
4187 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4197 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4207 /* Mark as an IO operation because we read the time. */
4210 gen_helper_mfc0_count(arg
);
4213 ctx
->bstate
= BS_STOP
;
4217 /* 6,7 are implementation dependent */
4225 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4235 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4238 /* 6,7 are implementation dependent */
4246 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4250 check_insn(env
, ctx
, ISA_MIPS32R2
);
4251 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4255 check_insn(env
, ctx
, ISA_MIPS32R2
);
4256 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4260 check_insn(env
, ctx
, ISA_MIPS32R2
);
4261 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4271 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4281 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4291 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4295 check_insn(env
, ctx
, ISA_MIPS32R2
);
4296 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4306 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4310 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4314 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4318 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4321 /* 6,7 are implementation dependent */
4323 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4327 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4337 gen_helper_dmfc0_lladdr(arg
);
4347 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4357 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4367 check_insn(env
, ctx
, ISA_MIPS3
);
4368 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4376 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4379 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4387 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4388 rn
= "'Diagnostic"; /* implementation dependent */
4393 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4397 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4398 rn
= "TraceControl";
4401 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4402 rn
= "TraceControl2";
4405 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4406 rn
= "UserTraceData";
4409 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4420 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4430 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4431 rn
= "Performance0";
4434 // gen_helper_dmfc0_performance1(arg);
4435 rn
= "Performance1";
4438 // gen_helper_dmfc0_performance2(arg);
4439 rn
= "Performance2";
4442 // gen_helper_dmfc0_performance3(arg);
4443 rn
= "Performance3";
4446 // gen_helper_dmfc0_performance4(arg);
4447 rn
= "Performance4";
4450 // gen_helper_dmfc0_performance5(arg);
4451 rn
= "Performance5";
4454 // gen_helper_dmfc0_performance6(arg);
4455 rn
= "Performance6";
4458 // gen_helper_dmfc0_performance7(arg);
4459 rn
= "Performance7";
4466 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4473 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4486 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4493 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4506 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4513 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4523 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4534 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4544 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4548 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4549 generate_exception(ctx
, EXCP_RI
);
4552 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4554 const char *rn
= "invalid";
4557 check_insn(env
, ctx
, ISA_MIPS64
);
4566 gen_helper_mtc0_index(arg
);
4570 check_insn(env
, ctx
, ASE_MT
);
4571 gen_helper_mtc0_mvpcontrol(arg
);
4575 check_insn(env
, ctx
, ASE_MT
);
4580 check_insn(env
, ctx
, ASE_MT
);
4595 check_insn(env
, ctx
, ASE_MT
);
4596 gen_helper_mtc0_vpecontrol(arg
);
4600 check_insn(env
, ctx
, ASE_MT
);
4601 gen_helper_mtc0_vpeconf0(arg
);
4605 check_insn(env
, ctx
, ASE_MT
);
4606 gen_helper_mtc0_vpeconf1(arg
);
4610 check_insn(env
, ctx
, ASE_MT
);
4611 gen_helper_mtc0_yqmask(arg
);
4615 check_insn(env
, ctx
, ASE_MT
);
4616 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4620 check_insn(env
, ctx
, ASE_MT
);
4621 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4622 rn
= "VPEScheFBack";
4625 check_insn(env
, ctx
, ASE_MT
);
4626 gen_helper_mtc0_vpeopt(arg
);
4636 gen_helper_mtc0_entrylo0(arg
);
4640 check_insn(env
, ctx
, ASE_MT
);
4641 gen_helper_mtc0_tcstatus(arg
);
4645 check_insn(env
, ctx
, ASE_MT
);
4646 gen_helper_mtc0_tcbind(arg
);
4650 check_insn(env
, ctx
, ASE_MT
);
4651 gen_helper_mtc0_tcrestart(arg
);
4655 check_insn(env
, ctx
, ASE_MT
);
4656 gen_helper_mtc0_tchalt(arg
);
4660 check_insn(env
, ctx
, ASE_MT
);
4661 gen_helper_mtc0_tccontext(arg
);
4665 check_insn(env
, ctx
, ASE_MT
);
4666 gen_helper_mtc0_tcschedule(arg
);
4670 check_insn(env
, ctx
, ASE_MT
);
4671 gen_helper_mtc0_tcschefback(arg
);
4681 gen_helper_mtc0_entrylo1(arg
);
4691 gen_helper_mtc0_context(arg
);
4695 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
4696 rn
= "ContextConfig";
4705 gen_helper_mtc0_pagemask(arg
);
4709 check_insn(env
, ctx
, ISA_MIPS32R2
);
4710 gen_helper_mtc0_pagegrain(arg
);
4720 gen_helper_mtc0_wired(arg
);
4724 check_insn(env
, ctx
, ISA_MIPS32R2
);
4725 gen_helper_mtc0_srsconf0(arg
);
4729 check_insn(env
, ctx
, ISA_MIPS32R2
);
4730 gen_helper_mtc0_srsconf1(arg
);
4734 check_insn(env
, ctx
, ISA_MIPS32R2
);
4735 gen_helper_mtc0_srsconf2(arg
);
4739 check_insn(env
, ctx
, ISA_MIPS32R2
);
4740 gen_helper_mtc0_srsconf3(arg
);
4744 check_insn(env
, ctx
, ISA_MIPS32R2
);
4745 gen_helper_mtc0_srsconf4(arg
);
4755 check_insn(env
, ctx
, ISA_MIPS32R2
);
4756 gen_helper_mtc0_hwrena(arg
);
4770 gen_helper_mtc0_count(arg
);
4773 /* 6,7 are implementation dependent */
4777 /* Stop translation as we may have switched the execution mode */
4778 ctx
->bstate
= BS_STOP
;
4783 gen_helper_mtc0_entryhi(arg
);
4793 gen_helper_mtc0_compare(arg
);
4796 /* 6,7 are implementation dependent */
4800 /* Stop translation as we may have switched the execution mode */
4801 ctx
->bstate
= BS_STOP
;
4806 save_cpu_state(ctx
, 1);
4807 gen_helper_mtc0_status(arg
);
4808 /* BS_STOP isn't good enough here, hflags may have changed. */
4809 gen_save_pc(ctx
->pc
+ 4);
4810 ctx
->bstate
= BS_EXCP
;
4814 check_insn(env
, ctx
, ISA_MIPS32R2
);
4815 gen_helper_mtc0_intctl(arg
);
4816 /* Stop translation as we may have switched the execution mode */
4817 ctx
->bstate
= BS_STOP
;
4821 check_insn(env
, ctx
, ISA_MIPS32R2
);
4822 gen_helper_mtc0_srsctl(arg
);
4823 /* Stop translation as we may have switched the execution mode */
4824 ctx
->bstate
= BS_STOP
;
4828 check_insn(env
, ctx
, ISA_MIPS32R2
);
4829 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4830 /* Stop translation as we may have switched the execution mode */
4831 ctx
->bstate
= BS_STOP
;
4841 save_cpu_state(ctx
, 1);
4842 gen_helper_mtc0_cause(arg
);
4852 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4866 check_insn(env
, ctx
, ISA_MIPS32R2
);
4867 gen_helper_mtc0_ebase(arg
);
4877 gen_helper_mtc0_config0(arg
);
4879 /* Stop translation as we may have switched the execution mode */
4880 ctx
->bstate
= BS_STOP
;
4883 /* ignored, read only */
4887 gen_helper_mtc0_config2(arg
);
4889 /* Stop translation as we may have switched the execution mode */
4890 ctx
->bstate
= BS_STOP
;
4896 /* 6,7 are implementation dependent */
4898 rn
= "Invalid config selector";
4905 gen_helper_mtc0_lladdr(arg
);
4915 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
4925 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
4935 check_insn(env
, ctx
, ISA_MIPS3
);
4936 gen_helper_mtc0_xcontext(arg
);
4944 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4947 gen_helper_mtc0_framemask(arg
);
4956 rn
= "Diagnostic"; /* implementation dependent */
4961 gen_helper_mtc0_debug(arg
); /* EJTAG support */
4962 /* BS_STOP isn't good enough here, hflags may have changed. */
4963 gen_save_pc(ctx
->pc
+ 4);
4964 ctx
->bstate
= BS_EXCP
;
4968 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
4969 /* Stop translation as we may have switched the execution mode */
4970 ctx
->bstate
= BS_STOP
;
4971 rn
= "TraceControl";
4974 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
4975 /* Stop translation as we may have switched the execution mode */
4976 ctx
->bstate
= BS_STOP
;
4977 rn
= "TraceControl2";
4980 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
4981 /* Stop translation as we may have switched the execution mode */
4982 ctx
->bstate
= BS_STOP
;
4983 rn
= "UserTraceData";
4986 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
4987 /* Stop translation as we may have switched the execution mode */
4988 ctx
->bstate
= BS_STOP
;
4999 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5009 gen_helper_mtc0_performance0(arg
);
5010 rn
= "Performance0";
5013 // gen_helper_mtc0_performance1(arg);
5014 rn
= "Performance1";
5017 // gen_helper_mtc0_performance2(arg);
5018 rn
= "Performance2";
5021 // gen_helper_mtc0_performance3(arg);
5022 rn
= "Performance3";
5025 // gen_helper_mtc0_performance4(arg);
5026 rn
= "Performance4";
5029 // gen_helper_mtc0_performance5(arg);
5030 rn
= "Performance5";
5033 // gen_helper_mtc0_performance6(arg);
5034 rn
= "Performance6";
5037 // gen_helper_mtc0_performance7(arg);
5038 rn
= "Performance7";
5064 gen_helper_mtc0_taglo(arg
);
5071 gen_helper_mtc0_datalo(arg
);
5084 gen_helper_mtc0_taghi(arg
);
5091 gen_helper_mtc0_datahi(arg
);
5102 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5113 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5119 /* Stop translation as we may have switched the execution mode */
5120 ctx
->bstate
= BS_STOP
;
5125 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5126 /* For simplicity assume that all writes can cause interrupts. */
5129 ctx
->bstate
= BS_STOP
;
5134 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5135 generate_exception(ctx
, EXCP_RI
);
5137 #endif /* TARGET_MIPS64 */
5139 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5140 int u
, int sel
, int h
)
5142 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5143 TCGv t0
= tcg_temp_local_new();
5145 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5146 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5147 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5148 tcg_gen_movi_tl(t0
, -1);
5149 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5150 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5151 tcg_gen_movi_tl(t0
, -1);
5157 gen_helper_mftc0_tcstatus(t0
);
5160 gen_helper_mftc0_tcbind(t0
);
5163 gen_helper_mftc0_tcrestart(t0
);
5166 gen_helper_mftc0_tchalt(t0
);
5169 gen_helper_mftc0_tccontext(t0
);
5172 gen_helper_mftc0_tcschedule(t0
);
5175 gen_helper_mftc0_tcschefback(t0
);
5178 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5185 gen_helper_mftc0_entryhi(t0
);
5188 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5194 gen_helper_mftc0_status(t0
);
5197 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5203 gen_helper_mftc0_debug(t0
);
5206 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5211 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5213 } else switch (sel
) {
5214 /* GPR registers. */
5216 gen_helper_1i(mftgpr
, t0
, rt
);
5218 /* Auxiliary CPU registers */
5222 gen_helper_1i(mftlo
, t0
, 0);
5225 gen_helper_1i(mfthi
, t0
, 0);
5228 gen_helper_1i(mftacx
, t0
, 0);
5231 gen_helper_1i(mftlo
, t0
, 1);
5234 gen_helper_1i(mfthi
, t0
, 1);
5237 gen_helper_1i(mftacx
, t0
, 1);
5240 gen_helper_1i(mftlo
, t0
, 2);
5243 gen_helper_1i(mfthi
, t0
, 2);
5246 gen_helper_1i(mftacx
, t0
, 2);
5249 gen_helper_1i(mftlo
, t0
, 3);
5252 gen_helper_1i(mfthi
, t0
, 3);
5255 gen_helper_1i(mftacx
, t0
, 3);
5258 gen_helper_mftdsp(t0
);
5264 /* Floating point (COP1). */
5266 /* XXX: For now we support only a single FPU context. */
5268 TCGv_i32 fp0
= tcg_temp_new_i32();
5270 gen_load_fpr32(fp0
, rt
);
5271 tcg_gen_ext_i32_tl(t0
, fp0
);
5272 tcg_temp_free_i32(fp0
);
5274 TCGv_i32 fp0
= tcg_temp_new_i32();
5276 gen_load_fpr32h(fp0
, rt
);
5277 tcg_gen_ext_i32_tl(t0
, fp0
);
5278 tcg_temp_free_i32(fp0
);
5282 /* XXX: For now we support only a single FPU context. */
5283 gen_helper_1i(cfc1
, t0
, rt
);
5285 /* COP2: Not implemented. */
5292 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5293 gen_store_gpr(t0
, rd
);
5299 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5300 generate_exception(ctx
, EXCP_RI
);
5303 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5304 int u
, int sel
, int h
)
5306 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5307 TCGv t0
= tcg_temp_local_new();
5309 gen_load_gpr(t0
, rt
);
5310 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5311 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5312 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5314 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5315 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5322 gen_helper_mttc0_tcstatus(t0
);
5325 gen_helper_mttc0_tcbind(t0
);
5328 gen_helper_mttc0_tcrestart(t0
);
5331 gen_helper_mttc0_tchalt(t0
);
5334 gen_helper_mttc0_tccontext(t0
);
5337 gen_helper_mttc0_tcschedule(t0
);
5340 gen_helper_mttc0_tcschefback(t0
);
5343 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5350 gen_helper_mttc0_entryhi(t0
);
5353 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5359 gen_helper_mttc0_status(t0
);
5362 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5368 gen_helper_mttc0_debug(t0
);
5371 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5376 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5378 } else switch (sel
) {
5379 /* GPR registers. */
5381 gen_helper_1i(mttgpr
, t0
, rd
);
5383 /* Auxiliary CPU registers */
5387 gen_helper_1i(mttlo
, t0
, 0);
5390 gen_helper_1i(mtthi
, t0
, 0);
5393 gen_helper_1i(mttacx
, t0
, 0);
5396 gen_helper_1i(mttlo
, t0
, 1);
5399 gen_helper_1i(mtthi
, t0
, 1);
5402 gen_helper_1i(mttacx
, t0
, 1);
5405 gen_helper_1i(mttlo
, t0
, 2);
5408 gen_helper_1i(mtthi
, t0
, 2);
5411 gen_helper_1i(mttacx
, t0
, 2);
5414 gen_helper_1i(mttlo
, t0
, 3);
5417 gen_helper_1i(mtthi
, t0
, 3);
5420 gen_helper_1i(mttacx
, t0
, 3);
5423 gen_helper_mttdsp(t0
);
5429 /* Floating point (COP1). */
5431 /* XXX: For now we support only a single FPU context. */
5433 TCGv_i32 fp0
= tcg_temp_new_i32();
5435 tcg_gen_trunc_tl_i32(fp0
, t0
);
5436 gen_store_fpr32(fp0
, rd
);
5437 tcg_temp_free_i32(fp0
);
5439 TCGv_i32 fp0
= tcg_temp_new_i32();
5441 tcg_gen_trunc_tl_i32(fp0
, t0
);
5442 gen_store_fpr32h(fp0
, rd
);
5443 tcg_temp_free_i32(fp0
);
5447 /* XXX: For now we support only a single FPU context. */
5448 gen_helper_1i(ctc1
, t0
, rd
);
5450 /* COP2: Not implemented. */
5457 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5463 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5464 generate_exception(ctx
, EXCP_RI
);
5467 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5469 const char *opn
= "ldst";
5477 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5482 TCGv t0
= tcg_temp_new();
5484 gen_load_gpr(t0
, rt
);
5485 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5490 #if defined(TARGET_MIPS64)
5492 check_insn(env
, ctx
, ISA_MIPS3
);
5497 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5501 check_insn(env
, ctx
, ISA_MIPS3
);
5503 TCGv t0
= tcg_temp_new();
5505 gen_load_gpr(t0
, rt
);
5506 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5513 check_insn(env
, ctx
, ASE_MT
);
5518 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5519 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5523 check_insn(env
, ctx
, ASE_MT
);
5524 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5525 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5530 if (!env
->tlb
->helper_tlbwi
)
5536 if (!env
->tlb
->helper_tlbwr
)
5542 if (!env
->tlb
->helper_tlbp
)
5548 if (!env
->tlb
->helper_tlbr
)
5554 check_insn(env
, ctx
, ISA_MIPS2
);
5556 ctx
->bstate
= BS_EXCP
;
5560 check_insn(env
, ctx
, ISA_MIPS32
);
5561 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5563 generate_exception(ctx
, EXCP_RI
);
5566 ctx
->bstate
= BS_EXCP
;
5571 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5572 /* If we get an exception, we want to restart at next instruction */
5574 save_cpu_state(ctx
, 1);
5577 ctx
->bstate
= BS_EXCP
;
5582 generate_exception(ctx
, EXCP_RI
);
5585 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5587 #endif /* !CONFIG_USER_ONLY */
5589 /* CP1 Branches (before delay slot) */
5590 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5591 int32_t cc
, int32_t offset
)
5593 target_ulong btarget
;
5594 const char *opn
= "cp1 cond branch";
5595 TCGv_i32 t0
= tcg_temp_new_i32();
5598 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5600 btarget
= ctx
->pc
+ 4 + offset
;
5604 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5605 tcg_gen_not_i32(t0
, t0
);
5606 tcg_gen_andi_i32(t0
, t0
, 1);
5607 tcg_gen_extu_i32_tl(bcond
, t0
);
5611 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5612 tcg_gen_not_i32(t0
, t0
);
5613 tcg_gen_andi_i32(t0
, t0
, 1);
5614 tcg_gen_extu_i32_tl(bcond
, t0
);
5618 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5619 tcg_gen_andi_i32(t0
, t0
, 1);
5620 tcg_gen_extu_i32_tl(bcond
, t0
);
5624 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5625 tcg_gen_andi_i32(t0
, t0
, 1);
5626 tcg_gen_extu_i32_tl(bcond
, t0
);
5629 ctx
->hflags
|= MIPS_HFLAG_BL
;
5633 TCGv_i32 t1
= tcg_temp_new_i32();
5634 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5635 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5636 tcg_gen_or_i32(t0
, t0
, t1
);
5637 tcg_temp_free_i32(t1
);
5638 tcg_gen_not_i32(t0
, t0
);
5639 tcg_gen_andi_i32(t0
, t0
, 1);
5640 tcg_gen_extu_i32_tl(bcond
, t0
);
5646 TCGv_i32 t1
= tcg_temp_new_i32();
5647 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5648 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5649 tcg_gen_or_i32(t0
, t0
, t1
);
5650 tcg_temp_free_i32(t1
);
5651 tcg_gen_andi_i32(t0
, t0
, 1);
5652 tcg_gen_extu_i32_tl(bcond
, t0
);
5658 TCGv_i32 t1
= tcg_temp_new_i32();
5659 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5660 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5661 tcg_gen_or_i32(t0
, t0
, t1
);
5662 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5663 tcg_gen_or_i32(t0
, t0
, t1
);
5664 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5665 tcg_gen_or_i32(t0
, t0
, t1
);
5666 tcg_temp_free_i32(t1
);
5667 tcg_gen_not_i32(t0
, t0
);
5668 tcg_gen_andi_i32(t0
, t0
, 1);
5669 tcg_gen_extu_i32_tl(bcond
, t0
);
5675 TCGv_i32 t1
= tcg_temp_new_i32();
5676 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5677 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5678 tcg_gen_or_i32(t0
, t0
, t1
);
5679 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5680 tcg_gen_or_i32(t0
, t0
, t1
);
5681 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5682 tcg_gen_or_i32(t0
, t0
, t1
);
5683 tcg_temp_free_i32(t1
);
5684 tcg_gen_andi_i32(t0
, t0
, 1);
5685 tcg_gen_extu_i32_tl(bcond
, t0
);
5689 ctx
->hflags
|= MIPS_HFLAG_BC
;
5693 generate_exception (ctx
, EXCP_RI
);
5696 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5697 ctx
->hflags
, btarget
);
5698 ctx
->btarget
= btarget
;
5701 tcg_temp_free_i32(t0
);
5704 /* Coprocessor 1 (FPU) */
5706 #define FOP(func, fmt) (((fmt) << 21) | (func))
5708 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5710 const char *opn
= "cp1 move";
5711 TCGv t0
= tcg_temp_new();
5716 TCGv_i32 fp0
= tcg_temp_new_i32();
5718 gen_load_fpr32(fp0
, fs
);
5719 tcg_gen_ext_i32_tl(t0
, fp0
);
5720 tcg_temp_free_i32(fp0
);
5722 gen_store_gpr(t0
, rt
);
5726 gen_load_gpr(t0
, rt
);
5728 TCGv_i32 fp0
= tcg_temp_new_i32();
5730 tcg_gen_trunc_tl_i32(fp0
, t0
);
5731 gen_store_fpr32(fp0
, fs
);
5732 tcg_temp_free_i32(fp0
);
5737 gen_helper_1i(cfc1
, t0
, fs
);
5738 gen_store_gpr(t0
, rt
);
5742 gen_load_gpr(t0
, rt
);
5743 gen_helper_1i(ctc1
, t0
, fs
);
5746 #if defined(TARGET_MIPS64)
5748 gen_load_fpr64(ctx
, t0
, fs
);
5749 gen_store_gpr(t0
, rt
);
5753 gen_load_gpr(t0
, rt
);
5754 gen_store_fpr64(ctx
, t0
, fs
);
5760 TCGv_i32 fp0
= tcg_temp_new_i32();
5762 gen_load_fpr32h(fp0
, fs
);
5763 tcg_gen_ext_i32_tl(t0
, fp0
);
5764 tcg_temp_free_i32(fp0
);
5766 gen_store_gpr(t0
, rt
);
5770 gen_load_gpr(t0
, rt
);
5772 TCGv_i32 fp0
= tcg_temp_new_i32();
5774 tcg_gen_trunc_tl_i32(fp0
, t0
);
5775 gen_store_fpr32h(fp0
, fs
);
5776 tcg_temp_free_i32(fp0
);
5782 generate_exception (ctx
, EXCP_RI
);
5785 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5791 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5807 l1
= gen_new_label();
5808 t0
= tcg_temp_new_i32();
5809 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5810 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5811 tcg_temp_free_i32(t0
);
5813 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
5815 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
5820 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5823 TCGv_i32 t0
= tcg_temp_new_i32();
5824 int l1
= gen_new_label();
5831 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5832 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5833 gen_load_fpr32(t0
, fs
);
5834 gen_store_fpr32(t0
, fd
);
5836 tcg_temp_free_i32(t0
);
5839 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5842 TCGv_i32 t0
= tcg_temp_new_i32();
5844 int l1
= gen_new_label();
5851 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5852 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5853 tcg_temp_free_i32(t0
);
5854 fp0
= tcg_temp_new_i64();
5855 gen_load_fpr64(ctx
, fp0
, fs
);
5856 gen_store_fpr64(ctx
, fp0
, fd
);
5857 tcg_temp_free_i64(fp0
);
5861 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5864 TCGv_i32 t0
= tcg_temp_new_i32();
5865 int l1
= gen_new_label();
5866 int l2
= gen_new_label();
5873 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5874 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5875 gen_load_fpr32(t0
, fs
);
5876 gen_store_fpr32(t0
, fd
);
5879 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
5880 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
5881 gen_load_fpr32h(t0
, fs
);
5882 gen_store_fpr32h(t0
, fd
);
5883 tcg_temp_free_i32(t0
);
5888 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5889 int ft
, int fs
, int fd
, int cc
)
5891 const char *opn
= "farith";
5892 const char *condnames
[] = {
5910 const char *condnames_abs
[] = {
5928 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5929 uint32_t func
= ctx
->opcode
& 0x3f;
5931 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5934 TCGv_i32 fp0
= tcg_temp_new_i32();
5935 TCGv_i32 fp1
= tcg_temp_new_i32();
5937 gen_load_fpr32(fp0
, fs
);
5938 gen_load_fpr32(fp1
, ft
);
5939 gen_helper_float_add_s(fp0
, fp0
, fp1
);
5940 tcg_temp_free_i32(fp1
);
5941 gen_store_fpr32(fp0
, fd
);
5942 tcg_temp_free_i32(fp0
);
5949 TCGv_i32 fp0
= tcg_temp_new_i32();
5950 TCGv_i32 fp1
= tcg_temp_new_i32();
5952 gen_load_fpr32(fp0
, fs
);
5953 gen_load_fpr32(fp1
, ft
);
5954 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
5955 tcg_temp_free_i32(fp1
);
5956 gen_store_fpr32(fp0
, fd
);
5957 tcg_temp_free_i32(fp0
);
5964 TCGv_i32 fp0
= tcg_temp_new_i32();
5965 TCGv_i32 fp1
= tcg_temp_new_i32();
5967 gen_load_fpr32(fp0
, fs
);
5968 gen_load_fpr32(fp1
, ft
);
5969 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
5970 tcg_temp_free_i32(fp1
);
5971 gen_store_fpr32(fp0
, fd
);
5972 tcg_temp_free_i32(fp0
);
5979 TCGv_i32 fp0
= tcg_temp_new_i32();
5980 TCGv_i32 fp1
= tcg_temp_new_i32();
5982 gen_load_fpr32(fp0
, fs
);
5983 gen_load_fpr32(fp1
, ft
);
5984 gen_helper_float_div_s(fp0
, fp0
, fp1
);
5985 tcg_temp_free_i32(fp1
);
5986 gen_store_fpr32(fp0
, fd
);
5987 tcg_temp_free_i32(fp0
);
5994 TCGv_i32 fp0
= tcg_temp_new_i32();
5996 gen_load_fpr32(fp0
, fs
);
5997 gen_helper_float_sqrt_s(fp0
, fp0
);
5998 gen_store_fpr32(fp0
, fd
);
5999 tcg_temp_free_i32(fp0
);
6005 TCGv_i32 fp0
= tcg_temp_new_i32();
6007 gen_load_fpr32(fp0
, fs
);
6008 gen_helper_float_abs_s(fp0
, fp0
);
6009 gen_store_fpr32(fp0
, fd
);
6010 tcg_temp_free_i32(fp0
);
6016 TCGv_i32 fp0
= tcg_temp_new_i32();
6018 gen_load_fpr32(fp0
, fs
);
6019 gen_store_fpr32(fp0
, fd
);
6020 tcg_temp_free_i32(fp0
);
6026 TCGv_i32 fp0
= tcg_temp_new_i32();
6028 gen_load_fpr32(fp0
, fs
);
6029 gen_helper_float_chs_s(fp0
, fp0
);
6030 gen_store_fpr32(fp0
, fd
);
6031 tcg_temp_free_i32(fp0
);
6036 check_cp1_64bitmode(ctx
);
6038 TCGv_i32 fp32
= tcg_temp_new_i32();
6039 TCGv_i64 fp64
= tcg_temp_new_i64();
6041 gen_load_fpr32(fp32
, fs
);
6042 gen_helper_float_roundl_s(fp64
, fp32
);
6043 tcg_temp_free_i32(fp32
);
6044 gen_store_fpr64(ctx
, fp64
, fd
);
6045 tcg_temp_free_i64(fp64
);
6050 check_cp1_64bitmode(ctx
);
6052 TCGv_i32 fp32
= tcg_temp_new_i32();
6053 TCGv_i64 fp64
= tcg_temp_new_i64();
6055 gen_load_fpr32(fp32
, fs
);
6056 gen_helper_float_truncl_s(fp64
, fp32
);
6057 tcg_temp_free_i32(fp32
);
6058 gen_store_fpr64(ctx
, fp64
, fd
);
6059 tcg_temp_free_i64(fp64
);
6064 check_cp1_64bitmode(ctx
);
6066 TCGv_i32 fp32
= tcg_temp_new_i32();
6067 TCGv_i64 fp64
= tcg_temp_new_i64();
6069 gen_load_fpr32(fp32
, fs
);
6070 gen_helper_float_ceill_s(fp64
, fp32
);
6071 tcg_temp_free_i32(fp32
);
6072 gen_store_fpr64(ctx
, fp64
, fd
);
6073 tcg_temp_free_i64(fp64
);
6078 check_cp1_64bitmode(ctx
);
6080 TCGv_i32 fp32
= tcg_temp_new_i32();
6081 TCGv_i64 fp64
= tcg_temp_new_i64();
6083 gen_load_fpr32(fp32
, fs
);
6084 gen_helper_float_floorl_s(fp64
, fp32
);
6085 tcg_temp_free_i32(fp32
);
6086 gen_store_fpr64(ctx
, fp64
, fd
);
6087 tcg_temp_free_i64(fp64
);
6093 TCGv_i32 fp0
= tcg_temp_new_i32();
6095 gen_load_fpr32(fp0
, fs
);
6096 gen_helper_float_roundw_s(fp0
, fp0
);
6097 gen_store_fpr32(fp0
, fd
);
6098 tcg_temp_free_i32(fp0
);
6104 TCGv_i32 fp0
= tcg_temp_new_i32();
6106 gen_load_fpr32(fp0
, fs
);
6107 gen_helper_float_truncw_s(fp0
, fp0
);
6108 gen_store_fpr32(fp0
, fd
);
6109 tcg_temp_free_i32(fp0
);
6115 TCGv_i32 fp0
= tcg_temp_new_i32();
6117 gen_load_fpr32(fp0
, fs
);
6118 gen_helper_float_ceilw_s(fp0
, fp0
);
6119 gen_store_fpr32(fp0
, fd
);
6120 tcg_temp_free_i32(fp0
);
6126 TCGv_i32 fp0
= tcg_temp_new_i32();
6128 gen_load_fpr32(fp0
, fs
);
6129 gen_helper_float_floorw_s(fp0
, fp0
);
6130 gen_store_fpr32(fp0
, fd
);
6131 tcg_temp_free_i32(fp0
);
6136 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6141 int l1
= gen_new_label();
6145 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6147 fp0
= tcg_temp_new_i32();
6148 gen_load_fpr32(fp0
, fs
);
6149 gen_store_fpr32(fp0
, fd
);
6150 tcg_temp_free_i32(fp0
);
6157 int l1
= gen_new_label();
6161 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6162 fp0
= tcg_temp_new_i32();
6163 gen_load_fpr32(fp0
, fs
);
6164 gen_store_fpr32(fp0
, fd
);
6165 tcg_temp_free_i32(fp0
);
6174 TCGv_i32 fp0
= tcg_temp_new_i32();
6176 gen_load_fpr32(fp0
, fs
);
6177 gen_helper_float_recip_s(fp0
, fp0
);
6178 gen_store_fpr32(fp0
, fd
);
6179 tcg_temp_free_i32(fp0
);
6186 TCGv_i32 fp0
= tcg_temp_new_i32();
6188 gen_load_fpr32(fp0
, fs
);
6189 gen_helper_float_rsqrt_s(fp0
, fp0
);
6190 gen_store_fpr32(fp0
, fd
);
6191 tcg_temp_free_i32(fp0
);
6196 check_cp1_64bitmode(ctx
);
6198 TCGv_i32 fp0
= tcg_temp_new_i32();
6199 TCGv_i32 fp1
= tcg_temp_new_i32();
6201 gen_load_fpr32(fp0
, fs
);
6202 gen_load_fpr32(fp1
, fd
);
6203 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6204 tcg_temp_free_i32(fp1
);
6205 gen_store_fpr32(fp0
, fd
);
6206 tcg_temp_free_i32(fp0
);
6211 check_cp1_64bitmode(ctx
);
6213 TCGv_i32 fp0
= tcg_temp_new_i32();
6215 gen_load_fpr32(fp0
, fs
);
6216 gen_helper_float_recip1_s(fp0
, fp0
);
6217 gen_store_fpr32(fp0
, fd
);
6218 tcg_temp_free_i32(fp0
);
6223 check_cp1_64bitmode(ctx
);
6225 TCGv_i32 fp0
= tcg_temp_new_i32();
6227 gen_load_fpr32(fp0
, fs
);
6228 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6229 gen_store_fpr32(fp0
, fd
);
6230 tcg_temp_free_i32(fp0
);
6235 check_cp1_64bitmode(ctx
);
6237 TCGv_i32 fp0
= tcg_temp_new_i32();
6238 TCGv_i32 fp1
= tcg_temp_new_i32();
6240 gen_load_fpr32(fp0
, fs
);
6241 gen_load_fpr32(fp1
, ft
);
6242 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6243 tcg_temp_free_i32(fp1
);
6244 gen_store_fpr32(fp0
, fd
);
6245 tcg_temp_free_i32(fp0
);
6250 check_cp1_registers(ctx
, fd
);
6252 TCGv_i32 fp32
= tcg_temp_new_i32();
6253 TCGv_i64 fp64
= tcg_temp_new_i64();
6255 gen_load_fpr32(fp32
, fs
);
6256 gen_helper_float_cvtd_s(fp64
, fp32
);
6257 tcg_temp_free_i32(fp32
);
6258 gen_store_fpr64(ctx
, fp64
, fd
);
6259 tcg_temp_free_i64(fp64
);
6265 TCGv_i32 fp0
= tcg_temp_new_i32();
6267 gen_load_fpr32(fp0
, fs
);
6268 gen_helper_float_cvtw_s(fp0
, fp0
);
6269 gen_store_fpr32(fp0
, fd
);
6270 tcg_temp_free_i32(fp0
);
6275 check_cp1_64bitmode(ctx
);
6277 TCGv_i32 fp32
= tcg_temp_new_i32();
6278 TCGv_i64 fp64
= tcg_temp_new_i64();
6280 gen_load_fpr32(fp32
, fs
);
6281 gen_helper_float_cvtl_s(fp64
, fp32
);
6282 tcg_temp_free_i32(fp32
);
6283 gen_store_fpr64(ctx
, fp64
, fd
);
6284 tcg_temp_free_i64(fp64
);
6289 check_cp1_64bitmode(ctx
);
6291 TCGv_i64 fp64
= tcg_temp_new_i64();
6292 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6293 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6295 gen_load_fpr32(fp32_0
, fs
);
6296 gen_load_fpr32(fp32_1
, ft
);
6297 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6298 tcg_temp_free_i32(fp32_1
);
6299 tcg_temp_free_i32(fp32_0
);
6300 gen_store_fpr64(ctx
, fp64
, fd
);
6301 tcg_temp_free_i64(fp64
);
6322 TCGv_i32 fp0
= tcg_temp_new_i32();
6323 TCGv_i32 fp1
= tcg_temp_new_i32();
6325 gen_load_fpr32(fp0
, fs
);
6326 gen_load_fpr32(fp1
, ft
);
6327 if (ctx
->opcode
& (1 << 6)) {
6329 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6330 opn
= condnames_abs
[func
-48];
6332 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6333 opn
= condnames
[func
-48];
6335 tcg_temp_free_i32(fp0
);
6336 tcg_temp_free_i32(fp1
);
6340 check_cp1_registers(ctx
, fs
| ft
| fd
);
6342 TCGv_i64 fp0
= tcg_temp_new_i64();
6343 TCGv_i64 fp1
= tcg_temp_new_i64();
6345 gen_load_fpr64(ctx
, fp0
, fs
);
6346 gen_load_fpr64(ctx
, fp1
, ft
);
6347 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6348 tcg_temp_free_i64(fp1
);
6349 gen_store_fpr64(ctx
, fp0
, fd
);
6350 tcg_temp_free_i64(fp0
);
6356 check_cp1_registers(ctx
, fs
| ft
| fd
);
6358 TCGv_i64 fp0
= tcg_temp_new_i64();
6359 TCGv_i64 fp1
= tcg_temp_new_i64();
6361 gen_load_fpr64(ctx
, fp0
, fs
);
6362 gen_load_fpr64(ctx
, fp1
, ft
);
6363 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6364 tcg_temp_free_i64(fp1
);
6365 gen_store_fpr64(ctx
, fp0
, fd
);
6366 tcg_temp_free_i64(fp0
);
6372 check_cp1_registers(ctx
, fs
| ft
| fd
);
6374 TCGv_i64 fp0
= tcg_temp_new_i64();
6375 TCGv_i64 fp1
= tcg_temp_new_i64();
6377 gen_load_fpr64(ctx
, fp0
, fs
);
6378 gen_load_fpr64(ctx
, fp1
, ft
);
6379 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6380 tcg_temp_free_i64(fp1
);
6381 gen_store_fpr64(ctx
, fp0
, fd
);
6382 tcg_temp_free_i64(fp0
);
6388 check_cp1_registers(ctx
, fs
| ft
| fd
);
6390 TCGv_i64 fp0
= tcg_temp_new_i64();
6391 TCGv_i64 fp1
= tcg_temp_new_i64();
6393 gen_load_fpr64(ctx
, fp0
, fs
);
6394 gen_load_fpr64(ctx
, fp1
, ft
);
6395 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6396 tcg_temp_free_i64(fp1
);
6397 gen_store_fpr64(ctx
, fp0
, fd
);
6398 tcg_temp_free_i64(fp0
);
6404 check_cp1_registers(ctx
, fs
| fd
);
6406 TCGv_i64 fp0
= tcg_temp_new_i64();
6408 gen_load_fpr64(ctx
, fp0
, fs
);
6409 gen_helper_float_sqrt_d(fp0
, fp0
);
6410 gen_store_fpr64(ctx
, fp0
, fd
);
6411 tcg_temp_free_i64(fp0
);
6416 check_cp1_registers(ctx
, fs
| fd
);
6418 TCGv_i64 fp0
= tcg_temp_new_i64();
6420 gen_load_fpr64(ctx
, fp0
, fs
);
6421 gen_helper_float_abs_d(fp0
, fp0
);
6422 gen_store_fpr64(ctx
, fp0
, fd
);
6423 tcg_temp_free_i64(fp0
);
6428 check_cp1_registers(ctx
, fs
| fd
);
6430 TCGv_i64 fp0
= tcg_temp_new_i64();
6432 gen_load_fpr64(ctx
, fp0
, fs
);
6433 gen_store_fpr64(ctx
, fp0
, fd
);
6434 tcg_temp_free_i64(fp0
);
6439 check_cp1_registers(ctx
, fs
| fd
);
6441 TCGv_i64 fp0
= tcg_temp_new_i64();
6443 gen_load_fpr64(ctx
, fp0
, fs
);
6444 gen_helper_float_chs_d(fp0
, fp0
);
6445 gen_store_fpr64(ctx
, fp0
, fd
);
6446 tcg_temp_free_i64(fp0
);
6451 check_cp1_64bitmode(ctx
);
6453 TCGv_i64 fp0
= tcg_temp_new_i64();
6455 gen_load_fpr64(ctx
, fp0
, fs
);
6456 gen_helper_float_roundl_d(fp0
, fp0
);
6457 gen_store_fpr64(ctx
, fp0
, fd
);
6458 tcg_temp_free_i64(fp0
);
6463 check_cp1_64bitmode(ctx
);
6465 TCGv_i64 fp0
= tcg_temp_new_i64();
6467 gen_load_fpr64(ctx
, fp0
, fs
);
6468 gen_helper_float_truncl_d(fp0
, fp0
);
6469 gen_store_fpr64(ctx
, fp0
, fd
);
6470 tcg_temp_free_i64(fp0
);
6475 check_cp1_64bitmode(ctx
);
6477 TCGv_i64 fp0
= tcg_temp_new_i64();
6479 gen_load_fpr64(ctx
, fp0
, fs
);
6480 gen_helper_float_ceill_d(fp0
, fp0
);
6481 gen_store_fpr64(ctx
, fp0
, fd
);
6482 tcg_temp_free_i64(fp0
);
6487 check_cp1_64bitmode(ctx
);
6489 TCGv_i64 fp0
= tcg_temp_new_i64();
6491 gen_load_fpr64(ctx
, fp0
, fs
);
6492 gen_helper_float_floorl_d(fp0
, fp0
);
6493 gen_store_fpr64(ctx
, fp0
, fd
);
6494 tcg_temp_free_i64(fp0
);
6499 check_cp1_registers(ctx
, fs
);
6501 TCGv_i32 fp32
= tcg_temp_new_i32();
6502 TCGv_i64 fp64
= tcg_temp_new_i64();
6504 gen_load_fpr64(ctx
, fp64
, fs
);
6505 gen_helper_float_roundw_d(fp32
, fp64
);
6506 tcg_temp_free_i64(fp64
);
6507 gen_store_fpr32(fp32
, fd
);
6508 tcg_temp_free_i32(fp32
);
6513 check_cp1_registers(ctx
, fs
);
6515 TCGv_i32 fp32
= tcg_temp_new_i32();
6516 TCGv_i64 fp64
= tcg_temp_new_i64();
6518 gen_load_fpr64(ctx
, fp64
, fs
);
6519 gen_helper_float_truncw_d(fp32
, fp64
);
6520 tcg_temp_free_i64(fp64
);
6521 gen_store_fpr32(fp32
, fd
);
6522 tcg_temp_free_i32(fp32
);
6527 check_cp1_registers(ctx
, fs
);
6529 TCGv_i32 fp32
= tcg_temp_new_i32();
6530 TCGv_i64 fp64
= tcg_temp_new_i64();
6532 gen_load_fpr64(ctx
, fp64
, fs
);
6533 gen_helper_float_ceilw_d(fp32
, fp64
);
6534 tcg_temp_free_i64(fp64
);
6535 gen_store_fpr32(fp32
, fd
);
6536 tcg_temp_free_i32(fp32
);
6541 check_cp1_registers(ctx
, fs
);
6543 TCGv_i32 fp32
= tcg_temp_new_i32();
6544 TCGv_i64 fp64
= tcg_temp_new_i64();
6546 gen_load_fpr64(ctx
, fp64
, fs
);
6547 gen_helper_float_floorw_d(fp32
, fp64
);
6548 tcg_temp_free_i64(fp64
);
6549 gen_store_fpr32(fp32
, fd
);
6550 tcg_temp_free_i32(fp32
);
6555 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6560 int l1
= gen_new_label();
6564 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6566 fp0
= tcg_temp_new_i64();
6567 gen_load_fpr64(ctx
, fp0
, fs
);
6568 gen_store_fpr64(ctx
, fp0
, fd
);
6569 tcg_temp_free_i64(fp0
);
6576 int l1
= gen_new_label();
6580 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6581 fp0
= tcg_temp_new_i64();
6582 gen_load_fpr64(ctx
, fp0
, fs
);
6583 gen_store_fpr64(ctx
, fp0
, fd
);
6584 tcg_temp_free_i64(fp0
);
6591 check_cp1_64bitmode(ctx
);
6593 TCGv_i64 fp0
= tcg_temp_new_i64();
6595 gen_load_fpr64(ctx
, fp0
, fs
);
6596 gen_helper_float_recip_d(fp0
, fp0
);
6597 gen_store_fpr64(ctx
, fp0
, fd
);
6598 tcg_temp_free_i64(fp0
);
6603 check_cp1_64bitmode(ctx
);
6605 TCGv_i64 fp0
= tcg_temp_new_i64();
6607 gen_load_fpr64(ctx
, fp0
, fs
);
6608 gen_helper_float_rsqrt_d(fp0
, fp0
);
6609 gen_store_fpr64(ctx
, fp0
, fd
);
6610 tcg_temp_free_i64(fp0
);
6615 check_cp1_64bitmode(ctx
);
6617 TCGv_i64 fp0
= tcg_temp_new_i64();
6618 TCGv_i64 fp1
= tcg_temp_new_i64();
6620 gen_load_fpr64(ctx
, fp0
, fs
);
6621 gen_load_fpr64(ctx
, fp1
, ft
);
6622 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6623 tcg_temp_free_i64(fp1
);
6624 gen_store_fpr64(ctx
, fp0
, fd
);
6625 tcg_temp_free_i64(fp0
);
6630 check_cp1_64bitmode(ctx
);
6632 TCGv_i64 fp0
= tcg_temp_new_i64();
6634 gen_load_fpr64(ctx
, fp0
, fs
);
6635 gen_helper_float_recip1_d(fp0
, fp0
);
6636 gen_store_fpr64(ctx
, fp0
, fd
);
6637 tcg_temp_free_i64(fp0
);
6642 check_cp1_64bitmode(ctx
);
6644 TCGv_i64 fp0
= tcg_temp_new_i64();
6646 gen_load_fpr64(ctx
, fp0
, fs
);
6647 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6648 gen_store_fpr64(ctx
, fp0
, fd
);
6649 tcg_temp_free_i64(fp0
);
6654 check_cp1_64bitmode(ctx
);
6656 TCGv_i64 fp0
= tcg_temp_new_i64();
6657 TCGv_i64 fp1
= tcg_temp_new_i64();
6659 gen_load_fpr64(ctx
, fp0
, fs
);
6660 gen_load_fpr64(ctx
, fp1
, ft
);
6661 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6662 tcg_temp_free_i64(fp1
);
6663 gen_store_fpr64(ctx
, fp0
, fd
);
6664 tcg_temp_free_i64(fp0
);
6685 TCGv_i64 fp0
= tcg_temp_new_i64();
6686 TCGv_i64 fp1
= tcg_temp_new_i64();
6688 gen_load_fpr64(ctx
, fp0
, fs
);
6689 gen_load_fpr64(ctx
, fp1
, ft
);
6690 if (ctx
->opcode
& (1 << 6)) {
6692 check_cp1_registers(ctx
, fs
| ft
);
6693 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6694 opn
= condnames_abs
[func
-48];
6696 check_cp1_registers(ctx
, fs
| ft
);
6697 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6698 opn
= condnames
[func
-48];
6700 tcg_temp_free_i64(fp0
);
6701 tcg_temp_free_i64(fp1
);
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_cvts_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_cvtw_d(fp32
, fp64
);
6726 tcg_temp_free_i64(fp64
);
6727 gen_store_fpr32(fp32
, fd
);
6728 tcg_temp_free_i32(fp32
);
6733 check_cp1_64bitmode(ctx
);
6735 TCGv_i64 fp0
= tcg_temp_new_i64();
6737 gen_load_fpr64(ctx
, fp0
, fs
);
6738 gen_helper_float_cvtl_d(fp0
, fp0
);
6739 gen_store_fpr64(ctx
, fp0
, fd
);
6740 tcg_temp_free_i64(fp0
);
6746 TCGv_i32 fp0
= tcg_temp_new_i32();
6748 gen_load_fpr32(fp0
, fs
);
6749 gen_helper_float_cvts_w(fp0
, fp0
);
6750 gen_store_fpr32(fp0
, fd
);
6751 tcg_temp_free_i32(fp0
);
6756 check_cp1_registers(ctx
, fd
);
6758 TCGv_i32 fp32
= tcg_temp_new_i32();
6759 TCGv_i64 fp64
= tcg_temp_new_i64();
6761 gen_load_fpr32(fp32
, fs
);
6762 gen_helper_float_cvtd_w(fp64
, fp32
);
6763 tcg_temp_free_i32(fp32
);
6764 gen_store_fpr64(ctx
, fp64
, fd
);
6765 tcg_temp_free_i64(fp64
);
6770 check_cp1_64bitmode(ctx
);
6772 TCGv_i32 fp32
= tcg_temp_new_i32();
6773 TCGv_i64 fp64
= tcg_temp_new_i64();
6775 gen_load_fpr64(ctx
, fp64
, fs
);
6776 gen_helper_float_cvts_l(fp32
, fp64
);
6777 tcg_temp_free_i64(fp64
);
6778 gen_store_fpr32(fp32
, fd
);
6779 tcg_temp_free_i32(fp32
);
6784 check_cp1_64bitmode(ctx
);
6786 TCGv_i64 fp0
= tcg_temp_new_i64();
6788 gen_load_fpr64(ctx
, fp0
, fs
);
6789 gen_helper_float_cvtd_l(fp0
, fp0
);
6790 gen_store_fpr64(ctx
, fp0
, fd
);
6791 tcg_temp_free_i64(fp0
);
6796 check_cp1_64bitmode(ctx
);
6798 TCGv_i64 fp0
= tcg_temp_new_i64();
6800 gen_load_fpr64(ctx
, fp0
, fs
);
6801 gen_helper_float_cvtps_pw(fp0
, fp0
);
6802 gen_store_fpr64(ctx
, fp0
, fd
);
6803 tcg_temp_free_i64(fp0
);
6808 check_cp1_64bitmode(ctx
);
6810 TCGv_i64 fp0
= tcg_temp_new_i64();
6811 TCGv_i64 fp1
= tcg_temp_new_i64();
6813 gen_load_fpr64(ctx
, fp0
, fs
);
6814 gen_load_fpr64(ctx
, fp1
, ft
);
6815 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6816 tcg_temp_free_i64(fp1
);
6817 gen_store_fpr64(ctx
, fp0
, fd
);
6818 tcg_temp_free_i64(fp0
);
6823 check_cp1_64bitmode(ctx
);
6825 TCGv_i64 fp0
= tcg_temp_new_i64();
6826 TCGv_i64 fp1
= tcg_temp_new_i64();
6828 gen_load_fpr64(ctx
, fp0
, fs
);
6829 gen_load_fpr64(ctx
, fp1
, ft
);
6830 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6831 tcg_temp_free_i64(fp1
);
6832 gen_store_fpr64(ctx
, fp0
, fd
);
6833 tcg_temp_free_i64(fp0
);
6838 check_cp1_64bitmode(ctx
);
6840 TCGv_i64 fp0
= tcg_temp_new_i64();
6841 TCGv_i64 fp1
= tcg_temp_new_i64();
6843 gen_load_fpr64(ctx
, fp0
, fs
);
6844 gen_load_fpr64(ctx
, fp1
, ft
);
6845 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6846 tcg_temp_free_i64(fp1
);
6847 gen_store_fpr64(ctx
, fp0
, fd
);
6848 tcg_temp_free_i64(fp0
);
6853 check_cp1_64bitmode(ctx
);
6855 TCGv_i64 fp0
= tcg_temp_new_i64();
6857 gen_load_fpr64(ctx
, fp0
, fs
);
6858 gen_helper_float_abs_ps(fp0
, fp0
);
6859 gen_store_fpr64(ctx
, fp0
, fd
);
6860 tcg_temp_free_i64(fp0
);
6865 check_cp1_64bitmode(ctx
);
6867 TCGv_i64 fp0
= tcg_temp_new_i64();
6869 gen_load_fpr64(ctx
, fp0
, fs
);
6870 gen_store_fpr64(ctx
, fp0
, fd
);
6871 tcg_temp_free_i64(fp0
);
6876 check_cp1_64bitmode(ctx
);
6878 TCGv_i64 fp0
= tcg_temp_new_i64();
6880 gen_load_fpr64(ctx
, fp0
, fs
);
6881 gen_helper_float_chs_ps(fp0
, fp0
);
6882 gen_store_fpr64(ctx
, fp0
, fd
);
6883 tcg_temp_free_i64(fp0
);
6888 check_cp1_64bitmode(ctx
);
6889 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6893 check_cp1_64bitmode(ctx
);
6895 int l1
= gen_new_label();
6899 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6900 fp0
= tcg_temp_new_i64();
6901 gen_load_fpr64(ctx
, fp0
, fs
);
6902 gen_store_fpr64(ctx
, fp0
, fd
);
6903 tcg_temp_free_i64(fp0
);
6909 check_cp1_64bitmode(ctx
);
6911 int l1
= gen_new_label();
6915 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6916 fp0
= tcg_temp_new_i64();
6917 gen_load_fpr64(ctx
, fp0
, fs
);
6918 gen_store_fpr64(ctx
, fp0
, fd
);
6919 tcg_temp_free_i64(fp0
);
6926 check_cp1_64bitmode(ctx
);
6928 TCGv_i64 fp0
= tcg_temp_new_i64();
6929 TCGv_i64 fp1
= tcg_temp_new_i64();
6931 gen_load_fpr64(ctx
, fp0
, ft
);
6932 gen_load_fpr64(ctx
, fp1
, fs
);
6933 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
6934 tcg_temp_free_i64(fp1
);
6935 gen_store_fpr64(ctx
, fp0
, fd
);
6936 tcg_temp_free_i64(fp0
);
6941 check_cp1_64bitmode(ctx
);
6943 TCGv_i64 fp0
= tcg_temp_new_i64();
6944 TCGv_i64 fp1
= tcg_temp_new_i64();
6946 gen_load_fpr64(ctx
, fp0
, ft
);
6947 gen_load_fpr64(ctx
, fp1
, fs
);
6948 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
6949 tcg_temp_free_i64(fp1
);
6950 gen_store_fpr64(ctx
, fp0
, fd
);
6951 tcg_temp_free_i64(fp0
);
6956 check_cp1_64bitmode(ctx
);
6958 TCGv_i64 fp0
= tcg_temp_new_i64();
6959 TCGv_i64 fp1
= tcg_temp_new_i64();
6961 gen_load_fpr64(ctx
, fp0
, fs
);
6962 gen_load_fpr64(ctx
, fp1
, fd
);
6963 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
6964 tcg_temp_free_i64(fp1
);
6965 gen_store_fpr64(ctx
, fp0
, fd
);
6966 tcg_temp_free_i64(fp0
);
6971 check_cp1_64bitmode(ctx
);
6973 TCGv_i64 fp0
= tcg_temp_new_i64();
6975 gen_load_fpr64(ctx
, fp0
, fs
);
6976 gen_helper_float_recip1_ps(fp0
, fp0
);
6977 gen_store_fpr64(ctx
, fp0
, fd
);
6978 tcg_temp_free_i64(fp0
);
6983 check_cp1_64bitmode(ctx
);
6985 TCGv_i64 fp0
= tcg_temp_new_i64();
6987 gen_load_fpr64(ctx
, fp0
, fs
);
6988 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
6989 gen_store_fpr64(ctx
, fp0
, fd
);
6990 tcg_temp_free_i64(fp0
);
6995 check_cp1_64bitmode(ctx
);
6997 TCGv_i64 fp0
= tcg_temp_new_i64();
6998 TCGv_i64 fp1
= tcg_temp_new_i64();
7000 gen_load_fpr64(ctx
, fp0
, fs
);
7001 gen_load_fpr64(ctx
, fp1
, ft
);
7002 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7003 tcg_temp_free_i64(fp1
);
7004 gen_store_fpr64(ctx
, fp0
, fd
);
7005 tcg_temp_free_i64(fp0
);
7010 check_cp1_64bitmode(ctx
);
7012 TCGv_i32 fp0
= tcg_temp_new_i32();
7014 gen_load_fpr32h(fp0
, fs
);
7015 gen_helper_float_cvts_pu(fp0
, fp0
);
7016 gen_store_fpr32(fp0
, fd
);
7017 tcg_temp_free_i32(fp0
);
7022 check_cp1_64bitmode(ctx
);
7024 TCGv_i64 fp0
= tcg_temp_new_i64();
7026 gen_load_fpr64(ctx
, fp0
, fs
);
7027 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7028 gen_store_fpr64(ctx
, fp0
, fd
);
7029 tcg_temp_free_i64(fp0
);
7034 check_cp1_64bitmode(ctx
);
7036 TCGv_i32 fp0
= tcg_temp_new_i32();
7038 gen_load_fpr32(fp0
, fs
);
7039 gen_helper_float_cvts_pl(fp0
, fp0
);
7040 gen_store_fpr32(fp0
, fd
);
7041 tcg_temp_free_i32(fp0
);
7046 check_cp1_64bitmode(ctx
);
7048 TCGv_i32 fp0
= tcg_temp_new_i32();
7049 TCGv_i32 fp1
= tcg_temp_new_i32();
7051 gen_load_fpr32(fp0
, fs
);
7052 gen_load_fpr32(fp1
, ft
);
7053 gen_store_fpr32h(fp0
, fd
);
7054 gen_store_fpr32(fp1
, fd
);
7055 tcg_temp_free_i32(fp0
);
7056 tcg_temp_free_i32(fp1
);
7061 check_cp1_64bitmode(ctx
);
7063 TCGv_i32 fp0
= tcg_temp_new_i32();
7064 TCGv_i32 fp1
= tcg_temp_new_i32();
7066 gen_load_fpr32(fp0
, fs
);
7067 gen_load_fpr32h(fp1
, ft
);
7068 gen_store_fpr32(fp1
, fd
);
7069 gen_store_fpr32h(fp0
, fd
);
7070 tcg_temp_free_i32(fp0
);
7071 tcg_temp_free_i32(fp1
);
7076 check_cp1_64bitmode(ctx
);
7078 TCGv_i32 fp0
= tcg_temp_new_i32();
7079 TCGv_i32 fp1
= tcg_temp_new_i32();
7081 gen_load_fpr32h(fp0
, fs
);
7082 gen_load_fpr32(fp1
, ft
);
7083 gen_store_fpr32(fp1
, fd
);
7084 gen_store_fpr32h(fp0
, fd
);
7085 tcg_temp_free_i32(fp0
);
7086 tcg_temp_free_i32(fp1
);
7091 check_cp1_64bitmode(ctx
);
7093 TCGv_i32 fp0
= tcg_temp_new_i32();
7094 TCGv_i32 fp1
= tcg_temp_new_i32();
7096 gen_load_fpr32h(fp0
, fs
);
7097 gen_load_fpr32h(fp1
, ft
);
7098 gen_store_fpr32(fp1
, fd
);
7099 gen_store_fpr32h(fp0
, fd
);
7100 tcg_temp_free_i32(fp0
);
7101 tcg_temp_free_i32(fp1
);
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
, fs
);
7127 gen_load_fpr64(ctx
, fp1
, ft
);
7128 if (ctx
->opcode
& (1 << 6)) {
7129 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7130 opn
= condnames_abs
[func
-48];
7132 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7133 opn
= condnames
[func
-48];
7135 tcg_temp_free_i64(fp0
);
7136 tcg_temp_free_i64(fp1
);
7141 generate_exception (ctx
, EXCP_RI
);
7146 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7149 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7152 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7157 /* Coprocessor 3 (FPU) */
7158 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7159 int fd
, int fs
, int base
, int index
)
7161 const char *opn
= "extended float load/store";
7163 TCGv t0
= tcg_temp_new();
7166 gen_load_gpr(t0
, index
);
7167 } else if (index
== 0) {
7168 gen_load_gpr(t0
, base
);
7170 gen_load_gpr(t0
, index
);
7171 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7173 /* Don't do NOP if destination is zero: we must perform the actual
7175 save_cpu_state(ctx
, 0);
7180 TCGv_i32 fp0
= tcg_temp_new_i32();
7182 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7183 tcg_gen_trunc_tl_i32(fp0
, t0
);
7184 gen_store_fpr32(fp0
, fd
);
7185 tcg_temp_free_i32(fp0
);
7191 check_cp1_registers(ctx
, fd
);
7193 TCGv_i64 fp0
= tcg_temp_new_i64();
7195 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7196 gen_store_fpr64(ctx
, fp0
, fd
);
7197 tcg_temp_free_i64(fp0
);
7202 check_cp1_64bitmode(ctx
);
7203 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7205 TCGv_i64 fp0
= tcg_temp_new_i64();
7207 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7208 gen_store_fpr64(ctx
, fp0
, fd
);
7209 tcg_temp_free_i64(fp0
);
7216 TCGv_i32 fp0
= tcg_temp_new_i32();
7217 TCGv t1
= tcg_temp_new();
7219 gen_load_fpr32(fp0
, fs
);
7220 tcg_gen_extu_i32_tl(t1
, fp0
);
7221 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7222 tcg_temp_free_i32(fp0
);
7230 check_cp1_registers(ctx
, fs
);
7232 TCGv_i64 fp0
= tcg_temp_new_i64();
7234 gen_load_fpr64(ctx
, fp0
, fs
);
7235 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7236 tcg_temp_free_i64(fp0
);
7242 check_cp1_64bitmode(ctx
);
7243 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7245 TCGv_i64 fp0
= tcg_temp_new_i64();
7247 gen_load_fpr64(ctx
, fp0
, fs
);
7248 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7249 tcg_temp_free_i64(fp0
);
7256 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7257 regnames
[index
], regnames
[base
]);
7260 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7261 int fd
, int fr
, int fs
, int ft
)
7263 const char *opn
= "flt3_arith";
7267 check_cp1_64bitmode(ctx
);
7269 TCGv t0
= tcg_temp_local_new();
7270 TCGv_i32 fp
= tcg_temp_new_i32();
7271 TCGv_i32 fph
= tcg_temp_new_i32();
7272 int l1
= gen_new_label();
7273 int l2
= gen_new_label();
7275 gen_load_gpr(t0
, fr
);
7276 tcg_gen_andi_tl(t0
, t0
, 0x7);
7278 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7279 gen_load_fpr32(fp
, fs
);
7280 gen_load_fpr32h(fph
, fs
);
7281 gen_store_fpr32(fp
, fd
);
7282 gen_store_fpr32h(fph
, fd
);
7285 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7287 #ifdef TARGET_WORDS_BIGENDIAN
7288 gen_load_fpr32(fp
, fs
);
7289 gen_load_fpr32h(fph
, ft
);
7290 gen_store_fpr32h(fp
, fd
);
7291 gen_store_fpr32(fph
, fd
);
7293 gen_load_fpr32h(fph
, fs
);
7294 gen_load_fpr32(fp
, ft
);
7295 gen_store_fpr32(fph
, fd
);
7296 gen_store_fpr32h(fp
, fd
);
7299 tcg_temp_free_i32(fp
);
7300 tcg_temp_free_i32(fph
);
7307 TCGv_i32 fp0
= tcg_temp_new_i32();
7308 TCGv_i32 fp1
= tcg_temp_new_i32();
7309 TCGv_i32 fp2
= tcg_temp_new_i32();
7311 gen_load_fpr32(fp0
, fs
);
7312 gen_load_fpr32(fp1
, ft
);
7313 gen_load_fpr32(fp2
, fr
);
7314 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7315 tcg_temp_free_i32(fp0
);
7316 tcg_temp_free_i32(fp1
);
7317 gen_store_fpr32(fp2
, fd
);
7318 tcg_temp_free_i32(fp2
);
7324 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7326 TCGv_i64 fp0
= tcg_temp_new_i64();
7327 TCGv_i64 fp1
= tcg_temp_new_i64();
7328 TCGv_i64 fp2
= tcg_temp_new_i64();
7330 gen_load_fpr64(ctx
, fp0
, fs
);
7331 gen_load_fpr64(ctx
, fp1
, ft
);
7332 gen_load_fpr64(ctx
, fp2
, fr
);
7333 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7334 tcg_temp_free_i64(fp0
);
7335 tcg_temp_free_i64(fp1
);
7336 gen_store_fpr64(ctx
, fp2
, fd
);
7337 tcg_temp_free_i64(fp2
);
7342 check_cp1_64bitmode(ctx
);
7344 TCGv_i64 fp0
= tcg_temp_new_i64();
7345 TCGv_i64 fp1
= tcg_temp_new_i64();
7346 TCGv_i64 fp2
= tcg_temp_new_i64();
7348 gen_load_fpr64(ctx
, fp0
, fs
);
7349 gen_load_fpr64(ctx
, fp1
, ft
);
7350 gen_load_fpr64(ctx
, fp2
, fr
);
7351 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7352 tcg_temp_free_i64(fp0
);
7353 tcg_temp_free_i64(fp1
);
7354 gen_store_fpr64(ctx
, fp2
, fd
);
7355 tcg_temp_free_i64(fp2
);
7362 TCGv_i32 fp0
= tcg_temp_new_i32();
7363 TCGv_i32 fp1
= tcg_temp_new_i32();
7364 TCGv_i32 fp2
= tcg_temp_new_i32();
7366 gen_load_fpr32(fp0
, fs
);
7367 gen_load_fpr32(fp1
, ft
);
7368 gen_load_fpr32(fp2
, fr
);
7369 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7370 tcg_temp_free_i32(fp0
);
7371 tcg_temp_free_i32(fp1
);
7372 gen_store_fpr32(fp2
, fd
);
7373 tcg_temp_free_i32(fp2
);
7379 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7381 TCGv_i64 fp0
= tcg_temp_new_i64();
7382 TCGv_i64 fp1
= tcg_temp_new_i64();
7383 TCGv_i64 fp2
= tcg_temp_new_i64();
7385 gen_load_fpr64(ctx
, fp0
, fs
);
7386 gen_load_fpr64(ctx
, fp1
, ft
);
7387 gen_load_fpr64(ctx
, fp2
, fr
);
7388 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7389 tcg_temp_free_i64(fp0
);
7390 tcg_temp_free_i64(fp1
);
7391 gen_store_fpr64(ctx
, fp2
, fd
);
7392 tcg_temp_free_i64(fp2
);
7397 check_cp1_64bitmode(ctx
);
7399 TCGv_i64 fp0
= tcg_temp_new_i64();
7400 TCGv_i64 fp1
= tcg_temp_new_i64();
7401 TCGv_i64 fp2
= tcg_temp_new_i64();
7403 gen_load_fpr64(ctx
, fp0
, fs
);
7404 gen_load_fpr64(ctx
, fp1
, ft
);
7405 gen_load_fpr64(ctx
, fp2
, fr
);
7406 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7407 tcg_temp_free_i64(fp0
);
7408 tcg_temp_free_i64(fp1
);
7409 gen_store_fpr64(ctx
, fp2
, fd
);
7410 tcg_temp_free_i64(fp2
);
7417 TCGv_i32 fp0
= tcg_temp_new_i32();
7418 TCGv_i32 fp1
= tcg_temp_new_i32();
7419 TCGv_i32 fp2
= tcg_temp_new_i32();
7421 gen_load_fpr32(fp0
, fs
);
7422 gen_load_fpr32(fp1
, ft
);
7423 gen_load_fpr32(fp2
, fr
);
7424 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7425 tcg_temp_free_i32(fp0
);
7426 tcg_temp_free_i32(fp1
);
7427 gen_store_fpr32(fp2
, fd
);
7428 tcg_temp_free_i32(fp2
);
7434 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7436 TCGv_i64 fp0
= tcg_temp_new_i64();
7437 TCGv_i64 fp1
= tcg_temp_new_i64();
7438 TCGv_i64 fp2
= tcg_temp_new_i64();
7440 gen_load_fpr64(ctx
, fp0
, fs
);
7441 gen_load_fpr64(ctx
, fp1
, ft
);
7442 gen_load_fpr64(ctx
, fp2
, fr
);
7443 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7444 tcg_temp_free_i64(fp0
);
7445 tcg_temp_free_i64(fp1
);
7446 gen_store_fpr64(ctx
, fp2
, fd
);
7447 tcg_temp_free_i64(fp2
);
7452 check_cp1_64bitmode(ctx
);
7454 TCGv_i64 fp0
= tcg_temp_new_i64();
7455 TCGv_i64 fp1
= tcg_temp_new_i64();
7456 TCGv_i64 fp2
= tcg_temp_new_i64();
7458 gen_load_fpr64(ctx
, fp0
, fs
);
7459 gen_load_fpr64(ctx
, fp1
, ft
);
7460 gen_load_fpr64(ctx
, fp2
, fr
);
7461 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7462 tcg_temp_free_i64(fp0
);
7463 tcg_temp_free_i64(fp1
);
7464 gen_store_fpr64(ctx
, fp2
, fd
);
7465 tcg_temp_free_i64(fp2
);
7472 TCGv_i32 fp0
= tcg_temp_new_i32();
7473 TCGv_i32 fp1
= tcg_temp_new_i32();
7474 TCGv_i32 fp2
= tcg_temp_new_i32();
7476 gen_load_fpr32(fp0
, fs
);
7477 gen_load_fpr32(fp1
, ft
);
7478 gen_load_fpr32(fp2
, fr
);
7479 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7480 tcg_temp_free_i32(fp0
);
7481 tcg_temp_free_i32(fp1
);
7482 gen_store_fpr32(fp2
, fd
);
7483 tcg_temp_free_i32(fp2
);
7489 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7491 TCGv_i64 fp0
= tcg_temp_new_i64();
7492 TCGv_i64 fp1
= tcg_temp_new_i64();
7493 TCGv_i64 fp2
= tcg_temp_new_i64();
7495 gen_load_fpr64(ctx
, fp0
, fs
);
7496 gen_load_fpr64(ctx
, fp1
, ft
);
7497 gen_load_fpr64(ctx
, fp2
, fr
);
7498 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7499 tcg_temp_free_i64(fp0
);
7500 tcg_temp_free_i64(fp1
);
7501 gen_store_fpr64(ctx
, fp2
, fd
);
7502 tcg_temp_free_i64(fp2
);
7507 check_cp1_64bitmode(ctx
);
7509 TCGv_i64 fp0
= tcg_temp_new_i64();
7510 TCGv_i64 fp1
= tcg_temp_new_i64();
7511 TCGv_i64 fp2
= tcg_temp_new_i64();
7513 gen_load_fpr64(ctx
, fp0
, fs
);
7514 gen_load_fpr64(ctx
, fp1
, ft
);
7515 gen_load_fpr64(ctx
, fp2
, fr
);
7516 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7517 tcg_temp_free_i64(fp0
);
7518 tcg_temp_free_i64(fp1
);
7519 gen_store_fpr64(ctx
, fp2
, fd
);
7520 tcg_temp_free_i64(fp2
);
7526 generate_exception (ctx
, EXCP_RI
);
7529 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7530 fregnames
[fs
], fregnames
[ft
]);
7533 static void handle_delay_slot (CPUState
*env
, DisasContext
*ctx
,
7536 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7537 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7538 /* Branches completion */
7539 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7540 ctx
->bstate
= BS_BRANCH
;
7541 save_cpu_state(ctx
, 0);
7542 /* FIXME: Need to clear can_do_io. */
7543 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
7545 /* unconditional branch */
7546 MIPS_DEBUG("unconditional branch");
7547 if (proc_hflags
& MIPS_HFLAG_BX
) {
7548 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
7550 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7553 /* blikely taken case */
7554 MIPS_DEBUG("blikely branch taken");
7555 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7558 /* Conditional branch */
7559 MIPS_DEBUG("conditional branch");
7561 int l1
= gen_new_label();
7563 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7564 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
7566 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7570 /* unconditional branch to register */
7571 MIPS_DEBUG("branch to register");
7572 if (env
->insn_flags
& ASE_MIPS16
) {
7573 TCGv t0
= tcg_temp_new();
7574 TCGv_i32 t1
= tcg_temp_new_i32();
7576 tcg_gen_andi_tl(t0
, btarget
, 0x1);
7577 tcg_gen_trunc_tl_i32(t1
, t0
);
7579 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
7580 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
7581 tcg_gen_or_i32(hflags
, hflags
, t1
);
7582 tcg_temp_free_i32(t1
);
7584 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
7586 tcg_gen_mov_tl(cpu_PC
, btarget
);
7588 if (ctx
->singlestep_enabled
) {
7589 save_cpu_state(ctx
, 0);
7590 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
7595 MIPS_DEBUG("unknown branch");
7601 /* ISA extensions (ASEs) */
7602 /* MIPS16 extension to MIPS32 */
7604 /* MIPS16 major opcodes */
7606 M16_OPC_ADDIUSP
= 0x00,
7607 M16_OPC_ADDIUPC
= 0x01,
7610 M16_OPC_BEQZ
= 0x04,
7611 M16_OPC_BNEQZ
= 0x05,
7612 M16_OPC_SHIFT
= 0x06,
7614 M16_OPC_RRIA
= 0x08,
7615 M16_OPC_ADDIU8
= 0x09,
7616 M16_OPC_SLTI
= 0x0a,
7617 M16_OPC_SLTIU
= 0x0b,
7620 M16_OPC_CMPI
= 0x0e,
7624 M16_OPC_LWSP
= 0x12,
7628 M16_OPC_LWPC
= 0x16,
7632 M16_OPC_SWSP
= 0x1a,
7636 M16_OPC_EXTEND
= 0x1e,
7640 /* I8 funct field */
7659 /* RR funct field */
7693 /* I64 funct field */
7705 /* RR ry field for CNVT */
7707 RR_RY_CNVT_ZEB
= 0x0,
7708 RR_RY_CNVT_ZEH
= 0x1,
7709 RR_RY_CNVT_ZEW
= 0x2,
7710 RR_RY_CNVT_SEB
= 0x4,
7711 RR_RY_CNVT_SEH
= 0x5,
7712 RR_RY_CNVT_SEW
= 0x6,
7715 static int xlat (int r
)
7717 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
7722 static void gen_mips16_save (DisasContext
*ctx
,
7723 int xsregs
, int aregs
,
7724 int do_ra
, int do_s0
, int do_s1
,
7727 TCGv t0
= tcg_temp_new();
7728 TCGv t1
= tcg_temp_new();
7758 generate_exception(ctx
, EXCP_RI
);
7764 gen_base_offset_addr(ctx
, t0
, 29, 12);
7765 gen_load_gpr(t1
, 7);
7766 op_ldst_sw(t1
, t0
, ctx
);
7769 gen_base_offset_addr(ctx
, t0
, 29, 8);
7770 gen_load_gpr(t1
, 6);
7771 op_ldst_sw(t1
, t0
, ctx
);
7774 gen_base_offset_addr(ctx
, t0
, 29, 4);
7775 gen_load_gpr(t1
, 5);
7776 op_ldst_sw(t1
, t0
, ctx
);
7779 gen_base_offset_addr(ctx
, t0
, 29, 0);
7780 gen_load_gpr(t1
, 4);
7781 op_ldst_sw(t1
, t0
, ctx
);
7784 gen_load_gpr(t0
, 29);
7786 #define DECR_AND_STORE(reg) do { \
7787 tcg_gen_subi_tl(t0, t0, 4); \
7788 gen_load_gpr(t1, reg); \
7789 op_ldst_sw(t1, t0, ctx); \
7853 generate_exception(ctx
, EXCP_RI
);
7869 #undef DECR_AND_STORE
7871 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
7876 static void gen_mips16_restore (DisasContext
*ctx
,
7877 int xsregs
, int aregs
,
7878 int do_ra
, int do_s0
, int do_s1
,
7882 TCGv t0
= tcg_temp_new();
7883 TCGv t1
= tcg_temp_new();
7885 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
7887 #define DECR_AND_LOAD(reg) do { \
7888 tcg_gen_subi_tl(t0, t0, 4); \
7889 op_ldst_lw(t1, t0, ctx); \
7890 gen_store_gpr(t1, reg); \
7954 generate_exception(ctx
, EXCP_RI
);
7970 #undef DECR_AND_LOAD
7972 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
7977 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
7978 int is_64_bit
, int extended
)
7982 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
7983 generate_exception(ctx
, EXCP_RI
);
7987 t0
= tcg_temp_new();
7989 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
7990 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
7992 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
7998 #if defined(TARGET_MIPS64)
7999 static void decode_i64_mips16 (CPUState
*env
, DisasContext
*ctx
,
8000 int ry
, int funct
, int16_t offset
,
8006 offset
= extended
? offset
: offset
<< 3;
8007 gen_ldst(ctx
, OPC_LD
, ry
, 29, offset
);
8011 offset
= extended
? offset
: offset
<< 3;
8012 gen_ldst(ctx
, OPC_SD
, ry
, 29, offset
);
8016 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8017 gen_ldst(ctx
, OPC_SD
, 31, 29, offset
);
8021 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8022 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8025 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8026 generate_exception(ctx
, EXCP_RI
);
8028 offset
= extended
? offset
: offset
<< 3;
8029 gen_ldst(ctx
, OPC_LDPC
, ry
, 0, offset
);
8034 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8035 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8039 offset
= extended
? offset
: offset
<< 2;
8040 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8044 offset
= extended
? offset
: offset
<< 2;
8045 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8051 static int decode_extended_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8054 int extend
= lduw_code(ctx
->pc
+ 2);
8055 int op
, rx
, ry
, funct
, sa
;
8056 int16_t imm
, offset
;
8058 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8059 op
= (ctx
->opcode
>> 11) & 0x1f;
8060 sa
= (ctx
->opcode
>> 22) & 0x1f;
8061 funct
= (ctx
->opcode
>> 8) & 0x7;
8062 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8063 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8064 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8065 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8066 | (ctx
->opcode
& 0x1f));
8068 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8071 case M16_OPC_ADDIUSP
:
8072 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8074 case M16_OPC_ADDIUPC
:
8075 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8078 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8079 /* No delay slot, so just process as a normal instruction */
8082 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8083 /* No delay slot, so just process as a normal instruction */
8086 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8087 /* No delay slot, so just process as a normal instruction */
8090 switch (ctx
->opcode
& 0x3) {
8092 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8095 #if defined(TARGET_MIPS64)
8097 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8099 generate_exception(ctx
, EXCP_RI
);
8103 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8106 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8110 #if defined(TARGET_MIPS64)
8113 gen_ldst(ctx
, OPC_LD
, ry
, rx
, offset
);
8117 imm
= ctx
->opcode
& 0xf;
8118 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8119 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8120 imm
= (int16_t) (imm
<< 1) >> 1;
8121 if ((ctx
->opcode
>> 4) & 0x1) {
8122 #if defined(TARGET_MIPS64)
8124 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8126 generate_exception(ctx
, EXCP_RI
);
8129 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8132 case M16_OPC_ADDIU8
:
8133 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8136 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8139 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8144 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8147 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8150 gen_ldst(ctx
, OPC_SW
, 31, 29, imm
);
8153 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8157 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8158 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8159 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8160 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8161 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8162 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8163 | (ctx
->opcode
& 0xf)) << 3;
8165 if (ctx
->opcode
& (1 << 7)) {
8166 gen_mips16_save(ctx
, xsregs
, aregs
,
8167 do_ra
, do_s0
, do_s1
,
8170 gen_mips16_restore(ctx
, xsregs
, aregs
,
8171 do_ra
, do_s0
, do_s1
,
8177 generate_exception(ctx
, EXCP_RI
);
8182 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8185 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8187 #if defined(TARGET_MIPS64)
8189 gen_ldst(ctx
, OPC_SD
, ry
, rx
, offset
);
8193 gen_ldst(ctx
, OPC_LB
, ry
, rx
, offset
);
8196 gen_ldst(ctx
, OPC_LH
, ry
, rx
, offset
);
8199 gen_ldst(ctx
, OPC_LW
, rx
, 29, offset
);
8202 gen_ldst(ctx
, OPC_LW
, ry
, rx
, offset
);
8205 gen_ldst(ctx
, OPC_LBU
, ry
, rx
, offset
);
8208 gen_ldst(ctx
, OPC_LHU
, ry
, rx
, offset
);
8211 gen_ldst(ctx
, OPC_LWPC
, rx
, 0, offset
);
8213 #if defined(TARGET_MIPS64)
8215 gen_ldst(ctx
, OPC_LWU
, ry
, rx
, offset
);
8219 gen_ldst(ctx
, OPC_SB
, ry
, rx
, offset
);
8222 gen_ldst(ctx
, OPC_SH
, ry
, rx
, offset
);
8225 gen_ldst(ctx
, OPC_SW
, rx
, 29, offset
);
8228 gen_ldst(ctx
, OPC_SW
, ry
, rx
, offset
);
8230 #if defined(TARGET_MIPS64)
8232 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8236 generate_exception(ctx
, EXCP_RI
);
8243 static int decode_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8248 int op
, cnvt_op
, op1
, offset
;
8252 op
= (ctx
->opcode
>> 11) & 0x1f;
8253 sa
= (ctx
->opcode
>> 2) & 0x7;
8254 sa
= sa
== 0 ? 8 : sa
;
8255 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8256 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8257 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8258 op1
= offset
= ctx
->opcode
& 0x1f;
8263 case M16_OPC_ADDIUSP
:
8265 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8267 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8270 case M16_OPC_ADDIUPC
:
8271 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8274 offset
= (ctx
->opcode
& 0x7ff) << 1;
8275 offset
= (int16_t)(offset
<< 4) >> 4;
8276 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8277 /* No delay slot, so just process as a normal instruction */
8280 offset
= lduw_code(ctx
->pc
+ 2);
8281 offset
= (((ctx
->opcode
& 0x1f) << 21)
8282 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8284 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALX
: OPC_JAL
;
8285 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8290 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8291 /* No delay slot, so just process as a normal instruction */
8294 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8295 /* No delay slot, so just process as a normal instruction */
8298 switch (ctx
->opcode
& 0x3) {
8300 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8303 #if defined(TARGET_MIPS64)
8305 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8307 generate_exception(ctx
, EXCP_RI
);
8311 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8314 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8318 #if defined(TARGET_MIPS64)
8321 gen_ldst(ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8326 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8328 if ((ctx
->opcode
>> 4) & 1) {
8329 #if defined(TARGET_MIPS64)
8331 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8333 generate_exception(ctx
, EXCP_RI
);
8336 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8340 case M16_OPC_ADDIU8
:
8342 int16_t imm
= (int8_t) ctx
->opcode
;
8344 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8349 int16_t imm
= (uint8_t) ctx
->opcode
;
8351 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8356 int16_t imm
= (uint8_t) ctx
->opcode
;
8358 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8365 funct
= (ctx
->opcode
>> 8) & 0x7;
8368 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
8369 ((int8_t)ctx
->opcode
) << 1);
8372 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
8373 ((int8_t)ctx
->opcode
) << 1);
8376 gen_ldst(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
8379 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
8380 ((int8_t)ctx
->opcode
) << 3);
8384 int do_ra
= ctx
->opcode
& (1 << 6);
8385 int do_s0
= ctx
->opcode
& (1 << 5);
8386 int do_s1
= ctx
->opcode
& (1 << 4);
8387 int framesize
= ctx
->opcode
& 0xf;
8389 if (framesize
== 0) {
8392 framesize
= framesize
<< 3;
8395 if (ctx
->opcode
& (1 << 7)) {
8396 gen_mips16_save(ctx
, 0, 0,
8397 do_ra
, do_s0
, do_s1
, framesize
);
8399 gen_mips16_restore(ctx
, 0, 0,
8400 do_ra
, do_s0
, do_s1
, framesize
);
8406 int rz
= xlat(ctx
->opcode
& 0x7);
8408 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
8409 ((ctx
->opcode
>> 5) & 0x7);
8410 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
8414 reg32
= ctx
->opcode
& 0x1f;
8415 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
8418 generate_exception(ctx
, EXCP_RI
);
8425 int16_t imm
= (uint8_t) ctx
->opcode
;
8427 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
8432 int16_t imm
= (uint8_t) ctx
->opcode
;
8434 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
8437 #if defined(TARGET_MIPS64)
8440 gen_ldst(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
8444 gen_ldst(ctx
, OPC_LB
, ry
, rx
, offset
);
8447 gen_ldst(ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
8450 gen_ldst(ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8453 gen_ldst(ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
8456 gen_ldst(ctx
, OPC_LBU
, ry
, rx
, offset
);
8459 gen_ldst(ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
8462 gen_ldst(ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
8464 #if defined (TARGET_MIPS64)
8467 gen_ldst(ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
8471 gen_ldst(ctx
, OPC_SB
, ry
, rx
, offset
);
8474 gen_ldst(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
8477 gen_ldst(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8480 gen_ldst(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
8484 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
8487 switch (ctx
->opcode
& 0x3) {
8489 mips32_op
= OPC_ADDU
;
8492 mips32_op
= OPC_SUBU
;
8494 #if defined(TARGET_MIPS64)
8496 mips32_op
= OPC_DADDU
;
8500 mips32_op
= OPC_DSUBU
;
8505 generate_exception(ctx
, EXCP_RI
);
8509 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
8518 int nd
= (ctx
->opcode
>> 7) & 0x1;
8519 int link
= (ctx
->opcode
>> 6) & 0x1;
8520 int ra
= (ctx
->opcode
>> 5) & 0x1;
8523 op
= nd
? OPC_JALRC
: OPC_JALR
;
8528 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
8535 /* XXX: not clear which exception should be raised
8536 * when in debug mode...
8538 check_insn(env
, ctx
, ISA_MIPS32
);
8539 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8540 generate_exception(ctx
, EXCP_DBp
);
8542 generate_exception(ctx
, EXCP_DBp
);
8546 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
8549 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
8552 generate_exception(ctx
, EXCP_BREAK
);
8555 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
8558 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
8561 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
8563 #if defined (TARGET_MIPS64)
8566 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
8570 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
8573 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
8576 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
8579 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
8582 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
8585 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
8588 gen_HILO(ctx
, OPC_MFHI
, rx
);
8592 case RR_RY_CNVT_ZEB
:
8593 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8595 case RR_RY_CNVT_ZEH
:
8596 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8598 case RR_RY_CNVT_SEB
:
8599 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8601 case RR_RY_CNVT_SEH
:
8602 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8604 #if defined (TARGET_MIPS64)
8605 case RR_RY_CNVT_ZEW
:
8607 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8609 case RR_RY_CNVT_SEW
:
8611 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8615 generate_exception(ctx
, EXCP_RI
);
8620 gen_HILO(ctx
, OPC_MFLO
, rx
);
8622 #if defined (TARGET_MIPS64)
8625 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
8629 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
8633 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
8637 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
8641 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
8644 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
8647 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
8650 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
8652 #if defined (TARGET_MIPS64)
8655 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
8659 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
8663 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
8667 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
8671 generate_exception(ctx
, EXCP_RI
);
8675 case M16_OPC_EXTEND
:
8676 decode_extended_mips16_opc(env
, ctx
, is_branch
);
8679 #if defined(TARGET_MIPS64)
8681 funct
= (ctx
->opcode
>> 8) & 0x7;
8682 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
8686 generate_exception(ctx
, EXCP_RI
);
8693 /* SmartMIPS extension to MIPS32 */
8695 #if defined(TARGET_MIPS64)
8697 /* MDMX extension to MIPS64 */
8701 static void decode_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
8705 uint32_t op
, op1
, op2
;
8708 /* make sure instructions are on a word boundary */
8709 if (ctx
->pc
& 0x3) {
8710 env
->CP0_BadVAddr
= ctx
->pc
;
8711 generate_exception(ctx
, EXCP_AdEL
);
8715 /* Handle blikely not taken case */
8716 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
8717 int l1
= gen_new_label();
8719 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
8720 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8721 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
8722 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8726 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
8727 tcg_gen_debug_insn_start(ctx
->pc
);
8729 op
= MASK_OP_MAJOR(ctx
->opcode
);
8730 rs
= (ctx
->opcode
>> 21) & 0x1f;
8731 rt
= (ctx
->opcode
>> 16) & 0x1f;
8732 rd
= (ctx
->opcode
>> 11) & 0x1f;
8733 sa
= (ctx
->opcode
>> 6) & 0x1f;
8734 imm
= (int16_t)ctx
->opcode
;
8737 op1
= MASK_SPECIAL(ctx
->opcode
);
8739 case OPC_SLL
: /* Shift with immediate */
8741 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8744 switch ((ctx
->opcode
>> 21) & 0x1f) {
8746 /* rotr is decoded as srl on non-R2 CPUs */
8747 if (env
->insn_flags
& ISA_MIPS32R2
) {
8752 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8755 generate_exception(ctx
, EXCP_RI
);
8759 case OPC_MOVN
: /* Conditional move */
8761 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8762 gen_cond_move(env
, op1
, rd
, rs
, rt
);
8764 case OPC_ADD
... OPC_SUBU
:
8765 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8767 case OPC_SLLV
: /* Shifts */
8769 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8772 switch ((ctx
->opcode
>> 6) & 0x1f) {
8774 /* rotrv is decoded as srlv on non-R2 CPUs */
8775 if (env
->insn_flags
& ISA_MIPS32R2
) {
8780 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8783 generate_exception(ctx
, EXCP_RI
);
8787 case OPC_SLT
: /* Set on less than */
8789 gen_slt(env
, op1
, rd
, rs
, rt
);
8791 case OPC_AND
: /* Logic*/
8795 gen_logic(env
, op1
, rd
, rs
, rt
);
8797 case OPC_MULT
... OPC_DIVU
:
8799 check_insn(env
, ctx
, INSN_VR54XX
);
8800 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
8801 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
8803 gen_muldiv(ctx
, op1
, rs
, rt
);
8805 case OPC_JR
... OPC_JALR
:
8806 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
8809 case OPC_TGE
... OPC_TEQ
: /* Traps */
8811 gen_trap(ctx
, op1
, rs
, rt
, -1);
8813 case OPC_MFHI
: /* Move from HI/LO */
8815 gen_HILO(ctx
, op1
, rd
);
8818 case OPC_MTLO
: /* Move to HI/LO */
8819 gen_HILO(ctx
, op1
, rs
);
8821 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
8822 #ifdef MIPS_STRICT_STANDARD
8823 MIPS_INVAL("PMON / selsl");
8824 generate_exception(ctx
, EXCP_RI
);
8826 gen_helper_0i(pmon
, sa
);
8830 generate_exception(ctx
, EXCP_SYSCALL
);
8831 ctx
->bstate
= BS_STOP
;
8834 generate_exception(ctx
, EXCP_BREAK
);
8837 #ifdef MIPS_STRICT_STANDARD
8839 generate_exception(ctx
, EXCP_RI
);
8841 /* Implemented as RI exception for now. */
8842 MIPS_INVAL("spim (unofficial)");
8843 generate_exception(ctx
, EXCP_RI
);
8851 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8852 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8853 check_cp1_enabled(ctx
);
8854 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
8855 (ctx
->opcode
>> 16) & 1);
8857 generate_exception_err(ctx
, EXCP_CpU
, 1);
8861 #if defined(TARGET_MIPS64)
8862 /* MIPS64 specific opcodes */
8867 check_insn(env
, ctx
, ISA_MIPS3
);
8869 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8872 switch ((ctx
->opcode
>> 21) & 0x1f) {
8874 /* drotr is decoded as dsrl on non-R2 CPUs */
8875 if (env
->insn_flags
& ISA_MIPS32R2
) {
8880 check_insn(env
, ctx
, ISA_MIPS3
);
8882 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8885 generate_exception(ctx
, EXCP_RI
);
8890 switch ((ctx
->opcode
>> 21) & 0x1f) {
8892 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
8893 if (env
->insn_flags
& ISA_MIPS32R2
) {
8898 check_insn(env
, ctx
, ISA_MIPS3
);
8900 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8903 generate_exception(ctx
, EXCP_RI
);
8907 case OPC_DADD
... OPC_DSUBU
:
8908 check_insn(env
, ctx
, ISA_MIPS3
);
8910 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8914 check_insn(env
, ctx
, ISA_MIPS3
);
8916 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8919 switch ((ctx
->opcode
>> 6) & 0x1f) {
8921 /* drotrv is decoded as dsrlv on non-R2 CPUs */
8922 if (env
->insn_flags
& ISA_MIPS32R2
) {
8927 check_insn(env
, ctx
, ISA_MIPS3
);
8929 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8932 generate_exception(ctx
, EXCP_RI
);
8936 case OPC_DMULT
... OPC_DDIVU
:
8937 check_insn(env
, ctx
, ISA_MIPS3
);
8939 gen_muldiv(ctx
, op1
, rs
, rt
);
8942 default: /* Invalid */
8943 MIPS_INVAL("special");
8944 generate_exception(ctx
, EXCP_RI
);
8949 op1
= MASK_SPECIAL2(ctx
->opcode
);
8951 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
8952 case OPC_MSUB
... OPC_MSUBU
:
8953 check_insn(env
, ctx
, ISA_MIPS32
);
8954 gen_muldiv(ctx
, op1
, rs
, rt
);
8957 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8961 check_insn(env
, ctx
, ISA_MIPS32
);
8962 gen_cl(ctx
, op1
, rd
, rs
);
8965 /* XXX: not clear which exception should be raised
8966 * when in debug mode...
8968 check_insn(env
, ctx
, ISA_MIPS32
);
8969 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8970 generate_exception(ctx
, EXCP_DBp
);
8972 generate_exception(ctx
, EXCP_DBp
);
8976 #if defined(TARGET_MIPS64)
8979 check_insn(env
, ctx
, ISA_MIPS64
);
8981 gen_cl(ctx
, op1
, rd
, rs
);
8984 default: /* Invalid */
8985 MIPS_INVAL("special2");
8986 generate_exception(ctx
, EXCP_RI
);
8991 op1
= MASK_SPECIAL3(ctx
->opcode
);
8995 check_insn(env
, ctx
, ISA_MIPS32R2
);
8996 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
8999 check_insn(env
, ctx
, ISA_MIPS32R2
);
9000 op2
= MASK_BSHFL(ctx
->opcode
);
9001 gen_bshfl(ctx
, op2
, rt
, rd
);
9004 check_insn(env
, ctx
, ISA_MIPS32R2
);
9006 TCGv t0
= tcg_temp_new();
9010 save_cpu_state(ctx
, 1);
9011 gen_helper_rdhwr_cpunum(t0
);
9012 gen_store_gpr(t0
, rt
);
9015 save_cpu_state(ctx
, 1);
9016 gen_helper_rdhwr_synci_step(t0
);
9017 gen_store_gpr(t0
, rt
);
9020 save_cpu_state(ctx
, 1);
9021 gen_helper_rdhwr_cc(t0
);
9022 gen_store_gpr(t0
, rt
);
9025 save_cpu_state(ctx
, 1);
9026 gen_helper_rdhwr_ccres(t0
);
9027 gen_store_gpr(t0
, rt
);
9030 #if defined(CONFIG_USER_ONLY)
9031 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
9032 gen_store_gpr(t0
, rt
);
9035 /* XXX: Some CPUs implement this in hardware.
9036 Not supported yet. */
9038 default: /* Invalid */
9039 MIPS_INVAL("rdhwr");
9040 generate_exception(ctx
, EXCP_RI
);
9047 check_insn(env
, ctx
, ASE_MT
);
9049 TCGv t0
= tcg_temp_new();
9050 TCGv t1
= tcg_temp_new();
9052 gen_load_gpr(t0
, rt
);
9053 gen_load_gpr(t1
, rs
);
9054 gen_helper_fork(t0
, t1
);
9060 check_insn(env
, ctx
, ASE_MT
);
9062 TCGv t0
= tcg_temp_new();
9064 save_cpu_state(ctx
, 1);
9065 gen_load_gpr(t0
, rs
);
9066 gen_helper_yield(t0
, t0
);
9067 gen_store_gpr(t0
, rd
);
9071 #if defined(TARGET_MIPS64)
9072 case OPC_DEXTM
... OPC_DEXT
:
9073 case OPC_DINSM
... OPC_DINS
:
9074 check_insn(env
, ctx
, ISA_MIPS64R2
);
9076 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
9079 check_insn(env
, ctx
, ISA_MIPS64R2
);
9081 op2
= MASK_DBSHFL(ctx
->opcode
);
9082 gen_bshfl(ctx
, op2
, rt
, rd
);
9085 default: /* Invalid */
9086 MIPS_INVAL("special3");
9087 generate_exception(ctx
, EXCP_RI
);
9092 op1
= MASK_REGIMM(ctx
->opcode
);
9094 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
9095 case OPC_BLTZAL
... OPC_BGEZALL
:
9096 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
9099 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
9101 gen_trap(ctx
, op1
, rs
, -1, imm
);
9104 check_insn(env
, ctx
, ISA_MIPS32R2
);
9107 default: /* Invalid */
9108 MIPS_INVAL("regimm");
9109 generate_exception(ctx
, EXCP_RI
);
9114 check_cp0_enabled(ctx
);
9115 op1
= MASK_CP0(ctx
->opcode
);
9121 #if defined(TARGET_MIPS64)
9125 #ifndef CONFIG_USER_ONLY
9126 gen_cp0(env
, ctx
, op1
, rt
, rd
);
9127 #endif /* !CONFIG_USER_ONLY */
9129 case OPC_C0_FIRST
... OPC_C0_LAST
:
9130 #ifndef CONFIG_USER_ONLY
9131 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
9132 #endif /* !CONFIG_USER_ONLY */
9135 #ifndef CONFIG_USER_ONLY
9137 TCGv t0
= tcg_temp_new();
9139 op2
= MASK_MFMC0(ctx
->opcode
);
9142 check_insn(env
, ctx
, ASE_MT
);
9143 gen_helper_dmt(t0
, t0
);
9144 gen_store_gpr(t0
, rt
);
9147 check_insn(env
, ctx
, ASE_MT
);
9148 gen_helper_emt(t0
, t0
);
9149 gen_store_gpr(t0
, rt
);
9152 check_insn(env
, ctx
, ASE_MT
);
9153 gen_helper_dvpe(t0
, t0
);
9154 gen_store_gpr(t0
, rt
);
9157 check_insn(env
, ctx
, ASE_MT
);
9158 gen_helper_evpe(t0
, t0
);
9159 gen_store_gpr(t0
, rt
);
9162 check_insn(env
, ctx
, ISA_MIPS32R2
);
9163 save_cpu_state(ctx
, 1);
9165 gen_store_gpr(t0
, rt
);
9166 /* Stop translation as we may have switched the execution mode */
9167 ctx
->bstate
= BS_STOP
;
9170 check_insn(env
, ctx
, ISA_MIPS32R2
);
9171 save_cpu_state(ctx
, 1);
9173 gen_store_gpr(t0
, rt
);
9174 /* Stop translation as we may have switched the execution mode */
9175 ctx
->bstate
= BS_STOP
;
9177 default: /* Invalid */
9178 MIPS_INVAL("mfmc0");
9179 generate_exception(ctx
, EXCP_RI
);
9184 #endif /* !CONFIG_USER_ONLY */
9187 check_insn(env
, ctx
, ISA_MIPS32R2
);
9188 gen_load_srsgpr(rt
, rd
);
9191 check_insn(env
, ctx
, ISA_MIPS32R2
);
9192 gen_store_srsgpr(rt
, rd
);
9196 generate_exception(ctx
, EXCP_RI
);
9200 case OPC_ADDI
: /* Arithmetic with immediate opcode */
9202 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
9204 case OPC_SLTI
: /* Set on less than with immediate opcode */
9206 gen_slt_imm(env
, op
, rt
, rs
, imm
);
9208 case OPC_ANDI
: /* Arithmetic with immediate opcode */
9212 gen_logic_imm(env
, op
, rt
, rs
, imm
);
9214 case OPC_J
... OPC_JAL
: /* Jump */
9215 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
9216 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
9219 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
9220 case OPC_BEQL
... OPC_BGTZL
:
9221 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
9224 case OPC_LB
... OPC_LWR
: /* Load and stores */
9225 case OPC_SB
... OPC_SW
:
9228 gen_ldst(ctx
, op
, rt
, rs
, imm
);
9231 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
9234 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
9238 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
9242 /* Floating point (COP1). */
9247 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9248 check_cp1_enabled(ctx
);
9249 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
9251 generate_exception_err(ctx
, EXCP_CpU
, 1);
9256 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9257 check_cp1_enabled(ctx
);
9258 op1
= MASK_CP1(ctx
->opcode
);
9262 check_insn(env
, ctx
, ISA_MIPS32R2
);
9267 gen_cp1(ctx
, op1
, rt
, rd
);
9269 #if defined(TARGET_MIPS64)
9272 check_insn(env
, ctx
, ISA_MIPS3
);
9273 gen_cp1(ctx
, op1
, rt
, rd
);
9279 check_insn(env
, ctx
, ASE_MIPS3D
);
9282 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
9283 (rt
>> 2) & 0x7, imm
<< 2);
9291 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
9296 generate_exception (ctx
, EXCP_RI
);
9300 generate_exception_err(ctx
, EXCP_CpU
, 1);
9310 /* COP2: Not implemented. */
9311 generate_exception_err(ctx
, EXCP_CpU
, 2);
9315 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9316 check_cp1_enabled(ctx
);
9317 op1
= MASK_CP3(ctx
->opcode
);
9325 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
9343 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
9347 generate_exception (ctx
, EXCP_RI
);
9351 generate_exception_err(ctx
, EXCP_CpU
, 1);
9355 #if defined(TARGET_MIPS64)
9356 /* MIPS64 opcodes */
9358 case OPC_LDL
... OPC_LDR
:
9359 case OPC_SDL
... OPC_SDR
:
9363 check_insn(env
, ctx
, ISA_MIPS3
);
9365 gen_ldst(ctx
, op
, rt
, rs
, imm
);
9368 check_insn(env
, ctx
, ISA_MIPS3
);
9370 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
9374 check_insn(env
, ctx
, ISA_MIPS3
);
9376 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
9380 check_insn(env
, ctx
, ASE_MIPS16
);
9381 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
9382 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
9386 check_insn(env
, ctx
, ASE_MDMX
);
9387 /* MDMX: Not implemented. */
9388 default: /* Invalid */
9389 MIPS_INVAL("major opcode");
9390 generate_exception(ctx
, EXCP_RI
);
9396 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
9400 target_ulong pc_start
;
9401 uint16_t *gen_opc_end
;
9410 qemu_log("search pc %d\n", search_pc
);
9413 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
9416 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
9418 ctx
.bstate
= BS_NONE
;
9419 /* Restore delay slot state from the tb context. */
9420 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
9421 restore_cpu_state(env
, &ctx
);
9422 #ifdef CONFIG_USER_ONLY
9423 ctx
.mem_idx
= MIPS_HFLAG_UM
;
9425 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
9428 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9430 max_insns
= CF_COUNT_MASK
;
9432 qemu_log_mask(CPU_LOG_TB_CPU
, "------------------------------------------------\n");
9433 /* FIXME: This may print out stale hflags from env... */
9434 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
9436 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
9438 while (ctx
.bstate
== BS_NONE
) {
9439 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9440 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9441 if (bp
->pc
== ctx
.pc
) {
9442 save_cpu_state(&ctx
, 1);
9443 ctx
.bstate
= BS_BRANCH
;
9444 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
9445 /* Include the breakpoint location or the tb won't
9446 * be flushed when it must be. */
9448 goto done_generating
;
9454 j
= gen_opc_ptr
- gen_opc_buf
;
9458 gen_opc_instr_start
[lj
++] = 0;
9460 gen_opc_pc
[lj
] = ctx
.pc
;
9461 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
9462 gen_opc_instr_start
[lj
] = 1;
9463 gen_opc_icount
[lj
] = num_insns
;
9465 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9469 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
9470 ctx
.opcode
= ldl_code(ctx
.pc
);
9472 decode_opc(env
, &ctx
, &is_branch
);
9473 } else if (env
->insn_flags
& ASE_MIPS16
) {
9474 ctx
.opcode
= lduw_code(ctx
.pc
);
9475 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
9477 generate_exception(&ctx
, EXCP_RI
);
9481 handle_delay_slot(env
, &ctx
, insn_bytes
);
9483 ctx
.pc
+= insn_bytes
;
9487 /* Execute a branch and its delay slot as a single instruction.
9488 This is what GDB expects and is consistent with what the
9489 hardware does (e.g. if a delay slot instruction faults, the
9490 reported PC is the PC of the branch). */
9491 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
9494 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
9497 if (gen_opc_ptr
>= gen_opc_end
)
9500 if (num_insns
>= max_insns
)
9506 if (tb
->cflags
& CF_LAST_IO
)
9508 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
9509 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
9510 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
9512 switch (ctx
.bstate
) {
9514 gen_helper_interrupt_restart();
9515 gen_goto_tb(&ctx
, 0, ctx
.pc
);
9518 save_cpu_state(&ctx
, 0);
9519 gen_goto_tb(&ctx
, 0, ctx
.pc
);
9522 gen_helper_interrupt_restart();
9531 gen_icount_end(tb
, num_insns
);
9532 *gen_opc_ptr
= INDEX_op_end
;
9534 j
= gen_opc_ptr
- gen_opc_buf
;
9537 gen_opc_instr_start
[lj
++] = 0;
9539 tb
->size
= ctx
.pc
- pc_start
;
9540 tb
->icount
= num_insns
;
9544 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9545 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9546 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
9549 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
9553 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
9555 gen_intermediate_code_internal(env
, tb
, 0);
9558 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
9560 gen_intermediate_code_internal(env
, tb
, 1);
9563 static void fpu_dump_state(CPUState
*env
, FILE *f
,
9564 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9568 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
9570 #define printfpr(fp) \
9573 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
9574 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
9575 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
9578 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
9579 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
9580 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
9581 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
9582 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
9587 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
9588 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
9589 get_float_exception_flags(&env
->active_fpu
.fp_status
));
9590 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
9591 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
9592 printfpr(&env
->active_fpu
.fpr
[i
]);
9598 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
9599 /* Debug help: The architecture requires 32bit code to maintain proper
9600 sign-extended values on 64bit machines. */
9602 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
9605 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
9606 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9611 if (!SIGN_EXT_P(env
->active_tc
.PC
))
9612 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
9613 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
9614 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
9615 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
9616 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
9617 if (!SIGN_EXT_P(env
->btarget
))
9618 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
9620 for (i
= 0; i
< 32; i
++) {
9621 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
9622 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
9625 if (!SIGN_EXT_P(env
->CP0_EPC
))
9626 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
9627 if (!SIGN_EXT_P(env
->lladdr
))
9628 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
9632 void cpu_dump_state (CPUState
*env
, FILE *f
,
9633 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9638 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
9639 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
9640 env
->hflags
, env
->btarget
, env
->bcond
);
9641 for (i
= 0; i
< 32; i
++) {
9643 cpu_fprintf(f
, "GPR%02d:", i
);
9644 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
9646 cpu_fprintf(f
, "\n");
9649 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
9650 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
9651 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
9652 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
9653 if (env
->hflags
& MIPS_HFLAG_FPU
)
9654 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
9655 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
9656 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
9660 static void mips_tcg_init(void)
9665 /* Initialize various static tables. */
9669 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
9670 TCGV_UNUSED(cpu_gpr
[0]);
9671 for (i
= 1; i
< 32; i
++)
9672 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
9673 offsetof(CPUState
, active_tc
.gpr
[i
]),
9675 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
9676 offsetof(CPUState
, active_tc
.PC
), "PC");
9677 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
9678 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
9679 offsetof(CPUState
, active_tc
.HI
[i
]),
9681 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
9682 offsetof(CPUState
, active_tc
.LO
[i
]),
9684 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
9685 offsetof(CPUState
, active_tc
.ACX
[i
]),
9688 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
9689 offsetof(CPUState
, active_tc
.DSPControl
),
9691 bcond
= tcg_global_mem_new(TCG_AREG0
,
9692 offsetof(CPUState
, bcond
), "bcond");
9693 btarget
= tcg_global_mem_new(TCG_AREG0
,
9694 offsetof(CPUState
, btarget
), "btarget");
9695 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
9696 offsetof(CPUState
, hflags
), "hflags");
9698 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
9699 offsetof(CPUState
, active_fpu
.fcr0
),
9701 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
9702 offsetof(CPUState
, active_fpu
.fcr31
),
9705 /* register helpers */
9706 #define GEN_HELPER 2
9712 #include "translate_init.c"
9714 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
9717 const mips_def_t
*def
;
9719 def
= cpu_mips_find_by_name(cpu_model
);
9722 env
= qemu_mallocz(sizeof(CPUMIPSState
));
9723 env
->cpu_model
= def
;
9724 env
->cpu_model_str
= cpu_model
;
9727 #ifndef CONFIG_USER_ONLY
9734 qemu_init_vcpu(env
);
9738 void cpu_reset (CPUMIPSState
*env
)
9740 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
9741 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
9742 log_cpu_state(env
, 0);
9745 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
9748 /* Reset registers to their default values */
9749 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
9750 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
9751 #ifdef TARGET_WORDS_BIGENDIAN
9752 env
->CP0_Config0
|= (1 << CP0C0_BE
);
9754 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
9755 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
9756 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
9757 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
9758 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
9759 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
9760 << env
->cpu_model
->CP0_LLAddr_shift
;
9761 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
9762 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
9763 env
->CCRes
= env
->cpu_model
->CCRes
;
9764 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
9765 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
9766 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
9767 env
->current_tc
= 0;
9768 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
9769 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
9770 #if defined(TARGET_MIPS64)
9771 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
9772 env
->SEGMask
|= 3ULL << 62;
9775 env
->PABITS
= env
->cpu_model
->PABITS
;
9776 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
9777 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
9778 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
9779 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
9780 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
9781 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
9782 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
9783 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
9784 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
9785 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
9786 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
9787 env
->insn_flags
= env
->cpu_model
->insn_flags
;
9789 #if defined(CONFIG_USER_ONLY)
9790 env
->hflags
= MIPS_HFLAG_UM
;
9791 /* Enable access to the SYNCI_Step register. */
9792 env
->CP0_HWREna
|= (1 << 1);
9793 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9794 env
->hflags
|= MIPS_HFLAG_FPU
;
9796 #ifdef TARGET_MIPS64
9797 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
9798 env
->hflags
|= MIPS_HFLAG_F64
;
9802 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
9803 /* If the exception was raised from a delay slot,
9804 come back to the jump. */
9805 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
9807 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
9809 env
->active_tc
.PC
= (int32_t)0xBFC00000;
9810 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
9811 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
9813 /* SMP not implemented */
9814 env
->CP0_EBase
= 0x80000000;
9815 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
9816 /* vectored interrupts not implemented, timer on int 7,
9817 no performance counters. */
9818 env
->CP0_IntCtl
= 0xe0000000;
9822 for (i
= 0; i
< 7; i
++) {
9823 env
->CP0_WatchLo
[i
] = 0;
9824 env
->CP0_WatchHi
[i
] = 0x80000000;
9826 env
->CP0_WatchLo
[7] = 0;
9827 env
->CP0_WatchHi
[7] = 0;
9829 /* Count register increments in debug mode, EJTAG version 1 */
9830 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
9831 env
->hflags
= MIPS_HFLAG_CP0
;
9833 #if defined(TARGET_MIPS64)
9834 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
9835 env
->hflags
|= MIPS_HFLAG_64
;
9838 env
->exception_index
= EXCP_NONE
;
9841 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
9842 unsigned long searched_pc
, int pc_pos
, void *puc
)
9844 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
9845 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
9846 env
->hflags
|= gen_opc_hflags
[pc_pos
];