2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
7 * Copyright (c) 2009 CodeSourcery (MIPS16 support)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
33 #include "qemu-common.h"
39 //#define MIPS_DEBUG_DISAS
40 //#define MIPS_DEBUG_SIGN_EXTENSIONS
42 /* MIPS major opcodes */
43 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
46 /* indirect opcode tables */
47 OPC_SPECIAL
= (0x00 << 26),
48 OPC_REGIMM
= (0x01 << 26),
49 OPC_CP0
= (0x10 << 26),
50 OPC_CP1
= (0x11 << 26),
51 OPC_CP2
= (0x12 << 26),
52 OPC_CP3
= (0x13 << 26),
53 OPC_SPECIAL2
= (0x1C << 26),
54 OPC_SPECIAL3
= (0x1F << 26),
55 /* arithmetic with immediate */
56 OPC_ADDI
= (0x08 << 26),
57 OPC_ADDIU
= (0x09 << 26),
58 OPC_SLTI
= (0x0A << 26),
59 OPC_SLTIU
= (0x0B << 26),
60 /* logic with immediate */
61 OPC_ANDI
= (0x0C << 26),
62 OPC_ORI
= (0x0D << 26),
63 OPC_XORI
= (0x0E << 26),
64 OPC_LUI
= (0x0F << 26),
65 /* arithmetic with immediate */
66 OPC_DADDI
= (0x18 << 26),
67 OPC_DADDIU
= (0x19 << 26),
68 /* Jump and branches */
70 OPC_JAL
= (0x03 << 26),
71 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
72 OPC_BEQL
= (0x14 << 26),
73 OPC_BNE
= (0x05 << 26),
74 OPC_BNEL
= (0x15 << 26),
75 OPC_BLEZ
= (0x06 << 26),
76 OPC_BLEZL
= (0x16 << 26),
77 OPC_BGTZ
= (0x07 << 26),
78 OPC_BGTZL
= (0x17 << 26),
79 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
81 OPC_LDL
= (0x1A << 26),
82 OPC_LDR
= (0x1B << 26),
83 OPC_LB
= (0x20 << 26),
84 OPC_LH
= (0x21 << 26),
85 OPC_LWL
= (0x22 << 26),
86 OPC_LW
= (0x23 << 26),
87 OPC_LWPC
= OPC_LW
| 0x5,
88 OPC_LBU
= (0x24 << 26),
89 OPC_LHU
= (0x25 << 26),
90 OPC_LWR
= (0x26 << 26),
91 OPC_LWU
= (0x27 << 26),
92 OPC_SB
= (0x28 << 26),
93 OPC_SH
= (0x29 << 26),
94 OPC_SWL
= (0x2A << 26),
95 OPC_SW
= (0x2B << 26),
96 OPC_SDL
= (0x2C << 26),
97 OPC_SDR
= (0x2D << 26),
98 OPC_SWR
= (0x2E << 26),
99 OPC_LL
= (0x30 << 26),
100 OPC_LLD
= (0x34 << 26),
101 OPC_LD
= (0x37 << 26),
102 OPC_LDPC
= OPC_LD
| 0x5,
103 OPC_SC
= (0x38 << 26),
104 OPC_SCD
= (0x3C << 26),
105 OPC_SD
= (0x3F << 26),
106 /* Floating point load/store */
107 OPC_LWC1
= (0x31 << 26),
108 OPC_LWC2
= (0x32 << 26),
109 OPC_LDC1
= (0x35 << 26),
110 OPC_LDC2
= (0x36 << 26),
111 OPC_SWC1
= (0x39 << 26),
112 OPC_SWC2
= (0x3A << 26),
113 OPC_SDC1
= (0x3D << 26),
114 OPC_SDC2
= (0x3E << 26),
115 /* MDMX ASE specific */
116 OPC_MDMX
= (0x1E << 26),
117 /* Cache and prefetch */
118 OPC_CACHE
= (0x2F << 26),
119 OPC_PREF
= (0x33 << 26),
120 /* Reserved major opcode */
121 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
124 /* MIPS special opcodes */
125 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
129 OPC_SLL
= 0x00 | OPC_SPECIAL
,
130 /* NOP is SLL r0, r0, 0 */
131 /* SSNOP is SLL r0, r0, 1 */
132 /* EHB is SLL r0, r0, 3 */
133 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
134 OPC_ROTR
= OPC_SRL
| (1 << 21),
135 OPC_SRA
= 0x03 | OPC_SPECIAL
,
136 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
137 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
138 OPC_ROTRV
= OPC_SRLV
| (1 << 6),
139 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
140 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
141 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
142 OPC_DROTRV
= OPC_DSRLV
| (1 << 6),
143 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
144 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
145 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
146 OPC_DROTR
= OPC_DSRL
| (1 << 21),
147 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
148 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
149 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
150 OPC_DROTR32
= OPC_DSRL32
| (1 << 21),
151 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
152 /* Multiplication / division */
153 OPC_MULT
= 0x18 | OPC_SPECIAL
,
154 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
155 OPC_DIV
= 0x1A | OPC_SPECIAL
,
156 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
157 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
158 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
159 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
160 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
161 /* 2 registers arithmetic / logic */
162 OPC_ADD
= 0x20 | OPC_SPECIAL
,
163 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
164 OPC_SUB
= 0x22 | OPC_SPECIAL
,
165 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
166 OPC_AND
= 0x24 | OPC_SPECIAL
,
167 OPC_OR
= 0x25 | OPC_SPECIAL
,
168 OPC_XOR
= 0x26 | OPC_SPECIAL
,
169 OPC_NOR
= 0x27 | OPC_SPECIAL
,
170 OPC_SLT
= 0x2A | OPC_SPECIAL
,
171 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
172 OPC_DADD
= 0x2C | OPC_SPECIAL
,
173 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
174 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
175 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
177 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
178 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
179 OPC_JALRC
= OPC_JALR
| (0x5 << 6),
181 OPC_TGE
= 0x30 | OPC_SPECIAL
,
182 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
183 OPC_TLT
= 0x32 | OPC_SPECIAL
,
184 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
185 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
186 OPC_TNE
= 0x36 | OPC_SPECIAL
,
187 /* HI / LO registers load & stores */
188 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
189 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
190 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
191 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
192 /* Conditional moves */
193 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
194 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
196 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
199 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* unofficial */
200 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
201 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
202 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
203 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
205 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
206 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
207 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
208 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
209 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
210 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
211 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
214 /* Multiplication variants of the vr54xx. */
215 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
218 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
219 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
220 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
221 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
222 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
223 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
224 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
225 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
226 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
227 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
228 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
229 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
230 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
231 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
234 /* REGIMM (rt field) opcodes */
235 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
238 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
239 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
240 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
241 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
242 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
243 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
244 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
245 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
246 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
247 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
248 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
249 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
250 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
251 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
252 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
255 /* Special2 opcodes */
256 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
259 /* Multiply & xxx operations */
260 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
261 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
262 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
263 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
264 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
266 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
267 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
268 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
269 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
271 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
274 /* Special3 opcodes */
275 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
278 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
279 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
280 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
281 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
282 OPC_INS
= 0x04 | OPC_SPECIAL3
,
283 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
284 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
285 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
286 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
287 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
288 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
289 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
290 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
294 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
297 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
298 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
299 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
303 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
306 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
307 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
310 /* Coprocessor 0 (rs field) */
311 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
314 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
315 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
316 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
317 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
318 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
319 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
320 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
321 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
322 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
323 OPC_C0
= (0x10 << 21) | OPC_CP0
,
324 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
325 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
329 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
332 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
333 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
334 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
335 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
336 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
337 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
340 /* Coprocessor 0 (with rs == C0) */
341 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
344 OPC_TLBR
= 0x01 | OPC_C0
,
345 OPC_TLBWI
= 0x02 | OPC_C0
,
346 OPC_TLBWR
= 0x06 | OPC_C0
,
347 OPC_TLBP
= 0x08 | OPC_C0
,
348 OPC_RFE
= 0x10 | OPC_C0
,
349 OPC_ERET
= 0x18 | OPC_C0
,
350 OPC_DERET
= 0x1F | OPC_C0
,
351 OPC_WAIT
= 0x20 | OPC_C0
,
354 /* Coprocessor 1 (rs field) */
355 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
358 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
359 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
360 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
361 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
362 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
363 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
364 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
365 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
366 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
367 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
368 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
369 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
370 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
371 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
372 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
373 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
374 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
375 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
378 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
379 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
382 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
383 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
384 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
385 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
389 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
390 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
394 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
395 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
398 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
401 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
402 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
403 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
404 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
405 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
406 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
407 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
408 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
409 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
412 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
415 OPC_LWXC1
= 0x00 | OPC_CP3
,
416 OPC_LDXC1
= 0x01 | OPC_CP3
,
417 OPC_LUXC1
= 0x05 | OPC_CP3
,
418 OPC_SWXC1
= 0x08 | OPC_CP3
,
419 OPC_SDXC1
= 0x09 | OPC_CP3
,
420 OPC_SUXC1
= 0x0D | OPC_CP3
,
421 OPC_PREFX
= 0x0F | OPC_CP3
,
422 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
423 OPC_MADD_S
= 0x20 | OPC_CP3
,
424 OPC_MADD_D
= 0x21 | OPC_CP3
,
425 OPC_MADD_PS
= 0x26 | OPC_CP3
,
426 OPC_MSUB_S
= 0x28 | OPC_CP3
,
427 OPC_MSUB_D
= 0x29 | OPC_CP3
,
428 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
429 OPC_NMADD_S
= 0x30 | OPC_CP3
,
430 OPC_NMADD_D
= 0x31 | OPC_CP3
,
431 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
432 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
433 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
434 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
437 /* global register indices */
438 static TCGv_ptr cpu_env
;
439 static TCGv cpu_gpr
[32], cpu_PC
;
440 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
441 static TCGv cpu_dspctrl
, btarget
, bcond
;
442 static TCGv_i32 hflags
;
443 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
445 #include "gen-icount.h"
447 #define gen_helper_0i(name, arg) do { \
448 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
449 gen_helper_##name(helper_tmp); \
450 tcg_temp_free_i32(helper_tmp); \
453 #define gen_helper_1i(name, arg1, arg2) do { \
454 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
455 gen_helper_##name(arg1, helper_tmp); \
456 tcg_temp_free_i32(helper_tmp); \
459 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
460 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
461 gen_helper_##name(arg1, arg2, helper_tmp); \
462 tcg_temp_free_i32(helper_tmp); \
465 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
466 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
467 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
468 tcg_temp_free_i32(helper_tmp); \
471 typedef struct DisasContext
{
472 struct TranslationBlock
*tb
;
473 target_ulong pc
, saved_pc
;
475 int singlestep_enabled
;
476 /* Routine used to access memory */
478 uint32_t hflags
, saved_hflags
;
480 target_ulong btarget
;
484 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
485 * exception condition */
486 BS_STOP
= 1, /* We want to stop translation for any reason */
487 BS_BRANCH
= 2, /* We reached a branch condition */
488 BS_EXCP
= 3, /* We reached an exception condition */
491 static const char *regnames
[] =
492 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
493 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
494 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
495 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
497 static const char *regnames_HI
[] =
498 { "HI0", "HI1", "HI2", "HI3", };
500 static const char *regnames_LO
[] =
501 { "LO0", "LO1", "LO2", "LO3", };
503 static const char *regnames_ACX
[] =
504 { "ACX0", "ACX1", "ACX2", "ACX3", };
506 static const char *fregnames
[] =
507 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
508 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
509 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
510 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
512 #ifdef MIPS_DEBUG_DISAS
513 #define MIPS_DEBUG(fmt, ...) \
514 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
515 TARGET_FMT_lx ": %08x " fmt "\n", \
516 ctx->pc, ctx->opcode , ## __VA_ARGS__)
517 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
519 #define MIPS_DEBUG(fmt, ...) do { } while(0)
520 #define LOG_DISAS(...) do { } while (0)
523 #define MIPS_INVAL(op) \
525 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
526 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
529 /* General purpose registers moves. */
530 static inline void gen_load_gpr (TCGv t
, int reg
)
533 tcg_gen_movi_tl(t
, 0);
535 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
538 static inline void gen_store_gpr (TCGv t
, int reg
)
541 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
544 /* Moves to/from ACX register. */
545 static inline void gen_load_ACX (TCGv t
, int reg
)
547 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
550 static inline void gen_store_ACX (TCGv t
, int reg
)
552 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
555 /* Moves to/from shadow registers. */
556 static inline void gen_load_srsgpr (int from
, int to
)
558 TCGv t0
= tcg_temp_new();
561 tcg_gen_movi_tl(t0
, 0);
563 TCGv_i32 t2
= tcg_temp_new_i32();
564 TCGv_ptr addr
= tcg_temp_new_ptr();
566 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
567 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
568 tcg_gen_andi_i32(t2
, t2
, 0xf);
569 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
570 tcg_gen_ext_i32_ptr(addr
, t2
);
571 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
573 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
574 tcg_temp_free_ptr(addr
);
575 tcg_temp_free_i32(t2
);
577 gen_store_gpr(t0
, to
);
581 static inline void gen_store_srsgpr (int from
, int to
)
584 TCGv t0
= tcg_temp_new();
585 TCGv_i32 t2
= tcg_temp_new_i32();
586 TCGv_ptr addr
= tcg_temp_new_ptr();
588 gen_load_gpr(t0
, from
);
589 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
590 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
591 tcg_gen_andi_i32(t2
, t2
, 0xf);
592 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
593 tcg_gen_ext_i32_ptr(addr
, t2
);
594 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
596 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
597 tcg_temp_free_ptr(addr
);
598 tcg_temp_free_i32(t2
);
603 /* Floating point register moves. */
604 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
606 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
609 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
611 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
614 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
616 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
619 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
621 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
624 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
626 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
627 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
629 TCGv_i32 t0
= tcg_temp_new_i32();
630 TCGv_i32 t1
= tcg_temp_new_i32();
631 gen_load_fpr32(t0
, reg
& ~1);
632 gen_load_fpr32(t1
, reg
| 1);
633 tcg_gen_concat_i32_i64(t
, t0
, t1
);
634 tcg_temp_free_i32(t0
);
635 tcg_temp_free_i32(t1
);
639 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
641 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
642 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
644 TCGv_i64 t0
= tcg_temp_new_i64();
645 TCGv_i32 t1
= tcg_temp_new_i32();
646 tcg_gen_trunc_i64_i32(t1
, t
);
647 gen_store_fpr32(t1
, reg
& ~1);
648 tcg_gen_shri_i64(t0
, t
, 32);
649 tcg_gen_trunc_i64_i32(t1
, t0
);
650 gen_store_fpr32(t1
, reg
| 1);
651 tcg_temp_free_i32(t1
);
652 tcg_temp_free_i64(t0
);
656 static inline int get_fp_bit (int cc
)
664 #define FOP_CONDS(type, fmt, bits) \
665 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
666 TCGv_i##bits b, int cc) \
669 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
670 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
671 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
672 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
673 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
674 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
675 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
676 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
677 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
678 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
679 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
680 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
681 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
682 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
683 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
684 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
690 FOP_CONDS(abs
, d
, 64)
692 FOP_CONDS(abs
, s
, 32)
694 FOP_CONDS(abs
, ps
, 64)
698 #define OP_COND(name, cond) \
699 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, TCGv t1) \
701 int l1 = gen_new_label(); \
702 int l2 = gen_new_label(); \
704 tcg_gen_brcond_tl(cond, t0, t1, l1); \
705 tcg_gen_movi_tl(ret, 0); \
708 tcg_gen_movi_tl(ret, 1); \
711 OP_COND(eq
, TCG_COND_EQ
);
712 OP_COND(ne
, TCG_COND_NE
);
713 OP_COND(ge
, TCG_COND_GE
);
714 OP_COND(geu
, TCG_COND_GEU
);
715 OP_COND(lt
, TCG_COND_LT
);
716 OP_COND(ltu
, TCG_COND_LTU
);
719 #define OP_CONDI(name, cond) \
720 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, target_ulong val) \
722 int l1 = gen_new_label(); \
723 int l2 = gen_new_label(); \
725 tcg_gen_brcondi_tl(cond, t0, val, l1); \
726 tcg_gen_movi_tl(ret, 0); \
729 tcg_gen_movi_tl(ret, 1); \
732 OP_CONDI(lti
, TCG_COND_LT
);
733 OP_CONDI(ltiu
, TCG_COND_LTU
);
736 #define OP_CONDZ(name, cond) \
737 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0) \
739 int l1 = gen_new_label(); \
740 int l2 = gen_new_label(); \
742 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
743 tcg_gen_movi_tl(ret, 0); \
746 tcg_gen_movi_tl(ret, 1); \
749 OP_CONDZ(gez
, TCG_COND_GE
);
750 OP_CONDZ(gtz
, TCG_COND_GT
);
751 OP_CONDZ(lez
, TCG_COND_LE
);
752 OP_CONDZ(ltz
, TCG_COND_LT
);
755 static inline void gen_save_pc(target_ulong pc
)
757 tcg_gen_movi_tl(cpu_PC
, pc
);
760 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
762 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
763 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
764 gen_save_pc(ctx
->pc
);
765 ctx
->saved_pc
= ctx
->pc
;
767 if (ctx
->hflags
!= ctx
->saved_hflags
) {
768 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
769 ctx
->saved_hflags
= ctx
->hflags
;
770 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
776 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
782 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
784 ctx
->saved_hflags
= ctx
->hflags
;
785 switch (ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) {
791 ctx
->btarget
= env
->btarget
;
797 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
799 TCGv_i32 texcp
= tcg_const_i32(excp
);
800 TCGv_i32 terr
= tcg_const_i32(err
);
801 save_cpu_state(ctx
, 1);
802 gen_helper_raise_exception_err(texcp
, terr
);
803 tcg_temp_free_i32(terr
);
804 tcg_temp_free_i32(texcp
);
808 generate_exception (DisasContext
*ctx
, int excp
)
810 save_cpu_state(ctx
, 1);
811 gen_helper_0i(raise_exception
, excp
);
814 /* Addresses computation */
815 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
817 tcg_gen_add_tl(ret
, arg0
, arg1
);
819 #if defined(TARGET_MIPS64)
820 /* For compatibility with 32-bit code, data reference in user mode
821 with Status_UX = 0 should be casted to 32-bit and sign extended.
822 See the MIPS64 PRA manual, section 4.10. */
823 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
824 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
825 tcg_gen_ext32s_i64(ret
, ret
);
830 static inline void check_cp0_enabled(DisasContext
*ctx
)
832 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
833 generate_exception_err(ctx
, EXCP_CpU
, 0);
836 static inline void check_cp1_enabled(DisasContext
*ctx
)
838 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
839 generate_exception_err(ctx
, EXCP_CpU
, 1);
842 /* Verify that the processor is running with COP1X instructions enabled.
843 This is associated with the nabla symbol in the MIPS32 and MIPS64
846 static inline void check_cop1x(DisasContext
*ctx
)
848 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
849 generate_exception(ctx
, EXCP_RI
);
852 /* Verify that the processor is running with 64-bit floating-point
853 operations enabled. */
855 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
857 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
858 generate_exception(ctx
, EXCP_RI
);
862 * Verify if floating point register is valid; an operation is not defined
863 * if bit 0 of any register specification is set and the FR bit in the
864 * Status register equals zero, since the register numbers specify an
865 * even-odd pair of adjacent coprocessor general registers. When the FR bit
866 * in the Status register equals one, both even and odd register numbers
867 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
869 * Multiple 64 bit wide registers can be checked by calling
870 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
872 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
874 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
875 generate_exception(ctx
, EXCP_RI
);
878 /* This code generates a "reserved instruction" exception if the
879 CPU does not support the instruction set corresponding to flags. */
880 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
882 if (unlikely(!(env
->insn_flags
& flags
)))
883 generate_exception(ctx
, EXCP_RI
);
886 /* This code generates a "reserved instruction" exception if 64-bit
887 instructions are not enabled. */
888 static inline void check_mips_64(DisasContext
*ctx
)
890 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
891 generate_exception(ctx
, EXCP_RI
);
894 /* load/store instructions. */
895 #define OP_LD(insn,fname) \
896 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
898 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
905 #if defined(TARGET_MIPS64)
911 #define OP_ST(insn,fname) \
912 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
914 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
919 #if defined(TARGET_MIPS64)
924 #ifdef CONFIG_USER_ONLY
925 #define OP_LD_ATOMIC(insn,fname) \
926 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
928 TCGv t0 = tcg_temp_new(); \
929 tcg_gen_mov_tl(t0, arg1); \
930 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
931 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
932 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
936 #define OP_LD_ATOMIC(insn,fname) \
937 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
939 gen_helper_2i(insn, ret, arg1, ctx->mem_idx); \
942 OP_LD_ATOMIC(ll
,ld32s
);
943 #if defined(TARGET_MIPS64)
944 OP_LD_ATOMIC(lld
,ld64
);
948 #ifdef CONFIG_USER_ONLY
949 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
950 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
952 TCGv t0 = tcg_temp_new(); \
953 int l1 = gen_new_label(); \
954 int l2 = gen_new_label(); \
956 tcg_gen_andi_tl(t0, arg2, almask); \
957 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
958 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
959 generate_exception(ctx, EXCP_AdES); \
961 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
962 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
963 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
964 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
965 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
966 gen_helper_0i(raise_exception, EXCP_SC); \
968 tcg_gen_movi_tl(t0, 0); \
969 gen_store_gpr(t0, rt); \
973 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
974 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
976 TCGv t0 = tcg_temp_new(); \
977 gen_helper_3i(insn, t0, arg1, arg2, ctx->mem_idx); \
978 gen_store_gpr(t0, rt); \
982 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
983 #if defined(TARGET_MIPS64)
984 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
988 static void gen_base_offset_addr (DisasContext
*ctx
, TCGv addr
,
989 int base
, int16_t offset
)
992 tcg_gen_movi_tl(addr
, offset
);
993 } else if (offset
== 0) {
994 gen_load_gpr(addr
, base
);
996 tcg_gen_movi_tl(addr
, offset
);
997 gen_op_addr_add(ctx
, addr
, cpu_gpr
[base
], addr
);
1001 static target_ulong
pc_relative_pc (DisasContext
*ctx
)
1003 target_ulong pc
= ctx
->pc
;
1005 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1006 int branch_bytes
= ctx
->hflags
& MIPS_HFLAG_BDS16
? 2 : 4;
1011 pc
&= ~(target_ulong
)3;
1015 /* Load and store */
1016 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
1017 int base
, int16_t offset
)
1019 const char *opn
= "ldst";
1020 TCGv t0
= tcg_temp_new();
1021 TCGv t1
= tcg_temp_new();
1023 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1024 /* Don't do NOP if destination is zero: we must perform the actual
1027 #if defined(TARGET_MIPS64)
1029 save_cpu_state(ctx
, 0);
1030 op_ldst_lwu(t0
, t0
, ctx
);
1031 gen_store_gpr(t0
, rt
);
1035 save_cpu_state(ctx
, 0);
1036 op_ldst_ld(t0
, t0
, ctx
);
1037 gen_store_gpr(t0
, rt
);
1041 save_cpu_state(ctx
, 0);
1042 op_ldst_lld(t0
, t0
, ctx
);
1043 gen_store_gpr(t0
, rt
);
1047 save_cpu_state(ctx
, 0);
1048 gen_load_gpr(t1
, rt
);
1049 op_ldst_sd(t1
, t0
, ctx
);
1053 save_cpu_state(ctx
, 1);
1054 gen_load_gpr(t1
, rt
);
1055 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1056 gen_store_gpr(t1
, rt
);
1060 save_cpu_state(ctx
, 1);
1061 gen_load_gpr(t1
, rt
);
1062 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1066 save_cpu_state(ctx
, 1);
1067 gen_load_gpr(t1
, rt
);
1068 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1069 gen_store_gpr(t1
, rt
);
1073 save_cpu_state(ctx
, 1);
1074 gen_load_gpr(t1
, rt
);
1075 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1079 save_cpu_state(ctx
, 1);
1080 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1081 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1082 op_ldst_ld(t0
, t0
, ctx
);
1083 gen_store_gpr(t0
, rt
);
1087 save_cpu_state(ctx
, 1);
1088 tcg_gen_movi_tl(t1
, pc_relative_pc(ctx
));
1089 gen_op_addr_add(ctx
, t0
, t0
, t1
);
1090 op_ldst_lw(t0
, t0
, ctx
);
1091 gen_store_gpr(t0
, rt
);
1094 save_cpu_state(ctx
, 0);
1095 op_ldst_lw(t0
, t0
, ctx
);
1096 gen_store_gpr(t0
, rt
);
1100 save_cpu_state(ctx
, 0);
1101 gen_load_gpr(t1
, rt
);
1102 op_ldst_sw(t1
, t0
, ctx
);
1106 save_cpu_state(ctx
, 0);
1107 op_ldst_lh(t0
, t0
, ctx
);
1108 gen_store_gpr(t0
, rt
);
1112 save_cpu_state(ctx
, 0);
1113 gen_load_gpr(t1
, rt
);
1114 op_ldst_sh(t1
, t0
, ctx
);
1118 save_cpu_state(ctx
, 0);
1119 op_ldst_lhu(t0
, t0
, ctx
);
1120 gen_store_gpr(t0
, rt
);
1124 save_cpu_state(ctx
, 0);
1125 op_ldst_lb(t0
, t0
, ctx
);
1126 gen_store_gpr(t0
, rt
);
1130 save_cpu_state(ctx
, 0);
1131 gen_load_gpr(t1
, rt
);
1132 op_ldst_sb(t1
, t0
, ctx
);
1136 save_cpu_state(ctx
, 0);
1137 op_ldst_lbu(t0
, t0
, ctx
);
1138 gen_store_gpr(t0
, rt
);
1142 save_cpu_state(ctx
, 1);
1143 gen_load_gpr(t1
, rt
);
1144 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1145 gen_store_gpr(t1
, rt
);
1149 save_cpu_state(ctx
, 1);
1150 gen_load_gpr(t1
, rt
);
1151 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1155 save_cpu_state(ctx
, 1);
1156 gen_load_gpr(t1
, rt
);
1157 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1158 gen_store_gpr(t1
, rt
);
1162 save_cpu_state(ctx
, 1);
1163 gen_load_gpr(t1
, rt
);
1164 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1168 save_cpu_state(ctx
, 1);
1169 op_ldst_ll(t0
, t0
, ctx
);
1170 gen_store_gpr(t0
, rt
);
1174 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1179 /* Store conditional */
1180 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1181 int base
, int16_t offset
)
1183 const char *opn
= "st_cond";
1186 t0
= tcg_temp_local_new();
1188 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1189 /* Don't do NOP if destination is zero: we must perform the actual
1192 t1
= tcg_temp_local_new();
1193 gen_load_gpr(t1
, rt
);
1195 #if defined(TARGET_MIPS64)
1197 save_cpu_state(ctx
, 0);
1198 op_ldst_scd(t1
, t0
, rt
, ctx
);
1203 save_cpu_state(ctx
, 1);
1204 op_ldst_sc(t1
, t0
, rt
, ctx
);
1208 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1213 /* Load and store */
1214 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1215 int base
, int16_t offset
)
1217 const char *opn
= "flt_ldst";
1218 TCGv t0
= tcg_temp_new();
1220 gen_base_offset_addr(ctx
, t0
, base
, offset
);
1221 /* Don't do NOP if destination is zero: we must perform the actual
1226 TCGv_i32 fp0
= tcg_temp_new_i32();
1228 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1229 tcg_gen_trunc_tl_i32(fp0
, t0
);
1230 gen_store_fpr32(fp0
, ft
);
1231 tcg_temp_free_i32(fp0
);
1237 TCGv_i32 fp0
= tcg_temp_new_i32();
1238 TCGv t1
= tcg_temp_new();
1240 gen_load_fpr32(fp0
, ft
);
1241 tcg_gen_extu_i32_tl(t1
, fp0
);
1242 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1244 tcg_temp_free_i32(fp0
);
1250 TCGv_i64 fp0
= tcg_temp_new_i64();
1252 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1253 gen_store_fpr64(ctx
, fp0
, ft
);
1254 tcg_temp_free_i64(fp0
);
1260 TCGv_i64 fp0
= tcg_temp_new_i64();
1262 gen_load_fpr64(ctx
, fp0
, ft
);
1263 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1264 tcg_temp_free_i64(fp0
);
1270 generate_exception(ctx
, EXCP_RI
);
1273 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1278 /* Arithmetic with immediate operand */
1279 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1280 int rt
, int rs
, int16_t imm
)
1282 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1283 const char *opn
= "imm arith";
1285 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1286 /* If no destination, treat it as a NOP.
1287 For addi, we must generate the overflow exception when needed. */
1294 TCGv t0
= tcg_temp_local_new();
1295 TCGv t1
= tcg_temp_new();
1296 TCGv t2
= tcg_temp_new();
1297 int l1
= gen_new_label();
1299 gen_load_gpr(t1
, rs
);
1300 tcg_gen_addi_tl(t0
, t1
, uimm
);
1301 tcg_gen_ext32s_tl(t0
, t0
);
1303 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1304 tcg_gen_xori_tl(t2
, t0
, uimm
);
1305 tcg_gen_and_tl(t1
, t1
, t2
);
1307 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1309 /* operands of same sign, result different sign */
1310 generate_exception(ctx
, EXCP_OVERFLOW
);
1312 tcg_gen_ext32s_tl(t0
, t0
);
1313 gen_store_gpr(t0
, rt
);
1320 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1321 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1323 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1327 #if defined(TARGET_MIPS64)
1330 TCGv t0
= tcg_temp_local_new();
1331 TCGv t1
= tcg_temp_new();
1332 TCGv t2
= tcg_temp_new();
1333 int l1
= gen_new_label();
1335 gen_load_gpr(t1
, rs
);
1336 tcg_gen_addi_tl(t0
, t1
, uimm
);
1338 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1339 tcg_gen_xori_tl(t2
, t0
, uimm
);
1340 tcg_gen_and_tl(t1
, t1
, t2
);
1342 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1344 /* operands of same sign, result different sign */
1345 generate_exception(ctx
, EXCP_OVERFLOW
);
1347 gen_store_gpr(t0
, rt
);
1354 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1356 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1362 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1365 /* Logic with immediate operand */
1366 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1369 const char *opn
= "imm logic";
1372 /* If no destination, treat it as a NOP. */
1376 uimm
= (uint16_t)imm
;
1379 if (likely(rs
!= 0))
1380 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1382 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1387 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1389 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1393 if (likely(rs
!= 0))
1394 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1396 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1400 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1404 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1407 /* Set on less than with immediate operand */
1408 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1410 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1411 const char *opn
= "imm arith";
1415 /* If no destination, treat it as a NOP. */
1419 t0
= tcg_temp_new();
1420 gen_load_gpr(t0
, rs
);
1423 gen_op_lti(cpu_gpr
[rt
], t0
, uimm
);
1427 gen_op_ltiu(cpu_gpr
[rt
], t0
, uimm
);
1431 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1435 /* Shifts with immediate operand */
1436 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1437 int rt
, int rs
, int16_t imm
)
1439 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1440 const char *opn
= "imm shift";
1444 /* If no destination, treat it as a NOP. */
1449 t0
= tcg_temp_new();
1450 gen_load_gpr(t0
, rs
);
1453 tcg_gen_shli_tl(t0
, t0
, uimm
);
1454 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1458 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1463 tcg_gen_ext32u_tl(t0
, t0
);
1464 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1466 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1472 TCGv_i32 t1
= tcg_temp_new_i32();
1474 tcg_gen_trunc_tl_i32(t1
, t0
);
1475 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1476 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1477 tcg_temp_free_i32(t1
);
1479 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1483 #if defined(TARGET_MIPS64)
1485 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1489 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1493 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1498 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1500 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
1505 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1509 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1513 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1517 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1522 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1527 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1528 int rd
, int rs
, int rt
)
1530 const char *opn
= "arith";
1532 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1533 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1534 /* If no destination, treat it as a NOP.
1535 For add & sub, we must generate the overflow exception when needed. */
1543 TCGv t0
= tcg_temp_local_new();
1544 TCGv t1
= tcg_temp_new();
1545 TCGv t2
= tcg_temp_new();
1546 int l1
= gen_new_label();
1548 gen_load_gpr(t1
, rs
);
1549 gen_load_gpr(t2
, rt
);
1550 tcg_gen_add_tl(t0
, t1
, t2
);
1551 tcg_gen_ext32s_tl(t0
, t0
);
1552 tcg_gen_xor_tl(t1
, t1
, t2
);
1553 tcg_gen_not_tl(t1
, t1
);
1554 tcg_gen_xor_tl(t2
, t0
, t2
);
1555 tcg_gen_and_tl(t1
, t1
, t2
);
1557 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1559 /* operands of same sign, result different sign */
1560 generate_exception(ctx
, EXCP_OVERFLOW
);
1562 gen_store_gpr(t0
, rd
);
1568 if (rs
!= 0 && rt
!= 0) {
1569 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1570 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1571 } else if (rs
== 0 && rt
!= 0) {
1572 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1573 } else if (rs
!= 0 && rt
== 0) {
1574 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1576 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1582 TCGv t0
= tcg_temp_local_new();
1583 TCGv t1
= tcg_temp_new();
1584 TCGv t2
= tcg_temp_new();
1585 int l1
= gen_new_label();
1587 gen_load_gpr(t1
, rs
);
1588 gen_load_gpr(t2
, rt
);
1589 tcg_gen_sub_tl(t0
, t1
, t2
);
1590 tcg_gen_ext32s_tl(t0
, t0
);
1591 tcg_gen_xor_tl(t2
, t1
, t2
);
1592 tcg_gen_xor_tl(t1
, t0
, t1
);
1593 tcg_gen_and_tl(t1
, t1
, t2
);
1595 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1597 /* operands of different sign, first operand and result different sign */
1598 generate_exception(ctx
, EXCP_OVERFLOW
);
1600 gen_store_gpr(t0
, rd
);
1606 if (rs
!= 0 && rt
!= 0) {
1607 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1608 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1609 } else if (rs
== 0 && rt
!= 0) {
1610 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1611 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1612 } else if (rs
!= 0 && rt
== 0) {
1613 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1615 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1619 #if defined(TARGET_MIPS64)
1622 TCGv t0
= tcg_temp_local_new();
1623 TCGv t1
= tcg_temp_new();
1624 TCGv t2
= tcg_temp_new();
1625 int l1
= gen_new_label();
1627 gen_load_gpr(t1
, rs
);
1628 gen_load_gpr(t2
, rt
);
1629 tcg_gen_add_tl(t0
, t1
, t2
);
1630 tcg_gen_xor_tl(t1
, t1
, t2
);
1631 tcg_gen_not_tl(t1
, t1
);
1632 tcg_gen_xor_tl(t2
, t0
, t2
);
1633 tcg_gen_and_tl(t1
, t1
, t2
);
1635 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1637 /* operands of same sign, result different sign */
1638 generate_exception(ctx
, EXCP_OVERFLOW
);
1640 gen_store_gpr(t0
, rd
);
1646 if (rs
!= 0 && rt
!= 0) {
1647 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1648 } else if (rs
== 0 && rt
!= 0) {
1649 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1650 } else if (rs
!= 0 && rt
== 0) {
1651 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1653 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1659 TCGv t0
= tcg_temp_local_new();
1660 TCGv t1
= tcg_temp_new();
1661 TCGv t2
= tcg_temp_new();
1662 int l1
= gen_new_label();
1664 gen_load_gpr(t1
, rs
);
1665 gen_load_gpr(t2
, rt
);
1666 tcg_gen_sub_tl(t0
, t1
, t2
);
1667 tcg_gen_xor_tl(t2
, t1
, t2
);
1668 tcg_gen_xor_tl(t1
, t0
, t1
);
1669 tcg_gen_and_tl(t1
, t1
, t2
);
1671 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1673 /* operands of different sign, first operand and result different sign */
1674 generate_exception(ctx
, EXCP_OVERFLOW
);
1676 gen_store_gpr(t0
, rd
);
1682 if (rs
!= 0 && rt
!= 0) {
1683 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1684 } else if (rs
== 0 && rt
!= 0) {
1685 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1686 } else if (rs
!= 0 && rt
== 0) {
1687 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1689 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1695 if (likely(rs
!= 0 && rt
!= 0)) {
1696 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1697 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1699 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1704 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1707 /* Conditional move */
1708 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1710 const char *opn
= "cond move";
1714 /* If no destination, treat it as a NOP.
1715 For add & sub, we must generate the overflow exception when needed. */
1720 l1
= gen_new_label();
1723 if (likely(rt
!= 0))
1724 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1730 if (likely(rt
!= 0))
1731 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1736 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1738 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1741 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1745 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1747 const char *opn
= "logic";
1750 /* If no destination, treat it as a NOP. */
1757 if (likely(rs
!= 0 && rt
!= 0)) {
1758 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1760 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1765 if (rs
!= 0 && rt
!= 0) {
1766 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1767 } else if (rs
== 0 && rt
!= 0) {
1768 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1769 } else if (rs
!= 0 && rt
== 0) {
1770 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1772 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1777 if (likely(rs
!= 0 && rt
!= 0)) {
1778 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1779 } else if (rs
== 0 && rt
!= 0) {
1780 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1781 } else if (rs
!= 0 && rt
== 0) {
1782 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1784 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1789 if (likely(rs
!= 0 && rt
!= 0)) {
1790 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1791 } else if (rs
== 0 && rt
!= 0) {
1792 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1793 } else if (rs
!= 0 && rt
== 0) {
1794 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1796 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1801 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1804 /* Set on lower than */
1805 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1807 const char *opn
= "slt";
1811 /* If no destination, treat it as a NOP. */
1816 t0
= tcg_temp_new();
1817 t1
= tcg_temp_new();
1818 gen_load_gpr(t0
, rs
);
1819 gen_load_gpr(t1
, rt
);
1822 gen_op_lt(cpu_gpr
[rd
], t0
, t1
);
1826 gen_op_ltu(cpu_gpr
[rd
], t0
, t1
);
1830 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1836 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1837 int rd
, int rs
, int rt
)
1839 const char *opn
= "shifts";
1843 /* If no destination, treat it as a NOP.
1844 For add & sub, we must generate the overflow exception when needed. */
1849 t0
= tcg_temp_new();
1850 t1
= tcg_temp_new();
1851 gen_load_gpr(t0
, rs
);
1852 gen_load_gpr(t1
, rt
);
1855 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1856 tcg_gen_shl_tl(t0
, t1
, t0
);
1857 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1861 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1862 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1866 tcg_gen_ext32u_tl(t1
, t1
);
1867 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1868 tcg_gen_shr_tl(t0
, t1
, t0
);
1869 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1874 TCGv_i32 t2
= tcg_temp_new_i32();
1875 TCGv_i32 t3
= tcg_temp_new_i32();
1877 tcg_gen_trunc_tl_i32(t2
, t0
);
1878 tcg_gen_trunc_tl_i32(t3
, t1
);
1879 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1880 tcg_gen_rotr_i32(t2
, t3
, t2
);
1881 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1882 tcg_temp_free_i32(t2
);
1883 tcg_temp_free_i32(t3
);
1887 #if defined(TARGET_MIPS64)
1889 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1890 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1894 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1895 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1899 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1900 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1904 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1905 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1910 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1915 /* Arithmetic on HI/LO registers */
1916 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1918 const char *opn
= "hilo";
1920 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1927 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1931 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1936 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1938 tcg_gen_movi_tl(cpu_HI
[0], 0);
1943 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
1945 tcg_gen_movi_tl(cpu_LO
[0], 0);
1949 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1952 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1955 const char *opn
= "mul/div";
1961 #if defined(TARGET_MIPS64)
1965 t0
= tcg_temp_local_new();
1966 t1
= tcg_temp_local_new();
1969 t0
= tcg_temp_new();
1970 t1
= tcg_temp_new();
1974 gen_load_gpr(t0
, rs
);
1975 gen_load_gpr(t1
, rt
);
1979 int l1
= gen_new_label();
1980 int l2
= gen_new_label();
1982 tcg_gen_ext32s_tl(t0
, t0
);
1983 tcg_gen_ext32s_tl(t1
, t1
);
1984 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1985 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
1986 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
1988 tcg_gen_mov_tl(cpu_LO
[0], t0
);
1989 tcg_gen_movi_tl(cpu_HI
[0], 0);
1992 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
1993 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
1994 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
1995 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2002 int l1
= gen_new_label();
2004 tcg_gen_ext32u_tl(t0
, t0
);
2005 tcg_gen_ext32u_tl(t1
, t1
);
2006 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2007 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2008 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2009 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2010 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2017 TCGv_i64 t2
= tcg_temp_new_i64();
2018 TCGv_i64 t3
= tcg_temp_new_i64();
2020 tcg_gen_ext_tl_i64(t2
, t0
);
2021 tcg_gen_ext_tl_i64(t3
, t1
);
2022 tcg_gen_mul_i64(t2
, t2
, t3
);
2023 tcg_temp_free_i64(t3
);
2024 tcg_gen_trunc_i64_tl(t0
, t2
);
2025 tcg_gen_shri_i64(t2
, t2
, 32);
2026 tcg_gen_trunc_i64_tl(t1
, t2
);
2027 tcg_temp_free_i64(t2
);
2028 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2029 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2035 TCGv_i64 t2
= tcg_temp_new_i64();
2036 TCGv_i64 t3
= tcg_temp_new_i64();
2038 tcg_gen_ext32u_tl(t0
, t0
);
2039 tcg_gen_ext32u_tl(t1
, t1
);
2040 tcg_gen_extu_tl_i64(t2
, t0
);
2041 tcg_gen_extu_tl_i64(t3
, t1
);
2042 tcg_gen_mul_i64(t2
, t2
, t3
);
2043 tcg_temp_free_i64(t3
);
2044 tcg_gen_trunc_i64_tl(t0
, t2
);
2045 tcg_gen_shri_i64(t2
, t2
, 32);
2046 tcg_gen_trunc_i64_tl(t1
, t2
);
2047 tcg_temp_free_i64(t2
);
2048 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2049 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2053 #if defined(TARGET_MIPS64)
2056 int l1
= gen_new_label();
2057 int l2
= gen_new_label();
2059 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2060 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2061 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2062 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2063 tcg_gen_movi_tl(cpu_HI
[0], 0);
2066 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2067 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2074 int l1
= gen_new_label();
2076 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2077 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2078 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2084 gen_helper_dmult(t0
, t1
);
2088 gen_helper_dmultu(t0
, t1
);
2094 TCGv_i64 t2
= tcg_temp_new_i64();
2095 TCGv_i64 t3
= tcg_temp_new_i64();
2097 tcg_gen_ext_tl_i64(t2
, t0
);
2098 tcg_gen_ext_tl_i64(t3
, t1
);
2099 tcg_gen_mul_i64(t2
, t2
, t3
);
2100 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2101 tcg_gen_add_i64(t2
, t2
, t3
);
2102 tcg_temp_free_i64(t3
);
2103 tcg_gen_trunc_i64_tl(t0
, t2
);
2104 tcg_gen_shri_i64(t2
, t2
, 32);
2105 tcg_gen_trunc_i64_tl(t1
, t2
);
2106 tcg_temp_free_i64(t2
);
2107 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2108 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2114 TCGv_i64 t2
= tcg_temp_new_i64();
2115 TCGv_i64 t3
= tcg_temp_new_i64();
2117 tcg_gen_ext32u_tl(t0
, t0
);
2118 tcg_gen_ext32u_tl(t1
, t1
);
2119 tcg_gen_extu_tl_i64(t2
, t0
);
2120 tcg_gen_extu_tl_i64(t3
, t1
);
2121 tcg_gen_mul_i64(t2
, t2
, t3
);
2122 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2123 tcg_gen_add_i64(t2
, t2
, t3
);
2124 tcg_temp_free_i64(t3
);
2125 tcg_gen_trunc_i64_tl(t0
, t2
);
2126 tcg_gen_shri_i64(t2
, t2
, 32);
2127 tcg_gen_trunc_i64_tl(t1
, t2
);
2128 tcg_temp_free_i64(t2
);
2129 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2130 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2136 TCGv_i64 t2
= tcg_temp_new_i64();
2137 TCGv_i64 t3
= tcg_temp_new_i64();
2139 tcg_gen_ext_tl_i64(t2
, t0
);
2140 tcg_gen_ext_tl_i64(t3
, t1
);
2141 tcg_gen_mul_i64(t2
, t2
, t3
);
2142 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2143 tcg_gen_sub_i64(t2
, t3
, t2
);
2144 tcg_temp_free_i64(t3
);
2145 tcg_gen_trunc_i64_tl(t0
, t2
);
2146 tcg_gen_shri_i64(t2
, t2
, 32);
2147 tcg_gen_trunc_i64_tl(t1
, t2
);
2148 tcg_temp_free_i64(t2
);
2149 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2150 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2156 TCGv_i64 t2
= tcg_temp_new_i64();
2157 TCGv_i64 t3
= tcg_temp_new_i64();
2159 tcg_gen_ext32u_tl(t0
, t0
);
2160 tcg_gen_ext32u_tl(t1
, t1
);
2161 tcg_gen_extu_tl_i64(t2
, t0
);
2162 tcg_gen_extu_tl_i64(t3
, t1
);
2163 tcg_gen_mul_i64(t2
, t2
, t3
);
2164 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2165 tcg_gen_sub_i64(t2
, t3
, t2
);
2166 tcg_temp_free_i64(t3
);
2167 tcg_gen_trunc_i64_tl(t0
, t2
);
2168 tcg_gen_shri_i64(t2
, t2
, 32);
2169 tcg_gen_trunc_i64_tl(t1
, t2
);
2170 tcg_temp_free_i64(t2
);
2171 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2172 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2178 generate_exception(ctx
, EXCP_RI
);
2181 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2187 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2188 int rd
, int rs
, int rt
)
2190 const char *opn
= "mul vr54xx";
2191 TCGv t0
= tcg_temp_new();
2192 TCGv t1
= tcg_temp_new();
2194 gen_load_gpr(t0
, rs
);
2195 gen_load_gpr(t1
, rt
);
2198 case OPC_VR54XX_MULS
:
2199 gen_helper_muls(t0
, t0
, t1
);
2202 case OPC_VR54XX_MULSU
:
2203 gen_helper_mulsu(t0
, t0
, t1
);
2206 case OPC_VR54XX_MACC
:
2207 gen_helper_macc(t0
, t0
, t1
);
2210 case OPC_VR54XX_MACCU
:
2211 gen_helper_maccu(t0
, t0
, t1
);
2214 case OPC_VR54XX_MSAC
:
2215 gen_helper_msac(t0
, t0
, t1
);
2218 case OPC_VR54XX_MSACU
:
2219 gen_helper_msacu(t0
, t0
, t1
);
2222 case OPC_VR54XX_MULHI
:
2223 gen_helper_mulhi(t0
, t0
, t1
);
2226 case OPC_VR54XX_MULHIU
:
2227 gen_helper_mulhiu(t0
, t0
, t1
);
2230 case OPC_VR54XX_MULSHI
:
2231 gen_helper_mulshi(t0
, t0
, t1
);
2234 case OPC_VR54XX_MULSHIU
:
2235 gen_helper_mulshiu(t0
, t0
, t1
);
2238 case OPC_VR54XX_MACCHI
:
2239 gen_helper_macchi(t0
, t0
, t1
);
2242 case OPC_VR54XX_MACCHIU
:
2243 gen_helper_macchiu(t0
, t0
, t1
);
2246 case OPC_VR54XX_MSACHI
:
2247 gen_helper_msachi(t0
, t0
, t1
);
2250 case OPC_VR54XX_MSACHIU
:
2251 gen_helper_msachiu(t0
, t0
, t1
);
2255 MIPS_INVAL("mul vr54xx");
2256 generate_exception(ctx
, EXCP_RI
);
2259 gen_store_gpr(t0
, rd
);
2260 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2267 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2270 const char *opn
= "CLx";
2278 t0
= tcg_temp_new();
2279 gen_load_gpr(t0
, rs
);
2282 gen_helper_clo(cpu_gpr
[rd
], t0
);
2286 gen_helper_clz(cpu_gpr
[rd
], t0
);
2289 #if defined(TARGET_MIPS64)
2291 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2295 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2300 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2305 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2306 int rs
, int rt
, int16_t imm
)
2309 TCGv t0
= tcg_temp_new();
2310 TCGv t1
= tcg_temp_new();
2313 /* Load needed operands */
2321 /* Compare two registers */
2323 gen_load_gpr(t0
, rs
);
2324 gen_load_gpr(t1
, rt
);
2334 /* Compare register to immediate */
2335 if (rs
!= 0 || imm
!= 0) {
2336 gen_load_gpr(t0
, rs
);
2337 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2344 case OPC_TEQ
: /* rs == rs */
2345 case OPC_TEQI
: /* r0 == 0 */
2346 case OPC_TGE
: /* rs >= rs */
2347 case OPC_TGEI
: /* r0 >= 0 */
2348 case OPC_TGEU
: /* rs >= rs unsigned */
2349 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2351 generate_exception(ctx
, EXCP_TRAP
);
2353 case OPC_TLT
: /* rs < rs */
2354 case OPC_TLTI
: /* r0 < 0 */
2355 case OPC_TLTU
: /* rs < rs unsigned */
2356 case OPC_TLTIU
: /* r0 < 0 unsigned */
2357 case OPC_TNE
: /* rs != rs */
2358 case OPC_TNEI
: /* r0 != 0 */
2359 /* Never trap: treat as NOP. */
2363 int l1
= gen_new_label();
2368 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2372 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2376 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2380 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2384 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2388 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2391 generate_exception(ctx
, EXCP_TRAP
);
2398 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2400 TranslationBlock
*tb
;
2402 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2403 likely(!ctx
->singlestep_enabled
)) {
2406 tcg_gen_exit_tb((long)tb
+ n
);
2409 if (ctx
->singlestep_enabled
) {
2410 save_cpu_state(ctx
, 0);
2411 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
2417 /* Branches (before delay slot) */
2418 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2420 int rs
, int rt
, int32_t offset
)
2422 target_ulong btgt
= -1;
2424 int bcond_compute
= 0;
2425 TCGv t0
= tcg_temp_new();
2426 TCGv t1
= tcg_temp_new();
2428 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2429 #ifdef MIPS_DEBUG_DISAS
2430 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2432 generate_exception(ctx
, EXCP_RI
);
2436 /* Load needed operands */
2442 /* Compare two registers */
2444 gen_load_gpr(t0
, rs
);
2445 gen_load_gpr(t1
, rt
);
2448 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2462 /* Compare to zero */
2464 gen_load_gpr(t0
, rs
);
2467 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2472 /* Jump to immediate */
2473 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
2478 /* Jump to register */
2479 if (offset
!= 0 && offset
!= 16) {
2480 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2481 others are reserved. */
2482 MIPS_INVAL("jump hint");
2483 generate_exception(ctx
, EXCP_RI
);
2486 gen_load_gpr(btarget
, rs
);
2489 MIPS_INVAL("branch/jump");
2490 generate_exception(ctx
, EXCP_RI
);
2493 if (bcond_compute
== 0) {
2494 /* No condition to be computed */
2496 case OPC_BEQ
: /* rx == rx */
2497 case OPC_BEQL
: /* rx == rx likely */
2498 case OPC_BGEZ
: /* 0 >= 0 */
2499 case OPC_BGEZL
: /* 0 >= 0 likely */
2500 case OPC_BLEZ
: /* 0 <= 0 */
2501 case OPC_BLEZL
: /* 0 <= 0 likely */
2503 ctx
->hflags
|= MIPS_HFLAG_B
;
2504 MIPS_DEBUG("balways");
2506 case OPC_BGEZAL
: /* 0 >= 0 */
2507 case OPC_BGEZALL
: /* 0 >= 0 likely */
2508 /* Always take and link */
2510 ctx
->hflags
|= MIPS_HFLAG_B
;
2511 MIPS_DEBUG("balways and link");
2513 case OPC_BNE
: /* rx != rx */
2514 case OPC_BGTZ
: /* 0 > 0 */
2515 case OPC_BLTZ
: /* 0 < 0 */
2517 MIPS_DEBUG("bnever (NOP)");
2519 case OPC_BLTZAL
: /* 0 < 0 */
2520 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2521 MIPS_DEBUG("bnever and link");
2523 case OPC_BLTZALL
: /* 0 < 0 likely */
2524 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2525 /* Skip the instruction in the delay slot */
2526 MIPS_DEBUG("bnever, link and skip");
2529 case OPC_BNEL
: /* rx != rx likely */
2530 case OPC_BGTZL
: /* 0 > 0 likely */
2531 case OPC_BLTZL
: /* 0 < 0 likely */
2532 /* Skip the instruction in the delay slot */
2533 MIPS_DEBUG("bnever and skip");
2537 ctx
->hflags
|= MIPS_HFLAG_B
;
2538 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2541 ctx
->hflags
|= MIPS_HFLAG_BX
;
2545 ctx
->hflags
|= MIPS_HFLAG_B
;
2546 ctx
->hflags
|= (ctx
->hflags
& MIPS_HFLAG_M16
2548 : MIPS_HFLAG_BDS32
);
2549 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2552 ctx
->hflags
|= MIPS_HFLAG_BR
;
2553 if (ctx
->hflags
& MIPS_HFLAG_M16
)
2554 ctx
->hflags
|= MIPS_HFLAG_BDS16
;
2555 MIPS_DEBUG("jr %s", regnames
[rs
]);
2560 ctx
->hflags
|= MIPS_HFLAG_BR
;
2561 if (ctx
->hflags
& MIPS_HFLAG_M16
)
2562 ctx
->hflags
|= MIPS_HFLAG_BDS16
;
2563 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2566 MIPS_INVAL("branch/jump");
2567 generate_exception(ctx
, EXCP_RI
);
2573 gen_op_eq(bcond
, t0
, t1
);
2574 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2575 regnames
[rs
], regnames
[rt
], btgt
);
2578 gen_op_eq(bcond
, t0
, t1
);
2579 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2580 regnames
[rs
], regnames
[rt
], btgt
);
2583 gen_op_ne(bcond
, t0
, t1
);
2584 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2585 regnames
[rs
], regnames
[rt
], btgt
);
2588 gen_op_ne(bcond
, t0
, t1
);
2589 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2590 regnames
[rs
], regnames
[rt
], btgt
);
2593 gen_op_gez(bcond
, t0
);
2594 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2597 gen_op_gez(bcond
, t0
);
2598 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2601 gen_op_gez(bcond
, t0
);
2602 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2606 gen_op_gez(bcond
, t0
);
2608 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2611 gen_op_gtz(bcond
, t0
);
2612 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2615 gen_op_gtz(bcond
, t0
);
2616 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2619 gen_op_lez(bcond
, t0
);
2620 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2623 gen_op_lez(bcond
, t0
);
2624 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2627 gen_op_ltz(bcond
, t0
);
2628 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2631 gen_op_ltz(bcond
, t0
);
2632 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2635 gen_op_ltz(bcond
, t0
);
2637 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2639 ctx
->hflags
|= MIPS_HFLAG_BC
;
2642 gen_op_ltz(bcond
, t0
);
2644 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2646 ctx
->hflags
|= MIPS_HFLAG_BL
;
2649 MIPS_INVAL("conditional branch/jump");
2650 generate_exception(ctx
, EXCP_RI
);
2654 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2655 blink
, ctx
->hflags
, btgt
);
2657 ctx
->btarget
= btgt
;
2659 int post_delay
= insn_bytes
;
2660 int lowbit
= !!(ctx
->hflags
& MIPS_HFLAG_M16
);
2662 if (opc
!= OPC_JALRC
)
2663 post_delay
+= ((ctx
->hflags
& MIPS_HFLAG_BDS16
) ? 2 : 4);
2665 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ post_delay
+ lowbit
);
2669 if (insn_bytes
== 2)
2670 ctx
->hflags
|= MIPS_HFLAG_B16
;
2675 /* special3 bitfield operations */
2676 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2677 int rs
, int lsb
, int msb
)
2679 TCGv t0
= tcg_temp_new();
2680 TCGv t1
= tcg_temp_new();
2683 gen_load_gpr(t1
, rs
);
2688 tcg_gen_shri_tl(t0
, t1
, lsb
);
2690 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2692 tcg_gen_ext32s_tl(t0
, t0
);
2695 #if defined(TARGET_MIPS64)
2697 tcg_gen_shri_tl(t0
, t1
, lsb
);
2699 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2703 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2704 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2707 tcg_gen_shri_tl(t0
, t1
, lsb
);
2708 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2714 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2715 gen_load_gpr(t0
, rt
);
2716 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2717 tcg_gen_shli_tl(t1
, t1
, lsb
);
2718 tcg_gen_andi_tl(t1
, t1
, mask
);
2719 tcg_gen_or_tl(t0
, t0
, t1
);
2720 tcg_gen_ext32s_tl(t0
, t0
);
2722 #if defined(TARGET_MIPS64)
2726 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2727 gen_load_gpr(t0
, rt
);
2728 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2729 tcg_gen_shli_tl(t1
, t1
, lsb
);
2730 tcg_gen_andi_tl(t1
, t1
, mask
);
2731 tcg_gen_or_tl(t0
, t0
, t1
);
2736 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2737 gen_load_gpr(t0
, rt
);
2738 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2739 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2740 tcg_gen_andi_tl(t1
, t1
, mask
);
2741 tcg_gen_or_tl(t0
, t0
, t1
);
2746 gen_load_gpr(t0
, rt
);
2747 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2748 gen_load_gpr(t0
, rt
);
2749 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2750 tcg_gen_shli_tl(t1
, t1
, lsb
);
2751 tcg_gen_andi_tl(t1
, t1
, mask
);
2752 tcg_gen_or_tl(t0
, t0
, t1
);
2757 MIPS_INVAL("bitops");
2758 generate_exception(ctx
, EXCP_RI
);
2763 gen_store_gpr(t0
, rt
);
2768 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2773 /* If no destination, treat it as a NOP. */
2778 t0
= tcg_temp_new();
2779 gen_load_gpr(t0
, rt
);
2783 TCGv t1
= tcg_temp_new();
2785 tcg_gen_shri_tl(t1
, t0
, 8);
2786 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2787 tcg_gen_shli_tl(t0
, t0
, 8);
2788 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2789 tcg_gen_or_tl(t0
, t0
, t1
);
2791 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2795 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2798 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2800 #if defined(TARGET_MIPS64)
2803 TCGv t1
= tcg_temp_new();
2805 tcg_gen_shri_tl(t1
, t0
, 8);
2806 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2807 tcg_gen_shli_tl(t0
, t0
, 8);
2808 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2809 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2815 TCGv t1
= tcg_temp_new();
2817 tcg_gen_shri_tl(t1
, t0
, 16);
2818 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2819 tcg_gen_shli_tl(t0
, t0
, 16);
2820 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2821 tcg_gen_or_tl(t0
, t0
, t1
);
2822 tcg_gen_shri_tl(t1
, t0
, 32);
2823 tcg_gen_shli_tl(t0
, t0
, 32);
2824 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2830 MIPS_INVAL("bsfhl");
2831 generate_exception(ctx
, EXCP_RI
);
2838 #ifndef CONFIG_USER_ONLY
2839 /* CP0 (MMU and control) */
2840 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
2842 TCGv_i32 t0
= tcg_temp_new_i32();
2844 tcg_gen_ld_i32(t0
, cpu_env
, off
);
2845 tcg_gen_ext_i32_tl(arg
, t0
);
2846 tcg_temp_free_i32(t0
);
2849 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
2851 tcg_gen_ld_tl(arg
, cpu_env
, off
);
2852 tcg_gen_ext32s_tl(arg
, arg
);
2855 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
2857 TCGv_i32 t0
= tcg_temp_new_i32();
2859 tcg_gen_trunc_tl_i32(t0
, arg
);
2860 tcg_gen_st_i32(t0
, cpu_env
, off
);
2861 tcg_temp_free_i32(t0
);
2864 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
2866 tcg_gen_ext32s_tl(arg
, arg
);
2867 tcg_gen_st_tl(arg
, cpu_env
, off
);
2870 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
2872 const char *rn
= "invalid";
2875 check_insn(env
, ctx
, ISA_MIPS32
);
2881 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
2885 check_insn(env
, ctx
, ASE_MT
);
2886 gen_helper_mfc0_mvpcontrol(arg
);
2890 check_insn(env
, ctx
, ASE_MT
);
2891 gen_helper_mfc0_mvpconf0(arg
);
2895 check_insn(env
, ctx
, ASE_MT
);
2896 gen_helper_mfc0_mvpconf1(arg
);
2906 gen_helper_mfc0_random(arg
);
2910 check_insn(env
, ctx
, ASE_MT
);
2911 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
2915 check_insn(env
, ctx
, ASE_MT
);
2916 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
2920 check_insn(env
, ctx
, ASE_MT
);
2921 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
2925 check_insn(env
, ctx
, ASE_MT
);
2926 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
2930 check_insn(env
, ctx
, ASE_MT
);
2931 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
2935 check_insn(env
, ctx
, ASE_MT
);
2936 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
2937 rn
= "VPEScheFBack";
2940 check_insn(env
, ctx
, ASE_MT
);
2941 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
2951 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2952 tcg_gen_ext32s_tl(arg
, arg
);
2956 check_insn(env
, ctx
, ASE_MT
);
2957 gen_helper_mfc0_tcstatus(arg
);
2961 check_insn(env
, ctx
, ASE_MT
);
2962 gen_helper_mfc0_tcbind(arg
);
2966 check_insn(env
, ctx
, ASE_MT
);
2967 gen_helper_mfc0_tcrestart(arg
);
2971 check_insn(env
, ctx
, ASE_MT
);
2972 gen_helper_mfc0_tchalt(arg
);
2976 check_insn(env
, ctx
, ASE_MT
);
2977 gen_helper_mfc0_tccontext(arg
);
2981 check_insn(env
, ctx
, ASE_MT
);
2982 gen_helper_mfc0_tcschedule(arg
);
2986 check_insn(env
, ctx
, ASE_MT
);
2987 gen_helper_mfc0_tcschefback(arg
);
2997 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2998 tcg_gen_ext32s_tl(arg
, arg
);
3008 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
3009 tcg_gen_ext32s_tl(arg
, arg
);
3013 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3014 rn
= "ContextConfig";
3023 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
3027 check_insn(env
, ctx
, ISA_MIPS32R2
);
3028 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
3038 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
3042 check_insn(env
, ctx
, ISA_MIPS32R2
);
3043 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3047 check_insn(env
, ctx
, ISA_MIPS32R2
);
3048 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3052 check_insn(env
, ctx
, ISA_MIPS32R2
);
3053 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3057 check_insn(env
, ctx
, ISA_MIPS32R2
);
3058 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3062 check_insn(env
, ctx
, ISA_MIPS32R2
);
3063 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3073 check_insn(env
, ctx
, ISA_MIPS32R2
);
3074 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3084 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3085 tcg_gen_ext32s_tl(arg
, arg
);
3095 /* Mark as an IO operation because we read the time. */
3098 gen_helper_mfc0_count(arg
);
3101 ctx
->bstate
= BS_STOP
;
3105 /* 6,7 are implementation dependent */
3113 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3114 tcg_gen_ext32s_tl(arg
, arg
);
3124 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3127 /* 6,7 are implementation dependent */
3135 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3139 check_insn(env
, ctx
, ISA_MIPS32R2
);
3140 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3144 check_insn(env
, ctx
, ISA_MIPS32R2
);
3145 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3149 check_insn(env
, ctx
, ISA_MIPS32R2
);
3150 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3160 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3170 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3171 tcg_gen_ext32s_tl(arg
, arg
);
3181 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3185 check_insn(env
, ctx
, ISA_MIPS32R2
);
3186 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3196 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3200 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3204 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3208 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3211 /* 4,5 are reserved */
3212 /* 6,7 are implementation dependent */
3214 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3218 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3228 gen_helper_mfc0_lladdr(arg
);
3238 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3248 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3258 #if defined(TARGET_MIPS64)
3259 check_insn(env
, ctx
, ISA_MIPS3
);
3260 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3261 tcg_gen_ext32s_tl(arg
, arg
);
3270 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3273 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3281 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3282 rn
= "'Diagnostic"; /* implementation dependent */
3287 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3291 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3292 rn
= "TraceControl";
3295 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3296 rn
= "TraceControl2";
3299 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3300 rn
= "UserTraceData";
3303 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3314 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3315 tcg_gen_ext32s_tl(arg
, arg
);
3325 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3326 rn
= "Performance0";
3329 // gen_helper_mfc0_performance1(arg);
3330 rn
= "Performance1";
3333 // gen_helper_mfc0_performance2(arg);
3334 rn
= "Performance2";
3337 // gen_helper_mfc0_performance3(arg);
3338 rn
= "Performance3";
3341 // gen_helper_mfc0_performance4(arg);
3342 rn
= "Performance4";
3345 // gen_helper_mfc0_performance5(arg);
3346 rn
= "Performance5";
3349 // gen_helper_mfc0_performance6(arg);
3350 rn
= "Performance6";
3353 // gen_helper_mfc0_performance7(arg);
3354 rn
= "Performance7";
3361 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3367 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3380 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3387 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3400 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3407 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3417 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3418 tcg_gen_ext32s_tl(arg
, arg
);
3429 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3439 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3443 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3444 generate_exception(ctx
, EXCP_RI
);
3447 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3449 const char *rn
= "invalid";
3452 check_insn(env
, ctx
, ISA_MIPS32
);
3461 gen_helper_mtc0_index(arg
);
3465 check_insn(env
, ctx
, ASE_MT
);
3466 gen_helper_mtc0_mvpcontrol(arg
);
3470 check_insn(env
, ctx
, ASE_MT
);
3475 check_insn(env
, ctx
, ASE_MT
);
3490 check_insn(env
, ctx
, ASE_MT
);
3491 gen_helper_mtc0_vpecontrol(arg
);
3495 check_insn(env
, ctx
, ASE_MT
);
3496 gen_helper_mtc0_vpeconf0(arg
);
3500 check_insn(env
, ctx
, ASE_MT
);
3501 gen_helper_mtc0_vpeconf1(arg
);
3505 check_insn(env
, ctx
, ASE_MT
);
3506 gen_helper_mtc0_yqmask(arg
);
3510 check_insn(env
, ctx
, ASE_MT
);
3511 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3515 check_insn(env
, ctx
, ASE_MT
);
3516 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3517 rn
= "VPEScheFBack";
3520 check_insn(env
, ctx
, ASE_MT
);
3521 gen_helper_mtc0_vpeopt(arg
);
3531 gen_helper_mtc0_entrylo0(arg
);
3535 check_insn(env
, ctx
, ASE_MT
);
3536 gen_helper_mtc0_tcstatus(arg
);
3540 check_insn(env
, ctx
, ASE_MT
);
3541 gen_helper_mtc0_tcbind(arg
);
3545 check_insn(env
, ctx
, ASE_MT
);
3546 gen_helper_mtc0_tcrestart(arg
);
3550 check_insn(env
, ctx
, ASE_MT
);
3551 gen_helper_mtc0_tchalt(arg
);
3555 check_insn(env
, ctx
, ASE_MT
);
3556 gen_helper_mtc0_tccontext(arg
);
3560 check_insn(env
, ctx
, ASE_MT
);
3561 gen_helper_mtc0_tcschedule(arg
);
3565 check_insn(env
, ctx
, ASE_MT
);
3566 gen_helper_mtc0_tcschefback(arg
);
3576 gen_helper_mtc0_entrylo1(arg
);
3586 gen_helper_mtc0_context(arg
);
3590 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3591 rn
= "ContextConfig";
3600 gen_helper_mtc0_pagemask(arg
);
3604 check_insn(env
, ctx
, ISA_MIPS32R2
);
3605 gen_helper_mtc0_pagegrain(arg
);
3615 gen_helper_mtc0_wired(arg
);
3619 check_insn(env
, ctx
, ISA_MIPS32R2
);
3620 gen_helper_mtc0_srsconf0(arg
);
3624 check_insn(env
, ctx
, ISA_MIPS32R2
);
3625 gen_helper_mtc0_srsconf1(arg
);
3629 check_insn(env
, ctx
, ISA_MIPS32R2
);
3630 gen_helper_mtc0_srsconf2(arg
);
3634 check_insn(env
, ctx
, ISA_MIPS32R2
);
3635 gen_helper_mtc0_srsconf3(arg
);
3639 check_insn(env
, ctx
, ISA_MIPS32R2
);
3640 gen_helper_mtc0_srsconf4(arg
);
3650 check_insn(env
, ctx
, ISA_MIPS32R2
);
3651 gen_helper_mtc0_hwrena(arg
);
3665 gen_helper_mtc0_count(arg
);
3668 /* 6,7 are implementation dependent */
3676 gen_helper_mtc0_entryhi(arg
);
3686 gen_helper_mtc0_compare(arg
);
3689 /* 6,7 are implementation dependent */
3697 save_cpu_state(ctx
, 1);
3698 gen_helper_mtc0_status(arg
);
3699 /* BS_STOP isn't good enough here, hflags may have changed. */
3700 gen_save_pc(ctx
->pc
+ 4);
3701 ctx
->bstate
= BS_EXCP
;
3705 check_insn(env
, ctx
, ISA_MIPS32R2
);
3706 gen_helper_mtc0_intctl(arg
);
3707 /* Stop translation as we may have switched the execution mode */
3708 ctx
->bstate
= BS_STOP
;
3712 check_insn(env
, ctx
, ISA_MIPS32R2
);
3713 gen_helper_mtc0_srsctl(arg
);
3714 /* Stop translation as we may have switched the execution mode */
3715 ctx
->bstate
= BS_STOP
;
3719 check_insn(env
, ctx
, ISA_MIPS32R2
);
3720 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3721 /* Stop translation as we may have switched the execution mode */
3722 ctx
->bstate
= BS_STOP
;
3732 save_cpu_state(ctx
, 1);
3733 gen_helper_mtc0_cause(arg
);
3743 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
3757 check_insn(env
, ctx
, ISA_MIPS32R2
);
3758 gen_helper_mtc0_ebase(arg
);
3768 gen_helper_mtc0_config0(arg
);
3770 /* Stop translation as we may have switched the execution mode */
3771 ctx
->bstate
= BS_STOP
;
3774 /* ignored, read only */
3778 gen_helper_mtc0_config2(arg
);
3780 /* Stop translation as we may have switched the execution mode */
3781 ctx
->bstate
= BS_STOP
;
3784 /* ignored, read only */
3787 /* 4,5 are reserved */
3788 /* 6,7 are implementation dependent */
3798 rn
= "Invalid config selector";
3805 gen_helper_mtc0_lladdr(arg
);
3815 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
3825 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
3835 #if defined(TARGET_MIPS64)
3836 check_insn(env
, ctx
, ISA_MIPS3
);
3837 gen_helper_mtc0_xcontext(arg
);
3846 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3849 gen_helper_mtc0_framemask(arg
);
3858 rn
= "Diagnostic"; /* implementation dependent */
3863 gen_helper_mtc0_debug(arg
); /* EJTAG support */
3864 /* BS_STOP isn't good enough here, hflags may have changed. */
3865 gen_save_pc(ctx
->pc
+ 4);
3866 ctx
->bstate
= BS_EXCP
;
3870 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
3871 rn
= "TraceControl";
3872 /* Stop translation as we may have switched the execution mode */
3873 ctx
->bstate
= BS_STOP
;
3876 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
3877 rn
= "TraceControl2";
3878 /* Stop translation as we may have switched the execution mode */
3879 ctx
->bstate
= BS_STOP
;
3882 /* Stop translation as we may have switched the execution mode */
3883 ctx
->bstate
= BS_STOP
;
3884 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
3885 rn
= "UserTraceData";
3886 /* Stop translation as we may have switched the execution mode */
3887 ctx
->bstate
= BS_STOP
;
3890 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
3891 /* Stop translation as we may have switched the execution mode */
3892 ctx
->bstate
= BS_STOP
;
3903 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
3913 gen_helper_mtc0_performance0(arg
);
3914 rn
= "Performance0";
3917 // gen_helper_mtc0_performance1(arg);
3918 rn
= "Performance1";
3921 // gen_helper_mtc0_performance2(arg);
3922 rn
= "Performance2";
3925 // gen_helper_mtc0_performance3(arg);
3926 rn
= "Performance3";
3929 // gen_helper_mtc0_performance4(arg);
3930 rn
= "Performance4";
3933 // gen_helper_mtc0_performance5(arg);
3934 rn
= "Performance5";
3937 // gen_helper_mtc0_performance6(arg);
3938 rn
= "Performance6";
3941 // gen_helper_mtc0_performance7(arg);
3942 rn
= "Performance7";
3968 gen_helper_mtc0_taglo(arg
);
3975 gen_helper_mtc0_datalo(arg
);
3988 gen_helper_mtc0_taghi(arg
);
3995 gen_helper_mtc0_datahi(arg
);
4006 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
4017 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4023 /* Stop translation as we may have switched the execution mode */
4024 ctx
->bstate
= BS_STOP
;
4029 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4030 /* For simplicity assume that all writes can cause interrupts. */
4033 ctx
->bstate
= BS_STOP
;
4038 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4039 generate_exception(ctx
, EXCP_RI
);
4042 #if defined(TARGET_MIPS64)
4043 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4045 const char *rn
= "invalid";
4048 check_insn(env
, ctx
, ISA_MIPS64
);
4054 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4058 check_insn(env
, ctx
, ASE_MT
);
4059 gen_helper_mfc0_mvpcontrol(arg
);
4063 check_insn(env
, ctx
, ASE_MT
);
4064 gen_helper_mfc0_mvpconf0(arg
);
4068 check_insn(env
, ctx
, ASE_MT
);
4069 gen_helper_mfc0_mvpconf1(arg
);
4079 gen_helper_mfc0_random(arg
);
4083 check_insn(env
, ctx
, ASE_MT
);
4084 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4088 check_insn(env
, ctx
, ASE_MT
);
4089 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4093 check_insn(env
, ctx
, ASE_MT
);
4094 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4098 check_insn(env
, ctx
, ASE_MT
);
4099 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4103 check_insn(env
, ctx
, ASE_MT
);
4104 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4108 check_insn(env
, ctx
, ASE_MT
);
4109 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4110 rn
= "VPEScheFBack";
4113 check_insn(env
, ctx
, ASE_MT
);
4114 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4124 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4128 check_insn(env
, ctx
, ASE_MT
);
4129 gen_helper_mfc0_tcstatus(arg
);
4133 check_insn(env
, ctx
, ASE_MT
);
4134 gen_helper_mfc0_tcbind(arg
);
4138 check_insn(env
, ctx
, ASE_MT
);
4139 gen_helper_dmfc0_tcrestart(arg
);
4143 check_insn(env
, ctx
, ASE_MT
);
4144 gen_helper_dmfc0_tchalt(arg
);
4148 check_insn(env
, ctx
, ASE_MT
);
4149 gen_helper_dmfc0_tccontext(arg
);
4153 check_insn(env
, ctx
, ASE_MT
);
4154 gen_helper_dmfc0_tcschedule(arg
);
4158 check_insn(env
, ctx
, ASE_MT
);
4159 gen_helper_dmfc0_tcschefback(arg
);
4169 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4179 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4183 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4184 rn
= "ContextConfig";
4193 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4197 check_insn(env
, ctx
, ISA_MIPS32R2
);
4198 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4208 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4212 check_insn(env
, ctx
, ISA_MIPS32R2
);
4213 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4217 check_insn(env
, ctx
, ISA_MIPS32R2
);
4218 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4222 check_insn(env
, ctx
, ISA_MIPS32R2
);
4223 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4227 check_insn(env
, ctx
, ISA_MIPS32R2
);
4228 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4232 check_insn(env
, ctx
, ISA_MIPS32R2
);
4233 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4243 check_insn(env
, ctx
, ISA_MIPS32R2
);
4244 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4254 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4264 /* Mark as an IO operation because we read the time. */
4267 gen_helper_mfc0_count(arg
);
4270 ctx
->bstate
= BS_STOP
;
4274 /* 6,7 are implementation dependent */
4282 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4292 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4295 /* 6,7 are implementation dependent */
4303 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4307 check_insn(env
, ctx
, ISA_MIPS32R2
);
4308 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4312 check_insn(env
, ctx
, ISA_MIPS32R2
);
4313 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4317 check_insn(env
, ctx
, ISA_MIPS32R2
);
4318 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4328 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4338 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4348 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4352 check_insn(env
, ctx
, ISA_MIPS32R2
);
4353 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4363 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4367 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4371 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4375 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4378 /* 6,7 are implementation dependent */
4380 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4384 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4394 gen_helper_dmfc0_lladdr(arg
);
4404 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4414 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4424 check_insn(env
, ctx
, ISA_MIPS3
);
4425 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4433 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4436 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4444 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4445 rn
= "'Diagnostic"; /* implementation dependent */
4450 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4454 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4455 rn
= "TraceControl";
4458 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4459 rn
= "TraceControl2";
4462 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4463 rn
= "UserTraceData";
4466 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4477 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4487 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4488 rn
= "Performance0";
4491 // gen_helper_dmfc0_performance1(arg);
4492 rn
= "Performance1";
4495 // gen_helper_dmfc0_performance2(arg);
4496 rn
= "Performance2";
4499 // gen_helper_dmfc0_performance3(arg);
4500 rn
= "Performance3";
4503 // gen_helper_dmfc0_performance4(arg);
4504 rn
= "Performance4";
4507 // gen_helper_dmfc0_performance5(arg);
4508 rn
= "Performance5";
4511 // gen_helper_dmfc0_performance6(arg);
4512 rn
= "Performance6";
4515 // gen_helper_dmfc0_performance7(arg);
4516 rn
= "Performance7";
4523 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4530 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4543 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4550 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4563 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4570 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4580 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4591 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4601 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4605 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4606 generate_exception(ctx
, EXCP_RI
);
4609 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4611 const char *rn
= "invalid";
4614 check_insn(env
, ctx
, ISA_MIPS64
);
4623 gen_helper_mtc0_index(arg
);
4627 check_insn(env
, ctx
, ASE_MT
);
4628 gen_helper_mtc0_mvpcontrol(arg
);
4632 check_insn(env
, ctx
, ASE_MT
);
4637 check_insn(env
, ctx
, ASE_MT
);
4652 check_insn(env
, ctx
, ASE_MT
);
4653 gen_helper_mtc0_vpecontrol(arg
);
4657 check_insn(env
, ctx
, ASE_MT
);
4658 gen_helper_mtc0_vpeconf0(arg
);
4662 check_insn(env
, ctx
, ASE_MT
);
4663 gen_helper_mtc0_vpeconf1(arg
);
4667 check_insn(env
, ctx
, ASE_MT
);
4668 gen_helper_mtc0_yqmask(arg
);
4672 check_insn(env
, ctx
, ASE_MT
);
4673 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4677 check_insn(env
, ctx
, ASE_MT
);
4678 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4679 rn
= "VPEScheFBack";
4682 check_insn(env
, ctx
, ASE_MT
);
4683 gen_helper_mtc0_vpeopt(arg
);
4693 gen_helper_mtc0_entrylo0(arg
);
4697 check_insn(env
, ctx
, ASE_MT
);
4698 gen_helper_mtc0_tcstatus(arg
);
4702 check_insn(env
, ctx
, ASE_MT
);
4703 gen_helper_mtc0_tcbind(arg
);
4707 check_insn(env
, ctx
, ASE_MT
);
4708 gen_helper_mtc0_tcrestart(arg
);
4712 check_insn(env
, ctx
, ASE_MT
);
4713 gen_helper_mtc0_tchalt(arg
);
4717 check_insn(env
, ctx
, ASE_MT
);
4718 gen_helper_mtc0_tccontext(arg
);
4722 check_insn(env
, ctx
, ASE_MT
);
4723 gen_helper_mtc0_tcschedule(arg
);
4727 check_insn(env
, ctx
, ASE_MT
);
4728 gen_helper_mtc0_tcschefback(arg
);
4738 gen_helper_mtc0_entrylo1(arg
);
4748 gen_helper_mtc0_context(arg
);
4752 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
4753 rn
= "ContextConfig";
4762 gen_helper_mtc0_pagemask(arg
);
4766 check_insn(env
, ctx
, ISA_MIPS32R2
);
4767 gen_helper_mtc0_pagegrain(arg
);
4777 gen_helper_mtc0_wired(arg
);
4781 check_insn(env
, ctx
, ISA_MIPS32R2
);
4782 gen_helper_mtc0_srsconf0(arg
);
4786 check_insn(env
, ctx
, ISA_MIPS32R2
);
4787 gen_helper_mtc0_srsconf1(arg
);
4791 check_insn(env
, ctx
, ISA_MIPS32R2
);
4792 gen_helper_mtc0_srsconf2(arg
);
4796 check_insn(env
, ctx
, ISA_MIPS32R2
);
4797 gen_helper_mtc0_srsconf3(arg
);
4801 check_insn(env
, ctx
, ISA_MIPS32R2
);
4802 gen_helper_mtc0_srsconf4(arg
);
4812 check_insn(env
, ctx
, ISA_MIPS32R2
);
4813 gen_helper_mtc0_hwrena(arg
);
4827 gen_helper_mtc0_count(arg
);
4830 /* 6,7 are implementation dependent */
4834 /* Stop translation as we may have switched the execution mode */
4835 ctx
->bstate
= BS_STOP
;
4840 gen_helper_mtc0_entryhi(arg
);
4850 gen_helper_mtc0_compare(arg
);
4853 /* 6,7 are implementation dependent */
4857 /* Stop translation as we may have switched the execution mode */
4858 ctx
->bstate
= BS_STOP
;
4863 save_cpu_state(ctx
, 1);
4864 gen_helper_mtc0_status(arg
);
4865 /* BS_STOP isn't good enough here, hflags may have changed. */
4866 gen_save_pc(ctx
->pc
+ 4);
4867 ctx
->bstate
= BS_EXCP
;
4871 check_insn(env
, ctx
, ISA_MIPS32R2
);
4872 gen_helper_mtc0_intctl(arg
);
4873 /* Stop translation as we may have switched the execution mode */
4874 ctx
->bstate
= BS_STOP
;
4878 check_insn(env
, ctx
, ISA_MIPS32R2
);
4879 gen_helper_mtc0_srsctl(arg
);
4880 /* Stop translation as we may have switched the execution mode */
4881 ctx
->bstate
= BS_STOP
;
4885 check_insn(env
, ctx
, ISA_MIPS32R2
);
4886 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4887 /* Stop translation as we may have switched the execution mode */
4888 ctx
->bstate
= BS_STOP
;
4898 save_cpu_state(ctx
, 1);
4899 gen_helper_mtc0_cause(arg
);
4909 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4923 check_insn(env
, ctx
, ISA_MIPS32R2
);
4924 gen_helper_mtc0_ebase(arg
);
4934 gen_helper_mtc0_config0(arg
);
4936 /* Stop translation as we may have switched the execution mode */
4937 ctx
->bstate
= BS_STOP
;
4940 /* ignored, read only */
4944 gen_helper_mtc0_config2(arg
);
4946 /* Stop translation as we may have switched the execution mode */
4947 ctx
->bstate
= BS_STOP
;
4953 /* 6,7 are implementation dependent */
4955 rn
= "Invalid config selector";
4962 gen_helper_mtc0_lladdr(arg
);
4972 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
4982 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
4992 check_insn(env
, ctx
, ISA_MIPS3
);
4993 gen_helper_mtc0_xcontext(arg
);
5001 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5004 gen_helper_mtc0_framemask(arg
);
5013 rn
= "Diagnostic"; /* implementation dependent */
5018 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5019 /* BS_STOP isn't good enough here, hflags may have changed. */
5020 gen_save_pc(ctx
->pc
+ 4);
5021 ctx
->bstate
= BS_EXCP
;
5025 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5026 /* Stop translation as we may have switched the execution mode */
5027 ctx
->bstate
= BS_STOP
;
5028 rn
= "TraceControl";
5031 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5032 /* Stop translation as we may have switched the execution mode */
5033 ctx
->bstate
= BS_STOP
;
5034 rn
= "TraceControl2";
5037 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5038 /* Stop translation as we may have switched the execution mode */
5039 ctx
->bstate
= BS_STOP
;
5040 rn
= "UserTraceData";
5043 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5044 /* Stop translation as we may have switched the execution mode */
5045 ctx
->bstate
= BS_STOP
;
5056 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5066 gen_helper_mtc0_performance0(arg
);
5067 rn
= "Performance0";
5070 // gen_helper_mtc0_performance1(arg);
5071 rn
= "Performance1";
5074 // gen_helper_mtc0_performance2(arg);
5075 rn
= "Performance2";
5078 // gen_helper_mtc0_performance3(arg);
5079 rn
= "Performance3";
5082 // gen_helper_mtc0_performance4(arg);
5083 rn
= "Performance4";
5086 // gen_helper_mtc0_performance5(arg);
5087 rn
= "Performance5";
5090 // gen_helper_mtc0_performance6(arg);
5091 rn
= "Performance6";
5094 // gen_helper_mtc0_performance7(arg);
5095 rn
= "Performance7";
5121 gen_helper_mtc0_taglo(arg
);
5128 gen_helper_mtc0_datalo(arg
);
5141 gen_helper_mtc0_taghi(arg
);
5148 gen_helper_mtc0_datahi(arg
);
5159 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5170 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5176 /* Stop translation as we may have switched the execution mode */
5177 ctx
->bstate
= BS_STOP
;
5182 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5183 /* For simplicity assume that all writes can cause interrupts. */
5186 ctx
->bstate
= BS_STOP
;
5191 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5192 generate_exception(ctx
, EXCP_RI
);
5194 #endif /* TARGET_MIPS64 */
5196 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5197 int u
, int sel
, int h
)
5199 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5200 TCGv t0
= tcg_temp_local_new();
5202 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5203 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5204 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5205 tcg_gen_movi_tl(t0
, -1);
5206 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5207 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5208 tcg_gen_movi_tl(t0
, -1);
5214 gen_helper_mftc0_tcstatus(t0
);
5217 gen_helper_mftc0_tcbind(t0
);
5220 gen_helper_mftc0_tcrestart(t0
);
5223 gen_helper_mftc0_tchalt(t0
);
5226 gen_helper_mftc0_tccontext(t0
);
5229 gen_helper_mftc0_tcschedule(t0
);
5232 gen_helper_mftc0_tcschefback(t0
);
5235 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5242 gen_helper_mftc0_entryhi(t0
);
5245 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5251 gen_helper_mftc0_status(t0
);
5254 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5260 gen_helper_mftc0_debug(t0
);
5263 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5268 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5270 } else switch (sel
) {
5271 /* GPR registers. */
5273 gen_helper_1i(mftgpr
, t0
, rt
);
5275 /* Auxiliary CPU registers */
5279 gen_helper_1i(mftlo
, t0
, 0);
5282 gen_helper_1i(mfthi
, t0
, 0);
5285 gen_helper_1i(mftacx
, t0
, 0);
5288 gen_helper_1i(mftlo
, t0
, 1);
5291 gen_helper_1i(mfthi
, t0
, 1);
5294 gen_helper_1i(mftacx
, t0
, 1);
5297 gen_helper_1i(mftlo
, t0
, 2);
5300 gen_helper_1i(mfthi
, t0
, 2);
5303 gen_helper_1i(mftacx
, t0
, 2);
5306 gen_helper_1i(mftlo
, t0
, 3);
5309 gen_helper_1i(mfthi
, t0
, 3);
5312 gen_helper_1i(mftacx
, t0
, 3);
5315 gen_helper_mftdsp(t0
);
5321 /* Floating point (COP1). */
5323 /* XXX: For now we support only a single FPU context. */
5325 TCGv_i32 fp0
= tcg_temp_new_i32();
5327 gen_load_fpr32(fp0
, rt
);
5328 tcg_gen_ext_i32_tl(t0
, fp0
);
5329 tcg_temp_free_i32(fp0
);
5331 TCGv_i32 fp0
= tcg_temp_new_i32();
5333 gen_load_fpr32h(fp0
, rt
);
5334 tcg_gen_ext_i32_tl(t0
, fp0
);
5335 tcg_temp_free_i32(fp0
);
5339 /* XXX: For now we support only a single FPU context. */
5340 gen_helper_1i(cfc1
, t0
, rt
);
5342 /* COP2: Not implemented. */
5349 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5350 gen_store_gpr(t0
, rd
);
5356 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5357 generate_exception(ctx
, EXCP_RI
);
5360 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5361 int u
, int sel
, int h
)
5363 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5364 TCGv t0
= tcg_temp_local_new();
5366 gen_load_gpr(t0
, rt
);
5367 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5368 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5369 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5371 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5372 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5379 gen_helper_mttc0_tcstatus(t0
);
5382 gen_helper_mttc0_tcbind(t0
);
5385 gen_helper_mttc0_tcrestart(t0
);
5388 gen_helper_mttc0_tchalt(t0
);
5391 gen_helper_mttc0_tccontext(t0
);
5394 gen_helper_mttc0_tcschedule(t0
);
5397 gen_helper_mttc0_tcschefback(t0
);
5400 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5407 gen_helper_mttc0_entryhi(t0
);
5410 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5416 gen_helper_mttc0_status(t0
);
5419 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5425 gen_helper_mttc0_debug(t0
);
5428 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5433 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5435 } else switch (sel
) {
5436 /* GPR registers. */
5438 gen_helper_1i(mttgpr
, t0
, rd
);
5440 /* Auxiliary CPU registers */
5444 gen_helper_1i(mttlo
, t0
, 0);
5447 gen_helper_1i(mtthi
, t0
, 0);
5450 gen_helper_1i(mttacx
, t0
, 0);
5453 gen_helper_1i(mttlo
, t0
, 1);
5456 gen_helper_1i(mtthi
, t0
, 1);
5459 gen_helper_1i(mttacx
, t0
, 1);
5462 gen_helper_1i(mttlo
, t0
, 2);
5465 gen_helper_1i(mtthi
, t0
, 2);
5468 gen_helper_1i(mttacx
, t0
, 2);
5471 gen_helper_1i(mttlo
, t0
, 3);
5474 gen_helper_1i(mtthi
, t0
, 3);
5477 gen_helper_1i(mttacx
, t0
, 3);
5480 gen_helper_mttdsp(t0
);
5486 /* Floating point (COP1). */
5488 /* XXX: For now we support only a single FPU context. */
5490 TCGv_i32 fp0
= tcg_temp_new_i32();
5492 tcg_gen_trunc_tl_i32(fp0
, t0
);
5493 gen_store_fpr32(fp0
, rd
);
5494 tcg_temp_free_i32(fp0
);
5496 TCGv_i32 fp0
= tcg_temp_new_i32();
5498 tcg_gen_trunc_tl_i32(fp0
, t0
);
5499 gen_store_fpr32h(fp0
, rd
);
5500 tcg_temp_free_i32(fp0
);
5504 /* XXX: For now we support only a single FPU context. */
5505 gen_helper_1i(ctc1
, t0
, rd
);
5507 /* COP2: Not implemented. */
5514 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5520 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5521 generate_exception(ctx
, EXCP_RI
);
5524 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5526 const char *opn
= "ldst";
5534 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5539 TCGv t0
= tcg_temp_new();
5541 gen_load_gpr(t0
, rt
);
5542 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5547 #if defined(TARGET_MIPS64)
5549 check_insn(env
, ctx
, ISA_MIPS3
);
5554 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5558 check_insn(env
, ctx
, ISA_MIPS3
);
5560 TCGv t0
= tcg_temp_new();
5562 gen_load_gpr(t0
, rt
);
5563 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5570 check_insn(env
, ctx
, ASE_MT
);
5575 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5576 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5580 check_insn(env
, ctx
, ASE_MT
);
5581 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5582 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5587 if (!env
->tlb
->helper_tlbwi
)
5593 if (!env
->tlb
->helper_tlbwr
)
5599 if (!env
->tlb
->helper_tlbp
)
5605 if (!env
->tlb
->helper_tlbr
)
5611 check_insn(env
, ctx
, ISA_MIPS2
);
5613 ctx
->bstate
= BS_EXCP
;
5617 check_insn(env
, ctx
, ISA_MIPS32
);
5618 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5620 generate_exception(ctx
, EXCP_RI
);
5623 ctx
->bstate
= BS_EXCP
;
5628 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5629 /* If we get an exception, we want to restart at next instruction */
5631 save_cpu_state(ctx
, 1);
5634 ctx
->bstate
= BS_EXCP
;
5639 generate_exception(ctx
, EXCP_RI
);
5642 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5644 #endif /* !CONFIG_USER_ONLY */
5646 /* CP1 Branches (before delay slot) */
5647 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5648 int32_t cc
, int32_t offset
)
5650 target_ulong btarget
;
5651 const char *opn
= "cp1 cond branch";
5652 TCGv_i32 t0
= tcg_temp_new_i32();
5655 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5657 btarget
= ctx
->pc
+ 4 + offset
;
5661 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5662 tcg_gen_not_i32(t0
, t0
);
5663 tcg_gen_andi_i32(t0
, t0
, 1);
5664 tcg_gen_extu_i32_tl(bcond
, t0
);
5668 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5669 tcg_gen_not_i32(t0
, t0
);
5670 tcg_gen_andi_i32(t0
, t0
, 1);
5671 tcg_gen_extu_i32_tl(bcond
, t0
);
5675 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5676 tcg_gen_andi_i32(t0
, t0
, 1);
5677 tcg_gen_extu_i32_tl(bcond
, t0
);
5681 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5682 tcg_gen_andi_i32(t0
, t0
, 1);
5683 tcg_gen_extu_i32_tl(bcond
, t0
);
5686 ctx
->hflags
|= MIPS_HFLAG_BL
;
5690 TCGv_i32 t1
= tcg_temp_new_i32();
5691 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5692 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5693 tcg_gen_or_i32(t0
, t0
, t1
);
5694 tcg_temp_free_i32(t1
);
5695 tcg_gen_not_i32(t0
, t0
);
5696 tcg_gen_andi_i32(t0
, t0
, 1);
5697 tcg_gen_extu_i32_tl(bcond
, t0
);
5703 TCGv_i32 t1
= tcg_temp_new_i32();
5704 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5705 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5706 tcg_gen_or_i32(t0
, t0
, t1
);
5707 tcg_temp_free_i32(t1
);
5708 tcg_gen_andi_i32(t0
, t0
, 1);
5709 tcg_gen_extu_i32_tl(bcond
, t0
);
5715 TCGv_i32 t1
= tcg_temp_new_i32();
5716 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5717 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5718 tcg_gen_or_i32(t0
, t0
, t1
);
5719 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5720 tcg_gen_or_i32(t0
, t0
, t1
);
5721 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5722 tcg_gen_or_i32(t0
, t0
, t1
);
5723 tcg_temp_free_i32(t1
);
5724 tcg_gen_not_i32(t0
, t0
);
5725 tcg_gen_andi_i32(t0
, t0
, 1);
5726 tcg_gen_extu_i32_tl(bcond
, t0
);
5732 TCGv_i32 t1
= tcg_temp_new_i32();
5733 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5734 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5735 tcg_gen_or_i32(t0
, t0
, t1
);
5736 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5737 tcg_gen_or_i32(t0
, t0
, t1
);
5738 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5739 tcg_gen_or_i32(t0
, t0
, t1
);
5740 tcg_temp_free_i32(t1
);
5741 tcg_gen_andi_i32(t0
, t0
, 1);
5742 tcg_gen_extu_i32_tl(bcond
, t0
);
5746 ctx
->hflags
|= MIPS_HFLAG_BC
;
5750 generate_exception (ctx
, EXCP_RI
);
5753 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5754 ctx
->hflags
, btarget
);
5755 ctx
->btarget
= btarget
;
5758 tcg_temp_free_i32(t0
);
5761 /* Coprocessor 1 (FPU) */
5763 #define FOP(func, fmt) (((fmt) << 21) | (func))
5765 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5767 const char *opn
= "cp1 move";
5768 TCGv t0
= tcg_temp_new();
5773 TCGv_i32 fp0
= tcg_temp_new_i32();
5775 gen_load_fpr32(fp0
, fs
);
5776 tcg_gen_ext_i32_tl(t0
, fp0
);
5777 tcg_temp_free_i32(fp0
);
5779 gen_store_gpr(t0
, rt
);
5783 gen_load_gpr(t0
, rt
);
5785 TCGv_i32 fp0
= tcg_temp_new_i32();
5787 tcg_gen_trunc_tl_i32(fp0
, t0
);
5788 gen_store_fpr32(fp0
, fs
);
5789 tcg_temp_free_i32(fp0
);
5794 gen_helper_1i(cfc1
, t0
, fs
);
5795 gen_store_gpr(t0
, rt
);
5799 gen_load_gpr(t0
, rt
);
5800 gen_helper_1i(ctc1
, t0
, fs
);
5803 #if defined(TARGET_MIPS64)
5805 gen_load_fpr64(ctx
, t0
, fs
);
5806 gen_store_gpr(t0
, rt
);
5810 gen_load_gpr(t0
, rt
);
5811 gen_store_fpr64(ctx
, t0
, fs
);
5817 TCGv_i32 fp0
= tcg_temp_new_i32();
5819 gen_load_fpr32h(fp0
, fs
);
5820 tcg_gen_ext_i32_tl(t0
, fp0
);
5821 tcg_temp_free_i32(fp0
);
5823 gen_store_gpr(t0
, rt
);
5827 gen_load_gpr(t0
, rt
);
5829 TCGv_i32 fp0
= tcg_temp_new_i32();
5831 tcg_gen_trunc_tl_i32(fp0
, t0
);
5832 gen_store_fpr32h(fp0
, fs
);
5833 tcg_temp_free_i32(fp0
);
5839 generate_exception (ctx
, EXCP_RI
);
5842 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5848 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5864 l1
= gen_new_label();
5865 t0
= tcg_temp_new_i32();
5866 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5867 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5868 tcg_temp_free_i32(t0
);
5870 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
5872 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
5877 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5880 TCGv_i32 t0
= tcg_temp_new_i32();
5881 int l1
= gen_new_label();
5888 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5889 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5890 gen_load_fpr32(t0
, fs
);
5891 gen_store_fpr32(t0
, fd
);
5893 tcg_temp_free_i32(t0
);
5896 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5899 TCGv_i32 t0
= tcg_temp_new_i32();
5901 int l1
= gen_new_label();
5908 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5909 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5910 tcg_temp_free_i32(t0
);
5911 fp0
= tcg_temp_new_i64();
5912 gen_load_fpr64(ctx
, fp0
, fs
);
5913 gen_store_fpr64(ctx
, fp0
, fd
);
5914 tcg_temp_free_i64(fp0
);
5918 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5921 TCGv_i32 t0
= tcg_temp_new_i32();
5922 int l1
= gen_new_label();
5923 int l2
= gen_new_label();
5930 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5931 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5932 gen_load_fpr32(t0
, fs
);
5933 gen_store_fpr32(t0
, fd
);
5936 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
5937 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
5938 gen_load_fpr32h(t0
, fs
);
5939 gen_store_fpr32h(t0
, fd
);
5940 tcg_temp_free_i32(t0
);
5945 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5946 int ft
, int fs
, int fd
, int cc
)
5948 const char *opn
= "farith";
5949 const char *condnames
[] = {
5967 const char *condnames_abs
[] = {
5985 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5986 uint32_t func
= ctx
->opcode
& 0x3f;
5988 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5991 TCGv_i32 fp0
= tcg_temp_new_i32();
5992 TCGv_i32 fp1
= tcg_temp_new_i32();
5994 gen_load_fpr32(fp0
, fs
);
5995 gen_load_fpr32(fp1
, ft
);
5996 gen_helper_float_add_s(fp0
, fp0
, fp1
);
5997 tcg_temp_free_i32(fp1
);
5998 gen_store_fpr32(fp0
, fd
);
5999 tcg_temp_free_i32(fp0
);
6006 TCGv_i32 fp0
= tcg_temp_new_i32();
6007 TCGv_i32 fp1
= tcg_temp_new_i32();
6009 gen_load_fpr32(fp0
, fs
);
6010 gen_load_fpr32(fp1
, ft
);
6011 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6012 tcg_temp_free_i32(fp1
);
6013 gen_store_fpr32(fp0
, fd
);
6014 tcg_temp_free_i32(fp0
);
6021 TCGv_i32 fp0
= tcg_temp_new_i32();
6022 TCGv_i32 fp1
= tcg_temp_new_i32();
6024 gen_load_fpr32(fp0
, fs
);
6025 gen_load_fpr32(fp1
, ft
);
6026 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6027 tcg_temp_free_i32(fp1
);
6028 gen_store_fpr32(fp0
, fd
);
6029 tcg_temp_free_i32(fp0
);
6036 TCGv_i32 fp0
= tcg_temp_new_i32();
6037 TCGv_i32 fp1
= tcg_temp_new_i32();
6039 gen_load_fpr32(fp0
, fs
);
6040 gen_load_fpr32(fp1
, ft
);
6041 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6042 tcg_temp_free_i32(fp1
);
6043 gen_store_fpr32(fp0
, fd
);
6044 tcg_temp_free_i32(fp0
);
6051 TCGv_i32 fp0
= tcg_temp_new_i32();
6053 gen_load_fpr32(fp0
, fs
);
6054 gen_helper_float_sqrt_s(fp0
, fp0
);
6055 gen_store_fpr32(fp0
, fd
);
6056 tcg_temp_free_i32(fp0
);
6062 TCGv_i32 fp0
= tcg_temp_new_i32();
6064 gen_load_fpr32(fp0
, fs
);
6065 gen_helper_float_abs_s(fp0
, fp0
);
6066 gen_store_fpr32(fp0
, fd
);
6067 tcg_temp_free_i32(fp0
);
6073 TCGv_i32 fp0
= tcg_temp_new_i32();
6075 gen_load_fpr32(fp0
, fs
);
6076 gen_store_fpr32(fp0
, fd
);
6077 tcg_temp_free_i32(fp0
);
6083 TCGv_i32 fp0
= tcg_temp_new_i32();
6085 gen_load_fpr32(fp0
, fs
);
6086 gen_helper_float_chs_s(fp0
, fp0
);
6087 gen_store_fpr32(fp0
, fd
);
6088 tcg_temp_free_i32(fp0
);
6093 check_cp1_64bitmode(ctx
);
6095 TCGv_i32 fp32
= tcg_temp_new_i32();
6096 TCGv_i64 fp64
= tcg_temp_new_i64();
6098 gen_load_fpr32(fp32
, fs
);
6099 gen_helper_float_roundl_s(fp64
, fp32
);
6100 tcg_temp_free_i32(fp32
);
6101 gen_store_fpr64(ctx
, fp64
, fd
);
6102 tcg_temp_free_i64(fp64
);
6107 check_cp1_64bitmode(ctx
);
6109 TCGv_i32 fp32
= tcg_temp_new_i32();
6110 TCGv_i64 fp64
= tcg_temp_new_i64();
6112 gen_load_fpr32(fp32
, fs
);
6113 gen_helper_float_truncl_s(fp64
, fp32
);
6114 tcg_temp_free_i32(fp32
);
6115 gen_store_fpr64(ctx
, fp64
, fd
);
6116 tcg_temp_free_i64(fp64
);
6121 check_cp1_64bitmode(ctx
);
6123 TCGv_i32 fp32
= tcg_temp_new_i32();
6124 TCGv_i64 fp64
= tcg_temp_new_i64();
6126 gen_load_fpr32(fp32
, fs
);
6127 gen_helper_float_ceill_s(fp64
, fp32
);
6128 tcg_temp_free_i32(fp32
);
6129 gen_store_fpr64(ctx
, fp64
, fd
);
6130 tcg_temp_free_i64(fp64
);
6135 check_cp1_64bitmode(ctx
);
6137 TCGv_i32 fp32
= tcg_temp_new_i32();
6138 TCGv_i64 fp64
= tcg_temp_new_i64();
6140 gen_load_fpr32(fp32
, fs
);
6141 gen_helper_float_floorl_s(fp64
, fp32
);
6142 tcg_temp_free_i32(fp32
);
6143 gen_store_fpr64(ctx
, fp64
, fd
);
6144 tcg_temp_free_i64(fp64
);
6150 TCGv_i32 fp0
= tcg_temp_new_i32();
6152 gen_load_fpr32(fp0
, fs
);
6153 gen_helper_float_roundw_s(fp0
, fp0
);
6154 gen_store_fpr32(fp0
, fd
);
6155 tcg_temp_free_i32(fp0
);
6161 TCGv_i32 fp0
= tcg_temp_new_i32();
6163 gen_load_fpr32(fp0
, fs
);
6164 gen_helper_float_truncw_s(fp0
, fp0
);
6165 gen_store_fpr32(fp0
, fd
);
6166 tcg_temp_free_i32(fp0
);
6172 TCGv_i32 fp0
= tcg_temp_new_i32();
6174 gen_load_fpr32(fp0
, fs
);
6175 gen_helper_float_ceilw_s(fp0
, fp0
);
6176 gen_store_fpr32(fp0
, fd
);
6177 tcg_temp_free_i32(fp0
);
6183 TCGv_i32 fp0
= tcg_temp_new_i32();
6185 gen_load_fpr32(fp0
, fs
);
6186 gen_helper_float_floorw_s(fp0
, fp0
);
6187 gen_store_fpr32(fp0
, fd
);
6188 tcg_temp_free_i32(fp0
);
6193 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6198 int l1
= gen_new_label();
6202 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6204 fp0
= tcg_temp_new_i32();
6205 gen_load_fpr32(fp0
, fs
);
6206 gen_store_fpr32(fp0
, fd
);
6207 tcg_temp_free_i32(fp0
);
6214 int l1
= gen_new_label();
6218 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6219 fp0
= tcg_temp_new_i32();
6220 gen_load_fpr32(fp0
, fs
);
6221 gen_store_fpr32(fp0
, fd
);
6222 tcg_temp_free_i32(fp0
);
6231 TCGv_i32 fp0
= tcg_temp_new_i32();
6233 gen_load_fpr32(fp0
, fs
);
6234 gen_helper_float_recip_s(fp0
, fp0
);
6235 gen_store_fpr32(fp0
, fd
);
6236 tcg_temp_free_i32(fp0
);
6243 TCGv_i32 fp0
= tcg_temp_new_i32();
6245 gen_load_fpr32(fp0
, fs
);
6246 gen_helper_float_rsqrt_s(fp0
, fp0
);
6247 gen_store_fpr32(fp0
, fd
);
6248 tcg_temp_free_i32(fp0
);
6253 check_cp1_64bitmode(ctx
);
6255 TCGv_i32 fp0
= tcg_temp_new_i32();
6256 TCGv_i32 fp1
= tcg_temp_new_i32();
6258 gen_load_fpr32(fp0
, fs
);
6259 gen_load_fpr32(fp1
, fd
);
6260 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6261 tcg_temp_free_i32(fp1
);
6262 gen_store_fpr32(fp0
, fd
);
6263 tcg_temp_free_i32(fp0
);
6268 check_cp1_64bitmode(ctx
);
6270 TCGv_i32 fp0
= tcg_temp_new_i32();
6272 gen_load_fpr32(fp0
, fs
);
6273 gen_helper_float_recip1_s(fp0
, fp0
);
6274 gen_store_fpr32(fp0
, fd
);
6275 tcg_temp_free_i32(fp0
);
6280 check_cp1_64bitmode(ctx
);
6282 TCGv_i32 fp0
= tcg_temp_new_i32();
6284 gen_load_fpr32(fp0
, fs
);
6285 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6286 gen_store_fpr32(fp0
, fd
);
6287 tcg_temp_free_i32(fp0
);
6292 check_cp1_64bitmode(ctx
);
6294 TCGv_i32 fp0
= tcg_temp_new_i32();
6295 TCGv_i32 fp1
= tcg_temp_new_i32();
6297 gen_load_fpr32(fp0
, fs
);
6298 gen_load_fpr32(fp1
, ft
);
6299 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6300 tcg_temp_free_i32(fp1
);
6301 gen_store_fpr32(fp0
, fd
);
6302 tcg_temp_free_i32(fp0
);
6307 check_cp1_registers(ctx
, fd
);
6309 TCGv_i32 fp32
= tcg_temp_new_i32();
6310 TCGv_i64 fp64
= tcg_temp_new_i64();
6312 gen_load_fpr32(fp32
, fs
);
6313 gen_helper_float_cvtd_s(fp64
, fp32
);
6314 tcg_temp_free_i32(fp32
);
6315 gen_store_fpr64(ctx
, fp64
, fd
);
6316 tcg_temp_free_i64(fp64
);
6322 TCGv_i32 fp0
= tcg_temp_new_i32();
6324 gen_load_fpr32(fp0
, fs
);
6325 gen_helper_float_cvtw_s(fp0
, fp0
);
6326 gen_store_fpr32(fp0
, fd
);
6327 tcg_temp_free_i32(fp0
);
6332 check_cp1_64bitmode(ctx
);
6334 TCGv_i32 fp32
= tcg_temp_new_i32();
6335 TCGv_i64 fp64
= tcg_temp_new_i64();
6337 gen_load_fpr32(fp32
, fs
);
6338 gen_helper_float_cvtl_s(fp64
, fp32
);
6339 tcg_temp_free_i32(fp32
);
6340 gen_store_fpr64(ctx
, fp64
, fd
);
6341 tcg_temp_free_i64(fp64
);
6346 check_cp1_64bitmode(ctx
);
6348 TCGv_i64 fp64
= tcg_temp_new_i64();
6349 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6350 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6352 gen_load_fpr32(fp32_0
, fs
);
6353 gen_load_fpr32(fp32_1
, ft
);
6354 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6355 tcg_temp_free_i32(fp32_1
);
6356 tcg_temp_free_i32(fp32_0
);
6357 gen_store_fpr64(ctx
, fp64
, fd
);
6358 tcg_temp_free_i64(fp64
);
6379 TCGv_i32 fp0
= tcg_temp_new_i32();
6380 TCGv_i32 fp1
= tcg_temp_new_i32();
6382 gen_load_fpr32(fp0
, fs
);
6383 gen_load_fpr32(fp1
, ft
);
6384 if (ctx
->opcode
& (1 << 6)) {
6386 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6387 opn
= condnames_abs
[func
-48];
6389 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6390 opn
= condnames
[func
-48];
6392 tcg_temp_free_i32(fp0
);
6393 tcg_temp_free_i32(fp1
);
6397 check_cp1_registers(ctx
, fs
| ft
| fd
);
6399 TCGv_i64 fp0
= tcg_temp_new_i64();
6400 TCGv_i64 fp1
= tcg_temp_new_i64();
6402 gen_load_fpr64(ctx
, fp0
, fs
);
6403 gen_load_fpr64(ctx
, fp1
, ft
);
6404 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6405 tcg_temp_free_i64(fp1
);
6406 gen_store_fpr64(ctx
, fp0
, fd
);
6407 tcg_temp_free_i64(fp0
);
6413 check_cp1_registers(ctx
, fs
| ft
| fd
);
6415 TCGv_i64 fp0
= tcg_temp_new_i64();
6416 TCGv_i64 fp1
= tcg_temp_new_i64();
6418 gen_load_fpr64(ctx
, fp0
, fs
);
6419 gen_load_fpr64(ctx
, fp1
, ft
);
6420 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6421 tcg_temp_free_i64(fp1
);
6422 gen_store_fpr64(ctx
, fp0
, fd
);
6423 tcg_temp_free_i64(fp0
);
6429 check_cp1_registers(ctx
, fs
| ft
| fd
);
6431 TCGv_i64 fp0
= tcg_temp_new_i64();
6432 TCGv_i64 fp1
= tcg_temp_new_i64();
6434 gen_load_fpr64(ctx
, fp0
, fs
);
6435 gen_load_fpr64(ctx
, fp1
, ft
);
6436 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6437 tcg_temp_free_i64(fp1
);
6438 gen_store_fpr64(ctx
, fp0
, fd
);
6439 tcg_temp_free_i64(fp0
);
6445 check_cp1_registers(ctx
, fs
| ft
| fd
);
6447 TCGv_i64 fp0
= tcg_temp_new_i64();
6448 TCGv_i64 fp1
= tcg_temp_new_i64();
6450 gen_load_fpr64(ctx
, fp0
, fs
);
6451 gen_load_fpr64(ctx
, fp1
, ft
);
6452 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6453 tcg_temp_free_i64(fp1
);
6454 gen_store_fpr64(ctx
, fp0
, fd
);
6455 tcg_temp_free_i64(fp0
);
6461 check_cp1_registers(ctx
, fs
| fd
);
6463 TCGv_i64 fp0
= tcg_temp_new_i64();
6465 gen_load_fpr64(ctx
, fp0
, fs
);
6466 gen_helper_float_sqrt_d(fp0
, fp0
);
6467 gen_store_fpr64(ctx
, fp0
, fd
);
6468 tcg_temp_free_i64(fp0
);
6473 check_cp1_registers(ctx
, fs
| fd
);
6475 TCGv_i64 fp0
= tcg_temp_new_i64();
6477 gen_load_fpr64(ctx
, fp0
, fs
);
6478 gen_helper_float_abs_d(fp0
, fp0
);
6479 gen_store_fpr64(ctx
, fp0
, fd
);
6480 tcg_temp_free_i64(fp0
);
6485 check_cp1_registers(ctx
, fs
| fd
);
6487 TCGv_i64 fp0
= tcg_temp_new_i64();
6489 gen_load_fpr64(ctx
, fp0
, fs
);
6490 gen_store_fpr64(ctx
, fp0
, fd
);
6491 tcg_temp_free_i64(fp0
);
6496 check_cp1_registers(ctx
, fs
| fd
);
6498 TCGv_i64 fp0
= tcg_temp_new_i64();
6500 gen_load_fpr64(ctx
, fp0
, fs
);
6501 gen_helper_float_chs_d(fp0
, fp0
);
6502 gen_store_fpr64(ctx
, fp0
, fd
);
6503 tcg_temp_free_i64(fp0
);
6508 check_cp1_64bitmode(ctx
);
6510 TCGv_i64 fp0
= tcg_temp_new_i64();
6512 gen_load_fpr64(ctx
, fp0
, fs
);
6513 gen_helper_float_roundl_d(fp0
, fp0
);
6514 gen_store_fpr64(ctx
, fp0
, fd
);
6515 tcg_temp_free_i64(fp0
);
6520 check_cp1_64bitmode(ctx
);
6522 TCGv_i64 fp0
= tcg_temp_new_i64();
6524 gen_load_fpr64(ctx
, fp0
, fs
);
6525 gen_helper_float_truncl_d(fp0
, fp0
);
6526 gen_store_fpr64(ctx
, fp0
, fd
);
6527 tcg_temp_free_i64(fp0
);
6532 check_cp1_64bitmode(ctx
);
6534 TCGv_i64 fp0
= tcg_temp_new_i64();
6536 gen_load_fpr64(ctx
, fp0
, fs
);
6537 gen_helper_float_ceill_d(fp0
, fp0
);
6538 gen_store_fpr64(ctx
, fp0
, fd
);
6539 tcg_temp_free_i64(fp0
);
6544 check_cp1_64bitmode(ctx
);
6546 TCGv_i64 fp0
= tcg_temp_new_i64();
6548 gen_load_fpr64(ctx
, fp0
, fs
);
6549 gen_helper_float_floorl_d(fp0
, fp0
);
6550 gen_store_fpr64(ctx
, fp0
, fd
);
6551 tcg_temp_free_i64(fp0
);
6556 check_cp1_registers(ctx
, fs
);
6558 TCGv_i32 fp32
= tcg_temp_new_i32();
6559 TCGv_i64 fp64
= tcg_temp_new_i64();
6561 gen_load_fpr64(ctx
, fp64
, fs
);
6562 gen_helper_float_roundw_d(fp32
, fp64
);
6563 tcg_temp_free_i64(fp64
);
6564 gen_store_fpr32(fp32
, fd
);
6565 tcg_temp_free_i32(fp32
);
6570 check_cp1_registers(ctx
, fs
);
6572 TCGv_i32 fp32
= tcg_temp_new_i32();
6573 TCGv_i64 fp64
= tcg_temp_new_i64();
6575 gen_load_fpr64(ctx
, fp64
, fs
);
6576 gen_helper_float_truncw_d(fp32
, fp64
);
6577 tcg_temp_free_i64(fp64
);
6578 gen_store_fpr32(fp32
, fd
);
6579 tcg_temp_free_i32(fp32
);
6584 check_cp1_registers(ctx
, fs
);
6586 TCGv_i32 fp32
= tcg_temp_new_i32();
6587 TCGv_i64 fp64
= tcg_temp_new_i64();
6589 gen_load_fpr64(ctx
, fp64
, fs
);
6590 gen_helper_float_ceilw_d(fp32
, fp64
);
6591 tcg_temp_free_i64(fp64
);
6592 gen_store_fpr32(fp32
, fd
);
6593 tcg_temp_free_i32(fp32
);
6598 check_cp1_registers(ctx
, fs
);
6600 TCGv_i32 fp32
= tcg_temp_new_i32();
6601 TCGv_i64 fp64
= tcg_temp_new_i64();
6603 gen_load_fpr64(ctx
, fp64
, fs
);
6604 gen_helper_float_floorw_d(fp32
, fp64
);
6605 tcg_temp_free_i64(fp64
);
6606 gen_store_fpr32(fp32
, fd
);
6607 tcg_temp_free_i32(fp32
);
6612 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6617 int l1
= gen_new_label();
6621 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6623 fp0
= tcg_temp_new_i64();
6624 gen_load_fpr64(ctx
, fp0
, fs
);
6625 gen_store_fpr64(ctx
, fp0
, fd
);
6626 tcg_temp_free_i64(fp0
);
6633 int l1
= gen_new_label();
6637 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6638 fp0
= tcg_temp_new_i64();
6639 gen_load_fpr64(ctx
, fp0
, fs
);
6640 gen_store_fpr64(ctx
, fp0
, fd
);
6641 tcg_temp_free_i64(fp0
);
6648 check_cp1_64bitmode(ctx
);
6650 TCGv_i64 fp0
= tcg_temp_new_i64();
6652 gen_load_fpr64(ctx
, fp0
, fs
);
6653 gen_helper_float_recip_d(fp0
, fp0
);
6654 gen_store_fpr64(ctx
, fp0
, fd
);
6655 tcg_temp_free_i64(fp0
);
6660 check_cp1_64bitmode(ctx
);
6662 TCGv_i64 fp0
= tcg_temp_new_i64();
6664 gen_load_fpr64(ctx
, fp0
, fs
);
6665 gen_helper_float_rsqrt_d(fp0
, fp0
);
6666 gen_store_fpr64(ctx
, fp0
, fd
);
6667 tcg_temp_free_i64(fp0
);
6672 check_cp1_64bitmode(ctx
);
6674 TCGv_i64 fp0
= tcg_temp_new_i64();
6675 TCGv_i64 fp1
= tcg_temp_new_i64();
6677 gen_load_fpr64(ctx
, fp0
, fs
);
6678 gen_load_fpr64(ctx
, fp1
, ft
);
6679 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6680 tcg_temp_free_i64(fp1
);
6681 gen_store_fpr64(ctx
, fp0
, fd
);
6682 tcg_temp_free_i64(fp0
);
6687 check_cp1_64bitmode(ctx
);
6689 TCGv_i64 fp0
= tcg_temp_new_i64();
6691 gen_load_fpr64(ctx
, fp0
, fs
);
6692 gen_helper_float_recip1_d(fp0
, fp0
);
6693 gen_store_fpr64(ctx
, fp0
, fd
);
6694 tcg_temp_free_i64(fp0
);
6699 check_cp1_64bitmode(ctx
);
6701 TCGv_i64 fp0
= tcg_temp_new_i64();
6703 gen_load_fpr64(ctx
, fp0
, fs
);
6704 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6705 gen_store_fpr64(ctx
, fp0
, fd
);
6706 tcg_temp_free_i64(fp0
);
6711 check_cp1_64bitmode(ctx
);
6713 TCGv_i64 fp0
= tcg_temp_new_i64();
6714 TCGv_i64 fp1
= tcg_temp_new_i64();
6716 gen_load_fpr64(ctx
, fp0
, fs
);
6717 gen_load_fpr64(ctx
, fp1
, ft
);
6718 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6719 tcg_temp_free_i64(fp1
);
6720 gen_store_fpr64(ctx
, fp0
, fd
);
6721 tcg_temp_free_i64(fp0
);
6742 TCGv_i64 fp0
= tcg_temp_new_i64();
6743 TCGv_i64 fp1
= tcg_temp_new_i64();
6745 gen_load_fpr64(ctx
, fp0
, fs
);
6746 gen_load_fpr64(ctx
, fp1
, ft
);
6747 if (ctx
->opcode
& (1 << 6)) {
6749 check_cp1_registers(ctx
, fs
| ft
);
6750 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6751 opn
= condnames_abs
[func
-48];
6753 check_cp1_registers(ctx
, fs
| ft
);
6754 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6755 opn
= condnames
[func
-48];
6757 tcg_temp_free_i64(fp0
);
6758 tcg_temp_free_i64(fp1
);
6762 check_cp1_registers(ctx
, fs
);
6764 TCGv_i32 fp32
= tcg_temp_new_i32();
6765 TCGv_i64 fp64
= tcg_temp_new_i64();
6767 gen_load_fpr64(ctx
, fp64
, fs
);
6768 gen_helper_float_cvts_d(fp32
, fp64
);
6769 tcg_temp_free_i64(fp64
);
6770 gen_store_fpr32(fp32
, fd
);
6771 tcg_temp_free_i32(fp32
);
6776 check_cp1_registers(ctx
, fs
);
6778 TCGv_i32 fp32
= tcg_temp_new_i32();
6779 TCGv_i64 fp64
= tcg_temp_new_i64();
6781 gen_load_fpr64(ctx
, fp64
, fs
);
6782 gen_helper_float_cvtw_d(fp32
, fp64
);
6783 tcg_temp_free_i64(fp64
);
6784 gen_store_fpr32(fp32
, fd
);
6785 tcg_temp_free_i32(fp32
);
6790 check_cp1_64bitmode(ctx
);
6792 TCGv_i64 fp0
= tcg_temp_new_i64();
6794 gen_load_fpr64(ctx
, fp0
, fs
);
6795 gen_helper_float_cvtl_d(fp0
, fp0
);
6796 gen_store_fpr64(ctx
, fp0
, fd
);
6797 tcg_temp_free_i64(fp0
);
6803 TCGv_i32 fp0
= tcg_temp_new_i32();
6805 gen_load_fpr32(fp0
, fs
);
6806 gen_helper_float_cvts_w(fp0
, fp0
);
6807 gen_store_fpr32(fp0
, fd
);
6808 tcg_temp_free_i32(fp0
);
6813 check_cp1_registers(ctx
, fd
);
6815 TCGv_i32 fp32
= tcg_temp_new_i32();
6816 TCGv_i64 fp64
= tcg_temp_new_i64();
6818 gen_load_fpr32(fp32
, fs
);
6819 gen_helper_float_cvtd_w(fp64
, fp32
);
6820 tcg_temp_free_i32(fp32
);
6821 gen_store_fpr64(ctx
, fp64
, fd
);
6822 tcg_temp_free_i64(fp64
);
6827 check_cp1_64bitmode(ctx
);
6829 TCGv_i32 fp32
= tcg_temp_new_i32();
6830 TCGv_i64 fp64
= tcg_temp_new_i64();
6832 gen_load_fpr64(ctx
, fp64
, fs
);
6833 gen_helper_float_cvts_l(fp32
, fp64
);
6834 tcg_temp_free_i64(fp64
);
6835 gen_store_fpr32(fp32
, fd
);
6836 tcg_temp_free_i32(fp32
);
6841 check_cp1_64bitmode(ctx
);
6843 TCGv_i64 fp0
= tcg_temp_new_i64();
6845 gen_load_fpr64(ctx
, fp0
, fs
);
6846 gen_helper_float_cvtd_l(fp0
, fp0
);
6847 gen_store_fpr64(ctx
, fp0
, fd
);
6848 tcg_temp_free_i64(fp0
);
6853 check_cp1_64bitmode(ctx
);
6855 TCGv_i64 fp0
= tcg_temp_new_i64();
6857 gen_load_fpr64(ctx
, fp0
, fs
);
6858 gen_helper_float_cvtps_pw(fp0
, fp0
);
6859 gen_store_fpr64(ctx
, fp0
, fd
);
6860 tcg_temp_free_i64(fp0
);
6865 check_cp1_64bitmode(ctx
);
6867 TCGv_i64 fp0
= tcg_temp_new_i64();
6868 TCGv_i64 fp1
= tcg_temp_new_i64();
6870 gen_load_fpr64(ctx
, fp0
, fs
);
6871 gen_load_fpr64(ctx
, fp1
, ft
);
6872 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6873 tcg_temp_free_i64(fp1
);
6874 gen_store_fpr64(ctx
, fp0
, fd
);
6875 tcg_temp_free_i64(fp0
);
6880 check_cp1_64bitmode(ctx
);
6882 TCGv_i64 fp0
= tcg_temp_new_i64();
6883 TCGv_i64 fp1
= tcg_temp_new_i64();
6885 gen_load_fpr64(ctx
, fp0
, fs
);
6886 gen_load_fpr64(ctx
, fp1
, ft
);
6887 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6888 tcg_temp_free_i64(fp1
);
6889 gen_store_fpr64(ctx
, fp0
, fd
);
6890 tcg_temp_free_i64(fp0
);
6895 check_cp1_64bitmode(ctx
);
6897 TCGv_i64 fp0
= tcg_temp_new_i64();
6898 TCGv_i64 fp1
= tcg_temp_new_i64();
6900 gen_load_fpr64(ctx
, fp0
, fs
);
6901 gen_load_fpr64(ctx
, fp1
, ft
);
6902 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6903 tcg_temp_free_i64(fp1
);
6904 gen_store_fpr64(ctx
, fp0
, fd
);
6905 tcg_temp_free_i64(fp0
);
6910 check_cp1_64bitmode(ctx
);
6912 TCGv_i64 fp0
= tcg_temp_new_i64();
6914 gen_load_fpr64(ctx
, fp0
, fs
);
6915 gen_helper_float_abs_ps(fp0
, fp0
);
6916 gen_store_fpr64(ctx
, fp0
, fd
);
6917 tcg_temp_free_i64(fp0
);
6922 check_cp1_64bitmode(ctx
);
6924 TCGv_i64 fp0
= tcg_temp_new_i64();
6926 gen_load_fpr64(ctx
, fp0
, fs
);
6927 gen_store_fpr64(ctx
, fp0
, fd
);
6928 tcg_temp_free_i64(fp0
);
6933 check_cp1_64bitmode(ctx
);
6935 TCGv_i64 fp0
= tcg_temp_new_i64();
6937 gen_load_fpr64(ctx
, fp0
, fs
);
6938 gen_helper_float_chs_ps(fp0
, fp0
);
6939 gen_store_fpr64(ctx
, fp0
, fd
);
6940 tcg_temp_free_i64(fp0
);
6945 check_cp1_64bitmode(ctx
);
6946 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6950 check_cp1_64bitmode(ctx
);
6952 int l1
= gen_new_label();
6956 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6957 fp0
= tcg_temp_new_i64();
6958 gen_load_fpr64(ctx
, fp0
, fs
);
6959 gen_store_fpr64(ctx
, fp0
, fd
);
6960 tcg_temp_free_i64(fp0
);
6966 check_cp1_64bitmode(ctx
);
6968 int l1
= gen_new_label();
6972 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6973 fp0
= tcg_temp_new_i64();
6974 gen_load_fpr64(ctx
, fp0
, fs
);
6975 gen_store_fpr64(ctx
, fp0
, fd
);
6976 tcg_temp_free_i64(fp0
);
6983 check_cp1_64bitmode(ctx
);
6985 TCGv_i64 fp0
= tcg_temp_new_i64();
6986 TCGv_i64 fp1
= tcg_temp_new_i64();
6988 gen_load_fpr64(ctx
, fp0
, ft
);
6989 gen_load_fpr64(ctx
, fp1
, fs
);
6990 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
6991 tcg_temp_free_i64(fp1
);
6992 gen_store_fpr64(ctx
, fp0
, fd
);
6993 tcg_temp_free_i64(fp0
);
6998 check_cp1_64bitmode(ctx
);
7000 TCGv_i64 fp0
= tcg_temp_new_i64();
7001 TCGv_i64 fp1
= tcg_temp_new_i64();
7003 gen_load_fpr64(ctx
, fp0
, ft
);
7004 gen_load_fpr64(ctx
, fp1
, fs
);
7005 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7006 tcg_temp_free_i64(fp1
);
7007 gen_store_fpr64(ctx
, fp0
, fd
);
7008 tcg_temp_free_i64(fp0
);
7013 check_cp1_64bitmode(ctx
);
7015 TCGv_i64 fp0
= tcg_temp_new_i64();
7016 TCGv_i64 fp1
= tcg_temp_new_i64();
7018 gen_load_fpr64(ctx
, fp0
, fs
);
7019 gen_load_fpr64(ctx
, fp1
, fd
);
7020 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7021 tcg_temp_free_i64(fp1
);
7022 gen_store_fpr64(ctx
, fp0
, fd
);
7023 tcg_temp_free_i64(fp0
);
7028 check_cp1_64bitmode(ctx
);
7030 TCGv_i64 fp0
= tcg_temp_new_i64();
7032 gen_load_fpr64(ctx
, fp0
, fs
);
7033 gen_helper_float_recip1_ps(fp0
, fp0
);
7034 gen_store_fpr64(ctx
, fp0
, fd
);
7035 tcg_temp_free_i64(fp0
);
7040 check_cp1_64bitmode(ctx
);
7042 TCGv_i64 fp0
= tcg_temp_new_i64();
7044 gen_load_fpr64(ctx
, fp0
, fs
);
7045 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7046 gen_store_fpr64(ctx
, fp0
, fd
);
7047 tcg_temp_free_i64(fp0
);
7052 check_cp1_64bitmode(ctx
);
7054 TCGv_i64 fp0
= tcg_temp_new_i64();
7055 TCGv_i64 fp1
= tcg_temp_new_i64();
7057 gen_load_fpr64(ctx
, fp0
, fs
);
7058 gen_load_fpr64(ctx
, fp1
, ft
);
7059 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7060 tcg_temp_free_i64(fp1
);
7061 gen_store_fpr64(ctx
, fp0
, fd
);
7062 tcg_temp_free_i64(fp0
);
7067 check_cp1_64bitmode(ctx
);
7069 TCGv_i32 fp0
= tcg_temp_new_i32();
7071 gen_load_fpr32h(fp0
, fs
);
7072 gen_helper_float_cvts_pu(fp0
, fp0
);
7073 gen_store_fpr32(fp0
, fd
);
7074 tcg_temp_free_i32(fp0
);
7079 check_cp1_64bitmode(ctx
);
7081 TCGv_i64 fp0
= tcg_temp_new_i64();
7083 gen_load_fpr64(ctx
, fp0
, fs
);
7084 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7085 gen_store_fpr64(ctx
, fp0
, fd
);
7086 tcg_temp_free_i64(fp0
);
7091 check_cp1_64bitmode(ctx
);
7093 TCGv_i32 fp0
= tcg_temp_new_i32();
7095 gen_load_fpr32(fp0
, fs
);
7096 gen_helper_float_cvts_pl(fp0
, fp0
);
7097 gen_store_fpr32(fp0
, fd
);
7098 tcg_temp_free_i32(fp0
);
7103 check_cp1_64bitmode(ctx
);
7105 TCGv_i32 fp0
= tcg_temp_new_i32();
7106 TCGv_i32 fp1
= tcg_temp_new_i32();
7108 gen_load_fpr32(fp0
, fs
);
7109 gen_load_fpr32(fp1
, ft
);
7110 gen_store_fpr32h(fp0
, fd
);
7111 gen_store_fpr32(fp1
, fd
);
7112 tcg_temp_free_i32(fp0
);
7113 tcg_temp_free_i32(fp1
);
7118 check_cp1_64bitmode(ctx
);
7120 TCGv_i32 fp0
= tcg_temp_new_i32();
7121 TCGv_i32 fp1
= tcg_temp_new_i32();
7123 gen_load_fpr32(fp0
, fs
);
7124 gen_load_fpr32h(fp1
, ft
);
7125 gen_store_fpr32(fp1
, fd
);
7126 gen_store_fpr32h(fp0
, fd
);
7127 tcg_temp_free_i32(fp0
);
7128 tcg_temp_free_i32(fp1
);
7133 check_cp1_64bitmode(ctx
);
7135 TCGv_i32 fp0
= tcg_temp_new_i32();
7136 TCGv_i32 fp1
= tcg_temp_new_i32();
7138 gen_load_fpr32h(fp0
, fs
);
7139 gen_load_fpr32(fp1
, ft
);
7140 gen_store_fpr32(fp1
, fd
);
7141 gen_store_fpr32h(fp0
, fd
);
7142 tcg_temp_free_i32(fp0
);
7143 tcg_temp_free_i32(fp1
);
7148 check_cp1_64bitmode(ctx
);
7150 TCGv_i32 fp0
= tcg_temp_new_i32();
7151 TCGv_i32 fp1
= tcg_temp_new_i32();
7153 gen_load_fpr32h(fp0
, fs
);
7154 gen_load_fpr32h(fp1
, ft
);
7155 gen_store_fpr32(fp1
, fd
);
7156 gen_store_fpr32h(fp0
, fd
);
7157 tcg_temp_free_i32(fp0
);
7158 tcg_temp_free_i32(fp1
);
7178 check_cp1_64bitmode(ctx
);
7180 TCGv_i64 fp0
= tcg_temp_new_i64();
7181 TCGv_i64 fp1
= tcg_temp_new_i64();
7183 gen_load_fpr64(ctx
, fp0
, fs
);
7184 gen_load_fpr64(ctx
, fp1
, ft
);
7185 if (ctx
->opcode
& (1 << 6)) {
7186 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7187 opn
= condnames_abs
[func
-48];
7189 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7190 opn
= condnames
[func
-48];
7192 tcg_temp_free_i64(fp0
);
7193 tcg_temp_free_i64(fp1
);
7198 generate_exception (ctx
, EXCP_RI
);
7203 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7206 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7209 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7214 /* Coprocessor 3 (FPU) */
7215 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7216 int fd
, int fs
, int base
, int index
)
7218 const char *opn
= "extended float load/store";
7220 TCGv t0
= tcg_temp_new();
7223 gen_load_gpr(t0
, index
);
7224 } else if (index
== 0) {
7225 gen_load_gpr(t0
, base
);
7227 gen_load_gpr(t0
, index
);
7228 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7230 /* Don't do NOP if destination is zero: we must perform the actual
7232 save_cpu_state(ctx
, 0);
7237 TCGv_i32 fp0
= tcg_temp_new_i32();
7239 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7240 tcg_gen_trunc_tl_i32(fp0
, t0
);
7241 gen_store_fpr32(fp0
, fd
);
7242 tcg_temp_free_i32(fp0
);
7248 check_cp1_registers(ctx
, fd
);
7250 TCGv_i64 fp0
= tcg_temp_new_i64();
7252 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7253 gen_store_fpr64(ctx
, fp0
, fd
);
7254 tcg_temp_free_i64(fp0
);
7259 check_cp1_64bitmode(ctx
);
7260 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7262 TCGv_i64 fp0
= tcg_temp_new_i64();
7264 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7265 gen_store_fpr64(ctx
, fp0
, fd
);
7266 tcg_temp_free_i64(fp0
);
7273 TCGv_i32 fp0
= tcg_temp_new_i32();
7274 TCGv t1
= tcg_temp_new();
7276 gen_load_fpr32(fp0
, fs
);
7277 tcg_gen_extu_i32_tl(t1
, fp0
);
7278 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7279 tcg_temp_free_i32(fp0
);
7287 check_cp1_registers(ctx
, fs
);
7289 TCGv_i64 fp0
= tcg_temp_new_i64();
7291 gen_load_fpr64(ctx
, fp0
, fs
);
7292 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7293 tcg_temp_free_i64(fp0
);
7299 check_cp1_64bitmode(ctx
);
7300 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7302 TCGv_i64 fp0
= tcg_temp_new_i64();
7304 gen_load_fpr64(ctx
, fp0
, fs
);
7305 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7306 tcg_temp_free_i64(fp0
);
7313 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7314 regnames
[index
], regnames
[base
]);
7317 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7318 int fd
, int fr
, int fs
, int ft
)
7320 const char *opn
= "flt3_arith";
7324 check_cp1_64bitmode(ctx
);
7326 TCGv t0
= tcg_temp_local_new();
7327 TCGv_i32 fp
= tcg_temp_new_i32();
7328 TCGv_i32 fph
= tcg_temp_new_i32();
7329 int l1
= gen_new_label();
7330 int l2
= gen_new_label();
7332 gen_load_gpr(t0
, fr
);
7333 tcg_gen_andi_tl(t0
, t0
, 0x7);
7335 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7336 gen_load_fpr32(fp
, fs
);
7337 gen_load_fpr32h(fph
, fs
);
7338 gen_store_fpr32(fp
, fd
);
7339 gen_store_fpr32h(fph
, fd
);
7342 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7344 #ifdef TARGET_WORDS_BIGENDIAN
7345 gen_load_fpr32(fp
, fs
);
7346 gen_load_fpr32h(fph
, ft
);
7347 gen_store_fpr32h(fp
, fd
);
7348 gen_store_fpr32(fph
, fd
);
7350 gen_load_fpr32h(fph
, fs
);
7351 gen_load_fpr32(fp
, ft
);
7352 gen_store_fpr32(fph
, fd
);
7353 gen_store_fpr32h(fp
, fd
);
7356 tcg_temp_free_i32(fp
);
7357 tcg_temp_free_i32(fph
);
7364 TCGv_i32 fp0
= tcg_temp_new_i32();
7365 TCGv_i32 fp1
= tcg_temp_new_i32();
7366 TCGv_i32 fp2
= tcg_temp_new_i32();
7368 gen_load_fpr32(fp0
, fs
);
7369 gen_load_fpr32(fp1
, ft
);
7370 gen_load_fpr32(fp2
, fr
);
7371 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7372 tcg_temp_free_i32(fp0
);
7373 tcg_temp_free_i32(fp1
);
7374 gen_store_fpr32(fp2
, fd
);
7375 tcg_temp_free_i32(fp2
);
7381 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7383 TCGv_i64 fp0
= tcg_temp_new_i64();
7384 TCGv_i64 fp1
= tcg_temp_new_i64();
7385 TCGv_i64 fp2
= tcg_temp_new_i64();
7387 gen_load_fpr64(ctx
, fp0
, fs
);
7388 gen_load_fpr64(ctx
, fp1
, ft
);
7389 gen_load_fpr64(ctx
, fp2
, fr
);
7390 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7391 tcg_temp_free_i64(fp0
);
7392 tcg_temp_free_i64(fp1
);
7393 gen_store_fpr64(ctx
, fp2
, fd
);
7394 tcg_temp_free_i64(fp2
);
7399 check_cp1_64bitmode(ctx
);
7401 TCGv_i64 fp0
= tcg_temp_new_i64();
7402 TCGv_i64 fp1
= tcg_temp_new_i64();
7403 TCGv_i64 fp2
= tcg_temp_new_i64();
7405 gen_load_fpr64(ctx
, fp0
, fs
);
7406 gen_load_fpr64(ctx
, fp1
, ft
);
7407 gen_load_fpr64(ctx
, fp2
, fr
);
7408 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7409 tcg_temp_free_i64(fp0
);
7410 tcg_temp_free_i64(fp1
);
7411 gen_store_fpr64(ctx
, fp2
, fd
);
7412 tcg_temp_free_i64(fp2
);
7419 TCGv_i32 fp0
= tcg_temp_new_i32();
7420 TCGv_i32 fp1
= tcg_temp_new_i32();
7421 TCGv_i32 fp2
= tcg_temp_new_i32();
7423 gen_load_fpr32(fp0
, fs
);
7424 gen_load_fpr32(fp1
, ft
);
7425 gen_load_fpr32(fp2
, fr
);
7426 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7427 tcg_temp_free_i32(fp0
);
7428 tcg_temp_free_i32(fp1
);
7429 gen_store_fpr32(fp2
, fd
);
7430 tcg_temp_free_i32(fp2
);
7436 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7438 TCGv_i64 fp0
= tcg_temp_new_i64();
7439 TCGv_i64 fp1
= tcg_temp_new_i64();
7440 TCGv_i64 fp2
= tcg_temp_new_i64();
7442 gen_load_fpr64(ctx
, fp0
, fs
);
7443 gen_load_fpr64(ctx
, fp1
, ft
);
7444 gen_load_fpr64(ctx
, fp2
, fr
);
7445 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7446 tcg_temp_free_i64(fp0
);
7447 tcg_temp_free_i64(fp1
);
7448 gen_store_fpr64(ctx
, fp2
, fd
);
7449 tcg_temp_free_i64(fp2
);
7454 check_cp1_64bitmode(ctx
);
7456 TCGv_i64 fp0
= tcg_temp_new_i64();
7457 TCGv_i64 fp1
= tcg_temp_new_i64();
7458 TCGv_i64 fp2
= tcg_temp_new_i64();
7460 gen_load_fpr64(ctx
, fp0
, fs
);
7461 gen_load_fpr64(ctx
, fp1
, ft
);
7462 gen_load_fpr64(ctx
, fp2
, fr
);
7463 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7464 tcg_temp_free_i64(fp0
);
7465 tcg_temp_free_i64(fp1
);
7466 gen_store_fpr64(ctx
, fp2
, fd
);
7467 tcg_temp_free_i64(fp2
);
7474 TCGv_i32 fp0
= tcg_temp_new_i32();
7475 TCGv_i32 fp1
= tcg_temp_new_i32();
7476 TCGv_i32 fp2
= tcg_temp_new_i32();
7478 gen_load_fpr32(fp0
, fs
);
7479 gen_load_fpr32(fp1
, ft
);
7480 gen_load_fpr32(fp2
, fr
);
7481 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7482 tcg_temp_free_i32(fp0
);
7483 tcg_temp_free_i32(fp1
);
7484 gen_store_fpr32(fp2
, fd
);
7485 tcg_temp_free_i32(fp2
);
7491 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7493 TCGv_i64 fp0
= tcg_temp_new_i64();
7494 TCGv_i64 fp1
= tcg_temp_new_i64();
7495 TCGv_i64 fp2
= tcg_temp_new_i64();
7497 gen_load_fpr64(ctx
, fp0
, fs
);
7498 gen_load_fpr64(ctx
, fp1
, ft
);
7499 gen_load_fpr64(ctx
, fp2
, fr
);
7500 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7501 tcg_temp_free_i64(fp0
);
7502 tcg_temp_free_i64(fp1
);
7503 gen_store_fpr64(ctx
, fp2
, fd
);
7504 tcg_temp_free_i64(fp2
);
7509 check_cp1_64bitmode(ctx
);
7511 TCGv_i64 fp0
= tcg_temp_new_i64();
7512 TCGv_i64 fp1
= tcg_temp_new_i64();
7513 TCGv_i64 fp2
= tcg_temp_new_i64();
7515 gen_load_fpr64(ctx
, fp0
, fs
);
7516 gen_load_fpr64(ctx
, fp1
, ft
);
7517 gen_load_fpr64(ctx
, fp2
, fr
);
7518 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7519 tcg_temp_free_i64(fp0
);
7520 tcg_temp_free_i64(fp1
);
7521 gen_store_fpr64(ctx
, fp2
, fd
);
7522 tcg_temp_free_i64(fp2
);
7529 TCGv_i32 fp0
= tcg_temp_new_i32();
7530 TCGv_i32 fp1
= tcg_temp_new_i32();
7531 TCGv_i32 fp2
= tcg_temp_new_i32();
7533 gen_load_fpr32(fp0
, fs
);
7534 gen_load_fpr32(fp1
, ft
);
7535 gen_load_fpr32(fp2
, fr
);
7536 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7537 tcg_temp_free_i32(fp0
);
7538 tcg_temp_free_i32(fp1
);
7539 gen_store_fpr32(fp2
, fd
);
7540 tcg_temp_free_i32(fp2
);
7546 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7548 TCGv_i64 fp0
= tcg_temp_new_i64();
7549 TCGv_i64 fp1
= tcg_temp_new_i64();
7550 TCGv_i64 fp2
= tcg_temp_new_i64();
7552 gen_load_fpr64(ctx
, fp0
, fs
);
7553 gen_load_fpr64(ctx
, fp1
, ft
);
7554 gen_load_fpr64(ctx
, fp2
, fr
);
7555 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7556 tcg_temp_free_i64(fp0
);
7557 tcg_temp_free_i64(fp1
);
7558 gen_store_fpr64(ctx
, fp2
, fd
);
7559 tcg_temp_free_i64(fp2
);
7564 check_cp1_64bitmode(ctx
);
7566 TCGv_i64 fp0
= tcg_temp_new_i64();
7567 TCGv_i64 fp1
= tcg_temp_new_i64();
7568 TCGv_i64 fp2
= tcg_temp_new_i64();
7570 gen_load_fpr64(ctx
, fp0
, fs
);
7571 gen_load_fpr64(ctx
, fp1
, ft
);
7572 gen_load_fpr64(ctx
, fp2
, fr
);
7573 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7574 tcg_temp_free_i64(fp0
);
7575 tcg_temp_free_i64(fp1
);
7576 gen_store_fpr64(ctx
, fp2
, fd
);
7577 tcg_temp_free_i64(fp2
);
7583 generate_exception (ctx
, EXCP_RI
);
7586 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7587 fregnames
[fs
], fregnames
[ft
]);
7590 static void handle_delay_slot (CPUState
*env
, DisasContext
*ctx
,
7593 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7594 int proc_hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7595 /* Branches completion */
7596 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7597 ctx
->bstate
= BS_BRANCH
;
7598 save_cpu_state(ctx
, 0);
7599 /* FIXME: Need to clear can_do_io. */
7600 switch (proc_hflags
& MIPS_HFLAG_BMASK_BASE
) {
7602 /* unconditional branch */
7603 MIPS_DEBUG("unconditional branch");
7604 if (proc_hflags
& MIPS_HFLAG_BX
) {
7605 tcg_gen_xori_i32(hflags
, hflags
, MIPS_HFLAG_M16
);
7607 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7610 /* blikely taken case */
7611 MIPS_DEBUG("blikely branch taken");
7612 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7615 /* Conditional branch */
7616 MIPS_DEBUG("conditional branch");
7618 int l1
= gen_new_label();
7620 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7621 gen_goto_tb(ctx
, 1, ctx
->pc
+ insn_bytes
);
7623 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7627 /* unconditional branch to register */
7628 MIPS_DEBUG("branch to register");
7629 if (env
->insn_flags
& ASE_MIPS16
) {
7630 TCGv t0
= tcg_temp_new();
7631 TCGv_i32 t1
= tcg_temp_new_i32();
7633 tcg_gen_andi_tl(t0
, btarget
, 0x1);
7634 tcg_gen_trunc_tl_i32(t1
, t0
);
7636 tcg_gen_andi_i32(hflags
, hflags
, ~(uint32_t)MIPS_HFLAG_M16
);
7637 tcg_gen_shli_i32(t1
, t1
, MIPS_HFLAG_M16_SHIFT
);
7638 tcg_gen_or_i32(hflags
, hflags
, t1
);
7639 tcg_temp_free_i32(t1
);
7641 tcg_gen_andi_tl(cpu_PC
, btarget
, ~(target_ulong
)0x1);
7643 tcg_gen_mov_tl(cpu_PC
, btarget
);
7645 if (ctx
->singlestep_enabled
) {
7646 save_cpu_state(ctx
, 0);
7647 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
7652 MIPS_DEBUG("unknown branch");
7658 /* ISA extensions (ASEs) */
7659 /* MIPS16 extension to MIPS32 */
7661 /* MIPS16 major opcodes */
7663 M16_OPC_ADDIUSP
= 0x00,
7664 M16_OPC_ADDIUPC
= 0x01,
7667 M16_OPC_BEQZ
= 0x04,
7668 M16_OPC_BNEQZ
= 0x05,
7669 M16_OPC_SHIFT
= 0x06,
7671 M16_OPC_RRIA
= 0x08,
7672 M16_OPC_ADDIU8
= 0x09,
7673 M16_OPC_SLTI
= 0x0a,
7674 M16_OPC_SLTIU
= 0x0b,
7677 M16_OPC_CMPI
= 0x0e,
7681 M16_OPC_LWSP
= 0x12,
7685 M16_OPC_LWPC
= 0x16,
7689 M16_OPC_SWSP
= 0x1a,
7693 M16_OPC_EXTEND
= 0x1e,
7697 /* I8 funct field */
7716 /* RR funct field */
7750 /* I64 funct field */
7762 /* RR ry field for CNVT */
7764 RR_RY_CNVT_ZEB
= 0x0,
7765 RR_RY_CNVT_ZEH
= 0x1,
7766 RR_RY_CNVT_ZEW
= 0x2,
7767 RR_RY_CNVT_SEB
= 0x4,
7768 RR_RY_CNVT_SEH
= 0x5,
7769 RR_RY_CNVT_SEW
= 0x6,
7772 static int xlat (int r
)
7774 static int map
[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
7779 static void gen_mips16_save (DisasContext
*ctx
,
7780 int xsregs
, int aregs
,
7781 int do_ra
, int do_s0
, int do_s1
,
7784 TCGv t0
= tcg_temp_new();
7785 TCGv t1
= tcg_temp_new();
7815 generate_exception(ctx
, EXCP_RI
);
7821 gen_base_offset_addr(ctx
, t0
, 29, 12);
7822 gen_load_gpr(t1
, 7);
7823 op_ldst_sw(t1
, t0
, ctx
);
7826 gen_base_offset_addr(ctx
, t0
, 29, 8);
7827 gen_load_gpr(t1
, 6);
7828 op_ldst_sw(t1
, t0
, ctx
);
7831 gen_base_offset_addr(ctx
, t0
, 29, 4);
7832 gen_load_gpr(t1
, 5);
7833 op_ldst_sw(t1
, t0
, ctx
);
7836 gen_base_offset_addr(ctx
, t0
, 29, 0);
7837 gen_load_gpr(t1
, 4);
7838 op_ldst_sw(t1
, t0
, ctx
);
7841 gen_load_gpr(t0
, 29);
7843 #define DECR_AND_STORE(reg) do { \
7844 tcg_gen_subi_tl(t0, t0, 4); \
7845 gen_load_gpr(t1, reg); \
7846 op_ldst_sw(t1, t0, ctx); \
7910 generate_exception(ctx
, EXCP_RI
);
7926 #undef DECR_AND_STORE
7928 tcg_gen_subi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
7933 static void gen_mips16_restore (DisasContext
*ctx
,
7934 int xsregs
, int aregs
,
7935 int do_ra
, int do_s0
, int do_s1
,
7939 TCGv t0
= tcg_temp_new();
7940 TCGv t1
= tcg_temp_new();
7942 tcg_gen_addi_tl(t0
, cpu_gpr
[29], framesize
);
7944 #define DECR_AND_LOAD(reg) do { \
7945 tcg_gen_subi_tl(t0, t0, 4); \
7946 op_ldst_lw(t1, t0, ctx); \
7947 gen_store_gpr(t1, reg); \
8011 generate_exception(ctx
, EXCP_RI
);
8027 #undef DECR_AND_LOAD
8029 tcg_gen_addi_tl(cpu_gpr
[29], cpu_gpr
[29], framesize
);
8034 static void gen_addiupc (DisasContext
*ctx
, int rx
, int imm
,
8035 int is_64_bit
, int extended
)
8039 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8040 generate_exception(ctx
, EXCP_RI
);
8044 t0
= tcg_temp_new();
8046 tcg_gen_movi_tl(t0
, pc_relative_pc(ctx
));
8047 tcg_gen_addi_tl(cpu_gpr
[rx
], t0
, imm
);
8049 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8055 #if defined(TARGET_MIPS64)
8056 static void decode_i64_mips16 (CPUState
*env
, DisasContext
*ctx
,
8057 int ry
, int funct
, int16_t offset
,
8063 offset
= extended
? offset
: offset
<< 3;
8064 gen_ldst(ctx
, OPC_LD
, ry
, 29, offset
);
8068 offset
= extended
? offset
: offset
<< 3;
8069 gen_ldst(ctx
, OPC_SD
, ry
, 29, offset
);
8073 offset
= extended
? offset
: (ctx
->opcode
& 0xff) << 3;
8074 gen_ldst(ctx
, OPC_SD
, 31, 29, offset
);
8078 offset
= extended
? offset
: ((int8_t)ctx
->opcode
) << 3;
8079 gen_arith_imm(env
, ctx
, OPC_DADDIU
, 29, 29, offset
);
8082 if (extended
&& (ctx
->hflags
& MIPS_HFLAG_BMASK
)) {
8083 generate_exception(ctx
, EXCP_RI
);
8085 offset
= extended
? offset
: offset
<< 3;
8086 gen_ldst(ctx
, OPC_LDPC
, ry
, 0, offset
);
8091 offset
= extended
? offset
: ((int8_t)(offset
<< 3)) >> 3;
8092 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, ry
, offset
);
8096 offset
= extended
? offset
: offset
<< 2;
8097 gen_addiupc(ctx
, ry
, offset
, 1, extended
);
8101 offset
= extended
? offset
: offset
<< 2;
8102 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, 29, offset
);
8108 static int decode_extended_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8111 int extend
= lduw_code(ctx
->pc
+ 2);
8112 int op
, rx
, ry
, funct
, sa
;
8113 int16_t imm
, offset
;
8115 ctx
->opcode
= (ctx
->opcode
<< 16) | extend
;
8116 op
= (ctx
->opcode
>> 11) & 0x1f;
8117 sa
= (ctx
->opcode
>> 22) & 0x1f;
8118 funct
= (ctx
->opcode
>> 8) & 0x7;
8119 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8120 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8121 offset
= imm
= (int16_t) (((ctx
->opcode
>> 16) & 0x1f) << 11
8122 | ((ctx
->opcode
>> 21) & 0x3f) << 5
8123 | (ctx
->opcode
& 0x1f));
8125 /* The extended opcodes cleverly reuse the opcodes from their 16-bit
8128 case M16_OPC_ADDIUSP
:
8129 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8131 case M16_OPC_ADDIUPC
:
8132 gen_addiupc(ctx
, rx
, imm
, 0, 1);
8135 gen_compute_branch(ctx
, OPC_BEQ
, 4, 0, 0, offset
<< 1);
8136 /* No delay slot, so just process as a normal instruction */
8139 gen_compute_branch(ctx
, OPC_BEQ
, 4, rx
, 0, offset
<< 1);
8140 /* No delay slot, so just process as a normal instruction */
8143 gen_compute_branch(ctx
, OPC_BNE
, 4, rx
, 0, offset
<< 1);
8144 /* No delay slot, so just process as a normal instruction */
8147 switch (ctx
->opcode
& 0x3) {
8149 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8152 #if defined(TARGET_MIPS64)
8154 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8156 generate_exception(ctx
, EXCP_RI
);
8160 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8163 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8167 #if defined(TARGET_MIPS64)
8170 gen_ldst(ctx
, OPC_LD
, ry
, rx
, offset
);
8174 imm
= ctx
->opcode
& 0xf;
8175 imm
= imm
| ((ctx
->opcode
>> 20) & 0x7f) << 4;
8176 imm
= imm
| ((ctx
->opcode
>> 16) & 0xf) << 11;
8177 imm
= (int16_t) (imm
<< 1) >> 1;
8178 if ((ctx
->opcode
>> 4) & 0x1) {
8179 #if defined(TARGET_MIPS64)
8181 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8183 generate_exception(ctx
, EXCP_RI
);
8186 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8189 case M16_OPC_ADDIU8
:
8190 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8193 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8196 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8201 gen_compute_branch(ctx
, OPC_BEQ
, 4, 24, 0, offset
<< 1);
8204 gen_compute_branch(ctx
, OPC_BNE
, 4, 24, 0, offset
<< 1);
8207 gen_ldst(ctx
, OPC_SW
, 31, 29, imm
);
8210 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29, imm
);
8214 int xsregs
= (ctx
->opcode
>> 24) & 0x7;
8215 int aregs
= (ctx
->opcode
>> 16) & 0xf;
8216 int do_ra
= (ctx
->opcode
>> 6) & 0x1;
8217 int do_s0
= (ctx
->opcode
>> 5) & 0x1;
8218 int do_s1
= (ctx
->opcode
>> 4) & 0x1;
8219 int framesize
= (((ctx
->opcode
>> 20) & 0xf) << 4
8220 | (ctx
->opcode
& 0xf)) << 3;
8222 if (ctx
->opcode
& (1 << 7)) {
8223 gen_mips16_save(ctx
, xsregs
, aregs
,
8224 do_ra
, do_s0
, do_s1
,
8227 gen_mips16_restore(ctx
, xsregs
, aregs
,
8228 do_ra
, do_s0
, do_s1
,
8234 generate_exception(ctx
, EXCP_RI
);
8239 tcg_gen_movi_tl(cpu_gpr
[rx
], (uint16_t) imm
);
8242 tcg_gen_xori_tl(cpu_gpr
[24], cpu_gpr
[rx
], (uint16_t) imm
);
8244 #if defined(TARGET_MIPS64)
8246 gen_ldst(ctx
, OPC_SD
, ry
, rx
, offset
);
8250 gen_ldst(ctx
, OPC_LB
, ry
, rx
, offset
);
8253 gen_ldst(ctx
, OPC_LH
, ry
, rx
, offset
);
8256 gen_ldst(ctx
, OPC_LW
, rx
, 29, offset
);
8259 gen_ldst(ctx
, OPC_LW
, ry
, rx
, offset
);
8262 gen_ldst(ctx
, OPC_LBU
, ry
, rx
, offset
);
8265 gen_ldst(ctx
, OPC_LHU
, ry
, rx
, offset
);
8268 gen_ldst(ctx
, OPC_LWPC
, rx
, 0, offset
);
8270 #if defined(TARGET_MIPS64)
8272 gen_ldst(ctx
, OPC_LWU
, ry
, rx
, offset
);
8276 gen_ldst(ctx
, OPC_SB
, ry
, rx
, offset
);
8279 gen_ldst(ctx
, OPC_SH
, ry
, rx
, offset
);
8282 gen_ldst(ctx
, OPC_SW
, rx
, 29, offset
);
8285 gen_ldst(ctx
, OPC_SW
, ry
, rx
, offset
);
8287 #if defined(TARGET_MIPS64)
8289 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 1);
8293 generate_exception(ctx
, EXCP_RI
);
8300 static int decode_mips16_opc (CPUState
*env
, DisasContext
*ctx
,
8305 int op
, cnvt_op
, op1
, offset
;
8309 op
= (ctx
->opcode
>> 11) & 0x1f;
8310 sa
= (ctx
->opcode
>> 2) & 0x7;
8311 sa
= sa
== 0 ? 8 : sa
;
8312 rx
= xlat((ctx
->opcode
>> 8) & 0x7);
8313 cnvt_op
= (ctx
->opcode
>> 5) & 0x7;
8314 ry
= xlat((ctx
->opcode
>> 5) & 0x7);
8315 op1
= offset
= ctx
->opcode
& 0x1f;
8320 case M16_OPC_ADDIUSP
:
8322 int16_t imm
= ((uint8_t) ctx
->opcode
) << 2;
8324 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 29, imm
);
8327 case M16_OPC_ADDIUPC
:
8328 gen_addiupc(ctx
, rx
, ((uint8_t) ctx
->opcode
) << 2, 0, 0);
8331 offset
= (ctx
->opcode
& 0x7ff) << 1;
8332 offset
= (int16_t)(offset
<< 4) >> 4;
8333 gen_compute_branch(ctx
, OPC_BEQ
, 2, 0, 0, offset
);
8334 /* No delay slot, so just process as a normal instruction */
8337 offset
= lduw_code(ctx
->pc
+ 2);
8338 offset
= (((ctx
->opcode
& 0x1f) << 21)
8339 | ((ctx
->opcode
>> 5) & 0x1f) << 16
8341 op
= ((ctx
->opcode
>> 10) & 0x1) ? OPC_JALX
: OPC_JAL
;
8342 gen_compute_branch(ctx
, op
, 4, rx
, ry
, offset
);
8347 gen_compute_branch(ctx
, OPC_BEQ
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8348 /* No delay slot, so just process as a normal instruction */
8351 gen_compute_branch(ctx
, OPC_BNE
, 2, rx
, 0, ((int8_t)ctx
->opcode
) << 1);
8352 /* No delay slot, so just process as a normal instruction */
8355 switch (ctx
->opcode
& 0x3) {
8357 gen_shift_imm(env
, ctx
, OPC_SLL
, rx
, ry
, sa
);
8360 #if defined(TARGET_MIPS64)
8362 gen_shift_imm(env
, ctx
, OPC_DSLL
, rx
, ry
, sa
);
8364 generate_exception(ctx
, EXCP_RI
);
8368 gen_shift_imm(env
, ctx
, OPC_SRL
, rx
, ry
, sa
);
8371 gen_shift_imm(env
, ctx
, OPC_SRA
, rx
, ry
, sa
);
8375 #if defined(TARGET_MIPS64)
8378 gen_ldst(ctx
, OPC_LD
, ry
, rx
, offset
<< 3);
8383 int16_t imm
= (int8_t)((ctx
->opcode
& 0xf) << 4) >> 4;
8385 if ((ctx
->opcode
>> 4) & 1) {
8386 #if defined(TARGET_MIPS64)
8388 gen_arith_imm(env
, ctx
, OPC_DADDIU
, ry
, rx
, imm
);
8390 generate_exception(ctx
, EXCP_RI
);
8393 gen_arith_imm(env
, ctx
, OPC_ADDIU
, ry
, rx
, imm
);
8397 case M16_OPC_ADDIU8
:
8399 int16_t imm
= (int8_t) ctx
->opcode
;
8401 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, rx
, imm
);
8406 int16_t imm
= (uint8_t) ctx
->opcode
;
8408 gen_slt_imm(env
, OPC_SLTI
, 24, rx
, imm
);
8413 int16_t imm
= (uint8_t) ctx
->opcode
;
8415 gen_slt_imm(env
, OPC_SLTIU
, 24, rx
, imm
);
8422 funct
= (ctx
->opcode
>> 8) & 0x7;
8425 gen_compute_branch(ctx
, OPC_BEQ
, 2, 24, 0,
8426 ((int8_t)ctx
->opcode
) << 1);
8429 gen_compute_branch(ctx
, OPC_BNE
, 2, 24, 0,
8430 ((int8_t)ctx
->opcode
) << 1);
8433 gen_ldst(ctx
, OPC_SW
, 31, 29, (ctx
->opcode
& 0xff) << 2);
8436 gen_arith_imm(env
, ctx
, OPC_ADDIU
, 29, 29,
8437 ((int8_t)ctx
->opcode
) << 3);
8441 int do_ra
= ctx
->opcode
& (1 << 6);
8442 int do_s0
= ctx
->opcode
& (1 << 5);
8443 int do_s1
= ctx
->opcode
& (1 << 4);
8444 int framesize
= ctx
->opcode
& 0xf;
8446 if (framesize
== 0) {
8449 framesize
= framesize
<< 3;
8452 if (ctx
->opcode
& (1 << 7)) {
8453 gen_mips16_save(ctx
, 0, 0,
8454 do_ra
, do_s0
, do_s1
, framesize
);
8456 gen_mips16_restore(ctx
, 0, 0,
8457 do_ra
, do_s0
, do_s1
, framesize
);
8463 int rz
= xlat(ctx
->opcode
& 0x7);
8465 reg32
= (((ctx
->opcode
>> 3) & 0x3) << 3) |
8466 ((ctx
->opcode
>> 5) & 0x7);
8467 gen_arith(env
, ctx
, OPC_ADDU
, reg32
, rz
, 0);
8471 reg32
= ctx
->opcode
& 0x1f;
8472 gen_arith(env
, ctx
, OPC_ADDU
, ry
, reg32
, 0);
8475 generate_exception(ctx
, EXCP_RI
);
8482 int16_t imm
= (uint8_t) ctx
->opcode
;
8484 gen_arith_imm(env
, ctx
, OPC_ADDIU
, rx
, 0, imm
);
8489 int16_t imm
= (uint8_t) ctx
->opcode
;
8491 gen_logic_imm(env
, OPC_XORI
, 24, rx
, imm
);
8494 #if defined(TARGET_MIPS64)
8497 gen_ldst(ctx
, OPC_SD
, ry
, rx
, offset
<< 3);
8501 gen_ldst(ctx
, OPC_LB
, ry
, rx
, offset
);
8504 gen_ldst(ctx
, OPC_LH
, ry
, rx
, offset
<< 1);
8507 gen_ldst(ctx
, OPC_LW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8510 gen_ldst(ctx
, OPC_LW
, ry
, rx
, offset
<< 2);
8513 gen_ldst(ctx
, OPC_LBU
, ry
, rx
, offset
);
8516 gen_ldst(ctx
, OPC_LHU
, ry
, rx
, offset
<< 1);
8519 gen_ldst(ctx
, OPC_LWPC
, rx
, 0, ((uint8_t)ctx
->opcode
) << 2);
8521 #if defined (TARGET_MIPS64)
8524 gen_ldst(ctx
, OPC_LWU
, ry
, rx
, offset
<< 2);
8528 gen_ldst(ctx
, OPC_SB
, ry
, rx
, offset
);
8531 gen_ldst(ctx
, OPC_SH
, ry
, rx
, offset
<< 1);
8534 gen_ldst(ctx
, OPC_SW
, rx
, 29, ((uint8_t)ctx
->opcode
) << 2);
8537 gen_ldst(ctx
, OPC_SW
, ry
, rx
, offset
<< 2);
8541 int rz
= xlat((ctx
->opcode
>> 2) & 0x7);
8544 switch (ctx
->opcode
& 0x3) {
8546 mips32_op
= OPC_ADDU
;
8549 mips32_op
= OPC_SUBU
;
8551 #if defined(TARGET_MIPS64)
8553 mips32_op
= OPC_DADDU
;
8557 mips32_op
= OPC_DSUBU
;
8562 generate_exception(ctx
, EXCP_RI
);
8566 gen_arith(env
, ctx
, mips32_op
, rz
, rx
, ry
);
8575 int nd
= (ctx
->opcode
>> 7) & 0x1;
8576 int link
= (ctx
->opcode
>> 6) & 0x1;
8577 int ra
= (ctx
->opcode
>> 5) & 0x1;
8580 op
= nd
? OPC_JALRC
: OPC_JALR
;
8585 gen_compute_branch(ctx
, op
, 2, ra
? 31 : rx
, 31, 0);
8592 /* XXX: not clear which exception should be raised
8593 * when in debug mode...
8595 check_insn(env
, ctx
, ISA_MIPS32
);
8596 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
8597 generate_exception(ctx
, EXCP_DBp
);
8599 generate_exception(ctx
, EXCP_DBp
);
8603 gen_slt(env
, OPC_SLT
, 24, rx
, ry
);
8606 gen_slt(env
, OPC_SLTU
, 24, rx
, ry
);
8609 generate_exception(ctx
, EXCP_BREAK
);
8612 gen_shift(env
, ctx
, OPC_SLLV
, ry
, rx
, ry
);
8615 gen_shift(env
, ctx
, OPC_SRLV
, ry
, rx
, ry
);
8618 gen_shift(env
, ctx
, OPC_SRAV
, ry
, rx
, ry
);
8620 #if defined (TARGET_MIPS64)
8623 gen_shift_imm(env
, ctx
, OPC_DSRL
, ry
, ry
, sa
);
8627 gen_logic(env
, OPC_XOR
, 24, rx
, ry
);
8630 gen_arith(env
, ctx
, OPC_SUBU
, rx
, 0, ry
);
8633 gen_logic(env
, OPC_AND
, rx
, rx
, ry
);
8636 gen_logic(env
, OPC_OR
, rx
, rx
, ry
);
8639 gen_logic(env
, OPC_XOR
, rx
, rx
, ry
);
8642 gen_logic(env
, OPC_NOR
, rx
, ry
, 0);
8645 gen_HILO(ctx
, OPC_MFHI
, rx
);
8649 case RR_RY_CNVT_ZEB
:
8650 tcg_gen_ext8u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8652 case RR_RY_CNVT_ZEH
:
8653 tcg_gen_ext16u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8655 case RR_RY_CNVT_SEB
:
8656 tcg_gen_ext8s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8658 case RR_RY_CNVT_SEH
:
8659 tcg_gen_ext16s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8661 #if defined (TARGET_MIPS64)
8662 case RR_RY_CNVT_ZEW
:
8664 tcg_gen_ext32u_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8666 case RR_RY_CNVT_SEW
:
8668 tcg_gen_ext32s_tl(cpu_gpr
[rx
], cpu_gpr
[rx
]);
8672 generate_exception(ctx
, EXCP_RI
);
8677 gen_HILO(ctx
, OPC_MFLO
, rx
);
8679 #if defined (TARGET_MIPS64)
8682 gen_shift_imm(env
, ctx
, OPC_DSRA
, ry
, ry
, sa
);
8686 gen_shift(env
, ctx
, OPC_DSLLV
, ry
, rx
, ry
);
8690 gen_shift(env
, ctx
, OPC_DSRLV
, ry
, rx
, ry
);
8694 gen_shift(env
, ctx
, OPC_DSRAV
, ry
, rx
, ry
);
8698 gen_muldiv(ctx
, OPC_MULT
, rx
, ry
);
8701 gen_muldiv(ctx
, OPC_MULTU
, rx
, ry
);
8704 gen_muldiv(ctx
, OPC_DIV
, rx
, ry
);
8707 gen_muldiv(ctx
, OPC_DIVU
, rx
, ry
);
8709 #if defined (TARGET_MIPS64)
8712 gen_muldiv(ctx
, OPC_DMULT
, rx
, ry
);
8716 gen_muldiv(ctx
, OPC_DMULTU
, rx
, ry
);
8720 gen_muldiv(ctx
, OPC_DDIV
, rx
, ry
);
8724 gen_muldiv(ctx
, OPC_DDIVU
, rx
, ry
);
8728 generate_exception(ctx
, EXCP_RI
);
8732 case M16_OPC_EXTEND
:
8733 decode_extended_mips16_opc(env
, ctx
, is_branch
);
8736 #if defined(TARGET_MIPS64)
8738 funct
= (ctx
->opcode
>> 8) & 0x7;
8739 decode_i64_mips16(env
, ctx
, ry
, funct
, offset
, 0);
8743 generate_exception(ctx
, EXCP_RI
);
8750 /* SmartMIPS extension to MIPS32 */
8752 #if defined(TARGET_MIPS64)
8754 /* MDMX extension to MIPS64 */
8758 static void decode_opc (CPUState
*env
, DisasContext
*ctx
, int *is_branch
)
8762 uint32_t op
, op1
, op2
;
8765 /* make sure instructions are on a word boundary */
8766 if (ctx
->pc
& 0x3) {
8767 env
->CP0_BadVAddr
= ctx
->pc
;
8768 generate_exception(ctx
, EXCP_AdEL
);
8772 /* Handle blikely not taken case */
8773 if ((ctx
->hflags
& MIPS_HFLAG_BMASK_BASE
) == MIPS_HFLAG_BL
) {
8774 int l1
= gen_new_label();
8776 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
8777 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8778 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
8779 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8783 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
8784 tcg_gen_debug_insn_start(ctx
->pc
);
8786 op
= MASK_OP_MAJOR(ctx
->opcode
);
8787 rs
= (ctx
->opcode
>> 21) & 0x1f;
8788 rt
= (ctx
->opcode
>> 16) & 0x1f;
8789 rd
= (ctx
->opcode
>> 11) & 0x1f;
8790 sa
= (ctx
->opcode
>> 6) & 0x1f;
8791 imm
= (int16_t)ctx
->opcode
;
8794 op1
= MASK_SPECIAL(ctx
->opcode
);
8796 case OPC_SLL
: /* Shift with immediate */
8798 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8801 switch ((ctx
->opcode
>> 21) & 0x1f) {
8803 /* rotr is decoded as srl on non-R2 CPUs */
8804 if (env
->insn_flags
& ISA_MIPS32R2
) {
8809 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8812 generate_exception(ctx
, EXCP_RI
);
8816 case OPC_MOVN
: /* Conditional move */
8818 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8819 gen_cond_move(env
, op1
, rd
, rs
, rt
);
8821 case OPC_ADD
... OPC_SUBU
:
8822 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8824 case OPC_SLLV
: /* Shifts */
8826 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8829 switch ((ctx
->opcode
>> 6) & 0x1f) {
8831 /* rotrv is decoded as srlv on non-R2 CPUs */
8832 if (env
->insn_flags
& ISA_MIPS32R2
) {
8837 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8840 generate_exception(ctx
, EXCP_RI
);
8844 case OPC_SLT
: /* Set on less than */
8846 gen_slt(env
, op1
, rd
, rs
, rt
);
8848 case OPC_AND
: /* Logic*/
8852 gen_logic(env
, op1
, rd
, rs
, rt
);
8854 case OPC_MULT
... OPC_DIVU
:
8856 check_insn(env
, ctx
, INSN_VR54XX
);
8857 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
8858 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
8860 gen_muldiv(ctx
, op1
, rs
, rt
);
8862 case OPC_JR
... OPC_JALR
:
8863 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
8866 case OPC_TGE
... OPC_TEQ
: /* Traps */
8868 gen_trap(ctx
, op1
, rs
, rt
, -1);
8870 case OPC_MFHI
: /* Move from HI/LO */
8872 gen_HILO(ctx
, op1
, rd
);
8875 case OPC_MTLO
: /* Move to HI/LO */
8876 gen_HILO(ctx
, op1
, rs
);
8878 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
8879 #ifdef MIPS_STRICT_STANDARD
8880 MIPS_INVAL("PMON / selsl");
8881 generate_exception(ctx
, EXCP_RI
);
8883 gen_helper_0i(pmon
, sa
);
8887 generate_exception(ctx
, EXCP_SYSCALL
);
8888 ctx
->bstate
= BS_STOP
;
8891 generate_exception(ctx
, EXCP_BREAK
);
8894 #ifdef MIPS_STRICT_STANDARD
8896 generate_exception(ctx
, EXCP_RI
);
8898 /* Implemented as RI exception for now. */
8899 MIPS_INVAL("spim (unofficial)");
8900 generate_exception(ctx
, EXCP_RI
);
8908 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8909 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8910 check_cp1_enabled(ctx
);
8911 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
8912 (ctx
->opcode
>> 16) & 1);
8914 generate_exception_err(ctx
, EXCP_CpU
, 1);
8918 #if defined(TARGET_MIPS64)
8919 /* MIPS64 specific opcodes */
8924 check_insn(env
, ctx
, ISA_MIPS3
);
8926 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8929 switch ((ctx
->opcode
>> 21) & 0x1f) {
8931 /* drotr is decoded as dsrl on non-R2 CPUs */
8932 if (env
->insn_flags
& ISA_MIPS32R2
) {
8937 check_insn(env
, ctx
, ISA_MIPS3
);
8939 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8942 generate_exception(ctx
, EXCP_RI
);
8947 switch ((ctx
->opcode
>> 21) & 0x1f) {
8949 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
8950 if (env
->insn_flags
& ISA_MIPS32R2
) {
8955 check_insn(env
, ctx
, ISA_MIPS3
);
8957 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
8960 generate_exception(ctx
, EXCP_RI
);
8964 case OPC_DADD
... OPC_DSUBU
:
8965 check_insn(env
, ctx
, ISA_MIPS3
);
8967 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
8971 check_insn(env
, ctx
, ISA_MIPS3
);
8973 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8976 switch ((ctx
->opcode
>> 6) & 0x1f) {
8978 /* drotrv is decoded as dsrlv on non-R2 CPUs */
8979 if (env
->insn_flags
& ISA_MIPS32R2
) {
8984 check_insn(env
, ctx
, ISA_MIPS3
);
8986 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
8989 generate_exception(ctx
, EXCP_RI
);
8993 case OPC_DMULT
... OPC_DDIVU
:
8994 check_insn(env
, ctx
, ISA_MIPS3
);
8996 gen_muldiv(ctx
, op1
, rs
, rt
);
8999 default: /* Invalid */
9000 MIPS_INVAL("special");
9001 generate_exception(ctx
, EXCP_RI
);
9006 op1
= MASK_SPECIAL2(ctx
->opcode
);
9008 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
9009 case OPC_MSUB
... OPC_MSUBU
:
9010 check_insn(env
, ctx
, ISA_MIPS32
);
9011 gen_muldiv(ctx
, op1
, rs
, rt
);
9014 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
9018 check_insn(env
, ctx
, ISA_MIPS32
);
9019 gen_cl(ctx
, op1
, rd
, rs
);
9022 /* XXX: not clear which exception should be raised
9023 * when in debug mode...
9025 check_insn(env
, ctx
, ISA_MIPS32
);
9026 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
9027 generate_exception(ctx
, EXCP_DBp
);
9029 generate_exception(ctx
, EXCP_DBp
);
9033 #if defined(TARGET_MIPS64)
9036 check_insn(env
, ctx
, ISA_MIPS64
);
9038 gen_cl(ctx
, op1
, rd
, rs
);
9041 default: /* Invalid */
9042 MIPS_INVAL("special2");
9043 generate_exception(ctx
, EXCP_RI
);
9048 op1
= MASK_SPECIAL3(ctx
->opcode
);
9052 check_insn(env
, ctx
, ISA_MIPS32R2
);
9053 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
9056 check_insn(env
, ctx
, ISA_MIPS32R2
);
9057 op2
= MASK_BSHFL(ctx
->opcode
);
9058 gen_bshfl(ctx
, op2
, rt
, rd
);
9061 check_insn(env
, ctx
, ISA_MIPS32R2
);
9063 TCGv t0
= tcg_temp_new();
9067 save_cpu_state(ctx
, 1);
9068 gen_helper_rdhwr_cpunum(t0
);
9069 gen_store_gpr(t0
, rt
);
9072 save_cpu_state(ctx
, 1);
9073 gen_helper_rdhwr_synci_step(t0
);
9074 gen_store_gpr(t0
, rt
);
9077 save_cpu_state(ctx
, 1);
9078 gen_helper_rdhwr_cc(t0
);
9079 gen_store_gpr(t0
, rt
);
9082 save_cpu_state(ctx
, 1);
9083 gen_helper_rdhwr_ccres(t0
);
9084 gen_store_gpr(t0
, rt
);
9087 #if defined(CONFIG_USER_ONLY)
9088 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
9089 gen_store_gpr(t0
, rt
);
9092 /* XXX: Some CPUs implement this in hardware.
9093 Not supported yet. */
9095 default: /* Invalid */
9096 MIPS_INVAL("rdhwr");
9097 generate_exception(ctx
, EXCP_RI
);
9104 check_insn(env
, ctx
, ASE_MT
);
9106 TCGv t0
= tcg_temp_new();
9107 TCGv t1
= tcg_temp_new();
9109 gen_load_gpr(t0
, rt
);
9110 gen_load_gpr(t1
, rs
);
9111 gen_helper_fork(t0
, t1
);
9117 check_insn(env
, ctx
, ASE_MT
);
9119 TCGv t0
= tcg_temp_new();
9121 save_cpu_state(ctx
, 1);
9122 gen_load_gpr(t0
, rs
);
9123 gen_helper_yield(t0
, t0
);
9124 gen_store_gpr(t0
, rd
);
9128 #if defined(TARGET_MIPS64)
9129 case OPC_DEXTM
... OPC_DEXT
:
9130 case OPC_DINSM
... OPC_DINS
:
9131 check_insn(env
, ctx
, ISA_MIPS64R2
);
9133 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
9136 check_insn(env
, ctx
, ISA_MIPS64R2
);
9138 op2
= MASK_DBSHFL(ctx
->opcode
);
9139 gen_bshfl(ctx
, op2
, rt
, rd
);
9142 default: /* Invalid */
9143 MIPS_INVAL("special3");
9144 generate_exception(ctx
, EXCP_RI
);
9149 op1
= MASK_REGIMM(ctx
->opcode
);
9151 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
9152 case OPC_BLTZAL
... OPC_BGEZALL
:
9153 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
9156 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
9158 gen_trap(ctx
, op1
, rs
, -1, imm
);
9161 check_insn(env
, ctx
, ISA_MIPS32R2
);
9164 default: /* Invalid */
9165 MIPS_INVAL("regimm");
9166 generate_exception(ctx
, EXCP_RI
);
9171 check_cp0_enabled(ctx
);
9172 op1
= MASK_CP0(ctx
->opcode
);
9178 #if defined(TARGET_MIPS64)
9182 #ifndef CONFIG_USER_ONLY
9183 gen_cp0(env
, ctx
, op1
, rt
, rd
);
9184 #endif /* !CONFIG_USER_ONLY */
9186 case OPC_C0_FIRST
... OPC_C0_LAST
:
9187 #ifndef CONFIG_USER_ONLY
9188 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
9189 #endif /* !CONFIG_USER_ONLY */
9192 #ifndef CONFIG_USER_ONLY
9194 TCGv t0
= tcg_temp_new();
9196 op2
= MASK_MFMC0(ctx
->opcode
);
9199 check_insn(env
, ctx
, ASE_MT
);
9200 gen_helper_dmt(t0
, t0
);
9201 gen_store_gpr(t0
, rt
);
9204 check_insn(env
, ctx
, ASE_MT
);
9205 gen_helper_emt(t0
, t0
);
9206 gen_store_gpr(t0
, rt
);
9209 check_insn(env
, ctx
, ASE_MT
);
9210 gen_helper_dvpe(t0
, t0
);
9211 gen_store_gpr(t0
, rt
);
9214 check_insn(env
, ctx
, ASE_MT
);
9215 gen_helper_evpe(t0
, t0
);
9216 gen_store_gpr(t0
, rt
);
9219 check_insn(env
, ctx
, ISA_MIPS32R2
);
9220 save_cpu_state(ctx
, 1);
9222 gen_store_gpr(t0
, rt
);
9223 /* Stop translation as we may have switched the execution mode */
9224 ctx
->bstate
= BS_STOP
;
9227 check_insn(env
, ctx
, ISA_MIPS32R2
);
9228 save_cpu_state(ctx
, 1);
9230 gen_store_gpr(t0
, rt
);
9231 /* Stop translation as we may have switched the execution mode */
9232 ctx
->bstate
= BS_STOP
;
9234 default: /* Invalid */
9235 MIPS_INVAL("mfmc0");
9236 generate_exception(ctx
, EXCP_RI
);
9241 #endif /* !CONFIG_USER_ONLY */
9244 check_insn(env
, ctx
, ISA_MIPS32R2
);
9245 gen_load_srsgpr(rt
, rd
);
9248 check_insn(env
, ctx
, ISA_MIPS32R2
);
9249 gen_store_srsgpr(rt
, rd
);
9253 generate_exception(ctx
, EXCP_RI
);
9257 case OPC_ADDI
: /* Arithmetic with immediate opcode */
9259 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
9261 case OPC_SLTI
: /* Set on less than with immediate opcode */
9263 gen_slt_imm(env
, op
, rt
, rs
, imm
);
9265 case OPC_ANDI
: /* Arithmetic with immediate opcode */
9269 gen_logic_imm(env
, op
, rt
, rs
, imm
);
9271 case OPC_J
... OPC_JAL
: /* Jump */
9272 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
9273 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
9276 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
9277 case OPC_BEQL
... OPC_BGTZL
:
9278 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
9281 case OPC_LB
... OPC_LWR
: /* Load and stores */
9282 case OPC_SB
... OPC_SW
:
9285 gen_ldst(ctx
, op
, rt
, rs
, imm
);
9288 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
9291 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
9295 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
9299 /* Floating point (COP1). */
9304 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9305 check_cp1_enabled(ctx
);
9306 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
9308 generate_exception_err(ctx
, EXCP_CpU
, 1);
9313 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9314 check_cp1_enabled(ctx
);
9315 op1
= MASK_CP1(ctx
->opcode
);
9319 check_insn(env
, ctx
, ISA_MIPS32R2
);
9324 gen_cp1(ctx
, op1
, rt
, rd
);
9326 #if defined(TARGET_MIPS64)
9329 check_insn(env
, ctx
, ISA_MIPS3
);
9330 gen_cp1(ctx
, op1
, rt
, rd
);
9336 check_insn(env
, ctx
, ASE_MIPS3D
);
9339 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
9340 (rt
>> 2) & 0x7, imm
<< 2);
9348 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
9353 generate_exception (ctx
, EXCP_RI
);
9357 generate_exception_err(ctx
, EXCP_CpU
, 1);
9367 /* COP2: Not implemented. */
9368 generate_exception_err(ctx
, EXCP_CpU
, 2);
9372 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9373 check_cp1_enabled(ctx
);
9374 op1
= MASK_CP3(ctx
->opcode
);
9382 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
9400 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
9404 generate_exception (ctx
, EXCP_RI
);
9408 generate_exception_err(ctx
, EXCP_CpU
, 1);
9412 #if defined(TARGET_MIPS64)
9413 /* MIPS64 opcodes */
9415 case OPC_LDL
... OPC_LDR
:
9416 case OPC_SDL
... OPC_SDR
:
9420 check_insn(env
, ctx
, ISA_MIPS3
);
9422 gen_ldst(ctx
, op
, rt
, rs
, imm
);
9425 check_insn(env
, ctx
, ISA_MIPS3
);
9427 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
9431 check_insn(env
, ctx
, ISA_MIPS3
);
9433 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
9437 check_insn(env
, ctx
, ASE_MIPS16
);
9438 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
9439 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
9443 check_insn(env
, ctx
, ASE_MDMX
);
9444 /* MDMX: Not implemented. */
9445 default: /* Invalid */
9446 MIPS_INVAL("major opcode");
9447 generate_exception(ctx
, EXCP_RI
);
9453 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
9457 target_ulong pc_start
;
9458 uint16_t *gen_opc_end
;
9467 qemu_log("search pc %d\n", search_pc
);
9470 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
9473 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
9475 ctx
.bstate
= BS_NONE
;
9476 /* Restore delay slot state from the tb context. */
9477 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
9478 restore_cpu_state(env
, &ctx
);
9479 #ifdef CONFIG_USER_ONLY
9480 ctx
.mem_idx
= MIPS_HFLAG_UM
;
9482 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
9485 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9487 max_insns
= CF_COUNT_MASK
;
9489 qemu_log_mask(CPU_LOG_TB_CPU
, "------------------------------------------------\n");
9490 /* FIXME: This may print out stale hflags from env... */
9491 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
9493 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
9495 while (ctx
.bstate
== BS_NONE
) {
9496 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9497 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9498 if (bp
->pc
== ctx
.pc
) {
9499 save_cpu_state(&ctx
, 1);
9500 ctx
.bstate
= BS_BRANCH
;
9501 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
9502 /* Include the breakpoint location or the tb won't
9503 * be flushed when it must be. */
9505 goto done_generating
;
9511 j
= gen_opc_ptr
- gen_opc_buf
;
9515 gen_opc_instr_start
[lj
++] = 0;
9517 gen_opc_pc
[lj
] = ctx
.pc
;
9518 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
9519 gen_opc_instr_start
[lj
] = 1;
9520 gen_opc_icount
[lj
] = num_insns
;
9522 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9526 if (!(ctx
.hflags
& MIPS_HFLAG_M16
)) {
9527 ctx
.opcode
= ldl_code(ctx
.pc
);
9529 decode_opc(env
, &ctx
, &is_branch
);
9530 } else if (env
->insn_flags
& ASE_MIPS16
) {
9531 ctx
.opcode
= lduw_code(ctx
.pc
);
9532 insn_bytes
= decode_mips16_opc(env
, &ctx
, &is_branch
);
9534 generate_exception(&ctx
, EXCP_RI
);
9538 handle_delay_slot(env
, &ctx
, insn_bytes
);
9540 ctx
.pc
+= insn_bytes
;
9544 /* Execute a branch and its delay slot as a single instruction.
9545 This is what GDB expects and is consistent with what the
9546 hardware does (e.g. if a delay slot instruction faults, the
9547 reported PC is the PC of the branch). */
9548 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
9551 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
9554 if (gen_opc_ptr
>= gen_opc_end
)
9557 if (num_insns
>= max_insns
)
9563 if (tb
->cflags
& CF_LAST_IO
)
9565 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
9566 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
9567 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
9569 switch (ctx
.bstate
) {
9571 gen_helper_interrupt_restart();
9572 gen_goto_tb(&ctx
, 0, ctx
.pc
);
9575 save_cpu_state(&ctx
, 0);
9576 gen_goto_tb(&ctx
, 0, ctx
.pc
);
9579 gen_helper_interrupt_restart();
9588 gen_icount_end(tb
, num_insns
);
9589 *gen_opc_ptr
= INDEX_op_end
;
9591 j
= gen_opc_ptr
- gen_opc_buf
;
9594 gen_opc_instr_start
[lj
++] = 0;
9596 tb
->size
= ctx
.pc
- pc_start
;
9597 tb
->icount
= num_insns
;
9601 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9602 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9603 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
9606 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
9610 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
9612 gen_intermediate_code_internal(env
, tb
, 0);
9615 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
9617 gen_intermediate_code_internal(env
, tb
, 1);
9620 static void fpu_dump_state(CPUState
*env
, FILE *f
,
9621 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9625 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
9627 #define printfpr(fp) \
9630 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
9631 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
9632 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
9635 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
9636 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
9637 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
9638 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
9639 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
9644 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
9645 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
9646 get_float_exception_flags(&env
->active_fpu
.fp_status
));
9647 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
9648 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
9649 printfpr(&env
->active_fpu
.fpr
[i
]);
9655 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
9656 /* Debug help: The architecture requires 32bit code to maintain proper
9657 sign-extended values on 64bit machines. */
9659 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
9662 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
9663 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9668 if (!SIGN_EXT_P(env
->active_tc
.PC
))
9669 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
9670 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
9671 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
9672 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
9673 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
9674 if (!SIGN_EXT_P(env
->btarget
))
9675 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
9677 for (i
= 0; i
< 32; i
++) {
9678 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
9679 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
9682 if (!SIGN_EXT_P(env
->CP0_EPC
))
9683 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
9684 if (!SIGN_EXT_P(env
->lladdr
))
9685 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
9689 void cpu_dump_state (CPUState
*env
, FILE *f
,
9690 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
9695 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
9696 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
9697 env
->hflags
, env
->btarget
, env
->bcond
);
9698 for (i
= 0; i
< 32; i
++) {
9700 cpu_fprintf(f
, "GPR%02d:", i
);
9701 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
9703 cpu_fprintf(f
, "\n");
9706 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
9707 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
9708 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
9709 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
9710 if (env
->hflags
& MIPS_HFLAG_FPU
)
9711 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
9712 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
9713 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
9717 static void mips_tcg_init(void)
9722 /* Initialize various static tables. */
9726 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
9727 TCGV_UNUSED(cpu_gpr
[0]);
9728 for (i
= 1; i
< 32; i
++)
9729 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
9730 offsetof(CPUState
, active_tc
.gpr
[i
]),
9732 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
9733 offsetof(CPUState
, active_tc
.PC
), "PC");
9734 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
9735 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
9736 offsetof(CPUState
, active_tc
.HI
[i
]),
9738 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
9739 offsetof(CPUState
, active_tc
.LO
[i
]),
9741 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
9742 offsetof(CPUState
, active_tc
.ACX
[i
]),
9745 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
9746 offsetof(CPUState
, active_tc
.DSPControl
),
9748 bcond
= tcg_global_mem_new(TCG_AREG0
,
9749 offsetof(CPUState
, bcond
), "bcond");
9750 btarget
= tcg_global_mem_new(TCG_AREG0
,
9751 offsetof(CPUState
, btarget
), "btarget");
9752 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
9753 offsetof(CPUState
, hflags
), "hflags");
9755 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
9756 offsetof(CPUState
, active_fpu
.fcr0
),
9758 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
9759 offsetof(CPUState
, active_fpu
.fcr31
),
9762 /* register helpers */
9763 #define GEN_HELPER 2
9769 #include "translate_init.c"
9771 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
9774 const mips_def_t
*def
;
9776 def
= cpu_mips_find_by_name(cpu_model
);
9779 env
= qemu_mallocz(sizeof(CPUMIPSState
));
9780 env
->cpu_model
= def
;
9781 env
->cpu_model_str
= cpu_model
;
9784 #ifndef CONFIG_USER_ONLY
9791 qemu_init_vcpu(env
);
9795 void cpu_reset (CPUMIPSState
*env
)
9797 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
9798 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
9799 log_cpu_state(env
, 0);
9802 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
9805 /* Reset registers to their default values */
9806 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
9807 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
9808 #ifdef TARGET_WORDS_BIGENDIAN
9809 env
->CP0_Config0
|= (1 << CP0C0_BE
);
9811 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
9812 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
9813 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
9814 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
9815 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
9816 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
9817 << env
->cpu_model
->CP0_LLAddr_shift
;
9818 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
9819 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
9820 env
->CCRes
= env
->cpu_model
->CCRes
;
9821 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
9822 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
9823 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
9824 env
->current_tc
= 0;
9825 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
9826 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
9827 #if defined(TARGET_MIPS64)
9828 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
9829 env
->SEGMask
|= 3ULL << 62;
9832 env
->PABITS
= env
->cpu_model
->PABITS
;
9833 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
9834 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
9835 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
9836 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
9837 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
9838 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
9839 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
9840 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
9841 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
9842 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
9843 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
9844 env
->insn_flags
= env
->cpu_model
->insn_flags
;
9846 #if defined(CONFIG_USER_ONLY)
9847 env
->hflags
= MIPS_HFLAG_UM
;
9848 /* Enable access to the SYNCI_Step register. */
9849 env
->CP0_HWREna
|= (1 << 1);
9850 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
9851 env
->hflags
|= MIPS_HFLAG_FPU
;
9853 #ifdef TARGET_MIPS64
9854 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
9855 env
->hflags
|= MIPS_HFLAG_F64
;
9859 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
9860 /* If the exception was raised from a delay slot,
9861 come back to the jump. */
9862 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
9864 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
9866 env
->active_tc
.PC
= (int32_t)0xBFC00000;
9867 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
9868 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
9870 /* SMP not implemented */
9871 env
->CP0_EBase
= 0x80000000;
9872 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
9873 /* vectored interrupts not implemented, timer on int 7,
9874 no performance counters. */
9875 env
->CP0_IntCtl
= 0xe0000000;
9879 for (i
= 0; i
< 7; i
++) {
9880 env
->CP0_WatchLo
[i
] = 0;
9881 env
->CP0_WatchHi
[i
] = 0x80000000;
9883 env
->CP0_WatchLo
[7] = 0;
9884 env
->CP0_WatchHi
[7] = 0;
9886 /* Count register increments in debug mode, EJTAG version 1 */
9887 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
9888 env
->hflags
= MIPS_HFLAG_CP0
;
9890 #if defined(TARGET_MIPS64)
9891 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
9892 env
->hflags
|= MIPS_HFLAG_64
;
9895 env
->exception_index
= EXCP_NONE
;
9898 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
9899 unsigned long searched_pc
, int pc_pos
, void *puc
)
9901 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
9902 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
9903 env
->hflags
|= gen_opc_hflags
[pc_pos
];