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 static uint32_t gen_opc_hflags
[OPC_BUF_SIZE
];
447 #include "gen-icount.h"
449 #define gen_helper_0i(name, arg) do { \
450 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
451 gen_helper_##name(helper_tmp); \
452 tcg_temp_free_i32(helper_tmp); \
455 #define gen_helper_1i(name, arg1, arg2) do { \
456 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
457 gen_helper_##name(arg1, helper_tmp); \
458 tcg_temp_free_i32(helper_tmp); \
461 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
462 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
463 gen_helper_##name(arg1, arg2, helper_tmp); \
464 tcg_temp_free_i32(helper_tmp); \
467 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
468 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
469 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
470 tcg_temp_free_i32(helper_tmp); \
473 typedef struct DisasContext
{
474 struct TranslationBlock
*tb
;
475 target_ulong pc
, saved_pc
;
477 int singlestep_enabled
;
478 /* Routine used to access memory */
480 uint32_t hflags
, saved_hflags
;
482 target_ulong btarget
;
486 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
487 * exception condition */
488 BS_STOP
= 1, /* We want to stop translation for any reason */
489 BS_BRANCH
= 2, /* We reached a branch condition */
490 BS_EXCP
= 3, /* We reached an exception condition */
493 static const char *regnames
[] =
494 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
495 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
496 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
497 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
499 static const char *regnames_HI
[] =
500 { "HI0", "HI1", "HI2", "HI3", };
502 static const char *regnames_LO
[] =
503 { "LO0", "LO1", "LO2", "LO3", };
505 static const char *regnames_ACX
[] =
506 { "ACX0", "ACX1", "ACX2", "ACX3", };
508 static const char *fregnames
[] =
509 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
510 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
511 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
512 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
514 #ifdef MIPS_DEBUG_DISAS
515 #define MIPS_DEBUG(fmt, ...) \
516 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
517 TARGET_FMT_lx ": %08x " fmt "\n", \
518 ctx->pc, ctx->opcode , ## __VA_ARGS__)
519 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
521 #define MIPS_DEBUG(fmt, ...) do { } while(0)
522 #define LOG_DISAS(...) do { } while (0)
525 #define MIPS_INVAL(op) \
527 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
528 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
531 /* General purpose registers moves. */
532 static inline void gen_load_gpr (TCGv t
, int reg
)
535 tcg_gen_movi_tl(t
, 0);
537 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
540 static inline void gen_store_gpr (TCGv t
, int reg
)
543 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
546 /* Moves to/from ACX register. */
547 static inline void gen_load_ACX (TCGv t
, int reg
)
549 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
552 static inline void gen_store_ACX (TCGv t
, int reg
)
554 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
557 /* Moves to/from shadow registers. */
558 static inline void gen_load_srsgpr (int from
, int to
)
560 TCGv t0
= tcg_temp_new();
563 tcg_gen_movi_tl(t0
, 0);
565 TCGv_i32 t2
= tcg_temp_new_i32();
566 TCGv_ptr addr
= tcg_temp_new_ptr();
568 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
569 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
570 tcg_gen_andi_i32(t2
, t2
, 0xf);
571 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
572 tcg_gen_ext_i32_ptr(addr
, t2
);
573 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
575 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
576 tcg_temp_free_ptr(addr
);
577 tcg_temp_free_i32(t2
);
579 gen_store_gpr(t0
, to
);
583 static inline void gen_store_srsgpr (int from
, int to
)
586 TCGv t0
= tcg_temp_new();
587 TCGv_i32 t2
= tcg_temp_new_i32();
588 TCGv_ptr addr
= tcg_temp_new_ptr();
590 gen_load_gpr(t0
, from
);
591 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
592 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
593 tcg_gen_andi_i32(t2
, t2
, 0xf);
594 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
595 tcg_gen_ext_i32_ptr(addr
, t2
);
596 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
598 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
599 tcg_temp_free_ptr(addr
);
600 tcg_temp_free_i32(t2
);
605 /* Floating point register moves. */
606 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
608 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
611 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
613 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
616 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
618 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
621 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
623 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
626 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
628 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
629 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
631 TCGv_i32 t0
= tcg_temp_new_i32();
632 TCGv_i32 t1
= tcg_temp_new_i32();
633 gen_load_fpr32(t0
, reg
& ~1);
634 gen_load_fpr32(t1
, reg
| 1);
635 tcg_gen_concat_i32_i64(t
, t0
, t1
);
636 tcg_temp_free_i32(t0
);
637 tcg_temp_free_i32(t1
);
641 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
643 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
644 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
646 TCGv_i64 t0
= tcg_temp_new_i64();
647 TCGv_i32 t1
= tcg_temp_new_i32();
648 tcg_gen_trunc_i64_i32(t1
, t
);
649 gen_store_fpr32(t1
, reg
& ~1);
650 tcg_gen_shri_i64(t0
, t
, 32);
651 tcg_gen_trunc_i64_i32(t1
, t0
);
652 gen_store_fpr32(t1
, reg
| 1);
653 tcg_temp_free_i32(t1
);
654 tcg_temp_free_i64(t0
);
658 static inline int get_fp_bit (int cc
)
666 #define FOP_CONDS(type, fmt, bits) \
667 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
668 TCGv_i##bits b, int cc) \
671 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
672 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
673 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
674 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
675 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
676 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
677 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
678 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
679 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
680 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
681 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
682 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
683 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
684 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
685 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
686 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
692 FOP_CONDS(abs
, d
, 64)
694 FOP_CONDS(abs
, s
, 32)
696 FOP_CONDS(abs
, ps
, 64)
700 static inline void gen_save_pc(target_ulong pc
)
702 tcg_gen_movi_tl(cpu_PC
, pc
);
705 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
707 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
708 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
709 gen_save_pc(ctx
->pc
);
710 ctx
->saved_pc
= ctx
->pc
;
712 if (ctx
->hflags
!= ctx
->saved_hflags
) {
713 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
714 ctx
->saved_hflags
= ctx
->hflags
;
715 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
721 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
727 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
729 ctx
->saved_hflags
= ctx
->hflags
;
730 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
736 ctx
->btarget
= env
->btarget
;
742 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
744 TCGv_i32 texcp
= tcg_const_i32(excp
);
745 TCGv_i32 terr
= tcg_const_i32(err
);
746 save_cpu_state(ctx
, 1);
747 gen_helper_raise_exception_err(texcp
, terr
);
748 tcg_temp_free_i32(terr
);
749 tcg_temp_free_i32(texcp
);
753 generate_exception (DisasContext
*ctx
, int excp
)
755 save_cpu_state(ctx
, 1);
756 gen_helper_0i(raise_exception
, excp
);
759 /* Addresses computation */
760 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
762 tcg_gen_add_tl(ret
, arg0
, arg1
);
764 #if defined(TARGET_MIPS64)
765 /* For compatibility with 32-bit code, data reference in user mode
766 with Status_UX = 0 should be casted to 32-bit and sign extended.
767 See the MIPS64 PRA manual, section 4.10. */
768 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
769 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
770 tcg_gen_ext32s_i64(ret
, ret
);
775 static inline void check_cp0_enabled(DisasContext
*ctx
)
777 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
778 generate_exception_err(ctx
, EXCP_CpU
, 0);
781 static inline void check_cp1_enabled(DisasContext
*ctx
)
783 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
784 generate_exception_err(ctx
, EXCP_CpU
, 1);
787 /* Verify that the processor is running with COP1X instructions enabled.
788 This is associated with the nabla symbol in the MIPS32 and MIPS64
791 static inline void check_cop1x(DisasContext
*ctx
)
793 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
794 generate_exception(ctx
, EXCP_RI
);
797 /* Verify that the processor is running with 64-bit floating-point
798 operations enabled. */
800 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
802 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
803 generate_exception(ctx
, EXCP_RI
);
807 * Verify if floating point register is valid; an operation is not defined
808 * if bit 0 of any register specification is set and the FR bit in the
809 * Status register equals zero, since the register numbers specify an
810 * even-odd pair of adjacent coprocessor general registers. When the FR bit
811 * in the Status register equals one, both even and odd register numbers
812 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
814 * Multiple 64 bit wide registers can be checked by calling
815 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
817 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
819 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
820 generate_exception(ctx
, EXCP_RI
);
823 /* This code generates a "reserved instruction" exception if the
824 CPU does not support the instruction set corresponding to flags. */
825 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
827 if (unlikely(!(env
->insn_flags
& flags
)))
828 generate_exception(ctx
, EXCP_RI
);
831 /* This code generates a "reserved instruction" exception if 64-bit
832 instructions are not enabled. */
833 static inline void check_mips_64(DisasContext
*ctx
)
835 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
836 generate_exception(ctx
, EXCP_RI
);
839 /* load/store instructions. */
840 #define OP_LD(insn,fname) \
841 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
843 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
850 #if defined(TARGET_MIPS64)
856 #define OP_ST(insn,fname) \
857 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
859 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
864 #if defined(TARGET_MIPS64)
869 #ifdef CONFIG_USER_ONLY
870 #define OP_LD_ATOMIC(insn,fname) \
871 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
873 TCGv t0 = tcg_temp_new(); \
874 tcg_gen_mov_tl(t0, arg1); \
875 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
876 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
877 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
881 #define OP_LD_ATOMIC(insn,fname) \
882 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
884 gen_helper_2i(insn, ret, arg1, ctx->mem_idx); \
887 OP_LD_ATOMIC(ll
,ld32s
);
888 #if defined(TARGET_MIPS64)
889 OP_LD_ATOMIC(lld
,ld64
);
893 #ifdef CONFIG_USER_ONLY
894 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
895 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
897 TCGv t0 = tcg_temp_new(); \
898 int l1 = gen_new_label(); \
899 int l2 = gen_new_label(); \
901 tcg_gen_andi_tl(t0, arg2, almask); \
902 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
903 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
904 generate_exception(ctx, EXCP_AdES); \
906 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
907 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
908 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
909 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
910 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
911 gen_helper_0i(raise_exception, EXCP_SC); \
913 tcg_gen_movi_tl(t0, 0); \
914 gen_store_gpr(t0, rt); \
918 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
919 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
921 TCGv t0 = tcg_temp_new(); \
922 gen_helper_3i(insn, t0, arg1, arg2, ctx->mem_idx); \
923 gen_store_gpr(t0, rt); \
927 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
928 #if defined(TARGET_MIPS64)
929 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
933 static void gen_base_offset_addr (DisasContext
*ctx
, TCGv addr
,
934 int base
, int16_t offset
)
937 tcg_gen_movi_tl(addr
, offset
);
938 } else if (offset
== 0) {
939 gen_load_gpr(addr
, base
);
941 tcg_gen_movi_tl(addr
, offset
);
942 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
946 static target_ulong
pc_relative_pc (DisasContext
*ctx
)
948 target_ulong pc
= ctx
->pc
;
950 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
951 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
956 pc
&= ~(target_ulong
)3;
961 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
962 int base
, int16_t offset
)
964 const char *opn
= "ldst";
965 TCGv t0
= tcg_temp_new();
966 TCGv t1
= tcg_temp_new();
968 gen_base_offset_addr(ctx
, t0
, base
, offset
);
969 /* Don't do NOP if destination is zero: we must perform the actual
972 #if defined(TARGET_MIPS64)
974 save_cpu_state(ctx
, 0);
975 op_ldst_lwu(t0
, t0
, ctx
);
976 gen_store_gpr(t0
, rt
);
980 save_cpu_state(ctx
, 0);
981 op_ldst_ld(t0
, t0
, ctx
);
982 gen_store_gpr(t0
, rt
);
986 save_cpu_state(ctx
, 0);
987 op_ldst_lld(t0
, t0
, ctx
);
988 gen_store_gpr(t0
, rt
);
992 save_cpu_state(ctx
, 0);
993 gen_load_gpr(t1
, rt
);
994 op_ldst_sd(t1
, t0
, ctx
);
998 save_cpu_state(ctx
, 1);
999 gen_load_gpr(t1
, rt
);
1000 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1001 gen_store_gpr(t1
, rt
);
1005 save_cpu_state(ctx
, 1);
1006 gen_load_gpr(t1
, rt
);
1007 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1011 save_cpu_state(ctx
, 1);
1012 gen_load_gpr(t1
, rt
);
1013 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1014 gen_store_gpr(t1
, rt
);
1018 save_cpu_state(ctx
, 1);
1019 gen_load_gpr(t1
, rt
);
1020 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1024 save_cpu_state(ctx
, 1);
1025 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1026 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1027 op_ldst_ld(t0
, t0
, ctx
);
1028 gen_store_gpr(t0
, rt
);
1032 save_cpu_state(ctx
, 1);
1033 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1034 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1035 op_ldst_lw(t0
, t0
, ctx
);
1036 gen_store_gpr(t0
, rt
);
1039 save_cpu_state(ctx
, 0);
1040 op_ldst_lw(t0
, t0
, ctx
);
1041 gen_store_gpr(t0
, rt
);
1045 save_cpu_state(ctx
, 0);
1046 gen_load_gpr(t1
, rt
);
1047 op_ldst_sw(t1
, t0
, ctx
);
1051 save_cpu_state(ctx
, 0);
1052 op_ldst_lh(t0
, t0
, ctx
);
1053 gen_store_gpr(t0
, rt
);
1057 save_cpu_state(ctx
, 0);
1058 gen_load_gpr(t1
, rt
);
1059 op_ldst_sh(t1
, t0
, ctx
);
1063 save_cpu_state(ctx
, 0);
1064 op_ldst_lhu(t0
, t0
, ctx
);
1065 gen_store_gpr(t0
, rt
);
1069 save_cpu_state(ctx
, 0);
1070 op_ldst_lb(t0
, t0
, ctx
);
1071 gen_store_gpr(t0
, rt
);
1075 save_cpu_state(ctx
, 0);
1076 gen_load_gpr(t1
, rt
);
1077 op_ldst_sb(t1
, t0
, ctx
);
1081 save_cpu_state(ctx
, 0);
1082 op_ldst_lbu(t0
, t0
, ctx
);
1083 gen_store_gpr(t0
, rt
);
1087 save_cpu_state(ctx
, 1);
1088 gen_load_gpr(t1
, rt
);
1089 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1090 gen_store_gpr(t1
, rt
);
1094 save_cpu_state(ctx
, 1);
1095 gen_load_gpr(t1
, rt
);
1096 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1100 save_cpu_state(ctx
, 1);
1101 gen_load_gpr(t1
, rt
);
1102 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1103 gen_store_gpr(t1
, rt
);
1107 save_cpu_state(ctx
, 1);
1108 gen_load_gpr(t1
, rt
);
1109 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1113 save_cpu_state(ctx
, 1);
1114 op_ldst_ll(t0
, t0
, ctx
);
1115 gen_store_gpr(t0
, rt
);
1119 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1124 /* Store conditional */
1125 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1126 int base
, int16_t offset
)
1128 const char *opn
= "st_cond";
1131 t0
= tcg_temp_local_new();
1133 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1134 /* Don't do NOP if destination is zero: we must perform the actual
1137 t1
= tcg_temp_local_new();
1138 gen_load_gpr(t1
, rt
);
1140 #if defined(TARGET_MIPS64)
1142 save_cpu_state(ctx
, 0);
1143 op_ldst_scd(t1
, t0
, rt
, ctx
);
1148 save_cpu_state(ctx
, 1);
1149 op_ldst_sc(t1
, t0
, rt
, ctx
);
1153 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1158 /* Load and store */
1159 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1160 int base
, int16_t offset
)
1162 const char *opn
= "flt_ldst";
1163 TCGv t0
= tcg_temp_new();
1165 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1166 /* Don't do NOP if destination is zero: we must perform the actual
1171 TCGv_i32 fp0
= tcg_temp_new_i32();
1173 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1174 tcg_gen_trunc_tl_i32(fp0
, t0
);
1175 gen_store_fpr32(fp0
, ft
);
1176 tcg_temp_free_i32(fp0
);
1182 TCGv_i32 fp0
= tcg_temp_new_i32();
1183 TCGv t1
= tcg_temp_new();
1185 gen_load_fpr32(fp0
, ft
);
1186 tcg_gen_extu_i32_tl(t1
, fp0
);
1187 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1189 tcg_temp_free_i32(fp0
);
1195 TCGv_i64 fp0
= tcg_temp_new_i64();
1197 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1198 gen_store_fpr64(ctx
, fp0
, ft
);
1199 tcg_temp_free_i64(fp0
);
1205 TCGv_i64 fp0
= tcg_temp_new_i64();
1207 gen_load_fpr64(ctx
, fp0
, ft
);
1208 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1209 tcg_temp_free_i64(fp0
);
1215 generate_exception(ctx
, EXCP_RI
);
1218 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1223 /* Arithmetic with immediate operand */
1224 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1225 int rt
, int rs
, int16_t imm
)
1227 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1228 const char *opn
= "imm arith";
1230 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1231 /* If no destination, treat it as a NOP.
1232 For addi, we must generate the overflow exception when needed. */
1239 TCGv t0
= tcg_temp_local_new();
1240 TCGv t1
= tcg_temp_new();
1241 TCGv t2
= tcg_temp_new();
1242 int l1
= gen_new_label();
1244 gen_load_gpr(t1
, rs
);
1245 tcg_gen_addi_tl(t0
, t1
, uimm
);
1246 tcg_gen_ext32s_tl(t0
, t0
);
1248 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1249 tcg_gen_xori_tl(t2
, t0
, uimm
);
1250 tcg_gen_and_tl(t1
, t1
, t2
);
1252 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1254 /* operands of same sign, result different sign */
1255 generate_exception(ctx
, EXCP_OVERFLOW
);
1257 tcg_gen_ext32s_tl(t0
, t0
);
1258 gen_store_gpr(t0
, rt
);
1265 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1266 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1268 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1272 #if defined(TARGET_MIPS64)
1275 TCGv t0
= tcg_temp_local_new();
1276 TCGv t1
= tcg_temp_new();
1277 TCGv t2
= tcg_temp_new();
1278 int l1
= gen_new_label();
1280 gen_load_gpr(t1
, rs
);
1281 tcg_gen_addi_tl(t0
, t1
, uimm
);
1283 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1284 tcg_gen_xori_tl(t2
, t0
, uimm
);
1285 tcg_gen_and_tl(t1
, t1
, t2
);
1287 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1289 /* operands of same sign, result different sign */
1290 generate_exception(ctx
, EXCP_OVERFLOW
);
1292 gen_store_gpr(t0
, rt
);
1299 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1301 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1307 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1310 /* Logic with immediate operand */
1311 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1314 const char *opn
= "imm logic";
1317 /* If no destination, treat it as a NOP. */
1321 uimm
= (uint16_t)imm
;
1324 if (likely(rs
!= 0))
1325 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1327 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1332 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1334 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1338 if (likely(rs
!= 0))
1339 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1341 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1345 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1349 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1352 /* Set on less than with immediate operand */
1353 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1355 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1356 const char *opn
= "imm arith";
1360 /* If no destination, treat it as a NOP. */
1364 t0
= tcg_temp_new();
1365 gen_load_gpr(t0
, rs
);
1368 tcg_gen_setcondi_tl(TCG_COND_LT
, cpu_gpr
[rt
], t0
, uimm
);
1372 tcg_gen_setcondi_tl(TCG_COND_LTU
, cpu_gpr
[rt
], t0
, uimm
);
1376 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1380 /* Shifts with immediate operand */
1381 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1382 int rt
, int rs
, int16_t imm
)
1384 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1385 const char *opn
= "imm shift";
1389 /* If no destination, treat it as a NOP. */
1394 t0
= tcg_temp_new();
1395 gen_load_gpr(t0
, rs
);
1398 tcg_gen_shli_tl(t0
, t0
, uimm
);
1399 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1403 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1408 tcg_gen_ext32u_tl(t0
, t0
);
1409 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1411 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1417 TCGv_i32 t1
= tcg_temp_new_i32();
1419 tcg_gen_trunc_tl_i32(t1
, t0
);
1420 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1421 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1422 tcg_temp_free_i32(t1
);
1424 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1428 #if defined(TARGET_MIPS64)
1430 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1434 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1438 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1443 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1445 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
1450 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1454 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1458 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1462 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1467 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1472 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1473 int rd
, int rs
, int rt
)
1475 const char *opn
= "arith";
1477 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1478 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1479 /* If no destination, treat it as a NOP.
1480 For add & sub, we must generate the overflow exception when needed. */
1488 TCGv t0
= tcg_temp_local_new();
1489 TCGv t1
= tcg_temp_new();
1490 TCGv t2
= tcg_temp_new();
1491 int l1
= gen_new_label();
1493 gen_load_gpr(t1
, rs
);
1494 gen_load_gpr(t2
, rt
);
1495 tcg_gen_add_tl(t0
, t1
, t2
);
1496 tcg_gen_ext32s_tl(t0
, t0
);
1497 tcg_gen_xor_tl(t1
, t1
, t2
);
1498 tcg_gen_xor_tl(t2
, t0
, t2
);
1499 tcg_gen_andc_tl(t1
, t2
, t1
);
1501 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1503 /* operands of same sign, result different sign */
1504 generate_exception(ctx
, EXCP_OVERFLOW
);
1506 gen_store_gpr(t0
, rd
);
1512 if (rs
!= 0 && rt
!= 0) {
1513 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1514 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1515 } else if (rs
== 0 && rt
!= 0) {
1516 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1517 } else if (rs
!= 0 && rt
== 0) {
1518 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1520 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1526 TCGv t0
= tcg_temp_local_new();
1527 TCGv t1
= tcg_temp_new();
1528 TCGv t2
= tcg_temp_new();
1529 int l1
= gen_new_label();
1531 gen_load_gpr(t1
, rs
);
1532 gen_load_gpr(t2
, rt
);
1533 tcg_gen_sub_tl(t0
, t1
, t2
);
1534 tcg_gen_ext32s_tl(t0
, t0
);
1535 tcg_gen_xor_tl(t2
, t1
, t2
);
1536 tcg_gen_xor_tl(t1
, t0
, t1
);
1537 tcg_gen_and_tl(t1
, t1
, t2
);
1539 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1541 /* operands of different sign, first operand and result different sign */
1542 generate_exception(ctx
, EXCP_OVERFLOW
);
1544 gen_store_gpr(t0
, rd
);
1550 if (rs
!= 0 && rt
!= 0) {
1551 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1552 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1553 } else if (rs
== 0 && rt
!= 0) {
1554 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1555 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1556 } else if (rs
!= 0 && rt
== 0) {
1557 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1559 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1563 #if defined(TARGET_MIPS64)
1566 TCGv t0
= tcg_temp_local_new();
1567 TCGv t1
= tcg_temp_new();
1568 TCGv t2
= tcg_temp_new();
1569 int l1
= gen_new_label();
1571 gen_load_gpr(t1
, rs
);
1572 gen_load_gpr(t2
, rt
);
1573 tcg_gen_add_tl(t0
, t1
, t2
);
1574 tcg_gen_xor_tl(t1
, t1
, t2
);
1575 tcg_gen_xor_tl(t2
, t0
, t2
);
1576 tcg_gen_andc_tl(t1
, t2
, t1
);
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_nor_i32(t0
, t0
, t1
);
5637 tcg_temp_free_i32(t1
);
5638 tcg_gen_andi_i32(t0
, t0
, 1);
5639 tcg_gen_extu_i32_tl(bcond
, t0
);
5645 TCGv_i32 t1
= tcg_temp_new_i32();
5646 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5647 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5648 tcg_gen_or_i32(t0
, t0
, t1
);
5649 tcg_temp_free_i32(t1
);
5650 tcg_gen_andi_i32(t0
, t0
, 1);
5651 tcg_gen_extu_i32_tl(bcond
, t0
);
5657 TCGv_i32 t1
= tcg_temp_new_i32();
5658 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5659 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5660 tcg_gen_or_i32(t0
, t0
, t1
);
5661 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5662 tcg_gen_or_i32(t0
, t0
, t1
);
5663 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5664 tcg_gen_nor_i32(t0
, t0
, t1
);
5665 tcg_temp_free_i32(t1
);
5666 tcg_gen_andi_i32(t0
, t0
, 1);
5667 tcg_gen_extu_i32_tl(bcond
, t0
);
5673 TCGv_i32 t1
= tcg_temp_new_i32();
5674 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5675 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5676 tcg_gen_or_i32(t0
, t0
, t1
);
5677 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5678 tcg_gen_or_i32(t0
, t0
, t1
);
5679 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5680 tcg_gen_or_i32(t0
, t0
, t1
);
5681 tcg_temp_free_i32(t1
);
5682 tcg_gen_andi_i32(t0
, t0
, 1);
5683 tcg_gen_extu_i32_tl(bcond
, t0
);
5687 ctx
->hflags
|= MIPS_HFLAG_BC
;
5691 generate_exception (ctx
, EXCP_RI
);
5694 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5695 ctx
->hflags
, btarget
);
5696 ctx
->btarget
= btarget
;
5699 tcg_temp_free_i32(t0
);
5702 /* Coprocessor 1 (FPU) */
5704 #define FOP(func, fmt) (((fmt) << 21) | (func))
5706 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5708 const char *opn
= "cp1 move";
5709 TCGv t0
= tcg_temp_new();
5714 TCGv_i32 fp0
= tcg_temp_new_i32();
5716 gen_load_fpr32(fp0
, fs
);
5717 tcg_gen_ext_i32_tl(t0
, fp0
);
5718 tcg_temp_free_i32(fp0
);
5720 gen_store_gpr(t0
, rt
);
5724 gen_load_gpr(t0
, rt
);
5726 TCGv_i32 fp0
= tcg_temp_new_i32();
5728 tcg_gen_trunc_tl_i32(fp0
, t0
);
5729 gen_store_fpr32(fp0
, fs
);
5730 tcg_temp_free_i32(fp0
);
5735 gen_helper_1i(cfc1
, t0
, fs
);
5736 gen_store_gpr(t0
, rt
);
5740 gen_load_gpr(t0
, rt
);
5741 gen_helper_1i(ctc1
, t0
, fs
);
5744 #if defined(TARGET_MIPS64)
5746 gen_load_fpr64(ctx
, t0
, fs
);
5747 gen_store_gpr(t0
, rt
);
5751 gen_load_gpr(t0
, rt
);
5752 gen_store_fpr64(ctx
, t0
, fs
);
5758 TCGv_i32 fp0
= tcg_temp_new_i32();
5760 gen_load_fpr32h(fp0
, fs
);
5761 tcg_gen_ext_i32_tl(t0
, fp0
);
5762 tcg_temp_free_i32(fp0
);
5764 gen_store_gpr(t0
, rt
);
5768 gen_load_gpr(t0
, rt
);
5770 TCGv_i32 fp0
= tcg_temp_new_i32();
5772 tcg_gen_trunc_tl_i32(fp0
, t0
);
5773 gen_store_fpr32h(fp0
, fs
);
5774 tcg_temp_free_i32(fp0
);
5780 generate_exception (ctx
, EXCP_RI
);
5783 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5789 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5805 l1
= gen_new_label();
5806 t0
= tcg_temp_new_i32();
5807 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5808 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5809 tcg_temp_free_i32(t0
);
5811 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
5813 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
5818 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5821 TCGv_i32 t0
= tcg_temp_new_i32();
5822 int l1
= gen_new_label();
5829 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5830 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5831 gen_load_fpr32(t0
, fs
);
5832 gen_store_fpr32(t0
, fd
);
5834 tcg_temp_free_i32(t0
);
5837 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5840 TCGv_i32 t0
= tcg_temp_new_i32();
5842 int l1
= gen_new_label();
5849 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5850 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5851 tcg_temp_free_i32(t0
);
5852 fp0
= tcg_temp_new_i64();
5853 gen_load_fpr64(ctx
, fp0
, fs
);
5854 gen_store_fpr64(ctx
, fp0
, fd
);
5855 tcg_temp_free_i64(fp0
);
5859 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5862 TCGv_i32 t0
= tcg_temp_new_i32();
5863 int l1
= gen_new_label();
5864 int l2
= gen_new_label();
5871 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5872 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5873 gen_load_fpr32(t0
, fs
);
5874 gen_store_fpr32(t0
, fd
);
5877 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
5878 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
5879 gen_load_fpr32h(t0
, fs
);
5880 gen_store_fpr32h(t0
, fd
);
5881 tcg_temp_free_i32(t0
);
5886 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5887 int ft
, int fs
, int fd
, int cc
)
5889 const char *opn
= "farith";
5890 const char *condnames
[] = {
5908 const char *condnames_abs
[] = {
5926 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5927 uint32_t func
= ctx
->opcode
& 0x3f;
5929 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5932 TCGv_i32 fp0
= tcg_temp_new_i32();
5933 TCGv_i32 fp1
= tcg_temp_new_i32();
5935 gen_load_fpr32(fp0
, fs
);
5936 gen_load_fpr32(fp1
, ft
);
5937 gen_helper_float_add_s(fp0
, fp0
, fp1
);
5938 tcg_temp_free_i32(fp1
);
5939 gen_store_fpr32(fp0
, fd
);
5940 tcg_temp_free_i32(fp0
);
5947 TCGv_i32 fp0
= tcg_temp_new_i32();
5948 TCGv_i32 fp1
= tcg_temp_new_i32();
5950 gen_load_fpr32(fp0
, fs
);
5951 gen_load_fpr32(fp1
, ft
);
5952 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
5953 tcg_temp_free_i32(fp1
);
5954 gen_store_fpr32(fp0
, fd
);
5955 tcg_temp_free_i32(fp0
);
5962 TCGv_i32 fp0
= tcg_temp_new_i32();
5963 TCGv_i32 fp1
= tcg_temp_new_i32();
5965 gen_load_fpr32(fp0
, fs
);
5966 gen_load_fpr32(fp1
, ft
);
5967 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
5968 tcg_temp_free_i32(fp1
);
5969 gen_store_fpr32(fp0
, fd
);
5970 tcg_temp_free_i32(fp0
);
5977 TCGv_i32 fp0
= tcg_temp_new_i32();
5978 TCGv_i32 fp1
= tcg_temp_new_i32();
5980 gen_load_fpr32(fp0
, fs
);
5981 gen_load_fpr32(fp1
, ft
);
5982 gen_helper_float_div_s(fp0
, fp0
, fp1
);
5983 tcg_temp_free_i32(fp1
);
5984 gen_store_fpr32(fp0
, fd
);
5985 tcg_temp_free_i32(fp0
);
5992 TCGv_i32 fp0
= tcg_temp_new_i32();
5994 gen_load_fpr32(fp0
, fs
);
5995 gen_helper_float_sqrt_s(fp0
, fp0
);
5996 gen_store_fpr32(fp0
, fd
);
5997 tcg_temp_free_i32(fp0
);
6003 TCGv_i32 fp0
= tcg_temp_new_i32();
6005 gen_load_fpr32(fp0
, fs
);
6006 gen_helper_float_abs_s(fp0
, fp0
);
6007 gen_store_fpr32(fp0
, fd
);
6008 tcg_temp_free_i32(fp0
);
6014 TCGv_i32 fp0
= tcg_temp_new_i32();
6016 gen_load_fpr32(fp0
, fs
);
6017 gen_store_fpr32(fp0
, fd
);
6018 tcg_temp_free_i32(fp0
);
6024 TCGv_i32 fp0
= tcg_temp_new_i32();
6026 gen_load_fpr32(fp0
, fs
);
6027 gen_helper_float_chs_s(fp0
, fp0
);
6028 gen_store_fpr32(fp0
, fd
);
6029 tcg_temp_free_i32(fp0
);
6034 check_cp1_64bitmode(ctx
);
6036 TCGv_i32 fp32
= tcg_temp_new_i32();
6037 TCGv_i64 fp64
= tcg_temp_new_i64();
6039 gen_load_fpr32(fp32
, fs
);
6040 gen_helper_float_roundl_s(fp64
, fp32
);
6041 tcg_temp_free_i32(fp32
);
6042 gen_store_fpr64(ctx
, fp64
, fd
);
6043 tcg_temp_free_i64(fp64
);
6048 check_cp1_64bitmode(ctx
);
6050 TCGv_i32 fp32
= tcg_temp_new_i32();
6051 TCGv_i64 fp64
= tcg_temp_new_i64();
6053 gen_load_fpr32(fp32
, fs
);
6054 gen_helper_float_truncl_s(fp64
, fp32
);
6055 tcg_temp_free_i32(fp32
);
6056 gen_store_fpr64(ctx
, fp64
, fd
);
6057 tcg_temp_free_i64(fp64
);
6062 check_cp1_64bitmode(ctx
);
6064 TCGv_i32 fp32
= tcg_temp_new_i32();
6065 TCGv_i64 fp64
= tcg_temp_new_i64();
6067 gen_load_fpr32(fp32
, fs
);
6068 gen_helper_float_ceill_s(fp64
, fp32
);
6069 tcg_temp_free_i32(fp32
);
6070 gen_store_fpr64(ctx
, fp64
, fd
);
6071 tcg_temp_free_i64(fp64
);
6076 check_cp1_64bitmode(ctx
);
6078 TCGv_i32 fp32
= tcg_temp_new_i32();
6079 TCGv_i64 fp64
= tcg_temp_new_i64();
6081 gen_load_fpr32(fp32
, fs
);
6082 gen_helper_float_floorl_s(fp64
, fp32
);
6083 tcg_temp_free_i32(fp32
);
6084 gen_store_fpr64(ctx
, fp64
, fd
);
6085 tcg_temp_free_i64(fp64
);
6091 TCGv_i32 fp0
= tcg_temp_new_i32();
6093 gen_load_fpr32(fp0
, fs
);
6094 gen_helper_float_roundw_s(fp0
, fp0
);
6095 gen_store_fpr32(fp0
, fd
);
6096 tcg_temp_free_i32(fp0
);
6102 TCGv_i32 fp0
= tcg_temp_new_i32();
6104 gen_load_fpr32(fp0
, fs
);
6105 gen_helper_float_truncw_s(fp0
, fp0
);
6106 gen_store_fpr32(fp0
, fd
);
6107 tcg_temp_free_i32(fp0
);
6113 TCGv_i32 fp0
= tcg_temp_new_i32();
6115 gen_load_fpr32(fp0
, fs
);
6116 gen_helper_float_ceilw_s(fp0
, fp0
);
6117 gen_store_fpr32(fp0
, fd
);
6118 tcg_temp_free_i32(fp0
);
6124 TCGv_i32 fp0
= tcg_temp_new_i32();
6126 gen_load_fpr32(fp0
, fs
);
6127 gen_helper_float_floorw_s(fp0
, fp0
);
6128 gen_store_fpr32(fp0
, fd
);
6129 tcg_temp_free_i32(fp0
);
6134 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6139 int l1
= gen_new_label();
6143 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6145 fp0
= tcg_temp_new_i32();
6146 gen_load_fpr32(fp0
, fs
);
6147 gen_store_fpr32(fp0
, fd
);
6148 tcg_temp_free_i32(fp0
);
6155 int l1
= gen_new_label();
6159 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6160 fp0
= tcg_temp_new_i32();
6161 gen_load_fpr32(fp0
, fs
);
6162 gen_store_fpr32(fp0
, fd
);
6163 tcg_temp_free_i32(fp0
);
6172 TCGv_i32 fp0
= tcg_temp_new_i32();
6174 gen_load_fpr32(fp0
, fs
);
6175 gen_helper_float_recip_s(fp0
, fp0
);
6176 gen_store_fpr32(fp0
, fd
);
6177 tcg_temp_free_i32(fp0
);
6184 TCGv_i32 fp0
= tcg_temp_new_i32();
6186 gen_load_fpr32(fp0
, fs
);
6187 gen_helper_float_rsqrt_s(fp0
, fp0
);
6188 gen_store_fpr32(fp0
, fd
);
6189 tcg_temp_free_i32(fp0
);
6194 check_cp1_64bitmode(ctx
);
6196 TCGv_i32 fp0
= tcg_temp_new_i32();
6197 TCGv_i32 fp1
= tcg_temp_new_i32();
6199 gen_load_fpr32(fp0
, fs
);
6200 gen_load_fpr32(fp1
, fd
);
6201 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6202 tcg_temp_free_i32(fp1
);
6203 gen_store_fpr32(fp0
, fd
);
6204 tcg_temp_free_i32(fp0
);
6209 check_cp1_64bitmode(ctx
);
6211 TCGv_i32 fp0
= tcg_temp_new_i32();
6213 gen_load_fpr32(fp0
, fs
);
6214 gen_helper_float_recip1_s(fp0
, fp0
);
6215 gen_store_fpr32(fp0
, fd
);
6216 tcg_temp_free_i32(fp0
);
6221 check_cp1_64bitmode(ctx
);
6223 TCGv_i32 fp0
= tcg_temp_new_i32();
6225 gen_load_fpr32(fp0
, fs
);
6226 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6227 gen_store_fpr32(fp0
, fd
);
6228 tcg_temp_free_i32(fp0
);
6233 check_cp1_64bitmode(ctx
);
6235 TCGv_i32 fp0
= tcg_temp_new_i32();
6236 TCGv_i32 fp1
= tcg_temp_new_i32();
6238 gen_load_fpr32(fp0
, fs
);
6239 gen_load_fpr32(fp1
, ft
);
6240 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6241 tcg_temp_free_i32(fp1
);
6242 gen_store_fpr32(fp0
, fd
);
6243 tcg_temp_free_i32(fp0
);
6248 check_cp1_registers(ctx
, fd
);
6250 TCGv_i32 fp32
= tcg_temp_new_i32();
6251 TCGv_i64 fp64
= tcg_temp_new_i64();
6253 gen_load_fpr32(fp32
, fs
);
6254 gen_helper_float_cvtd_s(fp64
, fp32
);
6255 tcg_temp_free_i32(fp32
);
6256 gen_store_fpr64(ctx
, fp64
, fd
);
6257 tcg_temp_free_i64(fp64
);
6263 TCGv_i32 fp0
= tcg_temp_new_i32();
6265 gen_load_fpr32(fp0
, fs
);
6266 gen_helper_float_cvtw_s(fp0
, fp0
);
6267 gen_store_fpr32(fp0
, fd
);
6268 tcg_temp_free_i32(fp0
);
6273 check_cp1_64bitmode(ctx
);
6275 TCGv_i32 fp32
= tcg_temp_new_i32();
6276 TCGv_i64 fp64
= tcg_temp_new_i64();
6278 gen_load_fpr32(fp32
, fs
);
6279 gen_helper_float_cvtl_s(fp64
, fp32
);
6280 tcg_temp_free_i32(fp32
);
6281 gen_store_fpr64(ctx
, fp64
, fd
);
6282 tcg_temp_free_i64(fp64
);
6287 check_cp1_64bitmode(ctx
);
6289 TCGv_i64 fp64
= tcg_temp_new_i64();
6290 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6291 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6293 gen_load_fpr32(fp32_0
, fs
);
6294 gen_load_fpr32(fp32_1
, ft
);
6295 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6296 tcg_temp_free_i32(fp32_1
);
6297 tcg_temp_free_i32(fp32_0
);
6298 gen_store_fpr64(ctx
, fp64
, fd
);
6299 tcg_temp_free_i64(fp64
);
6320 TCGv_i32 fp0
= tcg_temp_new_i32();
6321 TCGv_i32 fp1
= tcg_temp_new_i32();
6323 gen_load_fpr32(fp0
, fs
);
6324 gen_load_fpr32(fp1
, ft
);
6325 if (ctx
->opcode
& (1 << 6)) {
6327 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6328 opn
= condnames_abs
[func
-48];
6330 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6331 opn
= condnames
[func
-48];
6333 tcg_temp_free_i32(fp0
);
6334 tcg_temp_free_i32(fp1
);
6338 check_cp1_registers(ctx
, fs
| ft
| fd
);
6340 TCGv_i64 fp0
= tcg_temp_new_i64();
6341 TCGv_i64 fp1
= tcg_temp_new_i64();
6343 gen_load_fpr64(ctx
, fp0
, fs
);
6344 gen_load_fpr64(ctx
, fp1
, ft
);
6345 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6346 tcg_temp_free_i64(fp1
);
6347 gen_store_fpr64(ctx
, fp0
, fd
);
6348 tcg_temp_free_i64(fp0
);
6354 check_cp1_registers(ctx
, fs
| ft
| fd
);
6356 TCGv_i64 fp0
= tcg_temp_new_i64();
6357 TCGv_i64 fp1
= tcg_temp_new_i64();
6359 gen_load_fpr64(ctx
, fp0
, fs
);
6360 gen_load_fpr64(ctx
, fp1
, ft
);
6361 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6362 tcg_temp_free_i64(fp1
);
6363 gen_store_fpr64(ctx
, fp0
, fd
);
6364 tcg_temp_free_i64(fp0
);
6370 check_cp1_registers(ctx
, fs
| ft
| fd
);
6372 TCGv_i64 fp0
= tcg_temp_new_i64();
6373 TCGv_i64 fp1
= tcg_temp_new_i64();
6375 gen_load_fpr64(ctx
, fp0
, fs
);
6376 gen_load_fpr64(ctx
, fp1
, ft
);
6377 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6378 tcg_temp_free_i64(fp1
);
6379 gen_store_fpr64(ctx
, fp0
, fd
);
6380 tcg_temp_free_i64(fp0
);
6386 check_cp1_registers(ctx
, fs
| ft
| fd
);
6388 TCGv_i64 fp0
= tcg_temp_new_i64();
6389 TCGv_i64 fp1
= tcg_temp_new_i64();
6391 gen_load_fpr64(ctx
, fp0
, fs
);
6392 gen_load_fpr64(ctx
, fp1
, ft
);
6393 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6394 tcg_temp_free_i64(fp1
);
6395 gen_store_fpr64(ctx
, fp0
, fd
);
6396 tcg_temp_free_i64(fp0
);
6402 check_cp1_registers(ctx
, fs
| fd
);
6404 TCGv_i64 fp0
= tcg_temp_new_i64();
6406 gen_load_fpr64(ctx
, fp0
, fs
);
6407 gen_helper_float_sqrt_d(fp0
, fp0
);
6408 gen_store_fpr64(ctx
, fp0
, fd
);
6409 tcg_temp_free_i64(fp0
);
6414 check_cp1_registers(ctx
, fs
| fd
);
6416 TCGv_i64 fp0
= tcg_temp_new_i64();
6418 gen_load_fpr64(ctx
, fp0
, fs
);
6419 gen_helper_float_abs_d(fp0
, fp0
);
6420 gen_store_fpr64(ctx
, fp0
, fd
);
6421 tcg_temp_free_i64(fp0
);
6426 check_cp1_registers(ctx
, fs
| fd
);
6428 TCGv_i64 fp0
= tcg_temp_new_i64();
6430 gen_load_fpr64(ctx
, fp0
, fs
);
6431 gen_store_fpr64(ctx
, fp0
, fd
);
6432 tcg_temp_free_i64(fp0
);
6437 check_cp1_registers(ctx
, fs
| fd
);
6439 TCGv_i64 fp0
= tcg_temp_new_i64();
6441 gen_load_fpr64(ctx
, fp0
, fs
);
6442 gen_helper_float_chs_d(fp0
, fp0
);
6443 gen_store_fpr64(ctx
, fp0
, fd
);
6444 tcg_temp_free_i64(fp0
);
6449 check_cp1_64bitmode(ctx
);
6451 TCGv_i64 fp0
= tcg_temp_new_i64();
6453 gen_load_fpr64(ctx
, fp0
, fs
);
6454 gen_helper_float_roundl_d(fp0
, fp0
);
6455 gen_store_fpr64(ctx
, fp0
, fd
);
6456 tcg_temp_free_i64(fp0
);
6461 check_cp1_64bitmode(ctx
);
6463 TCGv_i64 fp0
= tcg_temp_new_i64();
6465 gen_load_fpr64(ctx
, fp0
, fs
);
6466 gen_helper_float_truncl_d(fp0
, fp0
);
6467 gen_store_fpr64(ctx
, fp0
, fd
);
6468 tcg_temp_free_i64(fp0
);
6473 check_cp1_64bitmode(ctx
);
6475 TCGv_i64 fp0
= tcg_temp_new_i64();
6477 gen_load_fpr64(ctx
, fp0
, fs
);
6478 gen_helper_float_ceill_d(fp0
, fp0
);
6479 gen_store_fpr64(ctx
, fp0
, fd
);
6480 tcg_temp_free_i64(fp0
);
6485 check_cp1_64bitmode(ctx
);
6487 TCGv_i64 fp0
= tcg_temp_new_i64();
6489 gen_load_fpr64(ctx
, fp0
, fs
);
6490 gen_helper_float_floorl_d(fp0
, fp0
);
6491 gen_store_fpr64(ctx
, fp0
, fd
);
6492 tcg_temp_free_i64(fp0
);
6497 check_cp1_registers(ctx
, fs
);
6499 TCGv_i32 fp32
= tcg_temp_new_i32();
6500 TCGv_i64 fp64
= tcg_temp_new_i64();
6502 gen_load_fpr64(ctx
, fp64
, fs
);
6503 gen_helper_float_roundw_d(fp32
, fp64
);
6504 tcg_temp_free_i64(fp64
);
6505 gen_store_fpr32(fp32
, fd
);
6506 tcg_temp_free_i32(fp32
);
6511 check_cp1_registers(ctx
, fs
);
6513 TCGv_i32 fp32
= tcg_temp_new_i32();
6514 TCGv_i64 fp64
= tcg_temp_new_i64();
6516 gen_load_fpr64(ctx
, fp64
, fs
);
6517 gen_helper_float_truncw_d(fp32
, fp64
);
6518 tcg_temp_free_i64(fp64
);
6519 gen_store_fpr32(fp32
, fd
);
6520 tcg_temp_free_i32(fp32
);
6525 check_cp1_registers(ctx
, fs
);
6527 TCGv_i32 fp32
= tcg_temp_new_i32();
6528 TCGv_i64 fp64
= tcg_temp_new_i64();
6530 gen_load_fpr64(ctx
, fp64
, fs
);
6531 gen_helper_float_ceilw_d(fp32
, fp64
);
6532 tcg_temp_free_i64(fp64
);
6533 gen_store_fpr32(fp32
, fd
);
6534 tcg_temp_free_i32(fp32
);
6539 check_cp1_registers(ctx
, fs
);
6541 TCGv_i32 fp32
= tcg_temp_new_i32();
6542 TCGv_i64 fp64
= tcg_temp_new_i64();
6544 gen_load_fpr64(ctx
, fp64
, fs
);
6545 gen_helper_float_floorw_d(fp32
, fp64
);
6546 tcg_temp_free_i64(fp64
);
6547 gen_store_fpr32(fp32
, fd
);
6548 tcg_temp_free_i32(fp32
);
6553 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6558 int l1
= gen_new_label();
6562 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6564 fp0
= tcg_temp_new_i64();
6565 gen_load_fpr64(ctx
, fp0
, fs
);
6566 gen_store_fpr64(ctx
, fp0
, fd
);
6567 tcg_temp_free_i64(fp0
);
6574 int l1
= gen_new_label();
6578 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6579 fp0
= tcg_temp_new_i64();
6580 gen_load_fpr64(ctx
, fp0
, fs
);
6581 gen_store_fpr64(ctx
, fp0
, fd
);
6582 tcg_temp_free_i64(fp0
);
6589 check_cp1_64bitmode(ctx
);
6591 TCGv_i64 fp0
= tcg_temp_new_i64();
6593 gen_load_fpr64(ctx
, fp0
, fs
);
6594 gen_helper_float_recip_d(fp0
, fp0
);
6595 gen_store_fpr64(ctx
, fp0
, fd
);
6596 tcg_temp_free_i64(fp0
);
6601 check_cp1_64bitmode(ctx
);
6603 TCGv_i64 fp0
= tcg_temp_new_i64();
6605 gen_load_fpr64(ctx
, fp0
, fs
);
6606 gen_helper_float_rsqrt_d(fp0
, fp0
);
6607 gen_store_fpr64(ctx
, fp0
, fd
);
6608 tcg_temp_free_i64(fp0
);
6613 check_cp1_64bitmode(ctx
);
6615 TCGv_i64 fp0
= tcg_temp_new_i64();
6616 TCGv_i64 fp1
= tcg_temp_new_i64();
6618 gen_load_fpr64(ctx
, fp0
, fs
);
6619 gen_load_fpr64(ctx
, fp1
, ft
);
6620 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6621 tcg_temp_free_i64(fp1
);
6622 gen_store_fpr64(ctx
, fp0
, fd
);
6623 tcg_temp_free_i64(fp0
);
6628 check_cp1_64bitmode(ctx
);
6630 TCGv_i64 fp0
= tcg_temp_new_i64();
6632 gen_load_fpr64(ctx
, fp0
, fs
);
6633 gen_helper_float_recip1_d(fp0
, fp0
);
6634 gen_store_fpr64(ctx
, fp0
, fd
);
6635 tcg_temp_free_i64(fp0
);
6640 check_cp1_64bitmode(ctx
);
6642 TCGv_i64 fp0
= tcg_temp_new_i64();
6644 gen_load_fpr64(ctx
, fp0
, fs
);
6645 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6646 gen_store_fpr64(ctx
, fp0
, fd
);
6647 tcg_temp_free_i64(fp0
);
6652 check_cp1_64bitmode(ctx
);
6654 TCGv_i64 fp0
= tcg_temp_new_i64();
6655 TCGv_i64 fp1
= tcg_temp_new_i64();
6657 gen_load_fpr64(ctx
, fp0
, fs
);
6658 gen_load_fpr64(ctx
, fp1
, ft
);
6659 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6660 tcg_temp_free_i64(fp1
);
6661 gen_store_fpr64(ctx
, fp0
, fd
);
6662 tcg_temp_free_i64(fp0
);
6683 TCGv_i64 fp0
= tcg_temp_new_i64();
6684 TCGv_i64 fp1
= tcg_temp_new_i64();
6686 gen_load_fpr64(ctx
, fp0
, fs
);
6687 gen_load_fpr64(ctx
, fp1
, ft
);
6688 if (ctx
->opcode
& (1 << 6)) {
6690 check_cp1_registers(ctx
, fs
| ft
);
6691 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6692 opn
= condnames_abs
[func
-48];
6694 check_cp1_registers(ctx
, fs
| ft
);
6695 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6696 opn
= condnames
[func
-48];
6698 tcg_temp_free_i64(fp0
);
6699 tcg_temp_free_i64(fp1
);
6703 check_cp1_registers(ctx
, fs
);
6705 TCGv_i32 fp32
= tcg_temp_new_i32();
6706 TCGv_i64 fp64
= tcg_temp_new_i64();
6708 gen_load_fpr64(ctx
, fp64
, fs
);
6709 gen_helper_float_cvts_d(fp32
, fp64
);
6710 tcg_temp_free_i64(fp64
);
6711 gen_store_fpr32(fp32
, fd
);
6712 tcg_temp_free_i32(fp32
);
6717 check_cp1_registers(ctx
, fs
);
6719 TCGv_i32 fp32
= tcg_temp_new_i32();
6720 TCGv_i64 fp64
= tcg_temp_new_i64();
6722 gen_load_fpr64(ctx
, fp64
, fs
);
6723 gen_helper_float_cvtw_d(fp32
, fp64
);
6724 tcg_temp_free_i64(fp64
);
6725 gen_store_fpr32(fp32
, fd
);
6726 tcg_temp_free_i32(fp32
);
6731 check_cp1_64bitmode(ctx
);
6733 TCGv_i64 fp0
= tcg_temp_new_i64();
6735 gen_load_fpr64(ctx
, fp0
, fs
);
6736 gen_helper_float_cvtl_d(fp0
, fp0
);
6737 gen_store_fpr64(ctx
, fp0
, fd
);
6738 tcg_temp_free_i64(fp0
);
6744 TCGv_i32 fp0
= tcg_temp_new_i32();
6746 gen_load_fpr32(fp0
, fs
);
6747 gen_helper_float_cvts_w(fp0
, fp0
);
6748 gen_store_fpr32(fp0
, fd
);
6749 tcg_temp_free_i32(fp0
);
6754 check_cp1_registers(ctx
, fd
);
6756 TCGv_i32 fp32
= tcg_temp_new_i32();
6757 TCGv_i64 fp64
= tcg_temp_new_i64();
6759 gen_load_fpr32(fp32
, fs
);
6760 gen_helper_float_cvtd_w(fp64
, fp32
);
6761 tcg_temp_free_i32(fp32
);
6762 gen_store_fpr64(ctx
, fp64
, fd
);
6763 tcg_temp_free_i64(fp64
);
6768 check_cp1_64bitmode(ctx
);
6770 TCGv_i32 fp32
= tcg_temp_new_i32();
6771 TCGv_i64 fp64
= tcg_temp_new_i64();
6773 gen_load_fpr64(ctx
, fp64
, fs
);
6774 gen_helper_float_cvts_l(fp32
, fp64
);
6775 tcg_temp_free_i64(fp64
);
6776 gen_store_fpr32(fp32
, fd
);
6777 tcg_temp_free_i32(fp32
);
6782 check_cp1_64bitmode(ctx
);
6784 TCGv_i64 fp0
= tcg_temp_new_i64();
6786 gen_load_fpr64(ctx
, fp0
, fs
);
6787 gen_helper_float_cvtd_l(fp0
, fp0
);
6788 gen_store_fpr64(ctx
, fp0
, fd
);
6789 tcg_temp_free_i64(fp0
);
6794 check_cp1_64bitmode(ctx
);
6796 TCGv_i64 fp0
= tcg_temp_new_i64();
6798 gen_load_fpr64(ctx
, fp0
, fs
);
6799 gen_helper_float_cvtps_pw(fp0
, fp0
);
6800 gen_store_fpr64(ctx
, fp0
, fd
);
6801 tcg_temp_free_i64(fp0
);
6806 check_cp1_64bitmode(ctx
);
6808 TCGv_i64 fp0
= tcg_temp_new_i64();
6809 TCGv_i64 fp1
= tcg_temp_new_i64();
6811 gen_load_fpr64(ctx
, fp0
, fs
);
6812 gen_load_fpr64(ctx
, fp1
, ft
);
6813 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6814 tcg_temp_free_i64(fp1
);
6815 gen_store_fpr64(ctx
, fp0
, fd
);
6816 tcg_temp_free_i64(fp0
);
6821 check_cp1_64bitmode(ctx
);
6823 TCGv_i64 fp0
= tcg_temp_new_i64();
6824 TCGv_i64 fp1
= tcg_temp_new_i64();
6826 gen_load_fpr64(ctx
, fp0
, fs
);
6827 gen_load_fpr64(ctx
, fp1
, ft
);
6828 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6829 tcg_temp_free_i64(fp1
);
6830 gen_store_fpr64(ctx
, fp0
, fd
);
6831 tcg_temp_free_i64(fp0
);
6836 check_cp1_64bitmode(ctx
);
6838 TCGv_i64 fp0
= tcg_temp_new_i64();
6839 TCGv_i64 fp1
= tcg_temp_new_i64();
6841 gen_load_fpr64(ctx
, fp0
, fs
);
6842 gen_load_fpr64(ctx
, fp1
, ft
);
6843 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6844 tcg_temp_free_i64(fp1
);
6845 gen_store_fpr64(ctx
, fp0
, fd
);
6846 tcg_temp_free_i64(fp0
);
6851 check_cp1_64bitmode(ctx
);
6853 TCGv_i64 fp0
= tcg_temp_new_i64();
6855 gen_load_fpr64(ctx
, fp0
, fs
);
6856 gen_helper_float_abs_ps(fp0
, fp0
);
6857 gen_store_fpr64(ctx
, fp0
, fd
);
6858 tcg_temp_free_i64(fp0
);
6863 check_cp1_64bitmode(ctx
);
6865 TCGv_i64 fp0
= tcg_temp_new_i64();
6867 gen_load_fpr64(ctx
, fp0
, fs
);
6868 gen_store_fpr64(ctx
, fp0
, fd
);
6869 tcg_temp_free_i64(fp0
);
6874 check_cp1_64bitmode(ctx
);
6876 TCGv_i64 fp0
= tcg_temp_new_i64();
6878 gen_load_fpr64(ctx
, fp0
, fs
);
6879 gen_helper_float_chs_ps(fp0
, fp0
);
6880 gen_store_fpr64(ctx
, fp0
, fd
);
6881 tcg_temp_free_i64(fp0
);
6886 check_cp1_64bitmode(ctx
);
6887 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6891 check_cp1_64bitmode(ctx
);
6893 int l1
= gen_new_label();
6897 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6898 fp0
= tcg_temp_new_i64();
6899 gen_load_fpr64(ctx
, fp0
, fs
);
6900 gen_store_fpr64(ctx
, fp0
, fd
);
6901 tcg_temp_free_i64(fp0
);
6907 check_cp1_64bitmode(ctx
);
6909 int l1
= gen_new_label();
6913 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6914 fp0
= tcg_temp_new_i64();
6915 gen_load_fpr64(ctx
, fp0
, fs
);
6916 gen_store_fpr64(ctx
, fp0
, fd
);
6917 tcg_temp_free_i64(fp0
);
6924 check_cp1_64bitmode(ctx
);
6926 TCGv_i64 fp0
= tcg_temp_new_i64();
6927 TCGv_i64 fp1
= tcg_temp_new_i64();
6929 gen_load_fpr64(ctx
, fp0
, ft
);
6930 gen_load_fpr64(ctx
, fp1
, fs
);
6931 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
6932 tcg_temp_free_i64(fp1
);
6933 gen_store_fpr64(ctx
, fp0
, fd
);
6934 tcg_temp_free_i64(fp0
);
6939 check_cp1_64bitmode(ctx
);
6941 TCGv_i64 fp0
= tcg_temp_new_i64();
6942 TCGv_i64 fp1
= tcg_temp_new_i64();
6944 gen_load_fpr64(ctx
, fp0
, ft
);
6945 gen_load_fpr64(ctx
, fp1
, fs
);
6946 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
6947 tcg_temp_free_i64(fp1
);
6948 gen_store_fpr64(ctx
, fp0
, fd
);
6949 tcg_temp_free_i64(fp0
);
6954 check_cp1_64bitmode(ctx
);
6956 TCGv_i64 fp0
= tcg_temp_new_i64();
6957 TCGv_i64 fp1
= tcg_temp_new_i64();
6959 gen_load_fpr64(ctx
, fp0
, fs
);
6960 gen_load_fpr64(ctx
, fp1
, fd
);
6961 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
6962 tcg_temp_free_i64(fp1
);
6963 gen_store_fpr64(ctx
, fp0
, fd
);
6964 tcg_temp_free_i64(fp0
);
6969 check_cp1_64bitmode(ctx
);
6971 TCGv_i64 fp0
= tcg_temp_new_i64();
6973 gen_load_fpr64(ctx
, fp0
, fs
);
6974 gen_helper_float_recip1_ps(fp0
, fp0
);
6975 gen_store_fpr64(ctx
, fp0
, fd
);
6976 tcg_temp_free_i64(fp0
);
6981 check_cp1_64bitmode(ctx
);
6983 TCGv_i64 fp0
= tcg_temp_new_i64();
6985 gen_load_fpr64(ctx
, fp0
, fs
);
6986 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
6987 gen_store_fpr64(ctx
, fp0
, fd
);
6988 tcg_temp_free_i64(fp0
);
6993 check_cp1_64bitmode(ctx
);
6995 TCGv_i64 fp0
= tcg_temp_new_i64();
6996 TCGv_i64 fp1
= tcg_temp_new_i64();
6998 gen_load_fpr64(ctx
, fp0
, fs
);
6999 gen_load_fpr64(ctx
, fp1
, ft
);
7000 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7001 tcg_temp_free_i64(fp1
);
7002 gen_store_fpr64(ctx
, fp0
, fd
);
7003 tcg_temp_free_i64(fp0
);
7008 check_cp1_64bitmode(ctx
);
7010 TCGv_i32 fp0
= tcg_temp_new_i32();
7012 gen_load_fpr32h(fp0
, fs
);
7013 gen_helper_float_cvts_pu(fp0
, fp0
);
7014 gen_store_fpr32(fp0
, fd
);
7015 tcg_temp_free_i32(fp0
);
7020 check_cp1_64bitmode(ctx
);
7022 TCGv_i64 fp0
= tcg_temp_new_i64();
7024 gen_load_fpr64(ctx
, fp0
, fs
);
7025 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7026 gen_store_fpr64(ctx
, fp0
, fd
);
7027 tcg_temp_free_i64(fp0
);
7032 check_cp1_64bitmode(ctx
);
7034 TCGv_i32 fp0
= tcg_temp_new_i32();
7036 gen_load_fpr32(fp0
, fs
);
7037 gen_helper_float_cvts_pl(fp0
, fp0
);
7038 gen_store_fpr32(fp0
, fd
);
7039 tcg_temp_free_i32(fp0
);
7044 check_cp1_64bitmode(ctx
);
7046 TCGv_i32 fp0
= tcg_temp_new_i32();
7047 TCGv_i32 fp1
= tcg_temp_new_i32();
7049 gen_load_fpr32(fp0
, fs
);
7050 gen_load_fpr32(fp1
, ft
);
7051 gen_store_fpr32h(fp0
, fd
);
7052 gen_store_fpr32(fp1
, fd
);
7053 tcg_temp_free_i32(fp0
);
7054 tcg_temp_free_i32(fp1
);
7059 check_cp1_64bitmode(ctx
);
7061 TCGv_i32 fp0
= tcg_temp_new_i32();
7062 TCGv_i32 fp1
= tcg_temp_new_i32();
7064 gen_load_fpr32(fp0
, fs
);
7065 gen_load_fpr32h(fp1
, ft
);
7066 gen_store_fpr32(fp1
, fd
);
7067 gen_store_fpr32h(fp0
, fd
);
7068 tcg_temp_free_i32(fp0
);
7069 tcg_temp_free_i32(fp1
);
7074 check_cp1_64bitmode(ctx
);
7076 TCGv_i32 fp0
= tcg_temp_new_i32();
7077 TCGv_i32 fp1
= tcg_temp_new_i32();
7079 gen_load_fpr32h(fp0
, fs
);
7080 gen_load_fpr32(fp1
, ft
);
7081 gen_store_fpr32(fp1
, fd
);
7082 gen_store_fpr32h(fp0
, fd
);
7083 tcg_temp_free_i32(fp0
);
7084 tcg_temp_free_i32(fp1
);
7089 check_cp1_64bitmode(ctx
);
7091 TCGv_i32 fp0
= tcg_temp_new_i32();
7092 TCGv_i32 fp1
= tcg_temp_new_i32();
7094 gen_load_fpr32h(fp0
, fs
);
7095 gen_load_fpr32h(fp1
, ft
);
7096 gen_store_fpr32(fp1
, fd
);
7097 gen_store_fpr32h(fp0
, fd
);
7098 tcg_temp_free_i32(fp0
);
7099 tcg_temp_free_i32(fp1
);
7119 check_cp1_64bitmode(ctx
);
7121 TCGv_i64 fp0
= tcg_temp_new_i64();
7122 TCGv_i64 fp1
= tcg_temp_new_i64();
7124 gen_load_fpr64(ctx
, fp0
, fs
);
7125 gen_load_fpr64(ctx
, fp1
, ft
);
7126 if (ctx
->opcode
& (1 << 6)) {
7127 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7128 opn
= condnames_abs
[func
-48];
7130 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7131 opn
= condnames
[func
-48];
7133 tcg_temp_free_i64(fp0
);
7134 tcg_temp_free_i64(fp1
);
7139 generate_exception (ctx
, EXCP_RI
);
7144 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7147 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7150 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7155 /* Coprocessor 3 (FPU) */
7156 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7157 int fd
, int fs
, int base
, int index
)
7159 const char *opn
= "extended float load/store";
7161 TCGv t0
= tcg_temp_new();
7164 gen_load_gpr(t0
, index
);
7165 } else if (index
== 0) {
7166 gen_load_gpr(t0
, base
);
7168 gen_load_gpr(t0
, index
);
7169 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7171 /* Don't do NOP if destination is zero: we must perform the actual
7173 save_cpu_state(ctx
, 0);
7178 TCGv_i32 fp0
= tcg_temp_new_i32();
7180 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7181 tcg_gen_trunc_tl_i32(fp0
, t0
);
7182 gen_store_fpr32(fp0
, fd
);
7183 tcg_temp_free_i32(fp0
);
7189 check_cp1_registers(ctx
, fd
);
7191 TCGv_i64 fp0
= tcg_temp_new_i64();
7193 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7194 gen_store_fpr64(ctx
, fp0
, fd
);
7195 tcg_temp_free_i64(fp0
);
7200 check_cp1_64bitmode(ctx
);
7201 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7203 TCGv_i64 fp0
= tcg_temp_new_i64();
7205 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7206 gen_store_fpr64(ctx
, fp0
, fd
);
7207 tcg_temp_free_i64(fp0
);
7214 TCGv_i32 fp0
= tcg_temp_new_i32();
7215 TCGv t1
= tcg_temp_new();
7217 gen_load_fpr32(fp0
, fs
);
7218 tcg_gen_extu_i32_tl(t1
, fp0
);
7219 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7220 tcg_temp_free_i32(fp0
);
7228 check_cp1_registers(ctx
, fs
);
7230 TCGv_i64 fp0
= tcg_temp_new_i64();
7232 gen_load_fpr64(ctx
, fp0
, fs
);
7233 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7234 tcg_temp_free_i64(fp0
);
7240 check_cp1_64bitmode(ctx
);
7241 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7243 TCGv_i64 fp0
= tcg_temp_new_i64();
7245 gen_load_fpr64(ctx
, fp0
, fs
);
7246 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7247 tcg_temp_free_i64(fp0
);
7254 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7255 regnames
[index
], regnames
[base
]);
7258 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7259 int fd
, int fr
, int fs
, int ft
)
7261 const char *opn
= "flt3_arith";
7265 check_cp1_64bitmode(ctx
);
7267 TCGv t0
= tcg_temp_local_new();
7268 TCGv_i32 fp
= tcg_temp_new_i32();
7269 TCGv_i32 fph
= tcg_temp_new_i32();
7270 int l1
= gen_new_label();
7271 int l2
= gen_new_label();
7273 gen_load_gpr(t0
, fr
);
7274 tcg_gen_andi_tl(t0
, t0
, 0x7);
7276 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7277 gen_load_fpr32(fp
, fs
);
7278 gen_load_fpr32h(fph
, fs
);
7279 gen_store_fpr32(fp
, fd
);
7280 gen_store_fpr32h(fph
, fd
);
7283 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7285 #ifdef TARGET_WORDS_BIGENDIAN
7286 gen_load_fpr32(fp
, fs
);
7287 gen_load_fpr32h(fph
, ft
);
7288 gen_store_fpr32h(fp
, fd
);
7289 gen_store_fpr32(fph
, fd
);
7291 gen_load_fpr32h(fph
, fs
);
7292 gen_load_fpr32(fp
, ft
);
7293 gen_store_fpr32(fph
, fd
);
7294 gen_store_fpr32h(fp
, fd
);
7297 tcg_temp_free_i32(fp
);
7298 tcg_temp_free_i32(fph
);
7305 TCGv_i32 fp0
= tcg_temp_new_i32();
7306 TCGv_i32 fp1
= tcg_temp_new_i32();
7307 TCGv_i32 fp2
= tcg_temp_new_i32();
7309 gen_load_fpr32(fp0
, fs
);
7310 gen_load_fpr32(fp1
, ft
);
7311 gen_load_fpr32(fp2
, fr
);
7312 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7313 tcg_temp_free_i32(fp0
);
7314 tcg_temp_free_i32(fp1
);
7315 gen_store_fpr32(fp2
, fd
);
7316 tcg_temp_free_i32(fp2
);
7322 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7324 TCGv_i64 fp0
= tcg_temp_new_i64();
7325 TCGv_i64 fp1
= tcg_temp_new_i64();
7326 TCGv_i64 fp2
= tcg_temp_new_i64();
7328 gen_load_fpr64(ctx
, fp0
, fs
);
7329 gen_load_fpr64(ctx
, fp1
, ft
);
7330 gen_load_fpr64(ctx
, fp2
, fr
);
7331 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7332 tcg_temp_free_i64(fp0
);
7333 tcg_temp_free_i64(fp1
);
7334 gen_store_fpr64(ctx
, fp2
, fd
);
7335 tcg_temp_free_i64(fp2
);
7340 check_cp1_64bitmode(ctx
);
7342 TCGv_i64 fp0
= tcg_temp_new_i64();
7343 TCGv_i64 fp1
= tcg_temp_new_i64();
7344 TCGv_i64 fp2
= tcg_temp_new_i64();
7346 gen_load_fpr64(ctx
, fp0
, fs
);
7347 gen_load_fpr64(ctx
, fp1
, ft
);
7348 gen_load_fpr64(ctx
, fp2
, fr
);
7349 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7350 tcg_temp_free_i64(fp0
);
7351 tcg_temp_free_i64(fp1
);
7352 gen_store_fpr64(ctx
, fp2
, fd
);
7353 tcg_temp_free_i64(fp2
);
7360 TCGv_i32 fp0
= tcg_temp_new_i32();
7361 TCGv_i32 fp1
= tcg_temp_new_i32();
7362 TCGv_i32 fp2
= tcg_temp_new_i32();
7364 gen_load_fpr32(fp0
, fs
);
7365 gen_load_fpr32(fp1
, ft
);
7366 gen_load_fpr32(fp2
, fr
);
7367 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7368 tcg_temp_free_i32(fp0
);
7369 tcg_temp_free_i32(fp1
);
7370 gen_store_fpr32(fp2
, fd
);
7371 tcg_temp_free_i32(fp2
);
7377 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7379 TCGv_i64 fp0
= tcg_temp_new_i64();
7380 TCGv_i64 fp1
= tcg_temp_new_i64();
7381 TCGv_i64 fp2
= tcg_temp_new_i64();
7383 gen_load_fpr64(ctx
, fp0
, fs
);
7384 gen_load_fpr64(ctx
, fp1
, ft
);
7385 gen_load_fpr64(ctx
, fp2
, fr
);
7386 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7387 tcg_temp_free_i64(fp0
);
7388 tcg_temp_free_i64(fp1
);
7389 gen_store_fpr64(ctx
, fp2
, fd
);
7390 tcg_temp_free_i64(fp2
);
7395 check_cp1_64bitmode(ctx
);
7397 TCGv_i64 fp0
= tcg_temp_new_i64();
7398 TCGv_i64 fp1
= tcg_temp_new_i64();
7399 TCGv_i64 fp2
= tcg_temp_new_i64();
7401 gen_load_fpr64(ctx
, fp0
, fs
);
7402 gen_load_fpr64(ctx
, fp1
, ft
);
7403 gen_load_fpr64(ctx
, fp2
, fr
);
7404 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7405 tcg_temp_free_i64(fp0
);
7406 tcg_temp_free_i64(fp1
);
7407 gen_store_fpr64(ctx
, fp2
, fd
);
7408 tcg_temp_free_i64(fp2
);
7415 TCGv_i32 fp0
= tcg_temp_new_i32();
7416 TCGv_i32 fp1
= tcg_temp_new_i32();
7417 TCGv_i32 fp2
= tcg_temp_new_i32();
7419 gen_load_fpr32(fp0
, fs
);
7420 gen_load_fpr32(fp1
, ft
);
7421 gen_load_fpr32(fp2
, fr
);
7422 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7423 tcg_temp_free_i32(fp0
);
7424 tcg_temp_free_i32(fp1
);
7425 gen_store_fpr32(fp2
, fd
);
7426 tcg_temp_free_i32(fp2
);
7432 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7434 TCGv_i64 fp0
= tcg_temp_new_i64();
7435 TCGv_i64 fp1
= tcg_temp_new_i64();
7436 TCGv_i64 fp2
= tcg_temp_new_i64();
7438 gen_load_fpr64(ctx
, fp0
, fs
);
7439 gen_load_fpr64(ctx
, fp1
, ft
);
7440 gen_load_fpr64(ctx
, fp2
, fr
);
7441 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7442 tcg_temp_free_i64(fp0
);
7443 tcg_temp_free_i64(fp1
);
7444 gen_store_fpr64(ctx
, fp2
, fd
);
7445 tcg_temp_free_i64(fp2
);
7450 check_cp1_64bitmode(ctx
);
7452 TCGv_i64 fp0
= tcg_temp_new_i64();
7453 TCGv_i64 fp1
= tcg_temp_new_i64();
7454 TCGv_i64 fp2
= tcg_temp_new_i64();
7456 gen_load_fpr64(ctx
, fp0
, fs
);
7457 gen_load_fpr64(ctx
, fp1
, ft
);
7458 gen_load_fpr64(ctx
, fp2
, fr
);
7459 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7460 tcg_temp_free_i64(fp0
);
7461 tcg_temp_free_i64(fp1
);
7462 gen_store_fpr64(ctx
, fp2
, fd
);
7463 tcg_temp_free_i64(fp2
);
7470 TCGv_i32 fp0
= tcg_temp_new_i32();
7471 TCGv_i32 fp1
= tcg_temp_new_i32();
7472 TCGv_i32 fp2
= tcg_temp_new_i32();
7474 gen_load_fpr32(fp0
, fs
);
7475 gen_load_fpr32(fp1
, ft
);
7476 gen_load_fpr32(fp2
, fr
);
7477 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7478 tcg_temp_free_i32(fp0
);
7479 tcg_temp_free_i32(fp1
);
7480 gen_store_fpr32(fp2
, fd
);
7481 tcg_temp_free_i32(fp2
);
7487 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7489 TCGv_i64 fp0
= tcg_temp_new_i64();
7490 TCGv_i64 fp1
= tcg_temp_new_i64();
7491 TCGv_i64 fp2
= tcg_temp_new_i64();
7493 gen_load_fpr64(ctx
, fp0
, fs
);
7494 gen_load_fpr64(ctx
, fp1
, ft
);
7495 gen_load_fpr64(ctx
, fp2
, fr
);
7496 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7497 tcg_temp_free_i64(fp0
);
7498 tcg_temp_free_i64(fp1
);
7499 gen_store_fpr64(ctx
, fp2
, fd
);
7500 tcg_temp_free_i64(fp2
);
7505 check_cp1_64bitmode(ctx
);
7507 TCGv_i64 fp0
= tcg_temp_new_i64();
7508 TCGv_i64 fp1
= tcg_temp_new_i64();
7509 TCGv_i64 fp2
= tcg_temp_new_i64();
7511 gen_load_fpr64(ctx
, fp0
, fs
);
7512 gen_load_fpr64(ctx
, fp1
, ft
);
7513 gen_load_fpr64(ctx
, fp2
, fr
);
7514 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7515 tcg_temp_free_i64(fp0
);
7516 tcg_temp_free_i64(fp1
);
7517 gen_store_fpr64(ctx
, fp2
, fd
);
7518 tcg_temp_free_i64(fp2
);
7524 generate_exception (ctx
, EXCP_RI
);
7527 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7528 fregnames
[fs
], fregnames
[ft
]);
7531 static void handle_delay_slot (CPUState
*env
, DisasContext
*ctx
,
7534 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7535 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7536 /* Branches completion */
7537 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7538 ctx
->bstate
= BS_BRANCH
;
7539 save_cpu_state(ctx
, 0);
7540 /* FIXME: Need to clear can_do_io. */
7541 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
7543 /* unconditional branch */
7544 MIPS_DEBUG("unconditional branch");
7545 if (proc_hflags
& MIPS_HFLAG_BX
) {
7546 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
7548 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7551 /* blikely taken case */
7552 MIPS_DEBUG("blikely branch taken");
7553 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7556 /* Conditional branch */
7557 MIPS_DEBUG("conditional branch");
7559 int l1
= gen_new_label();
7561 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7562 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
7564 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7568 /* unconditional branch to register */
7569 MIPS_DEBUG("branch to register");
7570 if (env
->insn_flags
& ASE_MIPS16
) {
7571 TCGv t0
= tcg_temp_new();
7572 TCGv_i32 t1
= tcg_temp_new_i32();
7574 tcg_gen_andi_tl(t0
, btarget
, 0x1);
7575 tcg_gen_trunc_tl_i32(t1
, t0
);
7577 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
7578 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
7579 tcg_gen_or_i32(hflags
, hflags
, t1
);
7580 tcg_temp_free_i32(t1
);
7582 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
7584 tcg_gen_mov_tl(cpu_PC
, btarget
);
7586 if (ctx
->singlestep_enabled
) {
7587 save_cpu_state(ctx
, 0);
7588 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
7593 MIPS_DEBUG("unknown branch");
7599 /* ISA extensions (ASEs) */
7600 /* MIPS16 extension to MIPS32 */
7602 /* MIPS16 major opcodes */
7604 M16_OPC_ADDIUSP
= 0x00,
7605 M16_OPC_ADDIUPC
= 0x01,
7608 M16_OPC_BEQZ
= 0x04,
7609 M16_OPC_BNEQZ
= 0x05,
7610 M16_OPC_SHIFT
= 0x06,
7612 M16_OPC_RRIA
= 0x08,
7613 M16_OPC_ADDIU8
= 0x09,
7614 M16_OPC_SLTI
= 0x0a,
7615 M16_OPC_SLTIU
= 0x0b,
7618 M16_OPC_CMPI
= 0x0e,
7622 M16_OPC_LWSP
= 0x12,
7626 M16_OPC_LWPC
= 0x16,
7630 M16_OPC_SWSP
= 0x1a,
7634 M16_OPC_EXTEND
= 0x1e,
7638 /* I8 funct field */
7657 /* RR funct field */
7691 /* I64 funct field */
7703 /* RR ry field for CNVT */
7705 RR_RY_CNVT_ZEB
= 0x0,
7706 RR_RY_CNVT_ZEH
= 0x1,
7707 RR_RY_CNVT_ZEW
= 0x2,
7708 RR_RY_CNVT_SEB
= 0x4,
7709 RR_RY_CNVT_SEH
= 0x5,
7710 RR_RY_CNVT_SEW
= 0x6,
7713 static int xlat (int r
)
7715 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
7720 static void gen_mips16_save (DisasContext
*ctx
,
7721 int xsregs
, int aregs
,
7722 int do_ra
, int do_s0
, int do_s1
,
7725 TCGv t0
= tcg_temp_new();
7726 TCGv t1
= tcg_temp_new();
7756 generate_exception(ctx
, EXCP_RI
);
7762 gen_base_offset_addr(ctx
, t0
, 29, 12);
7763 gen_load_gpr(t1
, 7);
7764 op_ldst_sw(t1
, t0
, ctx
);
7767 gen_base_offset_addr(ctx
, t0
, 29, 8);
7768 gen_load_gpr(t1
, 6);
7769 op_ldst_sw(t1
, t0
, ctx
);
7772 gen_base_offset_addr(ctx
, t0
, 29, 4);
7773 gen_load_gpr(t1
, 5);
7774 op_ldst_sw(t1
, t0
, ctx
);
7777 gen_base_offset_addr(ctx
, t0
, 29, 0);
7778 gen_load_gpr(t1
, 4);
7779 op_ldst_sw(t1
, t0
, ctx
);
7782 gen_load_gpr(t0
, 29);
7784 #define DECR_AND_STORE(reg) do { \
7785 tcg_gen_subi_tl(t0, t0, 4); \
7786 gen_load_gpr(t1, reg); \
7787 op_ldst_sw(t1, t0, ctx); \
7851 generate_exception(ctx
, EXCP_RI
);
7867 #undef DECR_AND_STORE
7869 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
7874 static void gen_mips16_restore (DisasContext
*ctx
,
7875 int xsregs
, int aregs
,
7876 int do_ra
, int do_s0
, int do_s1
,
7880 TCGv t0
= tcg_temp_new();
7881 TCGv t1
= tcg_temp_new();
7883 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
7885 #define DECR_AND_LOAD(reg) do { \
7886 tcg_gen_subi_tl(t0, t0, 4); \
7887 op_ldst_lw(t1, t0, ctx); \
7888 gen_store_gpr(t1, reg); \
7952 generate_exception(ctx
, EXCP_RI
);
7968 #undef DECR_AND_LOAD
7970 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
7975 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
7976 int is_64_bit
, int extended
)
7980 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
7981 generate_exception(ctx
, EXCP_RI
);
7985 t0
= tcg_temp_new();
7987 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
7988 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
7990 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
7996 #if defined(TARGET_MIPS64)
7997 static void decode_i64_mips16 (CPUState
*env
, DisasContext
*ctx
,
7998 int ry
, int funct
, int16_t offset
,
8004 offset
= extended
? offset
: offset
<< 3;
8005 gen_ldst(ctx
, OPC_LD
, ry
, 29, offset
);
8009 offset
= extended
? offset
: offset
<< 3;
8010 gen_ldst(ctx
, OPC_SD
, ry
, 29, offset
);
8014 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8015 gen_ldst(ctx
, OPC_SD
, 31, 29, offset
);
8019 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8020 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8023 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8024 generate_exception(ctx
, EXCP_RI
);
8026 offset
= extended
? offset
: offset
<< 3;
8027 gen_ldst(ctx
, OPC_LDPC
, ry
, 0, offset
);
8032 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8033 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8037 offset
= extended
? offset
: offset
<< 2;
8038 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8042 offset
= extended
? offset
: offset
<< 2;
8043 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8049 static int decode_extended_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8052 int extend
= lduw_code(ctx
->pc
+ 2);
8053 int op
, rx
, ry
, funct
, sa
;
8054 int16_t imm
, offset
;
8056 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8057 op
= (ctx
->opcode
>> 11) & 0x1f;
8058 sa
= (ctx
->opcode
>> 22) & 0x1f;
8059 funct
= (ctx
->opcode
>> 8) & 0x7;
8060 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8061 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8062 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8063 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8064 | (ctx
->opcode
& 0x1f));
8066 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8069 case M16_OPC_ADDIUSP
:
8070 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8072 case M16_OPC_ADDIUPC
:
8073 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8076 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8077 /* No delay slot, so just process as a normal instruction */
8080 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8081 /* No delay slot, so just process as a normal instruction */
8084 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8085 /* No delay slot, so just process as a normal instruction */
8088 switch (ctx
->opcode
& 0x3) {
8090 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8093 #if defined(TARGET_MIPS64)
8095 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8097 generate_exception(ctx
, EXCP_RI
);
8101 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8104 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8108 #if defined(TARGET_MIPS64)
8111 gen_ldst(ctx
, OPC_LD
, ry
, rx
, offset
);
8115 imm
= ctx
->opcode
& 0xf;
8116 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8117 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8118 imm
= (int16_t) (imm
<< 1) >> 1;
8119 if ((ctx
->opcode
>> 4) & 0x1) {
8120 #if defined(TARGET_MIPS64)
8122 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8124 generate_exception(ctx
, EXCP_RI
);
8127 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8130 case M16_OPC_ADDIU8
:
8131 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8134 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8137 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8142 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8145 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8148 gen_ldst(ctx
, OPC_SW
, 31, 29, imm
);
8151 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8155 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8156 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8157 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8158 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8159 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8160 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8161 | (ctx
->opcode
& 0xf)) << 3;
8163 if (ctx
->opcode
& (1 << 7)) {
8164 gen_mips16_save(ctx
, xsregs
, aregs
,
8165 do_ra
, do_s0
, do_s1
,
8168 gen_mips16_restore(ctx
, xsregs
, aregs
,
8169 do_ra
, do_s0
, do_s1
,
8175 generate_exception(ctx
, EXCP_RI
);
8180 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8183 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8185 #if defined(TARGET_MIPS64)
8187 gen_ldst(ctx
, OPC_SD
, ry
, rx
, offset
);
8191 gen_ldst(ctx
, OPC_LB
, ry
, rx
, offset
);
8194 gen_ldst(ctx
, OPC_LH
, ry
, rx
, offset
);
8197 gen_ldst(ctx
, OPC_LW
, rx
, 29, offset
);
8200 gen_ldst(ctx
, OPC_LW
, ry
, rx
, offset
);
8203 gen_ldst(ctx
, OPC_LBU
, ry
, rx
, offset
);
8206 gen_ldst(ctx
, OPC_LHU
, ry
, rx
, offset
);
8209 gen_ldst(ctx
, OPC_LWPC
, rx
, 0, offset
);
8211 #if defined(TARGET_MIPS64)
8213 gen_ldst(ctx
, OPC_LWU
, ry
, rx
, offset
);
8217 gen_ldst(ctx
, OPC_SB
, ry
, rx
, offset
);
8220 gen_ldst(ctx
, OPC_SH
, ry
, rx
, offset
);
8223 gen_ldst(ctx
, OPC_SW
, rx
, 29, offset
);
8226 gen_ldst(ctx
, OPC_SW
, ry
, rx
, offset
);
8228 #if defined(TARGET_MIPS64)
8230 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8234 generate_exception(ctx
, EXCP_RI
);
8241 static int decode_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8246 int op
, cnvt_op
, op1
, offset
;
8250 op
= (ctx
->opcode
>> 11) & 0x1f;
8251 sa
= (ctx
->opcode
>> 2) & 0x7;
8252 sa
= sa
== 0 ? 8 : sa
;
8253 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8254 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8255 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8256 op1
= offset
= ctx
->opcode
& 0x1f;
8261 case M16_OPC_ADDIUSP
:
8263 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8265 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8268 case M16_OPC_ADDIUPC
:
8269 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8272 offset
= (ctx
->opcode
& 0x7ff) << 1;
8273 offset
= (int16_t)(offset
<< 4) >> 4;
8274 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8275 /* No delay slot, so just process as a normal instruction */
8278 offset
= lduw_code(ctx
->pc
+ 2);
8279 offset
= (((ctx
->opcode
& 0x1f) << 21)
8280 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8282 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALX
: OPC_JAL
;
8283 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8288 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8289 /* No delay slot, so just process as a normal instruction */
8292 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8293 /* No delay slot, so just process as a normal instruction */
8296 switch (ctx
->opcode
& 0x3) {
8298 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8301 #if defined(TARGET_MIPS64)
8303 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8305 generate_exception(ctx
, EXCP_RI
);
8309 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8312 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8316 #if defined(TARGET_MIPS64)
8319 gen_ldst(ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8324 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8326 if ((ctx
->opcode
>> 4) & 1) {
8327 #if defined(TARGET_MIPS64)
8329 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8331 generate_exception(ctx
, EXCP_RI
);
8334 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8338 case M16_OPC_ADDIU8
:
8340 int16_t imm
= (int8_t) ctx
->opcode
;
8342 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8347 int16_t imm
= (uint8_t) ctx
->opcode
;
8349 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8354 int16_t imm
= (uint8_t) ctx
->opcode
;
8356 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8363 funct
= (ctx
->opcode
>> 8) & 0x7;
8366 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
8367 ((int8_t)ctx
->opcode
) << 1);
8370 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
8371 ((int8_t)ctx
->opcode
) << 1);
8374 gen_ldst(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
8377 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
8378 ((int8_t)ctx
->opcode
) << 3);
8382 int do_ra
= ctx
->opcode
& (1 << 6);
8383 int do_s0
= ctx
->opcode
& (1 << 5);
8384 int do_s1
= ctx
->opcode
& (1 << 4);
8385 int framesize
= ctx
->opcode
& 0xf;
8387 if (framesize
== 0) {
8390 framesize
= framesize
<< 3;
8393 if (ctx
->opcode
& (1 << 7)) {
8394 gen_mips16_save(ctx
, 0, 0,
8395 do_ra
, do_s0
, do_s1
, framesize
);
8397 gen_mips16_restore(ctx
, 0, 0,
8398 do_ra
, do_s0
, do_s1
, framesize
);
8404 int rz
= xlat(ctx
->opcode
& 0x7);
8406 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
8407 ((ctx
->opcode
>> 5) & 0x7);
8408 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
8412 reg32
= ctx
->opcode
& 0x1f;
8413 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
8416 generate_exception(ctx
, EXCP_RI
);
8423 int16_t imm
= (uint8_t) ctx
->opcode
;
8425 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
8430 int16_t imm
= (uint8_t) ctx
->opcode
;
8432 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
8435 #if defined(TARGET_MIPS64)
8438 gen_ldst(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
8442 gen_ldst(ctx
, OPC_LB
, ry
, rx
, offset
);
8445 gen_ldst(ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
8448 gen_ldst(ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8451 gen_ldst(ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
8454 gen_ldst(ctx
, OPC_LBU
, ry
, rx
, offset
);
8457 gen_ldst(ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
8460 gen_ldst(ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
8462 #if defined (TARGET_MIPS64)
8465 gen_ldst(ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
8469 gen_ldst(ctx
, OPC_SB
, ry
, rx
, offset
);
8472 gen_ldst(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
8475 gen_ldst(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8478 gen_ldst(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
8482 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
8485 switch (ctx
->opcode
& 0x3) {
8487 mips32_op
= OPC_ADDU
;
8490 mips32_op
= OPC_SUBU
;
8492 #if defined(TARGET_MIPS64)
8494 mips32_op
= OPC_DADDU
;
8498 mips32_op
= OPC_DSUBU
;
8503 generate_exception(ctx
, EXCP_RI
);
8507 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
8516 int nd
= (ctx
->opcode
>> 7) & 0x1;
8517 int link
= (ctx
->opcode
>> 6) & 0x1;
8518 int ra
= (ctx
->opcode
>> 5) & 0x1;
8521 op
= nd
? OPC_JALRC
: OPC_JALR
;
8526 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
8533 /* XXX: not clear which exception should be raised
8534 * when in debug mode...
8536 check_insn(env
, ctx
, ISA_MIPS32
);
8537 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8538 generate_exception(ctx
, EXCP_DBp
);
8540 generate_exception(ctx
, EXCP_DBp
);
8544 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
8547 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
8550 generate_exception(ctx
, EXCP_BREAK
);
8553 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
8556 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
8559 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
8561 #if defined (TARGET_MIPS64)
8564 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
8568 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
8571 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
8574 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
8577 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
8580 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
8583 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
8586 gen_HILO(ctx
, OPC_MFHI
, rx
);
8590 case RR_RY_CNVT_ZEB
:
8591 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8593 case RR_RY_CNVT_ZEH
:
8594 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8596 case RR_RY_CNVT_SEB
:
8597 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8599 case RR_RY_CNVT_SEH
:
8600 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8602 #if defined (TARGET_MIPS64)
8603 case RR_RY_CNVT_ZEW
:
8605 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8607 case RR_RY_CNVT_SEW
:
8609 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8613 generate_exception(ctx
, EXCP_RI
);
8618 gen_HILO(ctx
, OPC_MFLO
, rx
);
8620 #if defined (TARGET_MIPS64)
8623 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
8627 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
8631 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
8635 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
8639 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
8642 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
8645 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
8648 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
8650 #if defined (TARGET_MIPS64)
8653 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
8657 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
8661 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
8665 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
8669 generate_exception(ctx
, EXCP_RI
);
8673 case M16_OPC_EXTEND
:
8674 decode_extended_mips16_opc(env
, ctx
, is_branch
);
8677 #if defined(TARGET_MIPS64)
8679 funct
= (ctx
->opcode
>> 8) & 0x7;
8680 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
8684 generate_exception(ctx
, EXCP_RI
);
8691 /* SmartMIPS extension to MIPS32 */
8693 #if defined(TARGET_MIPS64)
8695 /* MDMX extension to MIPS64 */
8699 static void decode_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
8703 uint32_t op
, op1
, op2
;
8706 /* make sure instructions are on a word boundary */
8707 if (ctx
->pc
& 0x3) {
8708 env
->CP0_BadVAddr
= ctx
->pc
;
8709 generate_exception(ctx
, EXCP_AdEL
);
8713 /* Handle blikely not taken case */
8714 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
8715 int l1
= gen_new_label();
8717 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
8718 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8719 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
8720 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8724 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
8725 tcg_gen_debug_insn_start(ctx
->pc
);
8727 op
= MASK_OP_MAJOR(ctx
->opcode
);
8728 rs
= (ctx
->opcode
>> 21) & 0x1f;
8729 rt
= (ctx
->opcode
>> 16) & 0x1f;
8730 rd
= (ctx
->opcode
>> 11) & 0x1f;
8731 sa
= (ctx
->opcode
>> 6) & 0x1f;
8732 imm
= (int16_t)ctx
->opcode
;
8735 op1
= MASK_SPECIAL(ctx
->opcode
);
8737 case OPC_SLL
: /* Shift with immediate */
8739 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8742 switch ((ctx
->opcode
>> 21) & 0x1f) {
8744 /* rotr is decoded as srl on non-R2 CPUs */
8745 if (env
->insn_flags
& ISA_MIPS32R2
) {
8750 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8753 generate_exception(ctx
, EXCP_RI
);
8757 case OPC_MOVN
: /* Conditional move */
8759 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8760 gen_cond_move(env
, op1
, rd
, rs
, rt
);
8762 case OPC_ADD
... OPC_SUBU
:
8763 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8765 case OPC_SLLV
: /* Shifts */
8767 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8770 switch ((ctx
->opcode
>> 6) & 0x1f) {
8772 /* rotrv is decoded as srlv on non-R2 CPUs */
8773 if (env
->insn_flags
& ISA_MIPS32R2
) {
8778 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8781 generate_exception(ctx
, EXCP_RI
);
8785 case OPC_SLT
: /* Set on less than */
8787 gen_slt(env
, op1
, rd
, rs
, rt
);
8789 case OPC_AND
: /* Logic*/
8793 gen_logic(env
, op1
, rd
, rs
, rt
);
8795 case OPC_MULT
... OPC_DIVU
:
8797 check_insn(env
, ctx
, INSN_VR54XX
);
8798 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
8799 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
8801 gen_muldiv(ctx
, op1
, rs
, rt
);
8803 case OPC_JR
... OPC_JALR
:
8804 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
8807 case OPC_TGE
... OPC_TEQ
: /* Traps */
8809 gen_trap(ctx
, op1
, rs
, rt
, -1);
8811 case OPC_MFHI
: /* Move from HI/LO */
8813 gen_HILO(ctx
, op1
, rd
);
8816 case OPC_MTLO
: /* Move to HI/LO */
8817 gen_HILO(ctx
, op1
, rs
);
8819 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
8820 #ifdef MIPS_STRICT_STANDARD
8821 MIPS_INVAL("PMON / selsl");
8822 generate_exception(ctx
, EXCP_RI
);
8824 gen_helper_0i(pmon
, sa
);
8828 generate_exception(ctx
, EXCP_SYSCALL
);
8829 ctx
->bstate
= BS_STOP
;
8832 generate_exception(ctx
, EXCP_BREAK
);
8835 #ifdef MIPS_STRICT_STANDARD
8837 generate_exception(ctx
, EXCP_RI
);
8839 /* Implemented as RI exception for now. */
8840 MIPS_INVAL("spim (unofficial)");
8841 generate_exception(ctx
, EXCP_RI
);
8849 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8850 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8851 check_cp1_enabled(ctx
);
8852 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
8853 (ctx
->opcode
>> 16) & 1);
8855 generate_exception_err(ctx
, EXCP_CpU
, 1);
8859 #if defined(TARGET_MIPS64)
8860 /* MIPS64 specific opcodes */
8865 check_insn(env
, ctx
, ISA_MIPS3
);
8867 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8870 switch ((ctx
->opcode
>> 21) & 0x1f) {
8872 /* drotr is decoded as dsrl on non-R2 CPUs */
8873 if (env
->insn_flags
& ISA_MIPS32R2
) {
8878 check_insn(env
, ctx
, ISA_MIPS3
);
8880 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8883 generate_exception(ctx
, EXCP_RI
);
8888 switch ((ctx
->opcode
>> 21) & 0x1f) {
8890 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
8891 if (env
->insn_flags
& ISA_MIPS32R2
) {
8896 check_insn(env
, ctx
, ISA_MIPS3
);
8898 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8901 generate_exception(ctx
, EXCP_RI
);
8905 case OPC_DADD
... OPC_DSUBU
:
8906 check_insn(env
, ctx
, ISA_MIPS3
);
8908 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8912 check_insn(env
, ctx
, ISA_MIPS3
);
8914 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8917 switch ((ctx
->opcode
>> 6) & 0x1f) {
8919 /* drotrv is decoded as dsrlv on non-R2 CPUs */
8920 if (env
->insn_flags
& ISA_MIPS32R2
) {
8925 check_insn(env
, ctx
, ISA_MIPS3
);
8927 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8930 generate_exception(ctx
, EXCP_RI
);
8934 case OPC_DMULT
... OPC_DDIVU
:
8935 check_insn(env
, ctx
, ISA_MIPS3
);
8937 gen_muldiv(ctx
, op1
, rs
, rt
);
8940 default: /* Invalid */
8941 MIPS_INVAL("special");
8942 generate_exception(ctx
, EXCP_RI
);
8947 op1
= MASK_SPECIAL2(ctx
->opcode
);
8949 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
8950 case OPC_MSUB
... OPC_MSUBU
:
8951 check_insn(env
, ctx
, ISA_MIPS32
);
8952 gen_muldiv(ctx
, op1
, rs
, rt
);
8955 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8959 check_insn(env
, ctx
, ISA_MIPS32
);
8960 gen_cl(ctx
, op1
, rd
, rs
);
8963 /* XXX: not clear which exception should be raised
8964 * when in debug mode...
8966 check_insn(env
, ctx
, ISA_MIPS32
);
8967 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8968 generate_exception(ctx
, EXCP_DBp
);
8970 generate_exception(ctx
, EXCP_DBp
);
8974 #if defined(TARGET_MIPS64)
8977 check_insn(env
, ctx
, ISA_MIPS64
);
8979 gen_cl(ctx
, op1
, rd
, rs
);
8982 default: /* Invalid */
8983 MIPS_INVAL("special2");
8984 generate_exception(ctx
, EXCP_RI
);
8989 op1
= MASK_SPECIAL3(ctx
->opcode
);
8993 check_insn(env
, ctx
, ISA_MIPS32R2
);
8994 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
8997 check_insn(env
, ctx
, ISA_MIPS32R2
);
8998 op2
= MASK_BSHFL(ctx
->opcode
);
8999 gen_bshfl(ctx
, op2
, rt
, rd
);
9002 check_insn(env
, ctx
, ISA_MIPS32R2
);
9004 TCGv t0
= tcg_temp_new();
9008 save_cpu_state(ctx
, 1);
9009 gen_helper_rdhwr_cpunum(t0
);
9010 gen_store_gpr(t0
, rt
);
9013 save_cpu_state(ctx
, 1);
9014 gen_helper_rdhwr_synci_step(t0
);
9015 gen_store_gpr(t0
, rt
);
9018 save_cpu_state(ctx
, 1);
9019 gen_helper_rdhwr_cc(t0
);
9020 gen_store_gpr(t0
, rt
);
9023 save_cpu_state(ctx
, 1);
9024 gen_helper_rdhwr_ccres(t0
);
9025 gen_store_gpr(t0
, rt
);
9028 #if defined(CONFIG_USER_ONLY)
9029 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
9030 gen_store_gpr(t0
, rt
);
9033 /* XXX: Some CPUs implement this in hardware.
9034 Not supported yet. */
9036 default: /* Invalid */
9037 MIPS_INVAL("rdhwr");
9038 generate_exception(ctx
, EXCP_RI
);
9045 check_insn(env
, ctx
, ASE_MT
);
9047 TCGv t0
= tcg_temp_new();
9048 TCGv t1
= tcg_temp_new();
9050 gen_load_gpr(t0
, rt
);
9051 gen_load_gpr(t1
, rs
);
9052 gen_helper_fork(t0
, t1
);
9058 check_insn(env
, ctx
, ASE_MT
);
9060 TCGv t0
= tcg_temp_new();
9062 save_cpu_state(ctx
, 1);
9063 gen_load_gpr(t0
, rs
);
9064 gen_helper_yield(t0
, t0
);
9065 gen_store_gpr(t0
, rd
);
9069 #if defined(TARGET_MIPS64)
9070 case OPC_DEXTM
... OPC_DEXT
:
9071 case OPC_DINSM
... OPC_DINS
:
9072 check_insn(env
, ctx
, ISA_MIPS64R2
);
9074 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
9077 check_insn(env
, ctx
, ISA_MIPS64R2
);
9079 op2
= MASK_DBSHFL(ctx
->opcode
);
9080 gen_bshfl(ctx
, op2
, rt
, rd
);
9083 default: /* Invalid */
9084 MIPS_INVAL("special3");
9085 generate_exception(ctx
, EXCP_RI
);
9090 op1
= MASK_REGIMM(ctx
->opcode
);
9092 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
9093 case OPC_BLTZAL
... OPC_BGEZALL
:
9094 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
9097 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
9099 gen_trap(ctx
, op1
, rs
, -1, imm
);
9102 check_insn(env
, ctx
, ISA_MIPS32R2
);
9105 default: /* Invalid */
9106 MIPS_INVAL("regimm");
9107 generate_exception(ctx
, EXCP_RI
);
9112 check_cp0_enabled(ctx
);
9113 op1
= MASK_CP0(ctx
->opcode
);
9119 #if defined(TARGET_MIPS64)
9123 #ifndef CONFIG_USER_ONLY
9124 gen_cp0(env
, ctx
, op1
, rt
, rd
);
9125 #endif /* !CONFIG_USER_ONLY */
9127 case OPC_C0_FIRST
... OPC_C0_LAST
:
9128 #ifndef CONFIG_USER_ONLY
9129 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
9130 #endif /* !CONFIG_USER_ONLY */
9133 #ifndef CONFIG_USER_ONLY
9135 TCGv t0
= tcg_temp_new();
9137 op2
= MASK_MFMC0(ctx
->opcode
);
9140 check_insn(env
, ctx
, ASE_MT
);
9141 gen_helper_dmt(t0
, t0
);
9142 gen_store_gpr(t0
, rt
);
9145 check_insn(env
, ctx
, ASE_MT
);
9146 gen_helper_emt(t0
, t0
);
9147 gen_store_gpr(t0
, rt
);
9150 check_insn(env
, ctx
, ASE_MT
);
9151 gen_helper_dvpe(t0
, t0
);
9152 gen_store_gpr(t0
, rt
);
9155 check_insn(env
, ctx
, ASE_MT
);
9156 gen_helper_evpe(t0
, t0
);
9157 gen_store_gpr(t0
, rt
);
9160 check_insn(env
, ctx
, ISA_MIPS32R2
);
9161 save_cpu_state(ctx
, 1);
9163 gen_store_gpr(t0
, rt
);
9164 /* Stop translation as we may have switched the execution mode */
9165 ctx
->bstate
= BS_STOP
;
9168 check_insn(env
, ctx
, ISA_MIPS32R2
);
9169 save_cpu_state(ctx
, 1);
9171 gen_store_gpr(t0
, rt
);
9172 /* Stop translation as we may have switched the execution mode */
9173 ctx
->bstate
= BS_STOP
;
9175 default: /* Invalid */
9176 MIPS_INVAL("mfmc0");
9177 generate_exception(ctx
, EXCP_RI
);
9182 #endif /* !CONFIG_USER_ONLY */
9185 check_insn(env
, ctx
, ISA_MIPS32R2
);
9186 gen_load_srsgpr(rt
, rd
);
9189 check_insn(env
, ctx
, ISA_MIPS32R2
);
9190 gen_store_srsgpr(rt
, rd
);
9194 generate_exception(ctx
, EXCP_RI
);
9198 case OPC_ADDI
: /* Arithmetic with immediate opcode */
9200 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
9202 case OPC_SLTI
: /* Set on less than with immediate opcode */
9204 gen_slt_imm(env
, op
, rt
, rs
, imm
);
9206 case OPC_ANDI
: /* Arithmetic with immediate opcode */
9210 gen_logic_imm(env
, op
, rt
, rs
, imm
);
9212 case OPC_J
... OPC_JAL
: /* Jump */
9213 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
9214 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
9217 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
9218 case OPC_BEQL
... OPC_BGTZL
:
9219 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
9222 case OPC_LB
... OPC_LWR
: /* Load and stores */
9223 case OPC_SB
... OPC_SW
:
9226 gen_ldst(ctx
, op
, rt
, rs
, imm
);
9229 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
9232 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
9236 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
9240 /* Floating point (COP1). */
9245 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9246 check_cp1_enabled(ctx
);
9247 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
9249 generate_exception_err(ctx
, EXCP_CpU
, 1);
9254 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9255 check_cp1_enabled(ctx
);
9256 op1
= MASK_CP1(ctx
->opcode
);
9260 check_insn(env
, ctx
, ISA_MIPS32R2
);
9265 gen_cp1(ctx
, op1
, rt
, rd
);
9267 #if defined(TARGET_MIPS64)
9270 check_insn(env
, ctx
, ISA_MIPS3
);
9271 gen_cp1(ctx
, op1
, rt
, rd
);
9277 check_insn(env
, ctx
, ASE_MIPS3D
);
9280 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
9281 (rt
>> 2) & 0x7, imm
<< 2);
9289 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
9294 generate_exception (ctx
, EXCP_RI
);
9298 generate_exception_err(ctx
, EXCP_CpU
, 1);
9308 /* COP2: Not implemented. */
9309 generate_exception_err(ctx
, EXCP_CpU
, 2);
9313 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9314 check_cp1_enabled(ctx
);
9315 op1
= MASK_CP3(ctx
->opcode
);
9323 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
9341 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
9345 generate_exception (ctx
, EXCP_RI
);
9349 generate_exception_err(ctx
, EXCP_CpU
, 1);
9353 #if defined(TARGET_MIPS64)
9354 /* MIPS64 opcodes */
9356 case OPC_LDL
... OPC_LDR
:
9357 case OPC_SDL
... OPC_SDR
:
9361 check_insn(env
, ctx
, ISA_MIPS3
);
9363 gen_ldst(ctx
, op
, rt
, rs
, imm
);
9366 check_insn(env
, ctx
, ISA_MIPS3
);
9368 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
9372 check_insn(env
, ctx
, ISA_MIPS3
);
9374 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
9378 check_insn(env
, ctx
, ASE_MIPS16
);
9379 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
9380 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
9384 check_insn(env
, ctx
, ASE_MDMX
);
9385 /* MDMX: Not implemented. */
9386 default: /* Invalid */
9387 MIPS_INVAL("major opcode");
9388 generate_exception(ctx
, EXCP_RI
);
9394 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
9398 target_ulong pc_start
;
9399 uint16_t *gen_opc_end
;
9408 qemu_log("search pc %d\n", search_pc
);
9411 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
9414 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
9416 ctx
.bstate
= BS_NONE
;
9417 /* Restore delay slot state from the tb context. */
9418 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
9419 restore_cpu_state(env
, &ctx
);
9420 #ifdef CONFIG_USER_ONLY
9421 ctx
.mem_idx
= MIPS_HFLAG_UM
;
9423 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
9426 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9428 max_insns
= CF_COUNT_MASK
;
9429 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
9431 while (ctx
.bstate
== BS_NONE
) {
9432 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9433 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9434 if (bp
->pc
== ctx
.pc
) {
9435 save_cpu_state(&ctx
, 1);
9436 ctx
.bstate
= BS_BRANCH
;
9437 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
9438 /* Include the breakpoint location or the tb won't
9439 * be flushed when it must be. */
9441 goto done_generating
;
9447 j
= gen_opc_ptr
- gen_opc_buf
;
9451 gen_opc_instr_start
[lj
++] = 0;
9453 gen_opc_pc
[lj
] = ctx
.pc
;
9454 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
9455 gen_opc_instr_start
[lj
] = 1;
9456 gen_opc_icount
[lj
] = num_insns
;
9458 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9462 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
9463 ctx
.opcode
= ldl_code(ctx
.pc
);
9465 decode_opc(env
, &ctx
, &is_branch
);
9466 } else if (env
->insn_flags
& ASE_MIPS16
) {
9467 ctx
.opcode
= lduw_code(ctx
.pc
);
9468 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
9470 generate_exception(&ctx
, EXCP_RI
);
9474 handle_delay_slot(env
, &ctx
, insn_bytes
);
9476 ctx
.pc
+= insn_bytes
;
9480 /* Execute a branch and its delay slot as a single instruction.
9481 This is what GDB expects and is consistent with what the
9482 hardware does (e.g. if a delay slot instruction faults, the
9483 reported PC is the PC of the branch). */
9484 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
9487 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
9490 if (gen_opc_ptr
>= gen_opc_end
)
9493 if (num_insns
>= max_insns
)
9499 if (tb
->cflags
& CF_LAST_IO
)
9501 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
9502 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
9503 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
9505 switch (ctx
.bstate
) {
9507 gen_helper_interrupt_restart();
9508 gen_goto_tb(&ctx
, 0, ctx
.pc
);
9511 save_cpu_state(&ctx
, 0);
9512 gen_goto_tb(&ctx
, 0, ctx
.pc
);
9515 gen_helper_interrupt_restart();
9524 gen_icount_end(tb
, num_insns
);
9525 *gen_opc_ptr
= INDEX_op_end
;
9527 j
= gen_opc_ptr
- gen_opc_buf
;
9530 gen_opc_instr_start
[lj
++] = 0;
9532 tb
->size
= ctx
.pc
- pc_start
;
9533 tb
->icount
= num_insns
;
9537 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9538 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9539 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
9545 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
9547 gen_intermediate_code_internal(env
, tb
, 0);
9550 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
9552 gen_intermediate_code_internal(env
, tb
, 1);
9555 static void fpu_dump_state(CPUState
*env
, FILE *f
,
9556 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9560 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
9562 #define printfpr(fp) \
9565 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
9566 " fd:%13g fs:%13g psu: %13g\n", \
9567 (fp)->w[FP_ENDIAN_IDX], (fp)->d, \
9569 (double)(fp)->fs[FP_ENDIAN_IDX], \
9570 (double)(fp)->fs[!FP_ENDIAN_IDX]); \
9573 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
9574 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
9575 fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
9576 " fd:%13g fs:%13g psu:%13g\n", \
9577 tmp.w[FP_ENDIAN_IDX], tmp.d, \
9579 (double)tmp.fs[FP_ENDIAN_IDX], \
9580 (double)tmp.fs[!FP_ENDIAN_IDX]); \
9585 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
9586 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
9587 get_float_exception_flags(&env
->active_fpu
.fp_status
));
9588 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
9589 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
9590 printfpr(&env
->active_fpu
.fpr
[i
]);
9596 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
9597 /* Debug help: The architecture requires 32bit code to maintain proper
9598 sign-extended values on 64bit machines. */
9600 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
9603 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
9604 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9609 if (!SIGN_EXT_P(env
->active_tc
.PC
))
9610 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
9611 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
9612 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
9613 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
9614 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
9615 if (!SIGN_EXT_P(env
->btarget
))
9616 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
9618 for (i
= 0; i
< 32; i
++) {
9619 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
9620 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
9623 if (!SIGN_EXT_P(env
->CP0_EPC
))
9624 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
9625 if (!SIGN_EXT_P(env
->lladdr
))
9626 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
9630 void cpu_dump_state (CPUState
*env
, FILE *f
,
9631 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9636 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
9637 " LO=0x" TARGET_FMT_lx
" ds %04x "
9638 TARGET_FMT_lx
" " TARGET_FMT_ld
"\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
];