]>
git.proxmox.com Git - qemu.git/blob - target-mips/translate.c
37515165bcda5641b1864647b52d576afb3a238d
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)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
32 #include "qemu-common.h"
38 //#define MIPS_DEBUG_DISAS
39 //#define MIPS_DEBUG_SIGN_EXTENSIONS
41 /* MIPS major opcodes */
42 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
45 /* indirect opcode tables */
46 OPC_SPECIAL
= (0x00 << 26),
47 OPC_REGIMM
= (0x01 << 26),
48 OPC_CP0
= (0x10 << 26),
49 OPC_CP1
= (0x11 << 26),
50 OPC_CP2
= (0x12 << 26),
51 OPC_CP3
= (0x13 << 26),
52 OPC_SPECIAL2
= (0x1C << 26),
53 OPC_SPECIAL3
= (0x1F << 26),
54 /* arithmetic with immediate */
55 OPC_ADDI
= (0x08 << 26),
56 OPC_ADDIU
= (0x09 << 26),
57 OPC_SLTI
= (0x0A << 26),
58 OPC_SLTIU
= (0x0B << 26),
59 /* logic with immediate */
60 OPC_ANDI
= (0x0C << 26),
61 OPC_ORI
= (0x0D << 26),
62 OPC_XORI
= (0x0E << 26),
63 OPC_LUI
= (0x0F << 26),
64 /* arithmetic with immediate */
65 OPC_DADDI
= (0x18 << 26),
66 OPC_DADDIU
= (0x19 << 26),
67 /* Jump and branches */
69 OPC_JAL
= (0x03 << 26),
70 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
71 OPC_BEQL
= (0x14 << 26),
72 OPC_BNE
= (0x05 << 26),
73 OPC_BNEL
= (0x15 << 26),
74 OPC_BLEZ
= (0x06 << 26),
75 OPC_BLEZL
= (0x16 << 26),
76 OPC_BGTZ
= (0x07 << 26),
77 OPC_BGTZL
= (0x17 << 26),
78 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
80 OPC_LDL
= (0x1A << 26),
81 OPC_LDR
= (0x1B << 26),
82 OPC_LB
= (0x20 << 26),
83 OPC_LH
= (0x21 << 26),
84 OPC_LWL
= (0x22 << 26),
85 OPC_LW
= (0x23 << 26),
86 OPC_LBU
= (0x24 << 26),
87 OPC_LHU
= (0x25 << 26),
88 OPC_LWR
= (0x26 << 26),
89 OPC_LWU
= (0x27 << 26),
90 OPC_SB
= (0x28 << 26),
91 OPC_SH
= (0x29 << 26),
92 OPC_SWL
= (0x2A << 26),
93 OPC_SW
= (0x2B << 26),
94 OPC_SDL
= (0x2C << 26),
95 OPC_SDR
= (0x2D << 26),
96 OPC_SWR
= (0x2E << 26),
97 OPC_LL
= (0x30 << 26),
98 OPC_LLD
= (0x34 << 26),
99 OPC_LD
= (0x37 << 26),
100 OPC_SC
= (0x38 << 26),
101 OPC_SCD
= (0x3C << 26),
102 OPC_SD
= (0x3F << 26),
103 /* Floating point load/store */
104 OPC_LWC1
= (0x31 << 26),
105 OPC_LWC2
= (0x32 << 26),
106 OPC_LDC1
= (0x35 << 26),
107 OPC_LDC2
= (0x36 << 26),
108 OPC_SWC1
= (0x39 << 26),
109 OPC_SWC2
= (0x3A << 26),
110 OPC_SDC1
= (0x3D << 26),
111 OPC_SDC2
= (0x3E << 26),
112 /* MDMX ASE specific */
113 OPC_MDMX
= (0x1E << 26),
114 /* Cache and prefetch */
115 OPC_CACHE
= (0x2F << 26),
116 OPC_PREF
= (0x33 << 26),
117 /* Reserved major opcode */
118 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
121 /* MIPS special opcodes */
122 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
126 OPC_SLL
= 0x00 | OPC_SPECIAL
,
127 /* NOP is SLL r0, r0, 0 */
128 /* SSNOP is SLL r0, r0, 1 */
129 /* EHB is SLL r0, r0, 3 */
130 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
131 OPC_ROTR
= OPC_SRL
| (1 << 21),
132 OPC_SRA
= 0x03 | OPC_SPECIAL
,
133 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
134 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
135 OPC_ROTRV
= OPC_SRLV
| (1 << 6),
136 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
137 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
138 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
139 OPC_DROTRV
= OPC_DSRLV
| (1 << 6),
140 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
141 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
142 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
143 OPC_DROTR
= OPC_DSRL
| (1 << 21),
144 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
145 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
146 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
147 OPC_DROTR32
= OPC_DSRL32
| (1 << 21),
148 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
149 /* Multiplication / division */
150 OPC_MULT
= 0x18 | OPC_SPECIAL
,
151 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
152 OPC_DIV
= 0x1A | OPC_SPECIAL
,
153 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
154 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
155 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
156 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
157 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
158 /* 2 registers arithmetic / logic */
159 OPC_ADD
= 0x20 | OPC_SPECIAL
,
160 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
161 OPC_SUB
= 0x22 | OPC_SPECIAL
,
162 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
163 OPC_AND
= 0x24 | OPC_SPECIAL
,
164 OPC_OR
= 0x25 | OPC_SPECIAL
,
165 OPC_XOR
= 0x26 | OPC_SPECIAL
,
166 OPC_NOR
= 0x27 | OPC_SPECIAL
,
167 OPC_SLT
= 0x2A | OPC_SPECIAL
,
168 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
169 OPC_DADD
= 0x2C | OPC_SPECIAL
,
170 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
171 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
172 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
174 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
175 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
177 OPC_TGE
= 0x30 | OPC_SPECIAL
,
178 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
179 OPC_TLT
= 0x32 | OPC_SPECIAL
,
180 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
181 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
182 OPC_TNE
= 0x36 | OPC_SPECIAL
,
183 /* HI / LO registers load & stores */
184 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
185 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
186 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
187 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
188 /* Conditional moves */
189 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
190 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
192 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
195 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* unofficial */
196 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
197 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
198 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* unofficial */
199 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
201 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
202 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
203 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
204 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
205 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
206 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
207 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
210 /* Multiplication variants of the vr54xx. */
211 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
214 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
215 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
216 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
217 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
218 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
219 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
220 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
221 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
222 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
223 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
224 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
225 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
226 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
227 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
230 /* REGIMM (rt field) opcodes */
231 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
234 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
235 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
236 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
237 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
238 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
239 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
240 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
241 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
242 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
243 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
244 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
245 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
246 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
247 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
248 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
251 /* Special2 opcodes */
252 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
255 /* Multiply & xxx operations */
256 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
257 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
258 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
259 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
260 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
262 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
263 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
264 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
265 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
267 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
270 /* Special3 opcodes */
271 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
274 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
275 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
276 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
277 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
278 OPC_INS
= 0x04 | OPC_SPECIAL3
,
279 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
280 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
281 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
282 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
283 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
284 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
285 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
286 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
290 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
293 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
294 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
295 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
299 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
302 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
303 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
306 /* Coprocessor 0 (rs field) */
307 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
310 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
311 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
312 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
313 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
314 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
315 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
316 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
317 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
318 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
319 OPC_C0
= (0x10 << 21) | OPC_CP0
,
320 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
321 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
325 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
328 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
329 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
330 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
331 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
332 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
333 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
336 /* Coprocessor 0 (with rs == C0) */
337 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
340 OPC_TLBR
= 0x01 | OPC_C0
,
341 OPC_TLBWI
= 0x02 | OPC_C0
,
342 OPC_TLBWR
= 0x06 | OPC_C0
,
343 OPC_TLBP
= 0x08 | OPC_C0
,
344 OPC_RFE
= 0x10 | OPC_C0
,
345 OPC_ERET
= 0x18 | OPC_C0
,
346 OPC_DERET
= 0x1F | OPC_C0
,
347 OPC_WAIT
= 0x20 | OPC_C0
,
350 /* Coprocessor 1 (rs field) */
351 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
354 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
355 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
356 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
357 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
358 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
359 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
360 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
361 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
362 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
363 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
364 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
365 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
366 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
367 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
368 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
369 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
370 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
371 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
374 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
375 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
378 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
379 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
380 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
381 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
385 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
386 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
390 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
391 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
394 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
397 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
398 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
399 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
400 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
401 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
402 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
403 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
404 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
405 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
408 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
411 OPC_LWXC1
= 0x00 | OPC_CP3
,
412 OPC_LDXC1
= 0x01 | OPC_CP3
,
413 OPC_LUXC1
= 0x05 | OPC_CP3
,
414 OPC_SWXC1
= 0x08 | OPC_CP3
,
415 OPC_SDXC1
= 0x09 | OPC_CP3
,
416 OPC_SUXC1
= 0x0D | OPC_CP3
,
417 OPC_PREFX
= 0x0F | OPC_CP3
,
418 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
419 OPC_MADD_S
= 0x20 | OPC_CP3
,
420 OPC_MADD_D
= 0x21 | OPC_CP3
,
421 OPC_MADD_PS
= 0x26 | OPC_CP3
,
422 OPC_MSUB_S
= 0x28 | OPC_CP3
,
423 OPC_MSUB_D
= 0x29 | OPC_CP3
,
424 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
425 OPC_NMADD_S
= 0x30 | OPC_CP3
,
426 OPC_NMADD_D
= 0x31 | OPC_CP3
,
427 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
428 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
429 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
430 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
433 /* global register indices */
434 static TCGv_ptr cpu_env
;
435 static TCGv cpu_gpr
[32], cpu_PC
;
436 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
437 static TCGv cpu_dspctrl
, btarget
, bcond
;
438 static TCGv_i32 hflags
;
439 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
441 #include "gen-icount.h"
443 #define gen_helper_0i(name, arg) do { \
444 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
445 gen_helper_##name(helper_tmp); \
446 tcg_temp_free_i32(helper_tmp); \
449 #define gen_helper_1i(name, arg1, arg2) do { \
450 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
451 gen_helper_##name(arg1, helper_tmp); \
452 tcg_temp_free_i32(helper_tmp); \
455 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
456 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
457 gen_helper_##name(arg1, arg2, helper_tmp); \
458 tcg_temp_free_i32(helper_tmp); \
461 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
462 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
463 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
464 tcg_temp_free_i32(helper_tmp); \
467 typedef struct DisasContext
{
468 struct TranslationBlock
*tb
;
469 target_ulong pc
, saved_pc
;
471 int singlestep_enabled
;
472 /* Routine used to access memory */
474 uint32_t hflags
, saved_hflags
;
476 target_ulong btarget
;
480 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
481 * exception condition */
482 BS_STOP
= 1, /* We want to stop translation for any reason */
483 BS_BRANCH
= 2, /* We reached a branch condition */
484 BS_EXCP
= 3, /* We reached an exception condition */
487 static const char *regnames
[] =
488 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
489 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
490 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
491 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
493 static const char *regnames_HI
[] =
494 { "HI0", "HI1", "HI2", "HI3", };
496 static const char *regnames_LO
[] =
497 { "LO0", "LO1", "LO2", "LO3", };
499 static const char *regnames_ACX
[] =
500 { "ACX0", "ACX1", "ACX2", "ACX3", };
502 static const char *fregnames
[] =
503 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
504 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
505 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
506 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
508 #ifdef MIPS_DEBUG_DISAS
509 #define MIPS_DEBUG(fmt, ...) \
510 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
511 TARGET_FMT_lx ": %08x " fmt "\n", \
512 ctx->pc, ctx->opcode , ## __VA_ARGS__)
513 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
515 #define MIPS_DEBUG(fmt, ...) do { } while(0)
516 #define LOG_DISAS(...) do { } while (0)
519 #define MIPS_INVAL(op) \
521 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
522 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
525 /* General purpose registers moves. */
526 static inline void gen_load_gpr (TCGv t
, int reg
)
529 tcg_gen_movi_tl(t
, 0);
531 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
534 static inline void gen_store_gpr (TCGv t
, int reg
)
537 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
540 /* Moves to/from ACX register. */
541 static inline void gen_load_ACX (TCGv t
, int reg
)
543 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
546 static inline void gen_store_ACX (TCGv t
, int reg
)
548 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
551 /* Moves to/from shadow registers. */
552 static inline void gen_load_srsgpr (int from
, int to
)
554 TCGv t0
= tcg_temp_new();
557 tcg_gen_movi_tl(t0
, 0);
559 TCGv_i32 t2
= tcg_temp_new_i32();
560 TCGv_ptr addr
= tcg_temp_new_ptr();
562 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
563 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
564 tcg_gen_andi_i32(t2
, t2
, 0xf);
565 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
566 tcg_gen_ext_i32_ptr(addr
, t2
);
567 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
569 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
570 tcg_temp_free_ptr(addr
);
571 tcg_temp_free_i32(t2
);
573 gen_store_gpr(t0
, to
);
577 static inline void gen_store_srsgpr (int from
, int to
)
580 TCGv t0
= tcg_temp_new();
581 TCGv_i32 t2
= tcg_temp_new_i32();
582 TCGv_ptr addr
= tcg_temp_new_ptr();
584 gen_load_gpr(t0
, from
);
585 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
586 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
587 tcg_gen_andi_i32(t2
, t2
, 0xf);
588 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
589 tcg_gen_ext_i32_ptr(addr
, t2
);
590 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
592 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
593 tcg_temp_free_ptr(addr
);
594 tcg_temp_free_i32(t2
);
599 /* Floating point register moves. */
600 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
602 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
605 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
607 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
610 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
612 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
615 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
617 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
620 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
622 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
623 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
625 TCGv_i32 t0
= tcg_temp_new_i32();
626 TCGv_i32 t1
= tcg_temp_new_i32();
627 gen_load_fpr32(t0
, reg
& ~1);
628 gen_load_fpr32(t1
, reg
| 1);
629 tcg_gen_concat_i32_i64(t
, t0
, t1
);
630 tcg_temp_free_i32(t0
);
631 tcg_temp_free_i32(t1
);
635 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
637 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
638 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
640 TCGv_i64 t0
= tcg_temp_new_i64();
641 TCGv_i32 t1
= tcg_temp_new_i32();
642 tcg_gen_trunc_i64_i32(t1
, t
);
643 gen_store_fpr32(t1
, reg
& ~1);
644 tcg_gen_shri_i64(t0
, t
, 32);
645 tcg_gen_trunc_i64_i32(t1
, t0
);
646 gen_store_fpr32(t1
, reg
| 1);
647 tcg_temp_free_i32(t1
);
648 tcg_temp_free_i64(t0
);
652 static inline int get_fp_bit (int cc
)
660 #define FOP_CONDS(type, fmt, bits) \
661 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
662 TCGv_i##bits b, int cc) \
665 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
666 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
667 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
668 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
669 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
670 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
671 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
672 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
673 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
674 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
675 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
676 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
677 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
678 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
679 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
680 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
686 FOP_CONDS(abs
, d
, 64)
688 FOP_CONDS(abs
, s
, 32)
690 FOP_CONDS(abs
, ps
, 64)
694 #define OP_COND(name, cond) \
695 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, TCGv t1) \
697 int l1 = gen_new_label(); \
698 int l2 = gen_new_label(); \
700 tcg_gen_brcond_tl(cond, t0, t1, l1); \
701 tcg_gen_movi_tl(ret, 0); \
704 tcg_gen_movi_tl(ret, 1); \
707 OP_COND(eq
, TCG_COND_EQ
);
708 OP_COND(ne
, TCG_COND_NE
);
709 OP_COND(ge
, TCG_COND_GE
);
710 OP_COND(geu
, TCG_COND_GEU
);
711 OP_COND(lt
, TCG_COND_LT
);
712 OP_COND(ltu
, TCG_COND_LTU
);
715 #define OP_CONDI(name, cond) \
716 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, target_ulong val) \
718 int l1 = gen_new_label(); \
719 int l2 = gen_new_label(); \
721 tcg_gen_brcondi_tl(cond, t0, val, l1); \
722 tcg_gen_movi_tl(ret, 0); \
725 tcg_gen_movi_tl(ret, 1); \
728 OP_CONDI(lti
, TCG_COND_LT
);
729 OP_CONDI(ltiu
, TCG_COND_LTU
);
732 #define OP_CONDZ(name, cond) \
733 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0) \
735 int l1 = gen_new_label(); \
736 int l2 = gen_new_label(); \
738 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
739 tcg_gen_movi_tl(ret, 0); \
742 tcg_gen_movi_tl(ret, 1); \
745 OP_CONDZ(gez
, TCG_COND_GE
);
746 OP_CONDZ(gtz
, TCG_COND_GT
);
747 OP_CONDZ(lez
, TCG_COND_LE
);
748 OP_CONDZ(ltz
, TCG_COND_LT
);
751 static inline void gen_save_pc(target_ulong pc
)
753 tcg_gen_movi_tl(cpu_PC
, pc
);
756 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
758 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
759 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
760 gen_save_pc(ctx
->pc
);
761 ctx
->saved_pc
= ctx
->pc
;
763 if (ctx
->hflags
!= ctx
->saved_hflags
) {
764 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
765 ctx
->saved_hflags
= ctx
->hflags
;
766 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
772 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
778 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
780 ctx
->saved_hflags
= ctx
->hflags
;
781 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
787 ctx
->btarget
= env
->btarget
;
793 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
795 TCGv_i32 texcp
= tcg_const_i32(excp
);
796 TCGv_i32 terr
= tcg_const_i32(err
);
797 save_cpu_state(ctx
, 1);
798 gen_helper_raise_exception_err(texcp
, terr
);
799 tcg_temp_free_i32(terr
);
800 tcg_temp_free_i32(texcp
);
804 generate_exception (DisasContext
*ctx
, int excp
)
806 save_cpu_state(ctx
, 1);
807 gen_helper_0i(raise_exception
, excp
);
810 /* Addresses computation */
811 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg0
, TCGv arg1
)
813 tcg_gen_add_tl(ret
, arg0
, arg1
);
815 #if defined(TARGET_MIPS64)
816 /* For compatibility with 32-bit code, data reference in user mode
817 with Status_UX = 0 should be casted to 32-bit and sign extended.
818 See the MIPS64 PRA manual, section 4.10. */
819 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
820 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
821 tcg_gen_ext32s_i64(ret
, ret
);
826 static inline void check_cp0_enabled(DisasContext
*ctx
)
828 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
829 generate_exception_err(ctx
, EXCP_CpU
, 1);
832 static inline void check_cp1_enabled(DisasContext
*ctx
)
834 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
835 generate_exception_err(ctx
, EXCP_CpU
, 1);
838 /* Verify that the processor is running with COP1X instructions enabled.
839 This is associated with the nabla symbol in the MIPS32 and MIPS64
842 static inline void check_cop1x(DisasContext
*ctx
)
844 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
845 generate_exception(ctx
, EXCP_RI
);
848 /* Verify that the processor is running with 64-bit floating-point
849 operations enabled. */
851 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
853 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
854 generate_exception(ctx
, EXCP_RI
);
858 * Verify if floating point register is valid; an operation is not defined
859 * if bit 0 of any register specification is set and the FR bit in the
860 * Status register equals zero, since the register numbers specify an
861 * even-odd pair of adjacent coprocessor general registers. When the FR bit
862 * in the Status register equals one, both even and odd register numbers
863 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
865 * Multiple 64 bit wide registers can be checked by calling
866 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
868 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
870 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
871 generate_exception(ctx
, EXCP_RI
);
874 /* This code generates a "reserved instruction" exception if the
875 CPU does not support the instruction set corresponding to flags. */
876 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
878 if (unlikely(!(env
->insn_flags
& flags
)))
879 generate_exception(ctx
, EXCP_RI
);
882 /* This code generates a "reserved instruction" exception if 64-bit
883 instructions are not enabled. */
884 static inline void check_mips_64(DisasContext
*ctx
)
886 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
887 generate_exception(ctx
, EXCP_RI
);
890 /* load/store instructions. */
891 #define OP_LD(insn,fname) \
892 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
894 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
901 #if defined(TARGET_MIPS64)
907 #define OP_ST(insn,fname) \
908 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
910 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
915 #if defined(TARGET_MIPS64)
920 #ifdef CONFIG_USER_ONLY
921 #define OP_LD_ATOMIC(insn,fname) \
922 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
924 TCGv t0 = tcg_temp_new(); \
925 tcg_gen_mov_tl(t0, arg1); \
926 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
927 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
928 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
932 #define OP_LD_ATOMIC(insn,fname) \
933 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
935 gen_helper_2i(insn, ret, arg1, ctx->mem_idx); \
938 OP_LD_ATOMIC(ll
,ld32s
);
939 #if defined(TARGET_MIPS64)
940 OP_LD_ATOMIC(lld
,ld64
);
944 #ifdef CONFIG_USER_ONLY
945 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
946 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
948 TCGv t0 = tcg_temp_new(); \
949 int l1 = gen_new_label(); \
950 int l2 = gen_new_label(); \
952 tcg_gen_andi_tl(t0, arg2, almask); \
953 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
954 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
955 generate_exception(ctx, EXCP_AdES); \
957 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, lladdr)); \
958 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
959 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
960 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
961 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
962 gen_helper_0i(raise_exception, EXCP_SC); \
964 tcg_gen_movi_tl(t0, 0); \
965 gen_store_gpr(t0, rt); \
969 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
970 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
972 TCGv t0 = tcg_temp_new(); \
973 gen_helper_3i(insn, t0, arg1, arg2, ctx->mem_idx); \
974 gen_store_gpr(t0, rt); \
978 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
979 #if defined(TARGET_MIPS64)
980 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
985 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
986 int base
, int16_t offset
)
988 const char *opn
= "ldst";
989 TCGv t0
= tcg_temp_new();
990 TCGv t1
= tcg_temp_new();
993 tcg_gen_movi_tl(t0
, offset
);
994 } else if (offset
== 0) {
995 gen_load_gpr(t0
, base
);
997 tcg_gen_movi_tl(t0
, offset
);
998 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
1000 /* Don't do NOP if destination is zero: we must perform the actual
1003 #if defined(TARGET_MIPS64)
1005 save_cpu_state(ctx
, 0);
1006 op_ldst_lwu(t0
, t0
, ctx
);
1007 gen_store_gpr(t0
, rt
);
1011 save_cpu_state(ctx
, 0);
1012 op_ldst_ld(t0
, t0
, ctx
);
1013 gen_store_gpr(t0
, rt
);
1017 save_cpu_state(ctx
, 0);
1018 op_ldst_lld(t0
, t0
, ctx
);
1019 gen_store_gpr(t0
, rt
);
1023 save_cpu_state(ctx
, 0);
1024 gen_load_gpr(t1
, rt
);
1025 op_ldst_sd(t1
, t0
, ctx
);
1029 save_cpu_state(ctx
, 1);
1030 gen_load_gpr(t1
, rt
);
1031 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1032 gen_store_gpr(t1
, rt
);
1036 save_cpu_state(ctx
, 1);
1037 gen_load_gpr(t1
, rt
);
1038 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1042 save_cpu_state(ctx
, 1);
1043 gen_load_gpr(t1
, rt
);
1044 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1045 gen_store_gpr(t1
, rt
);
1049 save_cpu_state(ctx
, 1);
1050 gen_load_gpr(t1
, rt
);
1051 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1056 save_cpu_state(ctx
, 0);
1057 op_ldst_lw(t0
, t0
, ctx
);
1058 gen_store_gpr(t0
, rt
);
1062 save_cpu_state(ctx
, 0);
1063 gen_load_gpr(t1
, rt
);
1064 op_ldst_sw(t1
, t0
, ctx
);
1068 save_cpu_state(ctx
, 0);
1069 op_ldst_lh(t0
, t0
, ctx
);
1070 gen_store_gpr(t0
, rt
);
1074 save_cpu_state(ctx
, 0);
1075 gen_load_gpr(t1
, rt
);
1076 op_ldst_sh(t1
, t0
, ctx
);
1080 save_cpu_state(ctx
, 0);
1081 op_ldst_lhu(t0
, t0
, ctx
);
1082 gen_store_gpr(t0
, rt
);
1086 save_cpu_state(ctx
, 0);
1087 op_ldst_lb(t0
, t0
, ctx
);
1088 gen_store_gpr(t0
, rt
);
1092 save_cpu_state(ctx
, 0);
1093 gen_load_gpr(t1
, rt
);
1094 op_ldst_sb(t1
, t0
, ctx
);
1098 save_cpu_state(ctx
, 0);
1099 op_ldst_lbu(t0
, t0
, ctx
);
1100 gen_store_gpr(t0
, rt
);
1104 save_cpu_state(ctx
, 1);
1105 gen_load_gpr(t1
, rt
);
1106 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1107 gen_store_gpr(t1
, rt
);
1111 save_cpu_state(ctx
, 1);
1112 gen_load_gpr(t1
, rt
);
1113 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1117 save_cpu_state(ctx
, 1);
1118 gen_load_gpr(t1
, rt
);
1119 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1120 gen_store_gpr(t1
, rt
);
1124 save_cpu_state(ctx
, 1);
1125 gen_load_gpr(t1
, rt
);
1126 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1130 save_cpu_state(ctx
, 1);
1131 op_ldst_ll(t0
, t0
, ctx
);
1132 gen_store_gpr(t0
, rt
);
1136 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1141 /* Store conditional */
1142 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1143 int base
, int16_t offset
)
1145 const char *opn
= "st_cond";
1148 t0
= tcg_temp_local_new();
1151 tcg_gen_movi_tl(t0
, offset
);
1152 } else if (offset
== 0) {
1153 gen_load_gpr(t0
, base
);
1155 tcg_gen_movi_tl(t0
, offset
);
1156 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
1158 /* Don't do NOP if destination is zero: we must perform the actual
1161 t1
= tcg_temp_local_new();
1162 gen_load_gpr(t1
, rt
);
1164 #if defined(TARGET_MIPS64)
1166 save_cpu_state(ctx
, 0);
1167 op_ldst_scd(t1
, t0
, rt
, ctx
);
1172 save_cpu_state(ctx
, 1);
1173 op_ldst_sc(t1
, t0
, rt
, ctx
);
1177 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1182 /* Load and store */
1183 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1184 int base
, int16_t offset
)
1186 const char *opn
= "flt_ldst";
1187 TCGv t0
= tcg_temp_new();
1190 tcg_gen_movi_tl(t0
, offset
);
1191 } else if (offset
== 0) {
1192 gen_load_gpr(t0
, base
);
1194 tcg_gen_movi_tl(t0
, offset
);
1195 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
1197 /* Don't do NOP if destination is zero: we must perform the actual
1202 TCGv_i32 fp0
= tcg_temp_new_i32();
1204 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1205 tcg_gen_trunc_tl_i32(fp0
, t0
);
1206 gen_store_fpr32(fp0
, ft
);
1207 tcg_temp_free_i32(fp0
);
1213 TCGv_i32 fp0
= tcg_temp_new_i32();
1214 TCGv t1
= tcg_temp_new();
1216 gen_load_fpr32(fp0
, ft
);
1217 tcg_gen_extu_i32_tl(t1
, fp0
);
1218 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1220 tcg_temp_free_i32(fp0
);
1226 TCGv_i64 fp0
= tcg_temp_new_i64();
1228 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1229 gen_store_fpr64(ctx
, fp0
, ft
);
1230 tcg_temp_free_i64(fp0
);
1236 TCGv_i64 fp0
= tcg_temp_new_i64();
1238 gen_load_fpr64(ctx
, fp0
, ft
);
1239 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1240 tcg_temp_free_i64(fp0
);
1246 generate_exception(ctx
, EXCP_RI
);
1249 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1254 /* Arithmetic with immediate operand */
1255 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1256 int rt
, int rs
, int16_t imm
)
1258 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1259 const char *opn
= "imm arith";
1261 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1262 /* If no destination, treat it as a NOP.
1263 For addi, we must generate the overflow exception when needed. */
1270 TCGv t0
= tcg_temp_local_new();
1271 TCGv t1
= tcg_temp_new();
1272 TCGv t2
= tcg_temp_new();
1273 int l1
= gen_new_label();
1275 gen_load_gpr(t1
, rs
);
1276 tcg_gen_addi_tl(t0
, t1
, uimm
);
1277 tcg_gen_ext32s_tl(t0
, t0
);
1279 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1280 tcg_gen_xori_tl(t2
, t0
, uimm
);
1281 tcg_gen_and_tl(t1
, t1
, t2
);
1283 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1285 /* operands of same sign, result different sign */
1286 generate_exception(ctx
, EXCP_OVERFLOW
);
1288 tcg_gen_ext32s_tl(t0
, t0
);
1289 gen_store_gpr(t0
, rt
);
1296 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1297 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1299 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1303 #if defined(TARGET_MIPS64)
1306 TCGv t0
= tcg_temp_local_new();
1307 TCGv t1
= tcg_temp_new();
1308 TCGv t2
= tcg_temp_new();
1309 int l1
= gen_new_label();
1311 gen_load_gpr(t1
, rs
);
1312 tcg_gen_addi_tl(t0
, t1
, uimm
);
1314 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1315 tcg_gen_xori_tl(t2
, t0
, uimm
);
1316 tcg_gen_and_tl(t1
, t1
, t2
);
1318 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1320 /* operands of same sign, result different sign */
1321 generate_exception(ctx
, EXCP_OVERFLOW
);
1323 gen_store_gpr(t0
, rt
);
1330 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1332 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1338 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1341 /* Logic with immediate operand */
1342 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1345 const char *opn
= "imm logic";
1348 /* If no destination, treat it as a NOP. */
1352 uimm
= (uint16_t)imm
;
1355 if (likely(rs
!= 0))
1356 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1358 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1363 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1365 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1369 if (likely(rs
!= 0))
1370 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1372 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1376 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1380 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1383 /* Set on less than with immediate operand */
1384 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1386 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1387 const char *opn
= "imm arith";
1391 /* If no destination, treat it as a NOP. */
1395 t0
= tcg_temp_new();
1396 gen_load_gpr(t0
, rs
);
1399 gen_op_lti(cpu_gpr
[rt
], t0
, uimm
);
1403 gen_op_ltiu(cpu_gpr
[rt
], t0
, uimm
);
1407 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1411 /* Shifts with immediate operand */
1412 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1413 int rt
, int rs
, int16_t imm
)
1415 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1416 const char *opn
= "imm shift";
1420 /* If no destination, treat it as a NOP. */
1425 t0
= tcg_temp_new();
1426 gen_load_gpr(t0
, rs
);
1429 tcg_gen_shli_tl(t0
, t0
, uimm
);
1430 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1434 tcg_gen_ext32s_tl(t0
, t0
);
1435 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1440 tcg_gen_ext32u_tl(t0
, t0
);
1441 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1443 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1449 TCGv_i32 t1
= tcg_temp_new_i32();
1451 tcg_gen_trunc_tl_i32(t1
, t0
);
1452 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1453 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1454 tcg_temp_free_i32(t1
);
1458 #if defined(TARGET_MIPS64)
1460 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1464 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1468 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1473 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1478 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1482 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1486 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1490 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1495 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1500 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1501 int rd
, int rs
, int rt
)
1503 const char *opn
= "arith";
1505 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1506 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1507 /* If no destination, treat it as a NOP.
1508 For add & sub, we must generate the overflow exception when needed. */
1516 TCGv t0
= tcg_temp_local_new();
1517 TCGv t1
= tcg_temp_new();
1518 TCGv t2
= tcg_temp_new();
1519 int l1
= gen_new_label();
1521 gen_load_gpr(t1
, rs
);
1522 gen_load_gpr(t2
, rt
);
1523 tcg_gen_add_tl(t0
, t1
, t2
);
1524 tcg_gen_ext32s_tl(t0
, t0
);
1525 tcg_gen_xor_tl(t1
, t1
, t2
);
1526 tcg_gen_not_tl(t1
, t1
);
1527 tcg_gen_xor_tl(t2
, t0
, t2
);
1528 tcg_gen_and_tl(t1
, t1
, t2
);
1530 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1532 /* operands of same sign, result different sign */
1533 generate_exception(ctx
, EXCP_OVERFLOW
);
1535 gen_store_gpr(t0
, rd
);
1541 if (rs
!= 0 && rt
!= 0) {
1542 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1543 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1544 } else if (rs
== 0 && rt
!= 0) {
1545 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1546 } else if (rs
!= 0 && rt
== 0) {
1547 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1549 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1555 TCGv t0
= tcg_temp_local_new();
1556 TCGv t1
= tcg_temp_new();
1557 TCGv t2
= tcg_temp_new();
1558 int l1
= gen_new_label();
1560 gen_load_gpr(t1
, rs
);
1561 gen_load_gpr(t2
, rt
);
1562 tcg_gen_sub_tl(t0
, t1
, t2
);
1563 tcg_gen_ext32s_tl(t0
, t0
);
1564 tcg_gen_xor_tl(t2
, t1
, t2
);
1565 tcg_gen_xor_tl(t1
, t0
, t1
);
1566 tcg_gen_and_tl(t1
, t1
, t2
);
1568 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1570 /* operands of different sign, first operand and result different sign */
1571 generate_exception(ctx
, EXCP_OVERFLOW
);
1573 gen_store_gpr(t0
, rd
);
1579 if (rs
!= 0 && rt
!= 0) {
1580 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1581 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1582 } else if (rs
== 0 && rt
!= 0) {
1583 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1584 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1585 } else if (rs
!= 0 && rt
== 0) {
1586 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1588 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1592 #if defined(TARGET_MIPS64)
1595 TCGv t0
= tcg_temp_local_new();
1596 TCGv t1
= tcg_temp_new();
1597 TCGv t2
= tcg_temp_new();
1598 int l1
= gen_new_label();
1600 gen_load_gpr(t1
, rs
);
1601 gen_load_gpr(t2
, rt
);
1602 tcg_gen_add_tl(t0
, t1
, t2
);
1603 tcg_gen_xor_tl(t1
, t1
, t2
);
1604 tcg_gen_not_tl(t1
, t1
);
1605 tcg_gen_xor_tl(t2
, t0
, t2
);
1606 tcg_gen_and_tl(t1
, t1
, t2
);
1608 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1610 /* operands of same sign, result different sign */
1611 generate_exception(ctx
, EXCP_OVERFLOW
);
1613 gen_store_gpr(t0
, rd
);
1619 if (rs
!= 0 && rt
!= 0) {
1620 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1621 } else if (rs
== 0 && rt
!= 0) {
1622 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1623 } else if (rs
!= 0 && rt
== 0) {
1624 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1626 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1632 TCGv t0
= tcg_temp_local_new();
1633 TCGv t1
= tcg_temp_new();
1634 TCGv t2
= tcg_temp_new();
1635 int l1
= gen_new_label();
1637 gen_load_gpr(t1
, rs
);
1638 gen_load_gpr(t2
, rt
);
1639 tcg_gen_sub_tl(t0
, t1
, t2
);
1640 tcg_gen_xor_tl(t2
, t1
, t2
);
1641 tcg_gen_xor_tl(t1
, t0
, t1
);
1642 tcg_gen_and_tl(t1
, t1
, t2
);
1644 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1646 /* operands of different sign, first operand and result different sign */
1647 generate_exception(ctx
, EXCP_OVERFLOW
);
1649 gen_store_gpr(t0
, rd
);
1655 if (rs
!= 0 && rt
!= 0) {
1656 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1657 } else if (rs
== 0 && rt
!= 0) {
1658 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1659 } else if (rs
!= 0 && rt
== 0) {
1660 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1662 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1668 if (likely(rs
!= 0 && rt
!= 0)) {
1669 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1670 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1672 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1677 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1680 /* Conditional move */
1681 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1683 const char *opn
= "cond move";
1687 /* If no destination, treat it as a NOP.
1688 For add & sub, we must generate the overflow exception when needed. */
1693 l1
= gen_new_label();
1696 if (likely(rt
!= 0))
1697 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1703 if (likely(rt
!= 0))
1704 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1709 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1711 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1714 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1718 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1720 const char *opn
= "logic";
1723 /* If no destination, treat it as a NOP. */
1730 if (likely(rs
!= 0 && rt
!= 0)) {
1731 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1733 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1738 if (rs
!= 0 && rt
!= 0) {
1739 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1740 } else if (rs
== 0 && rt
!= 0) {
1741 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1742 } else if (rs
!= 0 && rt
== 0) {
1743 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1745 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1750 if (likely(rs
!= 0 && rt
!= 0)) {
1751 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1752 } else if (rs
== 0 && rt
!= 0) {
1753 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1754 } else if (rs
!= 0 && rt
== 0) {
1755 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1757 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1762 if (likely(rs
!= 0 && rt
!= 0)) {
1763 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1764 } else if (rs
== 0 && rt
!= 0) {
1765 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1766 } else if (rs
!= 0 && rt
== 0) {
1767 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1769 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1774 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1777 /* Set on lower than */
1778 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1780 const char *opn
= "slt";
1784 /* If no destination, treat it as a NOP. */
1789 t0
= tcg_temp_new();
1790 t1
= tcg_temp_new();
1791 gen_load_gpr(t0
, rs
);
1792 gen_load_gpr(t1
, rt
);
1795 gen_op_lt(cpu_gpr
[rd
], t0
, t1
);
1799 gen_op_ltu(cpu_gpr
[rd
], t0
, t1
);
1803 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1809 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1810 int rd
, int rs
, int rt
)
1812 const char *opn
= "shifts";
1816 /* If no destination, treat it as a NOP.
1817 For add & sub, we must generate the overflow exception when needed. */
1822 t0
= tcg_temp_new();
1823 t1
= tcg_temp_new();
1824 gen_load_gpr(t0
, rs
);
1825 gen_load_gpr(t1
, rt
);
1828 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1829 tcg_gen_shl_tl(t0
, t1
, t0
);
1830 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1834 tcg_gen_ext32s_tl(t1
, t1
);
1835 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1836 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1840 tcg_gen_ext32u_tl(t1
, t1
);
1841 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1842 tcg_gen_shr_tl(t0
, t1
, t0
);
1843 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1848 TCGv_i32 t2
= tcg_temp_new_i32();
1849 TCGv_i32 t3
= tcg_temp_new_i32();
1851 tcg_gen_trunc_tl_i32(t2
, t0
);
1852 tcg_gen_trunc_tl_i32(t3
, t1
);
1853 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1854 tcg_gen_rotr_i32(t2
, t3
, t2
);
1855 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1856 tcg_temp_free_i32(t2
);
1857 tcg_temp_free_i32(t3
);
1861 #if defined(TARGET_MIPS64)
1863 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1864 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1868 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1869 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1873 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1874 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1878 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1879 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1884 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1889 /* Arithmetic on HI/LO registers */
1890 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1892 const char *opn
= "hilo";
1894 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1901 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1905 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1910 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1912 tcg_gen_movi_tl(cpu_HI
[0], 0);
1917 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
1919 tcg_gen_movi_tl(cpu_LO
[0], 0);
1923 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1926 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1929 const char *opn
= "mul/div";
1935 #if defined(TARGET_MIPS64)
1939 t0
= tcg_temp_local_new();
1940 t1
= tcg_temp_local_new();
1943 t0
= tcg_temp_new();
1944 t1
= tcg_temp_new();
1948 gen_load_gpr(t0
, rs
);
1949 gen_load_gpr(t1
, rt
);
1953 int l1
= gen_new_label();
1954 int l2
= gen_new_label();
1956 tcg_gen_ext32s_tl(t0
, t0
);
1957 tcg_gen_ext32s_tl(t1
, t1
);
1958 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1959 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
1960 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
1962 tcg_gen_mov_tl(cpu_LO
[0], t0
);
1963 tcg_gen_movi_tl(cpu_HI
[0], 0);
1966 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
1967 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
1968 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
1969 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
1976 int l1
= gen_new_label();
1978 tcg_gen_ext32u_tl(t0
, t0
);
1979 tcg_gen_ext32u_tl(t1
, t1
);
1980 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1981 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
1982 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
1983 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
1984 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
1991 TCGv_i64 t2
= tcg_temp_new_i64();
1992 TCGv_i64 t3
= tcg_temp_new_i64();
1994 tcg_gen_ext_tl_i64(t2
, t0
);
1995 tcg_gen_ext_tl_i64(t3
, t1
);
1996 tcg_gen_mul_i64(t2
, t2
, t3
);
1997 tcg_temp_free_i64(t3
);
1998 tcg_gen_trunc_i64_tl(t0
, t2
);
1999 tcg_gen_shri_i64(t2
, t2
, 32);
2000 tcg_gen_trunc_i64_tl(t1
, t2
);
2001 tcg_temp_free_i64(t2
);
2002 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2003 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2009 TCGv_i64 t2
= tcg_temp_new_i64();
2010 TCGv_i64 t3
= tcg_temp_new_i64();
2012 tcg_gen_ext32u_tl(t0
, t0
);
2013 tcg_gen_ext32u_tl(t1
, t1
);
2014 tcg_gen_extu_tl_i64(t2
, t0
);
2015 tcg_gen_extu_tl_i64(t3
, t1
);
2016 tcg_gen_mul_i64(t2
, t2
, t3
);
2017 tcg_temp_free_i64(t3
);
2018 tcg_gen_trunc_i64_tl(t0
, t2
);
2019 tcg_gen_shri_i64(t2
, t2
, 32);
2020 tcg_gen_trunc_i64_tl(t1
, t2
);
2021 tcg_temp_free_i64(t2
);
2022 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2023 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2027 #if defined(TARGET_MIPS64)
2030 int l1
= gen_new_label();
2031 int l2
= gen_new_label();
2033 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2034 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2035 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2036 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2037 tcg_gen_movi_tl(cpu_HI
[0], 0);
2040 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2041 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2048 int l1
= gen_new_label();
2050 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2051 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2052 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2058 gen_helper_dmult(t0
, t1
);
2062 gen_helper_dmultu(t0
, t1
);
2068 TCGv_i64 t2
= tcg_temp_new_i64();
2069 TCGv_i64 t3
= tcg_temp_new_i64();
2071 tcg_gen_ext_tl_i64(t2
, t0
);
2072 tcg_gen_ext_tl_i64(t3
, t1
);
2073 tcg_gen_mul_i64(t2
, t2
, t3
);
2074 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2075 tcg_gen_add_i64(t2
, t2
, t3
);
2076 tcg_temp_free_i64(t3
);
2077 tcg_gen_trunc_i64_tl(t0
, t2
);
2078 tcg_gen_shri_i64(t2
, t2
, 32);
2079 tcg_gen_trunc_i64_tl(t1
, t2
);
2080 tcg_temp_free_i64(t2
);
2081 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2082 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2088 TCGv_i64 t2
= tcg_temp_new_i64();
2089 TCGv_i64 t3
= tcg_temp_new_i64();
2091 tcg_gen_ext32u_tl(t0
, t0
);
2092 tcg_gen_ext32u_tl(t1
, t1
);
2093 tcg_gen_extu_tl_i64(t2
, t0
);
2094 tcg_gen_extu_tl_i64(t3
, t1
);
2095 tcg_gen_mul_i64(t2
, t2
, t3
);
2096 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2097 tcg_gen_add_i64(t2
, t2
, t3
);
2098 tcg_temp_free_i64(t3
);
2099 tcg_gen_trunc_i64_tl(t0
, t2
);
2100 tcg_gen_shri_i64(t2
, t2
, 32);
2101 tcg_gen_trunc_i64_tl(t1
, t2
);
2102 tcg_temp_free_i64(t2
);
2103 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2104 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2110 TCGv_i64 t2
= tcg_temp_new_i64();
2111 TCGv_i64 t3
= tcg_temp_new_i64();
2113 tcg_gen_ext_tl_i64(t2
, t0
);
2114 tcg_gen_ext_tl_i64(t3
, t1
);
2115 tcg_gen_mul_i64(t2
, t2
, t3
);
2116 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2117 tcg_gen_sub_i64(t2
, t3
, t2
);
2118 tcg_temp_free_i64(t3
);
2119 tcg_gen_trunc_i64_tl(t0
, t2
);
2120 tcg_gen_shri_i64(t2
, t2
, 32);
2121 tcg_gen_trunc_i64_tl(t1
, t2
);
2122 tcg_temp_free_i64(t2
);
2123 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2124 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2130 TCGv_i64 t2
= tcg_temp_new_i64();
2131 TCGv_i64 t3
= tcg_temp_new_i64();
2133 tcg_gen_ext32u_tl(t0
, t0
);
2134 tcg_gen_ext32u_tl(t1
, t1
);
2135 tcg_gen_extu_tl_i64(t2
, t0
);
2136 tcg_gen_extu_tl_i64(t3
, t1
);
2137 tcg_gen_mul_i64(t2
, t2
, t3
);
2138 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2139 tcg_gen_sub_i64(t2
, t3
, t2
);
2140 tcg_temp_free_i64(t3
);
2141 tcg_gen_trunc_i64_tl(t0
, t2
);
2142 tcg_gen_shri_i64(t2
, t2
, 32);
2143 tcg_gen_trunc_i64_tl(t1
, t2
);
2144 tcg_temp_free_i64(t2
);
2145 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2146 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2152 generate_exception(ctx
, EXCP_RI
);
2155 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2161 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2162 int rd
, int rs
, int rt
)
2164 const char *opn
= "mul vr54xx";
2165 TCGv t0
= tcg_temp_new();
2166 TCGv t1
= tcg_temp_new();
2168 gen_load_gpr(t0
, rs
);
2169 gen_load_gpr(t1
, rt
);
2172 case OPC_VR54XX_MULS
:
2173 gen_helper_muls(t0
, t0
, t1
);
2176 case OPC_VR54XX_MULSU
:
2177 gen_helper_mulsu(t0
, t0
, t1
);
2180 case OPC_VR54XX_MACC
:
2181 gen_helper_macc(t0
, t0
, t1
);
2184 case OPC_VR54XX_MACCU
:
2185 gen_helper_maccu(t0
, t0
, t1
);
2188 case OPC_VR54XX_MSAC
:
2189 gen_helper_msac(t0
, t0
, t1
);
2192 case OPC_VR54XX_MSACU
:
2193 gen_helper_msacu(t0
, t0
, t1
);
2196 case OPC_VR54XX_MULHI
:
2197 gen_helper_mulhi(t0
, t0
, t1
);
2200 case OPC_VR54XX_MULHIU
:
2201 gen_helper_mulhiu(t0
, t0
, t1
);
2204 case OPC_VR54XX_MULSHI
:
2205 gen_helper_mulshi(t0
, t0
, t1
);
2208 case OPC_VR54XX_MULSHIU
:
2209 gen_helper_mulshiu(t0
, t0
, t1
);
2212 case OPC_VR54XX_MACCHI
:
2213 gen_helper_macchi(t0
, t0
, t1
);
2216 case OPC_VR54XX_MACCHIU
:
2217 gen_helper_macchiu(t0
, t0
, t1
);
2220 case OPC_VR54XX_MSACHI
:
2221 gen_helper_msachi(t0
, t0
, t1
);
2224 case OPC_VR54XX_MSACHIU
:
2225 gen_helper_msachiu(t0
, t0
, t1
);
2229 MIPS_INVAL("mul vr54xx");
2230 generate_exception(ctx
, EXCP_RI
);
2233 gen_store_gpr(t0
, rd
);
2234 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2241 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2244 const char *opn
= "CLx";
2252 t0
= tcg_temp_new();
2253 gen_load_gpr(t0
, rs
);
2256 gen_helper_clo(cpu_gpr
[rd
], t0
);
2260 gen_helper_clz(cpu_gpr
[rd
], t0
);
2263 #if defined(TARGET_MIPS64)
2265 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2269 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2274 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2279 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2280 int rs
, int rt
, int16_t imm
)
2283 TCGv t0
= tcg_temp_new();
2284 TCGv t1
= tcg_temp_new();
2287 /* Load needed operands */
2295 /* Compare two registers */
2297 gen_load_gpr(t0
, rs
);
2298 gen_load_gpr(t1
, rt
);
2308 /* Compare register to immediate */
2309 if (rs
!= 0 || imm
!= 0) {
2310 gen_load_gpr(t0
, rs
);
2311 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2318 case OPC_TEQ
: /* rs == rs */
2319 case OPC_TEQI
: /* r0 == 0 */
2320 case OPC_TGE
: /* rs >= rs */
2321 case OPC_TGEI
: /* r0 >= 0 */
2322 case OPC_TGEU
: /* rs >= rs unsigned */
2323 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2325 generate_exception(ctx
, EXCP_TRAP
);
2327 case OPC_TLT
: /* rs < rs */
2328 case OPC_TLTI
: /* r0 < 0 */
2329 case OPC_TLTU
: /* rs < rs unsigned */
2330 case OPC_TLTIU
: /* r0 < 0 unsigned */
2331 case OPC_TNE
: /* rs != rs */
2332 case OPC_TNEI
: /* r0 != 0 */
2333 /* Never trap: treat as NOP. */
2337 int l1
= gen_new_label();
2342 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2346 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2350 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2354 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2358 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2362 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2365 generate_exception(ctx
, EXCP_TRAP
);
2372 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2374 TranslationBlock
*tb
;
2376 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2377 likely(!ctx
->singlestep_enabled
)) {
2380 tcg_gen_exit_tb((long)tb
+ n
);
2383 if (ctx
->singlestep_enabled
) {
2384 save_cpu_state(ctx
, 0);
2385 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
2391 /* Branches (before delay slot) */
2392 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2394 int rs
, int rt
, int32_t offset
)
2396 target_ulong btgt
= -1;
2398 int bcond_compute
= 0;
2399 TCGv t0
= tcg_temp_new();
2400 TCGv t1
= tcg_temp_new();
2402 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2403 #ifdef MIPS_DEBUG_DISAS
2404 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2406 generate_exception(ctx
, EXCP_RI
);
2410 /* Load needed operands */
2416 /* Compare two registers */
2418 gen_load_gpr(t0
, rs
);
2419 gen_load_gpr(t1
, rt
);
2422 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2436 /* Compare to zero */
2438 gen_load_gpr(t0
, rs
);
2441 btgt
= ctx
->pc
+ insn_bytes
+ offset
;
2445 /* Jump to immediate */
2446 btgt
= ((ctx
->pc
+ insn_bytes
) & (int32_t)0xF0000000) | (uint32_t)offset
;
2450 /* Jump to register */
2451 if (offset
!= 0 && offset
!= 16) {
2452 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2453 others are reserved. */
2454 MIPS_INVAL("jump hint");
2455 generate_exception(ctx
, EXCP_RI
);
2458 gen_load_gpr(btarget
, rs
);
2461 MIPS_INVAL("branch/jump");
2462 generate_exception(ctx
, EXCP_RI
);
2465 if (bcond_compute
== 0) {
2466 /* No condition to be computed */
2468 case OPC_BEQ
: /* rx == rx */
2469 case OPC_BEQL
: /* rx == rx likely */
2470 case OPC_BGEZ
: /* 0 >= 0 */
2471 case OPC_BGEZL
: /* 0 >= 0 likely */
2472 case OPC_BLEZ
: /* 0 <= 0 */
2473 case OPC_BLEZL
: /* 0 <= 0 likely */
2475 ctx
->hflags
|= MIPS_HFLAG_B
;
2476 MIPS_DEBUG("balways");
2478 case OPC_BGEZAL
: /* 0 >= 0 */
2479 case OPC_BGEZALL
: /* 0 >= 0 likely */
2480 /* Always take and link */
2482 ctx
->hflags
|= MIPS_HFLAG_B
;
2483 MIPS_DEBUG("balways and link");
2485 case OPC_BNE
: /* rx != rx */
2486 case OPC_BGTZ
: /* 0 > 0 */
2487 case OPC_BLTZ
: /* 0 < 0 */
2489 MIPS_DEBUG("bnever (NOP)");
2491 case OPC_BLTZAL
: /* 0 < 0 */
2492 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2493 MIPS_DEBUG("bnever and link");
2495 case OPC_BLTZALL
: /* 0 < 0 likely */
2496 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2497 /* Skip the instruction in the delay slot */
2498 MIPS_DEBUG("bnever, link and skip");
2501 case OPC_BNEL
: /* rx != rx likely */
2502 case OPC_BGTZL
: /* 0 > 0 likely */
2503 case OPC_BLTZL
: /* 0 < 0 likely */
2504 /* Skip the instruction in the delay slot */
2505 MIPS_DEBUG("bnever and skip");
2509 ctx
->hflags
|= MIPS_HFLAG_B
;
2510 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2514 ctx
->hflags
|= MIPS_HFLAG_B
;
2515 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2518 ctx
->hflags
|= MIPS_HFLAG_BR
;
2519 MIPS_DEBUG("jr %s", regnames
[rs
]);
2523 ctx
->hflags
|= MIPS_HFLAG_BR
;
2524 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2527 MIPS_INVAL("branch/jump");
2528 generate_exception(ctx
, EXCP_RI
);
2534 gen_op_eq(bcond
, t0
, t1
);
2535 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2536 regnames
[rs
], regnames
[rt
], btgt
);
2539 gen_op_eq(bcond
, t0
, t1
);
2540 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2541 regnames
[rs
], regnames
[rt
], btgt
);
2544 gen_op_ne(bcond
, t0
, t1
);
2545 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2546 regnames
[rs
], regnames
[rt
], btgt
);
2549 gen_op_ne(bcond
, t0
, t1
);
2550 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2551 regnames
[rs
], regnames
[rt
], btgt
);
2554 gen_op_gez(bcond
, t0
);
2555 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2558 gen_op_gez(bcond
, t0
);
2559 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2562 gen_op_gez(bcond
, t0
);
2563 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2567 gen_op_gez(bcond
, t0
);
2569 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2572 gen_op_gtz(bcond
, t0
);
2573 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2576 gen_op_gtz(bcond
, t0
);
2577 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2580 gen_op_lez(bcond
, t0
);
2581 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2584 gen_op_lez(bcond
, t0
);
2585 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2588 gen_op_ltz(bcond
, t0
);
2589 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2592 gen_op_ltz(bcond
, t0
);
2593 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2596 gen_op_ltz(bcond
, t0
);
2598 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2600 ctx
->hflags
|= MIPS_HFLAG_BC
;
2603 gen_op_ltz(bcond
, t0
);
2605 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2607 ctx
->hflags
|= MIPS_HFLAG_BL
;
2610 MIPS_INVAL("conditional branch/jump");
2611 generate_exception(ctx
, EXCP_RI
);
2615 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2616 blink
, ctx
->hflags
, btgt
);
2618 ctx
->btarget
= btgt
;
2620 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ 8);
2628 /* special3 bitfield operations */
2629 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2630 int rs
, int lsb
, int msb
)
2632 TCGv t0
= tcg_temp_new();
2633 TCGv t1
= tcg_temp_new();
2636 gen_load_gpr(t1
, rs
);
2641 tcg_gen_shri_tl(t0
, t1
, lsb
);
2643 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2645 tcg_gen_ext32s_tl(t0
, t0
);
2648 #if defined(TARGET_MIPS64)
2650 tcg_gen_shri_tl(t0
, t1
, lsb
);
2652 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2656 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2657 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2660 tcg_gen_shri_tl(t0
, t1
, lsb
);
2661 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2667 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2668 gen_load_gpr(t0
, rt
);
2669 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2670 tcg_gen_shli_tl(t1
, t1
, lsb
);
2671 tcg_gen_andi_tl(t1
, t1
, mask
);
2672 tcg_gen_or_tl(t0
, t0
, t1
);
2673 tcg_gen_ext32s_tl(t0
, t0
);
2675 #if defined(TARGET_MIPS64)
2679 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2680 gen_load_gpr(t0
, rt
);
2681 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2682 tcg_gen_shli_tl(t1
, t1
, lsb
);
2683 tcg_gen_andi_tl(t1
, t1
, mask
);
2684 tcg_gen_or_tl(t0
, t0
, t1
);
2689 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2690 gen_load_gpr(t0
, rt
);
2691 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2692 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2693 tcg_gen_andi_tl(t1
, t1
, mask
);
2694 tcg_gen_or_tl(t0
, t0
, t1
);
2699 gen_load_gpr(t0
, rt
);
2700 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2701 gen_load_gpr(t0
, rt
);
2702 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2703 tcg_gen_shli_tl(t1
, t1
, lsb
);
2704 tcg_gen_andi_tl(t1
, t1
, mask
);
2705 tcg_gen_or_tl(t0
, t0
, t1
);
2710 MIPS_INVAL("bitops");
2711 generate_exception(ctx
, EXCP_RI
);
2716 gen_store_gpr(t0
, rt
);
2721 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2726 /* If no destination, treat it as a NOP. */
2731 t0
= tcg_temp_new();
2732 gen_load_gpr(t0
, rt
);
2736 TCGv t1
= tcg_temp_new();
2738 tcg_gen_shri_tl(t1
, t0
, 8);
2739 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2740 tcg_gen_shli_tl(t0
, t0
, 8);
2741 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2742 tcg_gen_or_tl(t0
, t0
, t1
);
2744 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2748 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2751 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2753 #if defined(TARGET_MIPS64)
2756 TCGv t1
= tcg_temp_new();
2758 tcg_gen_shri_tl(t1
, t0
, 8);
2759 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2760 tcg_gen_shli_tl(t0
, t0
, 8);
2761 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2762 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2768 TCGv t1
= tcg_temp_new();
2770 tcg_gen_shri_tl(t1
, t0
, 16);
2771 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2772 tcg_gen_shli_tl(t0
, t0
, 16);
2773 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2774 tcg_gen_or_tl(t0
, t0
, t1
);
2775 tcg_gen_shri_tl(t1
, t0
, 32);
2776 tcg_gen_shli_tl(t0
, t0
, 32);
2777 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2783 MIPS_INVAL("bsfhl");
2784 generate_exception(ctx
, EXCP_RI
);
2791 #ifndef CONFIG_USER_ONLY
2792 /* CP0 (MMU and control) */
2793 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
2795 TCGv_i32 t0
= tcg_temp_new_i32();
2797 tcg_gen_ld_i32(t0
, cpu_env
, off
);
2798 tcg_gen_ext_i32_tl(arg
, t0
);
2799 tcg_temp_free_i32(t0
);
2802 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
2804 tcg_gen_ld_tl(arg
, cpu_env
, off
);
2805 tcg_gen_ext32s_tl(arg
, arg
);
2808 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
2810 TCGv_i32 t0
= tcg_temp_new_i32();
2812 tcg_gen_trunc_tl_i32(t0
, arg
);
2813 tcg_gen_st_i32(t0
, cpu_env
, off
);
2814 tcg_temp_free_i32(t0
);
2817 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
2819 tcg_gen_ext32s_tl(arg
, arg
);
2820 tcg_gen_st_tl(arg
, cpu_env
, off
);
2823 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
2825 const char *rn
= "invalid";
2828 check_insn(env
, ctx
, ISA_MIPS32
);
2834 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
2838 check_insn(env
, ctx
, ASE_MT
);
2839 gen_helper_mfc0_mvpcontrol(arg
);
2843 check_insn(env
, ctx
, ASE_MT
);
2844 gen_helper_mfc0_mvpconf0(arg
);
2848 check_insn(env
, ctx
, ASE_MT
);
2849 gen_helper_mfc0_mvpconf1(arg
);
2859 gen_helper_mfc0_random(arg
);
2863 check_insn(env
, ctx
, ASE_MT
);
2864 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
2868 check_insn(env
, ctx
, ASE_MT
);
2869 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
2873 check_insn(env
, ctx
, ASE_MT
);
2874 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
2878 check_insn(env
, ctx
, ASE_MT
);
2879 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
2883 check_insn(env
, ctx
, ASE_MT
);
2884 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
2888 check_insn(env
, ctx
, ASE_MT
);
2889 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
2890 rn
= "VPEScheFBack";
2893 check_insn(env
, ctx
, ASE_MT
);
2894 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
2904 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2905 tcg_gen_ext32s_tl(arg
, arg
);
2909 check_insn(env
, ctx
, ASE_MT
);
2910 gen_helper_mfc0_tcstatus(arg
);
2914 check_insn(env
, ctx
, ASE_MT
);
2915 gen_helper_mfc0_tcbind(arg
);
2919 check_insn(env
, ctx
, ASE_MT
);
2920 gen_helper_mfc0_tcrestart(arg
);
2924 check_insn(env
, ctx
, ASE_MT
);
2925 gen_helper_mfc0_tchalt(arg
);
2929 check_insn(env
, ctx
, ASE_MT
);
2930 gen_helper_mfc0_tccontext(arg
);
2934 check_insn(env
, ctx
, ASE_MT
);
2935 gen_helper_mfc0_tcschedule(arg
);
2939 check_insn(env
, ctx
, ASE_MT
);
2940 gen_helper_mfc0_tcschefback(arg
);
2950 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2951 tcg_gen_ext32s_tl(arg
, arg
);
2961 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
2962 tcg_gen_ext32s_tl(arg
, arg
);
2966 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
2967 rn
= "ContextConfig";
2976 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
2980 check_insn(env
, ctx
, ISA_MIPS32R2
);
2981 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
2991 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
2995 check_insn(env
, ctx
, ISA_MIPS32R2
);
2996 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3000 check_insn(env
, ctx
, ISA_MIPS32R2
);
3001 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3005 check_insn(env
, ctx
, ISA_MIPS32R2
);
3006 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3010 check_insn(env
, ctx
, ISA_MIPS32R2
);
3011 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3015 check_insn(env
, ctx
, ISA_MIPS32R2
);
3016 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3026 check_insn(env
, ctx
, ISA_MIPS32R2
);
3027 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3037 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3038 tcg_gen_ext32s_tl(arg
, arg
);
3048 /* Mark as an IO operation because we read the time. */
3051 gen_helper_mfc0_count(arg
);
3054 ctx
->bstate
= BS_STOP
;
3058 /* 6,7 are implementation dependent */
3066 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3067 tcg_gen_ext32s_tl(arg
, arg
);
3077 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3080 /* 6,7 are implementation dependent */
3088 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3092 check_insn(env
, ctx
, ISA_MIPS32R2
);
3093 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3097 check_insn(env
, ctx
, ISA_MIPS32R2
);
3098 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3102 check_insn(env
, ctx
, ISA_MIPS32R2
);
3103 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3113 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3123 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3124 tcg_gen_ext32s_tl(arg
, arg
);
3134 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3138 check_insn(env
, ctx
, ISA_MIPS32R2
);
3139 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3149 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3153 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3157 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3161 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3164 /* 4,5 are reserved */
3165 /* 6,7 are implementation dependent */
3167 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3171 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3181 gen_helper_mfc0_lladdr(arg
);
3191 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3201 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3211 #if defined(TARGET_MIPS64)
3212 check_insn(env
, ctx
, ISA_MIPS3
);
3213 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3214 tcg_gen_ext32s_tl(arg
, arg
);
3223 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3226 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3234 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3235 rn
= "'Diagnostic"; /* implementation dependent */
3240 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3244 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3245 rn
= "TraceControl";
3248 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3249 rn
= "TraceControl2";
3252 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3253 rn
= "UserTraceData";
3256 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3267 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3268 tcg_gen_ext32s_tl(arg
, arg
);
3278 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3279 rn
= "Performance0";
3282 // gen_helper_mfc0_performance1(arg);
3283 rn
= "Performance1";
3286 // gen_helper_mfc0_performance2(arg);
3287 rn
= "Performance2";
3290 // gen_helper_mfc0_performance3(arg);
3291 rn
= "Performance3";
3294 // gen_helper_mfc0_performance4(arg);
3295 rn
= "Performance4";
3298 // gen_helper_mfc0_performance5(arg);
3299 rn
= "Performance5";
3302 // gen_helper_mfc0_performance6(arg);
3303 rn
= "Performance6";
3306 // gen_helper_mfc0_performance7(arg);
3307 rn
= "Performance7";
3314 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3320 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3333 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3340 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3353 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3360 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3370 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3371 tcg_gen_ext32s_tl(arg
, arg
);
3382 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3392 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3396 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3397 generate_exception(ctx
, EXCP_RI
);
3400 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3402 const char *rn
= "invalid";
3405 check_insn(env
, ctx
, ISA_MIPS32
);
3414 gen_helper_mtc0_index(arg
);
3418 check_insn(env
, ctx
, ASE_MT
);
3419 gen_helper_mtc0_mvpcontrol(arg
);
3423 check_insn(env
, ctx
, ASE_MT
);
3428 check_insn(env
, ctx
, ASE_MT
);
3443 check_insn(env
, ctx
, ASE_MT
);
3444 gen_helper_mtc0_vpecontrol(arg
);
3448 check_insn(env
, ctx
, ASE_MT
);
3449 gen_helper_mtc0_vpeconf0(arg
);
3453 check_insn(env
, ctx
, ASE_MT
);
3454 gen_helper_mtc0_vpeconf1(arg
);
3458 check_insn(env
, ctx
, ASE_MT
);
3459 gen_helper_mtc0_yqmask(arg
);
3463 check_insn(env
, ctx
, ASE_MT
);
3464 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3468 check_insn(env
, ctx
, ASE_MT
);
3469 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3470 rn
= "VPEScheFBack";
3473 check_insn(env
, ctx
, ASE_MT
);
3474 gen_helper_mtc0_vpeopt(arg
);
3484 gen_helper_mtc0_entrylo0(arg
);
3488 check_insn(env
, ctx
, ASE_MT
);
3489 gen_helper_mtc0_tcstatus(arg
);
3493 check_insn(env
, ctx
, ASE_MT
);
3494 gen_helper_mtc0_tcbind(arg
);
3498 check_insn(env
, ctx
, ASE_MT
);
3499 gen_helper_mtc0_tcrestart(arg
);
3503 check_insn(env
, ctx
, ASE_MT
);
3504 gen_helper_mtc0_tchalt(arg
);
3508 check_insn(env
, ctx
, ASE_MT
);
3509 gen_helper_mtc0_tccontext(arg
);
3513 check_insn(env
, ctx
, ASE_MT
);
3514 gen_helper_mtc0_tcschedule(arg
);
3518 check_insn(env
, ctx
, ASE_MT
);
3519 gen_helper_mtc0_tcschefback(arg
);
3529 gen_helper_mtc0_entrylo1(arg
);
3539 gen_helper_mtc0_context(arg
);
3543 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3544 rn
= "ContextConfig";
3553 gen_helper_mtc0_pagemask(arg
);
3557 check_insn(env
, ctx
, ISA_MIPS32R2
);
3558 gen_helper_mtc0_pagegrain(arg
);
3568 gen_helper_mtc0_wired(arg
);
3572 check_insn(env
, ctx
, ISA_MIPS32R2
);
3573 gen_helper_mtc0_srsconf0(arg
);
3577 check_insn(env
, ctx
, ISA_MIPS32R2
);
3578 gen_helper_mtc0_srsconf1(arg
);
3582 check_insn(env
, ctx
, ISA_MIPS32R2
);
3583 gen_helper_mtc0_srsconf2(arg
);
3587 check_insn(env
, ctx
, ISA_MIPS32R2
);
3588 gen_helper_mtc0_srsconf3(arg
);
3592 check_insn(env
, ctx
, ISA_MIPS32R2
);
3593 gen_helper_mtc0_srsconf4(arg
);
3603 check_insn(env
, ctx
, ISA_MIPS32R2
);
3604 gen_helper_mtc0_hwrena(arg
);
3618 gen_helper_mtc0_count(arg
);
3621 /* 6,7 are implementation dependent */
3629 gen_helper_mtc0_entryhi(arg
);
3639 gen_helper_mtc0_compare(arg
);
3642 /* 6,7 are implementation dependent */
3650 save_cpu_state(ctx
, 1);
3651 gen_helper_mtc0_status(arg
);
3652 /* BS_STOP isn't good enough here, hflags may have changed. */
3653 gen_save_pc(ctx
->pc
+ 4);
3654 ctx
->bstate
= BS_EXCP
;
3658 check_insn(env
, ctx
, ISA_MIPS32R2
);
3659 gen_helper_mtc0_intctl(arg
);
3660 /* Stop translation as we may have switched the execution mode */
3661 ctx
->bstate
= BS_STOP
;
3665 check_insn(env
, ctx
, ISA_MIPS32R2
);
3666 gen_helper_mtc0_srsctl(arg
);
3667 /* Stop translation as we may have switched the execution mode */
3668 ctx
->bstate
= BS_STOP
;
3672 check_insn(env
, ctx
, ISA_MIPS32R2
);
3673 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3674 /* Stop translation as we may have switched the execution mode */
3675 ctx
->bstate
= BS_STOP
;
3685 save_cpu_state(ctx
, 1);
3686 gen_helper_mtc0_cause(arg
);
3696 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
3710 check_insn(env
, ctx
, ISA_MIPS32R2
);
3711 gen_helper_mtc0_ebase(arg
);
3721 gen_helper_mtc0_config0(arg
);
3723 /* Stop translation as we may have switched the execution mode */
3724 ctx
->bstate
= BS_STOP
;
3727 /* ignored, read only */
3731 gen_helper_mtc0_config2(arg
);
3733 /* Stop translation as we may have switched the execution mode */
3734 ctx
->bstate
= BS_STOP
;
3737 /* ignored, read only */
3740 /* 4,5 are reserved */
3741 /* 6,7 are implementation dependent */
3751 rn
= "Invalid config selector";
3758 gen_helper_mtc0_lladdr(arg
);
3768 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
3778 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
3788 #if defined(TARGET_MIPS64)
3789 check_insn(env
, ctx
, ISA_MIPS3
);
3790 gen_helper_mtc0_xcontext(arg
);
3799 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3802 gen_helper_mtc0_framemask(arg
);
3811 rn
= "Diagnostic"; /* implementation dependent */
3816 gen_helper_mtc0_debug(arg
); /* EJTAG support */
3817 /* BS_STOP isn't good enough here, hflags may have changed. */
3818 gen_save_pc(ctx
->pc
+ 4);
3819 ctx
->bstate
= BS_EXCP
;
3823 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
3824 rn
= "TraceControl";
3825 /* Stop translation as we may have switched the execution mode */
3826 ctx
->bstate
= BS_STOP
;
3829 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
3830 rn
= "TraceControl2";
3831 /* Stop translation as we may have switched the execution mode */
3832 ctx
->bstate
= BS_STOP
;
3835 /* Stop translation as we may have switched the execution mode */
3836 ctx
->bstate
= BS_STOP
;
3837 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
3838 rn
= "UserTraceData";
3839 /* Stop translation as we may have switched the execution mode */
3840 ctx
->bstate
= BS_STOP
;
3843 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
3844 /* Stop translation as we may have switched the execution mode */
3845 ctx
->bstate
= BS_STOP
;
3856 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
3866 gen_helper_mtc0_performance0(arg
);
3867 rn
= "Performance0";
3870 // gen_helper_mtc0_performance1(arg);
3871 rn
= "Performance1";
3874 // gen_helper_mtc0_performance2(arg);
3875 rn
= "Performance2";
3878 // gen_helper_mtc0_performance3(arg);
3879 rn
= "Performance3";
3882 // gen_helper_mtc0_performance4(arg);
3883 rn
= "Performance4";
3886 // gen_helper_mtc0_performance5(arg);
3887 rn
= "Performance5";
3890 // gen_helper_mtc0_performance6(arg);
3891 rn
= "Performance6";
3894 // gen_helper_mtc0_performance7(arg);
3895 rn
= "Performance7";
3921 gen_helper_mtc0_taglo(arg
);
3928 gen_helper_mtc0_datalo(arg
);
3941 gen_helper_mtc0_taghi(arg
);
3948 gen_helper_mtc0_datahi(arg
);
3959 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
3970 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3976 /* Stop translation as we may have switched the execution mode */
3977 ctx
->bstate
= BS_STOP
;
3982 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3983 /* For simplicity assume that all writes can cause interrupts. */
3986 ctx
->bstate
= BS_STOP
;
3991 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3992 generate_exception(ctx
, EXCP_RI
);
3995 #if defined(TARGET_MIPS64)
3996 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3998 const char *rn
= "invalid";
4001 check_insn(env
, ctx
, ISA_MIPS64
);
4007 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4011 check_insn(env
, ctx
, ASE_MT
);
4012 gen_helper_mfc0_mvpcontrol(arg
);
4016 check_insn(env
, ctx
, ASE_MT
);
4017 gen_helper_mfc0_mvpconf0(arg
);
4021 check_insn(env
, ctx
, ASE_MT
);
4022 gen_helper_mfc0_mvpconf1(arg
);
4032 gen_helper_mfc0_random(arg
);
4036 check_insn(env
, ctx
, ASE_MT
);
4037 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4041 check_insn(env
, ctx
, ASE_MT
);
4042 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4046 check_insn(env
, ctx
, ASE_MT
);
4047 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4051 check_insn(env
, ctx
, ASE_MT
);
4052 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4056 check_insn(env
, ctx
, ASE_MT
);
4057 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4061 check_insn(env
, ctx
, ASE_MT
);
4062 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4063 rn
= "VPEScheFBack";
4066 check_insn(env
, ctx
, ASE_MT
);
4067 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4077 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4081 check_insn(env
, ctx
, ASE_MT
);
4082 gen_helper_mfc0_tcstatus(arg
);
4086 check_insn(env
, ctx
, ASE_MT
);
4087 gen_helper_mfc0_tcbind(arg
);
4091 check_insn(env
, ctx
, ASE_MT
);
4092 gen_helper_dmfc0_tcrestart(arg
);
4096 check_insn(env
, ctx
, ASE_MT
);
4097 gen_helper_dmfc0_tchalt(arg
);
4101 check_insn(env
, ctx
, ASE_MT
);
4102 gen_helper_dmfc0_tccontext(arg
);
4106 check_insn(env
, ctx
, ASE_MT
);
4107 gen_helper_dmfc0_tcschedule(arg
);
4111 check_insn(env
, ctx
, ASE_MT
);
4112 gen_helper_dmfc0_tcschefback(arg
);
4122 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4132 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4136 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4137 rn
= "ContextConfig";
4146 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4150 check_insn(env
, ctx
, ISA_MIPS32R2
);
4151 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4161 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4165 check_insn(env
, ctx
, ISA_MIPS32R2
);
4166 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4170 check_insn(env
, ctx
, ISA_MIPS32R2
);
4171 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4175 check_insn(env
, ctx
, ISA_MIPS32R2
);
4176 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4180 check_insn(env
, ctx
, ISA_MIPS32R2
);
4181 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4185 check_insn(env
, ctx
, ISA_MIPS32R2
);
4186 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4196 check_insn(env
, ctx
, ISA_MIPS32R2
);
4197 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4207 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4217 /* Mark as an IO operation because we read the time. */
4220 gen_helper_mfc0_count(arg
);
4223 ctx
->bstate
= BS_STOP
;
4227 /* 6,7 are implementation dependent */
4235 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4245 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4248 /* 6,7 are implementation dependent */
4256 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4260 check_insn(env
, ctx
, ISA_MIPS32R2
);
4261 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4265 check_insn(env
, ctx
, ISA_MIPS32R2
);
4266 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4270 check_insn(env
, ctx
, ISA_MIPS32R2
);
4271 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4281 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4291 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4301 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4305 check_insn(env
, ctx
, ISA_MIPS32R2
);
4306 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4316 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4320 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4324 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4328 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4331 /* 6,7 are implementation dependent */
4333 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4337 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4347 gen_helper_dmfc0_lladdr(arg
);
4357 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4367 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4377 check_insn(env
, ctx
, ISA_MIPS3
);
4378 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4386 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4389 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4397 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4398 rn
= "'Diagnostic"; /* implementation dependent */
4403 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4407 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4408 rn
= "TraceControl";
4411 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4412 rn
= "TraceControl2";
4415 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4416 rn
= "UserTraceData";
4419 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4430 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4440 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4441 rn
= "Performance0";
4444 // gen_helper_dmfc0_performance1(arg);
4445 rn
= "Performance1";
4448 // gen_helper_dmfc0_performance2(arg);
4449 rn
= "Performance2";
4452 // gen_helper_dmfc0_performance3(arg);
4453 rn
= "Performance3";
4456 // gen_helper_dmfc0_performance4(arg);
4457 rn
= "Performance4";
4460 // gen_helper_dmfc0_performance5(arg);
4461 rn
= "Performance5";
4464 // gen_helper_dmfc0_performance6(arg);
4465 rn
= "Performance6";
4468 // gen_helper_dmfc0_performance7(arg);
4469 rn
= "Performance7";
4476 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4483 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4496 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4503 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4516 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4523 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4533 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4544 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4554 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4558 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4559 generate_exception(ctx
, EXCP_RI
);
4562 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4564 const char *rn
= "invalid";
4567 check_insn(env
, ctx
, ISA_MIPS64
);
4576 gen_helper_mtc0_index(arg
);
4580 check_insn(env
, ctx
, ASE_MT
);
4581 gen_helper_mtc0_mvpcontrol(arg
);
4585 check_insn(env
, ctx
, ASE_MT
);
4590 check_insn(env
, ctx
, ASE_MT
);
4605 check_insn(env
, ctx
, ASE_MT
);
4606 gen_helper_mtc0_vpecontrol(arg
);
4610 check_insn(env
, ctx
, ASE_MT
);
4611 gen_helper_mtc0_vpeconf0(arg
);
4615 check_insn(env
, ctx
, ASE_MT
);
4616 gen_helper_mtc0_vpeconf1(arg
);
4620 check_insn(env
, ctx
, ASE_MT
);
4621 gen_helper_mtc0_yqmask(arg
);
4625 check_insn(env
, ctx
, ASE_MT
);
4626 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4630 check_insn(env
, ctx
, ASE_MT
);
4631 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4632 rn
= "VPEScheFBack";
4635 check_insn(env
, ctx
, ASE_MT
);
4636 gen_helper_mtc0_vpeopt(arg
);
4646 gen_helper_mtc0_entrylo0(arg
);
4650 check_insn(env
, ctx
, ASE_MT
);
4651 gen_helper_mtc0_tcstatus(arg
);
4655 check_insn(env
, ctx
, ASE_MT
);
4656 gen_helper_mtc0_tcbind(arg
);
4660 check_insn(env
, ctx
, ASE_MT
);
4661 gen_helper_mtc0_tcrestart(arg
);
4665 check_insn(env
, ctx
, ASE_MT
);
4666 gen_helper_mtc0_tchalt(arg
);
4670 check_insn(env
, ctx
, ASE_MT
);
4671 gen_helper_mtc0_tccontext(arg
);
4675 check_insn(env
, ctx
, ASE_MT
);
4676 gen_helper_mtc0_tcschedule(arg
);
4680 check_insn(env
, ctx
, ASE_MT
);
4681 gen_helper_mtc0_tcschefback(arg
);
4691 gen_helper_mtc0_entrylo1(arg
);
4701 gen_helper_mtc0_context(arg
);
4705 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
4706 rn
= "ContextConfig";
4715 gen_helper_mtc0_pagemask(arg
);
4719 check_insn(env
, ctx
, ISA_MIPS32R2
);
4720 gen_helper_mtc0_pagegrain(arg
);
4730 gen_helper_mtc0_wired(arg
);
4734 check_insn(env
, ctx
, ISA_MIPS32R2
);
4735 gen_helper_mtc0_srsconf0(arg
);
4739 check_insn(env
, ctx
, ISA_MIPS32R2
);
4740 gen_helper_mtc0_srsconf1(arg
);
4744 check_insn(env
, ctx
, ISA_MIPS32R2
);
4745 gen_helper_mtc0_srsconf2(arg
);
4749 check_insn(env
, ctx
, ISA_MIPS32R2
);
4750 gen_helper_mtc0_srsconf3(arg
);
4754 check_insn(env
, ctx
, ISA_MIPS32R2
);
4755 gen_helper_mtc0_srsconf4(arg
);
4765 check_insn(env
, ctx
, ISA_MIPS32R2
);
4766 gen_helper_mtc0_hwrena(arg
);
4780 gen_helper_mtc0_count(arg
);
4783 /* 6,7 are implementation dependent */
4787 /* Stop translation as we may have switched the execution mode */
4788 ctx
->bstate
= BS_STOP
;
4793 gen_helper_mtc0_entryhi(arg
);
4803 gen_helper_mtc0_compare(arg
);
4806 /* 6,7 are implementation dependent */
4810 /* Stop translation as we may have switched the execution mode */
4811 ctx
->bstate
= BS_STOP
;
4816 save_cpu_state(ctx
, 1);
4817 gen_helper_mtc0_status(arg
);
4818 /* BS_STOP isn't good enough here, hflags may have changed. */
4819 gen_save_pc(ctx
->pc
+ 4);
4820 ctx
->bstate
= BS_EXCP
;
4824 check_insn(env
, ctx
, ISA_MIPS32R2
);
4825 gen_helper_mtc0_intctl(arg
);
4826 /* Stop translation as we may have switched the execution mode */
4827 ctx
->bstate
= BS_STOP
;
4831 check_insn(env
, ctx
, ISA_MIPS32R2
);
4832 gen_helper_mtc0_srsctl(arg
);
4833 /* Stop translation as we may have switched the execution mode */
4834 ctx
->bstate
= BS_STOP
;
4838 check_insn(env
, ctx
, ISA_MIPS32R2
);
4839 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4840 /* Stop translation as we may have switched the execution mode */
4841 ctx
->bstate
= BS_STOP
;
4851 save_cpu_state(ctx
, 1);
4852 gen_helper_mtc0_cause(arg
);
4862 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4876 check_insn(env
, ctx
, ISA_MIPS32R2
);
4877 gen_helper_mtc0_ebase(arg
);
4887 gen_helper_mtc0_config0(arg
);
4889 /* Stop translation as we may have switched the execution mode */
4890 ctx
->bstate
= BS_STOP
;
4893 /* ignored, read only */
4897 gen_helper_mtc0_config2(arg
);
4899 /* Stop translation as we may have switched the execution mode */
4900 ctx
->bstate
= BS_STOP
;
4906 /* 6,7 are implementation dependent */
4908 rn
= "Invalid config selector";
4915 gen_helper_mtc0_lladdr(arg
);
4925 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
4935 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
4945 check_insn(env
, ctx
, ISA_MIPS3
);
4946 gen_helper_mtc0_xcontext(arg
);
4954 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4957 gen_helper_mtc0_framemask(arg
);
4966 rn
= "Diagnostic"; /* implementation dependent */
4971 gen_helper_mtc0_debug(arg
); /* EJTAG support */
4972 /* BS_STOP isn't good enough here, hflags may have changed. */
4973 gen_save_pc(ctx
->pc
+ 4);
4974 ctx
->bstate
= BS_EXCP
;
4978 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
4979 /* Stop translation as we may have switched the execution mode */
4980 ctx
->bstate
= BS_STOP
;
4981 rn
= "TraceControl";
4984 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
4985 /* Stop translation as we may have switched the execution mode */
4986 ctx
->bstate
= BS_STOP
;
4987 rn
= "TraceControl2";
4990 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
4991 /* Stop translation as we may have switched the execution mode */
4992 ctx
->bstate
= BS_STOP
;
4993 rn
= "UserTraceData";
4996 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
4997 /* Stop translation as we may have switched the execution mode */
4998 ctx
->bstate
= BS_STOP
;
5009 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5019 gen_helper_mtc0_performance0(arg
);
5020 rn
= "Performance0";
5023 // gen_helper_mtc0_performance1(arg);
5024 rn
= "Performance1";
5027 // gen_helper_mtc0_performance2(arg);
5028 rn
= "Performance2";
5031 // gen_helper_mtc0_performance3(arg);
5032 rn
= "Performance3";
5035 // gen_helper_mtc0_performance4(arg);
5036 rn
= "Performance4";
5039 // gen_helper_mtc0_performance5(arg);
5040 rn
= "Performance5";
5043 // gen_helper_mtc0_performance6(arg);
5044 rn
= "Performance6";
5047 // gen_helper_mtc0_performance7(arg);
5048 rn
= "Performance7";
5074 gen_helper_mtc0_taglo(arg
);
5081 gen_helper_mtc0_datalo(arg
);
5094 gen_helper_mtc0_taghi(arg
);
5101 gen_helper_mtc0_datahi(arg
);
5112 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5123 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5129 /* Stop translation as we may have switched the execution mode */
5130 ctx
->bstate
= BS_STOP
;
5135 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5136 /* For simplicity assume that all writes can cause interrupts. */
5139 ctx
->bstate
= BS_STOP
;
5144 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5145 generate_exception(ctx
, EXCP_RI
);
5147 #endif /* TARGET_MIPS64 */
5149 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5150 int u
, int sel
, int h
)
5152 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5153 TCGv t0
= tcg_temp_local_new();
5155 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5156 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5157 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5158 tcg_gen_movi_tl(t0
, -1);
5159 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5160 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5161 tcg_gen_movi_tl(t0
, -1);
5167 gen_helper_mftc0_tcstatus(t0
);
5170 gen_helper_mftc0_tcbind(t0
);
5173 gen_helper_mftc0_tcrestart(t0
);
5176 gen_helper_mftc0_tchalt(t0
);
5179 gen_helper_mftc0_tccontext(t0
);
5182 gen_helper_mftc0_tcschedule(t0
);
5185 gen_helper_mftc0_tcschefback(t0
);
5188 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5195 gen_helper_mftc0_entryhi(t0
);
5198 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5204 gen_helper_mftc0_status(t0
);
5207 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5213 gen_helper_mftc0_debug(t0
);
5216 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5221 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5223 } else switch (sel
) {
5224 /* GPR registers. */
5226 gen_helper_1i(mftgpr
, t0
, rt
);
5228 /* Auxiliary CPU registers */
5232 gen_helper_1i(mftlo
, t0
, 0);
5235 gen_helper_1i(mfthi
, t0
, 0);
5238 gen_helper_1i(mftacx
, t0
, 0);
5241 gen_helper_1i(mftlo
, t0
, 1);
5244 gen_helper_1i(mfthi
, t0
, 1);
5247 gen_helper_1i(mftacx
, t0
, 1);
5250 gen_helper_1i(mftlo
, t0
, 2);
5253 gen_helper_1i(mfthi
, t0
, 2);
5256 gen_helper_1i(mftacx
, t0
, 2);
5259 gen_helper_1i(mftlo
, t0
, 3);
5262 gen_helper_1i(mfthi
, t0
, 3);
5265 gen_helper_1i(mftacx
, t0
, 3);
5268 gen_helper_mftdsp(t0
);
5274 /* Floating point (COP1). */
5276 /* XXX: For now we support only a single FPU context. */
5278 TCGv_i32 fp0
= tcg_temp_new_i32();
5280 gen_load_fpr32(fp0
, rt
);
5281 tcg_gen_ext_i32_tl(t0
, fp0
);
5282 tcg_temp_free_i32(fp0
);
5284 TCGv_i32 fp0
= tcg_temp_new_i32();
5286 gen_load_fpr32h(fp0
, rt
);
5287 tcg_gen_ext_i32_tl(t0
, fp0
);
5288 tcg_temp_free_i32(fp0
);
5292 /* XXX: For now we support only a single FPU context. */
5293 gen_helper_1i(cfc1
, t0
, rt
);
5295 /* COP2: Not implemented. */
5302 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5303 gen_store_gpr(t0
, rd
);
5309 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5310 generate_exception(ctx
, EXCP_RI
);
5313 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5314 int u
, int sel
, int h
)
5316 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5317 TCGv t0
= tcg_temp_local_new();
5319 gen_load_gpr(t0
, rt
);
5320 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5321 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5322 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5324 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5325 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5332 gen_helper_mttc0_tcstatus(t0
);
5335 gen_helper_mttc0_tcbind(t0
);
5338 gen_helper_mttc0_tcrestart(t0
);
5341 gen_helper_mttc0_tchalt(t0
);
5344 gen_helper_mttc0_tccontext(t0
);
5347 gen_helper_mttc0_tcschedule(t0
);
5350 gen_helper_mttc0_tcschefback(t0
);
5353 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5360 gen_helper_mttc0_entryhi(t0
);
5363 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5369 gen_helper_mttc0_status(t0
);
5372 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5378 gen_helper_mttc0_debug(t0
);
5381 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5386 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5388 } else switch (sel
) {
5389 /* GPR registers. */
5391 gen_helper_1i(mttgpr
, t0
, rd
);
5393 /* Auxiliary CPU registers */
5397 gen_helper_1i(mttlo
, t0
, 0);
5400 gen_helper_1i(mtthi
, t0
, 0);
5403 gen_helper_1i(mttacx
, t0
, 0);
5406 gen_helper_1i(mttlo
, t0
, 1);
5409 gen_helper_1i(mtthi
, t0
, 1);
5412 gen_helper_1i(mttacx
, t0
, 1);
5415 gen_helper_1i(mttlo
, t0
, 2);
5418 gen_helper_1i(mtthi
, t0
, 2);
5421 gen_helper_1i(mttacx
, t0
, 2);
5424 gen_helper_1i(mttlo
, t0
, 3);
5427 gen_helper_1i(mtthi
, t0
, 3);
5430 gen_helper_1i(mttacx
, t0
, 3);
5433 gen_helper_mttdsp(t0
);
5439 /* Floating point (COP1). */
5441 /* XXX: For now we support only a single FPU context. */
5443 TCGv_i32 fp0
= tcg_temp_new_i32();
5445 tcg_gen_trunc_tl_i32(fp0
, t0
);
5446 gen_store_fpr32(fp0
, rd
);
5447 tcg_temp_free_i32(fp0
);
5449 TCGv_i32 fp0
= tcg_temp_new_i32();
5451 tcg_gen_trunc_tl_i32(fp0
, t0
);
5452 gen_store_fpr32h(fp0
, rd
);
5453 tcg_temp_free_i32(fp0
);
5457 /* XXX: For now we support only a single FPU context. */
5458 gen_helper_1i(ctc1
, t0
, rd
);
5460 /* COP2: Not implemented. */
5467 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5473 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5474 generate_exception(ctx
, EXCP_RI
);
5477 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5479 const char *opn
= "ldst";
5487 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5492 TCGv t0
= tcg_temp_new();
5494 gen_load_gpr(t0
, rt
);
5495 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5500 #if defined(TARGET_MIPS64)
5502 check_insn(env
, ctx
, ISA_MIPS3
);
5507 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5511 check_insn(env
, ctx
, ISA_MIPS3
);
5513 TCGv t0
= tcg_temp_new();
5515 gen_load_gpr(t0
, rt
);
5516 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5523 check_insn(env
, ctx
, ASE_MT
);
5528 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5529 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5533 check_insn(env
, ctx
, ASE_MT
);
5534 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5535 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5540 if (!env
->tlb
->helper_tlbwi
)
5546 if (!env
->tlb
->helper_tlbwr
)
5552 if (!env
->tlb
->helper_tlbp
)
5558 if (!env
->tlb
->helper_tlbr
)
5564 check_insn(env
, ctx
, ISA_MIPS2
);
5566 ctx
->bstate
= BS_EXCP
;
5570 check_insn(env
, ctx
, ISA_MIPS32
);
5571 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5573 generate_exception(ctx
, EXCP_RI
);
5576 ctx
->bstate
= BS_EXCP
;
5581 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5582 /* If we get an exception, we want to restart at next instruction */
5584 save_cpu_state(ctx
, 1);
5587 ctx
->bstate
= BS_EXCP
;
5592 generate_exception(ctx
, EXCP_RI
);
5595 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5597 #endif /* !CONFIG_USER_ONLY */
5599 /* CP1 Branches (before delay slot) */
5600 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5601 int32_t cc
, int32_t offset
)
5603 target_ulong btarget
;
5604 const char *opn
= "cp1 cond branch";
5605 TCGv_i32 t0
= tcg_temp_new_i32();
5608 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5610 btarget
= ctx
->pc
+ 4 + offset
;
5614 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5615 tcg_gen_not_i32(t0
, t0
);
5616 tcg_gen_andi_i32(t0
, t0
, 1);
5617 tcg_gen_extu_i32_tl(bcond
, t0
);
5621 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5622 tcg_gen_not_i32(t0
, t0
);
5623 tcg_gen_andi_i32(t0
, t0
, 1);
5624 tcg_gen_extu_i32_tl(bcond
, t0
);
5628 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5629 tcg_gen_andi_i32(t0
, t0
, 1);
5630 tcg_gen_extu_i32_tl(bcond
, t0
);
5634 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5635 tcg_gen_andi_i32(t0
, t0
, 1);
5636 tcg_gen_extu_i32_tl(bcond
, t0
);
5639 ctx
->hflags
|= MIPS_HFLAG_BL
;
5643 TCGv_i32 t1
= tcg_temp_new_i32();
5644 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5645 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5646 tcg_gen_or_i32(t0
, t0
, t1
);
5647 tcg_temp_free_i32(t1
);
5648 tcg_gen_not_i32(t0
, t0
);
5649 tcg_gen_andi_i32(t0
, t0
, 1);
5650 tcg_gen_extu_i32_tl(bcond
, t0
);
5656 TCGv_i32 t1
= tcg_temp_new_i32();
5657 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5658 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5659 tcg_gen_or_i32(t0
, t0
, t1
);
5660 tcg_temp_free_i32(t1
);
5661 tcg_gen_andi_i32(t0
, t0
, 1);
5662 tcg_gen_extu_i32_tl(bcond
, t0
);
5668 TCGv_i32 t1
= tcg_temp_new_i32();
5669 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5670 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5671 tcg_gen_or_i32(t0
, t0
, t1
);
5672 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5673 tcg_gen_or_i32(t0
, t0
, t1
);
5674 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5675 tcg_gen_or_i32(t0
, t0
, t1
);
5676 tcg_temp_free_i32(t1
);
5677 tcg_gen_not_i32(t0
, t0
);
5678 tcg_gen_andi_i32(t0
, t0
, 1);
5679 tcg_gen_extu_i32_tl(bcond
, t0
);
5685 TCGv_i32 t1
= tcg_temp_new_i32();
5686 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5687 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5688 tcg_gen_or_i32(t0
, t0
, t1
);
5689 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5690 tcg_gen_or_i32(t0
, t0
, t1
);
5691 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5692 tcg_gen_or_i32(t0
, t0
, t1
);
5693 tcg_temp_free_i32(t1
);
5694 tcg_gen_andi_i32(t0
, t0
, 1);
5695 tcg_gen_extu_i32_tl(bcond
, t0
);
5699 ctx
->hflags
|= MIPS_HFLAG_BC
;
5703 generate_exception (ctx
, EXCP_RI
);
5706 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5707 ctx
->hflags
, btarget
);
5708 ctx
->btarget
= btarget
;
5711 tcg_temp_free_i32(t0
);
5714 /* Coprocessor 1 (FPU) */
5716 #define FOP(func, fmt) (((fmt) << 21) | (func))
5718 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5720 const char *opn
= "cp1 move";
5721 TCGv t0
= tcg_temp_new();
5726 TCGv_i32 fp0
= tcg_temp_new_i32();
5728 gen_load_fpr32(fp0
, fs
);
5729 tcg_gen_ext_i32_tl(t0
, fp0
);
5730 tcg_temp_free_i32(fp0
);
5732 gen_store_gpr(t0
, rt
);
5736 gen_load_gpr(t0
, rt
);
5738 TCGv_i32 fp0
= tcg_temp_new_i32();
5740 tcg_gen_trunc_tl_i32(fp0
, t0
);
5741 gen_store_fpr32(fp0
, fs
);
5742 tcg_temp_free_i32(fp0
);
5747 gen_helper_1i(cfc1
, t0
, fs
);
5748 gen_store_gpr(t0
, rt
);
5752 gen_load_gpr(t0
, rt
);
5753 gen_helper_1i(ctc1
, t0
, fs
);
5756 #if defined(TARGET_MIPS64)
5758 gen_load_fpr64(ctx
, t0
, fs
);
5759 gen_store_gpr(t0
, rt
);
5763 gen_load_gpr(t0
, rt
);
5764 gen_store_fpr64(ctx
, t0
, fs
);
5770 TCGv_i32 fp0
= tcg_temp_new_i32();
5772 gen_load_fpr32h(fp0
, fs
);
5773 tcg_gen_ext_i32_tl(t0
, fp0
);
5774 tcg_temp_free_i32(fp0
);
5776 gen_store_gpr(t0
, rt
);
5780 gen_load_gpr(t0
, rt
);
5782 TCGv_i32 fp0
= tcg_temp_new_i32();
5784 tcg_gen_trunc_tl_i32(fp0
, t0
);
5785 gen_store_fpr32h(fp0
, fs
);
5786 tcg_temp_free_i32(fp0
);
5792 generate_exception (ctx
, EXCP_RI
);
5795 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5801 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5817 l1
= gen_new_label();
5818 t0
= tcg_temp_new_i32();
5819 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5820 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5821 tcg_temp_free_i32(t0
);
5823 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
5825 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
5830 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5833 TCGv_i32 t0
= tcg_temp_new_i32();
5834 int l1
= gen_new_label();
5841 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5842 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5843 gen_load_fpr32(t0
, fs
);
5844 gen_store_fpr32(t0
, fd
);
5846 tcg_temp_free_i32(t0
);
5849 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5852 TCGv_i32 t0
= tcg_temp_new_i32();
5854 int l1
= gen_new_label();
5861 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5862 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5863 tcg_temp_free_i32(t0
);
5864 fp0
= tcg_temp_new_i64();
5865 gen_load_fpr64(ctx
, fp0
, fs
);
5866 gen_store_fpr64(ctx
, fp0
, fd
);
5867 tcg_temp_free_i64(fp0
);
5871 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5874 TCGv_i32 t0
= tcg_temp_new_i32();
5875 int l1
= gen_new_label();
5876 int l2
= gen_new_label();
5883 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
));
5884 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5885 gen_load_fpr32(t0
, fs
);
5886 gen_store_fpr32(t0
, fd
);
5889 tcg_gen_andi_i32(t0
, fpu_fcr31
, 1 << get_fp_bit(cc
+1));
5890 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
5891 gen_load_fpr32h(t0
, fs
);
5892 gen_store_fpr32h(t0
, fd
);
5893 tcg_temp_free_i32(t0
);
5898 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5899 int ft
, int fs
, int fd
, int cc
)
5901 const char *opn
= "farith";
5902 const char *condnames
[] = {
5920 const char *condnames_abs
[] = {
5938 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5939 uint32_t func
= ctx
->opcode
& 0x3f;
5941 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5944 TCGv_i32 fp0
= tcg_temp_new_i32();
5945 TCGv_i32 fp1
= tcg_temp_new_i32();
5947 gen_load_fpr32(fp0
, fs
);
5948 gen_load_fpr32(fp1
, ft
);
5949 gen_helper_float_add_s(fp0
, fp0
, fp1
);
5950 tcg_temp_free_i32(fp1
);
5951 gen_store_fpr32(fp0
, fd
);
5952 tcg_temp_free_i32(fp0
);
5959 TCGv_i32 fp0
= tcg_temp_new_i32();
5960 TCGv_i32 fp1
= tcg_temp_new_i32();
5962 gen_load_fpr32(fp0
, fs
);
5963 gen_load_fpr32(fp1
, ft
);
5964 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
5965 tcg_temp_free_i32(fp1
);
5966 gen_store_fpr32(fp0
, fd
);
5967 tcg_temp_free_i32(fp0
);
5974 TCGv_i32 fp0
= tcg_temp_new_i32();
5975 TCGv_i32 fp1
= tcg_temp_new_i32();
5977 gen_load_fpr32(fp0
, fs
);
5978 gen_load_fpr32(fp1
, ft
);
5979 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
5980 tcg_temp_free_i32(fp1
);
5981 gen_store_fpr32(fp0
, fd
);
5982 tcg_temp_free_i32(fp0
);
5989 TCGv_i32 fp0
= tcg_temp_new_i32();
5990 TCGv_i32 fp1
= tcg_temp_new_i32();
5992 gen_load_fpr32(fp0
, fs
);
5993 gen_load_fpr32(fp1
, ft
);
5994 gen_helper_float_div_s(fp0
, fp0
, fp1
);
5995 tcg_temp_free_i32(fp1
);
5996 gen_store_fpr32(fp0
, fd
);
5997 tcg_temp_free_i32(fp0
);
6004 TCGv_i32 fp0
= tcg_temp_new_i32();
6006 gen_load_fpr32(fp0
, fs
);
6007 gen_helper_float_sqrt_s(fp0
, fp0
);
6008 gen_store_fpr32(fp0
, fd
);
6009 tcg_temp_free_i32(fp0
);
6015 TCGv_i32 fp0
= tcg_temp_new_i32();
6017 gen_load_fpr32(fp0
, fs
);
6018 gen_helper_float_abs_s(fp0
, fp0
);
6019 gen_store_fpr32(fp0
, fd
);
6020 tcg_temp_free_i32(fp0
);
6026 TCGv_i32 fp0
= tcg_temp_new_i32();
6028 gen_load_fpr32(fp0
, fs
);
6029 gen_store_fpr32(fp0
, fd
);
6030 tcg_temp_free_i32(fp0
);
6036 TCGv_i32 fp0
= tcg_temp_new_i32();
6038 gen_load_fpr32(fp0
, fs
);
6039 gen_helper_float_chs_s(fp0
, fp0
);
6040 gen_store_fpr32(fp0
, fd
);
6041 tcg_temp_free_i32(fp0
);
6046 check_cp1_64bitmode(ctx
);
6048 TCGv_i32 fp32
= tcg_temp_new_i32();
6049 TCGv_i64 fp64
= tcg_temp_new_i64();
6051 gen_load_fpr32(fp32
, fs
);
6052 gen_helper_float_roundl_s(fp64
, fp32
);
6053 tcg_temp_free_i32(fp32
);
6054 gen_store_fpr64(ctx
, fp64
, fd
);
6055 tcg_temp_free_i64(fp64
);
6060 check_cp1_64bitmode(ctx
);
6062 TCGv_i32 fp32
= tcg_temp_new_i32();
6063 TCGv_i64 fp64
= tcg_temp_new_i64();
6065 gen_load_fpr32(fp32
, fs
);
6066 gen_helper_float_truncl_s(fp64
, fp32
);
6067 tcg_temp_free_i32(fp32
);
6068 gen_store_fpr64(ctx
, fp64
, fd
);
6069 tcg_temp_free_i64(fp64
);
6074 check_cp1_64bitmode(ctx
);
6076 TCGv_i32 fp32
= tcg_temp_new_i32();
6077 TCGv_i64 fp64
= tcg_temp_new_i64();
6079 gen_load_fpr32(fp32
, fs
);
6080 gen_helper_float_ceill_s(fp64
, fp32
);
6081 tcg_temp_free_i32(fp32
);
6082 gen_store_fpr64(ctx
, fp64
, fd
);
6083 tcg_temp_free_i64(fp64
);
6088 check_cp1_64bitmode(ctx
);
6090 TCGv_i32 fp32
= tcg_temp_new_i32();
6091 TCGv_i64 fp64
= tcg_temp_new_i64();
6093 gen_load_fpr32(fp32
, fs
);
6094 gen_helper_float_floorl_s(fp64
, fp32
);
6095 tcg_temp_free_i32(fp32
);
6096 gen_store_fpr64(ctx
, fp64
, fd
);
6097 tcg_temp_free_i64(fp64
);
6103 TCGv_i32 fp0
= tcg_temp_new_i32();
6105 gen_load_fpr32(fp0
, fs
);
6106 gen_helper_float_roundw_s(fp0
, fp0
);
6107 gen_store_fpr32(fp0
, fd
);
6108 tcg_temp_free_i32(fp0
);
6114 TCGv_i32 fp0
= tcg_temp_new_i32();
6116 gen_load_fpr32(fp0
, fs
);
6117 gen_helper_float_truncw_s(fp0
, fp0
);
6118 gen_store_fpr32(fp0
, fd
);
6119 tcg_temp_free_i32(fp0
);
6125 TCGv_i32 fp0
= tcg_temp_new_i32();
6127 gen_load_fpr32(fp0
, fs
);
6128 gen_helper_float_ceilw_s(fp0
, fp0
);
6129 gen_store_fpr32(fp0
, fd
);
6130 tcg_temp_free_i32(fp0
);
6136 TCGv_i32 fp0
= tcg_temp_new_i32();
6138 gen_load_fpr32(fp0
, fs
);
6139 gen_helper_float_floorw_s(fp0
, fp0
);
6140 gen_store_fpr32(fp0
, fd
);
6141 tcg_temp_free_i32(fp0
);
6146 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6151 int l1
= gen_new_label();
6155 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6157 fp0
= tcg_temp_new_i32();
6158 gen_load_fpr32(fp0
, fs
);
6159 gen_store_fpr32(fp0
, fd
);
6160 tcg_temp_free_i32(fp0
);
6167 int l1
= gen_new_label();
6171 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6172 fp0
= tcg_temp_new_i32();
6173 gen_load_fpr32(fp0
, fs
);
6174 gen_store_fpr32(fp0
, fd
);
6175 tcg_temp_free_i32(fp0
);
6184 TCGv_i32 fp0
= tcg_temp_new_i32();
6186 gen_load_fpr32(fp0
, fs
);
6187 gen_helper_float_recip_s(fp0
, fp0
);
6188 gen_store_fpr32(fp0
, fd
);
6189 tcg_temp_free_i32(fp0
);
6196 TCGv_i32 fp0
= tcg_temp_new_i32();
6198 gen_load_fpr32(fp0
, fs
);
6199 gen_helper_float_rsqrt_s(fp0
, fp0
);
6200 gen_store_fpr32(fp0
, fd
);
6201 tcg_temp_free_i32(fp0
);
6206 check_cp1_64bitmode(ctx
);
6208 TCGv_i32 fp0
= tcg_temp_new_i32();
6209 TCGv_i32 fp1
= tcg_temp_new_i32();
6211 gen_load_fpr32(fp0
, fs
);
6212 gen_load_fpr32(fp1
, fd
);
6213 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6214 tcg_temp_free_i32(fp1
);
6215 gen_store_fpr32(fp0
, fd
);
6216 tcg_temp_free_i32(fp0
);
6221 check_cp1_64bitmode(ctx
);
6223 TCGv_i32 fp0
= tcg_temp_new_i32();
6225 gen_load_fpr32(fp0
, fs
);
6226 gen_helper_float_recip1_s(fp0
, fp0
);
6227 gen_store_fpr32(fp0
, fd
);
6228 tcg_temp_free_i32(fp0
);
6233 check_cp1_64bitmode(ctx
);
6235 TCGv_i32 fp0
= tcg_temp_new_i32();
6237 gen_load_fpr32(fp0
, fs
);
6238 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6239 gen_store_fpr32(fp0
, fd
);
6240 tcg_temp_free_i32(fp0
);
6245 check_cp1_64bitmode(ctx
);
6247 TCGv_i32 fp0
= tcg_temp_new_i32();
6248 TCGv_i32 fp1
= tcg_temp_new_i32();
6250 gen_load_fpr32(fp0
, fs
);
6251 gen_load_fpr32(fp1
, ft
);
6252 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6253 tcg_temp_free_i32(fp1
);
6254 gen_store_fpr32(fp0
, fd
);
6255 tcg_temp_free_i32(fp0
);
6260 check_cp1_registers(ctx
, fd
);
6262 TCGv_i32 fp32
= tcg_temp_new_i32();
6263 TCGv_i64 fp64
= tcg_temp_new_i64();
6265 gen_load_fpr32(fp32
, fs
);
6266 gen_helper_float_cvtd_s(fp64
, fp32
);
6267 tcg_temp_free_i32(fp32
);
6268 gen_store_fpr64(ctx
, fp64
, fd
);
6269 tcg_temp_free_i64(fp64
);
6275 TCGv_i32 fp0
= tcg_temp_new_i32();
6277 gen_load_fpr32(fp0
, fs
);
6278 gen_helper_float_cvtw_s(fp0
, fp0
);
6279 gen_store_fpr32(fp0
, fd
);
6280 tcg_temp_free_i32(fp0
);
6285 check_cp1_64bitmode(ctx
);
6287 TCGv_i32 fp32
= tcg_temp_new_i32();
6288 TCGv_i64 fp64
= tcg_temp_new_i64();
6290 gen_load_fpr32(fp32
, fs
);
6291 gen_helper_float_cvtl_s(fp64
, fp32
);
6292 tcg_temp_free_i32(fp32
);
6293 gen_store_fpr64(ctx
, fp64
, fd
);
6294 tcg_temp_free_i64(fp64
);
6299 check_cp1_64bitmode(ctx
);
6301 TCGv_i64 fp64
= tcg_temp_new_i64();
6302 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6303 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6305 gen_load_fpr32(fp32_0
, fs
);
6306 gen_load_fpr32(fp32_1
, ft
);
6307 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6308 tcg_temp_free_i32(fp32_1
);
6309 tcg_temp_free_i32(fp32_0
);
6310 gen_store_fpr64(ctx
, fp64
, fd
);
6311 tcg_temp_free_i64(fp64
);
6332 TCGv_i32 fp0
= tcg_temp_new_i32();
6333 TCGv_i32 fp1
= tcg_temp_new_i32();
6335 gen_load_fpr32(fp0
, fs
);
6336 gen_load_fpr32(fp1
, ft
);
6337 if (ctx
->opcode
& (1 << 6)) {
6339 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6340 opn
= condnames_abs
[func
-48];
6342 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6343 opn
= condnames
[func
-48];
6345 tcg_temp_free_i32(fp0
);
6346 tcg_temp_free_i32(fp1
);
6350 check_cp1_registers(ctx
, fs
| ft
| fd
);
6352 TCGv_i64 fp0
= tcg_temp_new_i64();
6353 TCGv_i64 fp1
= tcg_temp_new_i64();
6355 gen_load_fpr64(ctx
, fp0
, fs
);
6356 gen_load_fpr64(ctx
, fp1
, ft
);
6357 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6358 tcg_temp_free_i64(fp1
);
6359 gen_store_fpr64(ctx
, fp0
, fd
);
6360 tcg_temp_free_i64(fp0
);
6366 check_cp1_registers(ctx
, fs
| ft
| fd
);
6368 TCGv_i64 fp0
= tcg_temp_new_i64();
6369 TCGv_i64 fp1
= tcg_temp_new_i64();
6371 gen_load_fpr64(ctx
, fp0
, fs
);
6372 gen_load_fpr64(ctx
, fp1
, ft
);
6373 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6374 tcg_temp_free_i64(fp1
);
6375 gen_store_fpr64(ctx
, fp0
, fd
);
6376 tcg_temp_free_i64(fp0
);
6382 check_cp1_registers(ctx
, fs
| ft
| fd
);
6384 TCGv_i64 fp0
= tcg_temp_new_i64();
6385 TCGv_i64 fp1
= tcg_temp_new_i64();
6387 gen_load_fpr64(ctx
, fp0
, fs
);
6388 gen_load_fpr64(ctx
, fp1
, ft
);
6389 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6390 tcg_temp_free_i64(fp1
);
6391 gen_store_fpr64(ctx
, fp0
, fd
);
6392 tcg_temp_free_i64(fp0
);
6398 check_cp1_registers(ctx
, fs
| ft
| fd
);
6400 TCGv_i64 fp0
= tcg_temp_new_i64();
6401 TCGv_i64 fp1
= tcg_temp_new_i64();
6403 gen_load_fpr64(ctx
, fp0
, fs
);
6404 gen_load_fpr64(ctx
, fp1
, ft
);
6405 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6406 tcg_temp_free_i64(fp1
);
6407 gen_store_fpr64(ctx
, fp0
, fd
);
6408 tcg_temp_free_i64(fp0
);
6414 check_cp1_registers(ctx
, fs
| fd
);
6416 TCGv_i64 fp0
= tcg_temp_new_i64();
6418 gen_load_fpr64(ctx
, fp0
, fs
);
6419 gen_helper_float_sqrt_d(fp0
, fp0
);
6420 gen_store_fpr64(ctx
, fp0
, fd
);
6421 tcg_temp_free_i64(fp0
);
6426 check_cp1_registers(ctx
, fs
| fd
);
6428 TCGv_i64 fp0
= tcg_temp_new_i64();
6430 gen_load_fpr64(ctx
, fp0
, fs
);
6431 gen_helper_float_abs_d(fp0
, fp0
);
6432 gen_store_fpr64(ctx
, fp0
, fd
);
6433 tcg_temp_free_i64(fp0
);
6438 check_cp1_registers(ctx
, fs
| fd
);
6440 TCGv_i64 fp0
= tcg_temp_new_i64();
6442 gen_load_fpr64(ctx
, fp0
, fs
);
6443 gen_store_fpr64(ctx
, fp0
, fd
);
6444 tcg_temp_free_i64(fp0
);
6449 check_cp1_registers(ctx
, fs
| fd
);
6451 TCGv_i64 fp0
= tcg_temp_new_i64();
6453 gen_load_fpr64(ctx
, fp0
, fs
);
6454 gen_helper_float_chs_d(fp0
, fp0
);
6455 gen_store_fpr64(ctx
, fp0
, fd
);
6456 tcg_temp_free_i64(fp0
);
6461 check_cp1_64bitmode(ctx
);
6463 TCGv_i64 fp0
= tcg_temp_new_i64();
6465 gen_load_fpr64(ctx
, fp0
, fs
);
6466 gen_helper_float_roundl_d(fp0
, fp0
);
6467 gen_store_fpr64(ctx
, fp0
, fd
);
6468 tcg_temp_free_i64(fp0
);
6473 check_cp1_64bitmode(ctx
);
6475 TCGv_i64 fp0
= tcg_temp_new_i64();
6477 gen_load_fpr64(ctx
, fp0
, fs
);
6478 gen_helper_float_truncl_d(fp0
, fp0
);
6479 gen_store_fpr64(ctx
, fp0
, fd
);
6480 tcg_temp_free_i64(fp0
);
6485 check_cp1_64bitmode(ctx
);
6487 TCGv_i64 fp0
= tcg_temp_new_i64();
6489 gen_load_fpr64(ctx
, fp0
, fs
);
6490 gen_helper_float_ceill_d(fp0
, fp0
);
6491 gen_store_fpr64(ctx
, fp0
, fd
);
6492 tcg_temp_free_i64(fp0
);
6497 check_cp1_64bitmode(ctx
);
6499 TCGv_i64 fp0
= tcg_temp_new_i64();
6501 gen_load_fpr64(ctx
, fp0
, fs
);
6502 gen_helper_float_floorl_d(fp0
, fp0
);
6503 gen_store_fpr64(ctx
, fp0
, fd
);
6504 tcg_temp_free_i64(fp0
);
6509 check_cp1_registers(ctx
, fs
);
6511 TCGv_i32 fp32
= tcg_temp_new_i32();
6512 TCGv_i64 fp64
= tcg_temp_new_i64();
6514 gen_load_fpr64(ctx
, fp64
, fs
);
6515 gen_helper_float_roundw_d(fp32
, fp64
);
6516 tcg_temp_free_i64(fp64
);
6517 gen_store_fpr32(fp32
, fd
);
6518 tcg_temp_free_i32(fp32
);
6523 check_cp1_registers(ctx
, fs
);
6525 TCGv_i32 fp32
= tcg_temp_new_i32();
6526 TCGv_i64 fp64
= tcg_temp_new_i64();
6528 gen_load_fpr64(ctx
, fp64
, fs
);
6529 gen_helper_float_truncw_d(fp32
, fp64
);
6530 tcg_temp_free_i64(fp64
);
6531 gen_store_fpr32(fp32
, fd
);
6532 tcg_temp_free_i32(fp32
);
6537 check_cp1_registers(ctx
, fs
);
6539 TCGv_i32 fp32
= tcg_temp_new_i32();
6540 TCGv_i64 fp64
= tcg_temp_new_i64();
6542 gen_load_fpr64(ctx
, fp64
, fs
);
6543 gen_helper_float_ceilw_d(fp32
, fp64
);
6544 tcg_temp_free_i64(fp64
);
6545 gen_store_fpr32(fp32
, fd
);
6546 tcg_temp_free_i32(fp32
);
6551 check_cp1_registers(ctx
, fs
);
6553 TCGv_i32 fp32
= tcg_temp_new_i32();
6554 TCGv_i64 fp64
= tcg_temp_new_i64();
6556 gen_load_fpr64(ctx
, fp64
, fs
);
6557 gen_helper_float_floorw_d(fp32
, fp64
);
6558 tcg_temp_free_i64(fp64
);
6559 gen_store_fpr32(fp32
, fd
);
6560 tcg_temp_free_i32(fp32
);
6565 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6570 int l1
= gen_new_label();
6574 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6576 fp0
= tcg_temp_new_i64();
6577 gen_load_fpr64(ctx
, fp0
, fs
);
6578 gen_store_fpr64(ctx
, fp0
, fd
);
6579 tcg_temp_free_i64(fp0
);
6586 int l1
= gen_new_label();
6590 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6591 fp0
= tcg_temp_new_i64();
6592 gen_load_fpr64(ctx
, fp0
, fs
);
6593 gen_store_fpr64(ctx
, fp0
, fd
);
6594 tcg_temp_free_i64(fp0
);
6601 check_cp1_64bitmode(ctx
);
6603 TCGv_i64 fp0
= tcg_temp_new_i64();
6605 gen_load_fpr64(ctx
, fp0
, fs
);
6606 gen_helper_float_recip_d(fp0
, fp0
);
6607 gen_store_fpr64(ctx
, fp0
, fd
);
6608 tcg_temp_free_i64(fp0
);
6613 check_cp1_64bitmode(ctx
);
6615 TCGv_i64 fp0
= tcg_temp_new_i64();
6617 gen_load_fpr64(ctx
, fp0
, fs
);
6618 gen_helper_float_rsqrt_d(fp0
, fp0
);
6619 gen_store_fpr64(ctx
, fp0
, fd
);
6620 tcg_temp_free_i64(fp0
);
6625 check_cp1_64bitmode(ctx
);
6627 TCGv_i64 fp0
= tcg_temp_new_i64();
6628 TCGv_i64 fp1
= tcg_temp_new_i64();
6630 gen_load_fpr64(ctx
, fp0
, fs
);
6631 gen_load_fpr64(ctx
, fp1
, ft
);
6632 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6633 tcg_temp_free_i64(fp1
);
6634 gen_store_fpr64(ctx
, fp0
, fd
);
6635 tcg_temp_free_i64(fp0
);
6640 check_cp1_64bitmode(ctx
);
6642 TCGv_i64 fp0
= tcg_temp_new_i64();
6644 gen_load_fpr64(ctx
, fp0
, fs
);
6645 gen_helper_float_recip1_d(fp0
, fp0
);
6646 gen_store_fpr64(ctx
, fp0
, fd
);
6647 tcg_temp_free_i64(fp0
);
6652 check_cp1_64bitmode(ctx
);
6654 TCGv_i64 fp0
= tcg_temp_new_i64();
6656 gen_load_fpr64(ctx
, fp0
, fs
);
6657 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6658 gen_store_fpr64(ctx
, fp0
, fd
);
6659 tcg_temp_free_i64(fp0
);
6664 check_cp1_64bitmode(ctx
);
6666 TCGv_i64 fp0
= tcg_temp_new_i64();
6667 TCGv_i64 fp1
= tcg_temp_new_i64();
6669 gen_load_fpr64(ctx
, fp0
, fs
);
6670 gen_load_fpr64(ctx
, fp1
, ft
);
6671 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6672 tcg_temp_free_i64(fp1
);
6673 gen_store_fpr64(ctx
, fp0
, fd
);
6674 tcg_temp_free_i64(fp0
);
6695 TCGv_i64 fp0
= tcg_temp_new_i64();
6696 TCGv_i64 fp1
= tcg_temp_new_i64();
6698 gen_load_fpr64(ctx
, fp0
, fs
);
6699 gen_load_fpr64(ctx
, fp1
, ft
);
6700 if (ctx
->opcode
& (1 << 6)) {
6702 check_cp1_registers(ctx
, fs
| ft
);
6703 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6704 opn
= condnames_abs
[func
-48];
6706 check_cp1_registers(ctx
, fs
| ft
);
6707 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6708 opn
= condnames
[func
-48];
6710 tcg_temp_free_i64(fp0
);
6711 tcg_temp_free_i64(fp1
);
6715 check_cp1_registers(ctx
, fs
);
6717 TCGv_i32 fp32
= tcg_temp_new_i32();
6718 TCGv_i64 fp64
= tcg_temp_new_i64();
6720 gen_load_fpr64(ctx
, fp64
, fs
);
6721 gen_helper_float_cvts_d(fp32
, fp64
);
6722 tcg_temp_free_i64(fp64
);
6723 gen_store_fpr32(fp32
, fd
);
6724 tcg_temp_free_i32(fp32
);
6729 check_cp1_registers(ctx
, fs
);
6731 TCGv_i32 fp32
= tcg_temp_new_i32();
6732 TCGv_i64 fp64
= tcg_temp_new_i64();
6734 gen_load_fpr64(ctx
, fp64
, fs
);
6735 gen_helper_float_cvtw_d(fp32
, fp64
);
6736 tcg_temp_free_i64(fp64
);
6737 gen_store_fpr32(fp32
, fd
);
6738 tcg_temp_free_i32(fp32
);
6743 check_cp1_64bitmode(ctx
);
6745 TCGv_i64 fp0
= tcg_temp_new_i64();
6747 gen_load_fpr64(ctx
, fp0
, fs
);
6748 gen_helper_float_cvtl_d(fp0
, fp0
);
6749 gen_store_fpr64(ctx
, fp0
, fd
);
6750 tcg_temp_free_i64(fp0
);
6756 TCGv_i32 fp0
= tcg_temp_new_i32();
6758 gen_load_fpr32(fp0
, fs
);
6759 gen_helper_float_cvts_w(fp0
, fp0
);
6760 gen_store_fpr32(fp0
, fd
);
6761 tcg_temp_free_i32(fp0
);
6766 check_cp1_registers(ctx
, fd
);
6768 TCGv_i32 fp32
= tcg_temp_new_i32();
6769 TCGv_i64 fp64
= tcg_temp_new_i64();
6771 gen_load_fpr32(fp32
, fs
);
6772 gen_helper_float_cvtd_w(fp64
, fp32
);
6773 tcg_temp_free_i32(fp32
);
6774 gen_store_fpr64(ctx
, fp64
, fd
);
6775 tcg_temp_free_i64(fp64
);
6780 check_cp1_64bitmode(ctx
);
6782 TCGv_i32 fp32
= tcg_temp_new_i32();
6783 TCGv_i64 fp64
= tcg_temp_new_i64();
6785 gen_load_fpr64(ctx
, fp64
, fs
);
6786 gen_helper_float_cvts_l(fp32
, fp64
);
6787 tcg_temp_free_i64(fp64
);
6788 gen_store_fpr32(fp32
, fd
);
6789 tcg_temp_free_i32(fp32
);
6794 check_cp1_64bitmode(ctx
);
6796 TCGv_i64 fp0
= tcg_temp_new_i64();
6798 gen_load_fpr64(ctx
, fp0
, fs
);
6799 gen_helper_float_cvtd_l(fp0
, fp0
);
6800 gen_store_fpr64(ctx
, fp0
, fd
);
6801 tcg_temp_free_i64(fp0
);
6806 check_cp1_64bitmode(ctx
);
6808 TCGv_i64 fp0
= tcg_temp_new_i64();
6810 gen_load_fpr64(ctx
, fp0
, fs
);
6811 gen_helper_float_cvtps_pw(fp0
, fp0
);
6812 gen_store_fpr64(ctx
, fp0
, fd
);
6813 tcg_temp_free_i64(fp0
);
6818 check_cp1_64bitmode(ctx
);
6820 TCGv_i64 fp0
= tcg_temp_new_i64();
6821 TCGv_i64 fp1
= tcg_temp_new_i64();
6823 gen_load_fpr64(ctx
, fp0
, fs
);
6824 gen_load_fpr64(ctx
, fp1
, ft
);
6825 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6826 tcg_temp_free_i64(fp1
);
6827 gen_store_fpr64(ctx
, fp0
, fd
);
6828 tcg_temp_free_i64(fp0
);
6833 check_cp1_64bitmode(ctx
);
6835 TCGv_i64 fp0
= tcg_temp_new_i64();
6836 TCGv_i64 fp1
= tcg_temp_new_i64();
6838 gen_load_fpr64(ctx
, fp0
, fs
);
6839 gen_load_fpr64(ctx
, fp1
, ft
);
6840 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6841 tcg_temp_free_i64(fp1
);
6842 gen_store_fpr64(ctx
, fp0
, fd
);
6843 tcg_temp_free_i64(fp0
);
6848 check_cp1_64bitmode(ctx
);
6850 TCGv_i64 fp0
= tcg_temp_new_i64();
6851 TCGv_i64 fp1
= tcg_temp_new_i64();
6853 gen_load_fpr64(ctx
, fp0
, fs
);
6854 gen_load_fpr64(ctx
, fp1
, ft
);
6855 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6856 tcg_temp_free_i64(fp1
);
6857 gen_store_fpr64(ctx
, fp0
, fd
);
6858 tcg_temp_free_i64(fp0
);
6863 check_cp1_64bitmode(ctx
);
6865 TCGv_i64 fp0
= tcg_temp_new_i64();
6867 gen_load_fpr64(ctx
, fp0
, fs
);
6868 gen_helper_float_abs_ps(fp0
, fp0
);
6869 gen_store_fpr64(ctx
, fp0
, fd
);
6870 tcg_temp_free_i64(fp0
);
6875 check_cp1_64bitmode(ctx
);
6877 TCGv_i64 fp0
= tcg_temp_new_i64();
6879 gen_load_fpr64(ctx
, fp0
, fs
);
6880 gen_store_fpr64(ctx
, fp0
, fd
);
6881 tcg_temp_free_i64(fp0
);
6886 check_cp1_64bitmode(ctx
);
6888 TCGv_i64 fp0
= tcg_temp_new_i64();
6890 gen_load_fpr64(ctx
, fp0
, fs
);
6891 gen_helper_float_chs_ps(fp0
, fp0
);
6892 gen_store_fpr64(ctx
, fp0
, fd
);
6893 tcg_temp_free_i64(fp0
);
6898 check_cp1_64bitmode(ctx
);
6899 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6903 check_cp1_64bitmode(ctx
);
6905 int l1
= gen_new_label();
6909 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6910 fp0
= tcg_temp_new_i64();
6911 gen_load_fpr64(ctx
, fp0
, fs
);
6912 gen_store_fpr64(ctx
, fp0
, fd
);
6913 tcg_temp_free_i64(fp0
);
6919 check_cp1_64bitmode(ctx
);
6921 int l1
= gen_new_label();
6925 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6926 fp0
= tcg_temp_new_i64();
6927 gen_load_fpr64(ctx
, fp0
, fs
);
6928 gen_store_fpr64(ctx
, fp0
, fd
);
6929 tcg_temp_free_i64(fp0
);
6936 check_cp1_64bitmode(ctx
);
6938 TCGv_i64 fp0
= tcg_temp_new_i64();
6939 TCGv_i64 fp1
= tcg_temp_new_i64();
6941 gen_load_fpr64(ctx
, fp0
, ft
);
6942 gen_load_fpr64(ctx
, fp1
, fs
);
6943 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
6944 tcg_temp_free_i64(fp1
);
6945 gen_store_fpr64(ctx
, fp0
, fd
);
6946 tcg_temp_free_i64(fp0
);
6951 check_cp1_64bitmode(ctx
);
6953 TCGv_i64 fp0
= tcg_temp_new_i64();
6954 TCGv_i64 fp1
= tcg_temp_new_i64();
6956 gen_load_fpr64(ctx
, fp0
, ft
);
6957 gen_load_fpr64(ctx
, fp1
, fs
);
6958 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
6959 tcg_temp_free_i64(fp1
);
6960 gen_store_fpr64(ctx
, fp0
, fd
);
6961 tcg_temp_free_i64(fp0
);
6966 check_cp1_64bitmode(ctx
);
6968 TCGv_i64 fp0
= tcg_temp_new_i64();
6969 TCGv_i64 fp1
= tcg_temp_new_i64();
6971 gen_load_fpr64(ctx
, fp0
, fs
);
6972 gen_load_fpr64(ctx
, fp1
, fd
);
6973 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
6974 tcg_temp_free_i64(fp1
);
6975 gen_store_fpr64(ctx
, fp0
, fd
);
6976 tcg_temp_free_i64(fp0
);
6981 check_cp1_64bitmode(ctx
);
6983 TCGv_i64 fp0
= tcg_temp_new_i64();
6985 gen_load_fpr64(ctx
, fp0
, fs
);
6986 gen_helper_float_recip1_ps(fp0
, fp0
);
6987 gen_store_fpr64(ctx
, fp0
, fd
);
6988 tcg_temp_free_i64(fp0
);
6993 check_cp1_64bitmode(ctx
);
6995 TCGv_i64 fp0
= tcg_temp_new_i64();
6997 gen_load_fpr64(ctx
, fp0
, fs
);
6998 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
6999 gen_store_fpr64(ctx
, fp0
, fd
);
7000 tcg_temp_free_i64(fp0
);
7005 check_cp1_64bitmode(ctx
);
7007 TCGv_i64 fp0
= tcg_temp_new_i64();
7008 TCGv_i64 fp1
= tcg_temp_new_i64();
7010 gen_load_fpr64(ctx
, fp0
, fs
);
7011 gen_load_fpr64(ctx
, fp1
, ft
);
7012 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7013 tcg_temp_free_i64(fp1
);
7014 gen_store_fpr64(ctx
, fp0
, fd
);
7015 tcg_temp_free_i64(fp0
);
7020 check_cp1_64bitmode(ctx
);
7022 TCGv_i32 fp0
= tcg_temp_new_i32();
7024 gen_load_fpr32h(fp0
, fs
);
7025 gen_helper_float_cvts_pu(fp0
, fp0
);
7026 gen_store_fpr32(fp0
, fd
);
7027 tcg_temp_free_i32(fp0
);
7032 check_cp1_64bitmode(ctx
);
7034 TCGv_i64 fp0
= tcg_temp_new_i64();
7036 gen_load_fpr64(ctx
, fp0
, fs
);
7037 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7038 gen_store_fpr64(ctx
, fp0
, fd
);
7039 tcg_temp_free_i64(fp0
);
7044 check_cp1_64bitmode(ctx
);
7046 TCGv_i32 fp0
= tcg_temp_new_i32();
7048 gen_load_fpr32(fp0
, fs
);
7049 gen_helper_float_cvts_pl(fp0
, fp0
);
7050 gen_store_fpr32(fp0
, fd
);
7051 tcg_temp_free_i32(fp0
);
7056 check_cp1_64bitmode(ctx
);
7058 TCGv_i32 fp0
= tcg_temp_new_i32();
7059 TCGv_i32 fp1
= tcg_temp_new_i32();
7061 gen_load_fpr32(fp0
, fs
);
7062 gen_load_fpr32(fp1
, ft
);
7063 gen_store_fpr32h(fp0
, fd
);
7064 gen_store_fpr32(fp1
, fd
);
7065 tcg_temp_free_i32(fp0
);
7066 tcg_temp_free_i32(fp1
);
7071 check_cp1_64bitmode(ctx
);
7073 TCGv_i32 fp0
= tcg_temp_new_i32();
7074 TCGv_i32 fp1
= tcg_temp_new_i32();
7076 gen_load_fpr32(fp0
, fs
);
7077 gen_load_fpr32h(fp1
, ft
);
7078 gen_store_fpr32(fp1
, fd
);
7079 gen_store_fpr32h(fp0
, fd
);
7080 tcg_temp_free_i32(fp0
);
7081 tcg_temp_free_i32(fp1
);
7086 check_cp1_64bitmode(ctx
);
7088 TCGv_i32 fp0
= tcg_temp_new_i32();
7089 TCGv_i32 fp1
= tcg_temp_new_i32();
7091 gen_load_fpr32h(fp0
, fs
);
7092 gen_load_fpr32(fp1
, ft
);
7093 gen_store_fpr32(fp1
, fd
);
7094 gen_store_fpr32h(fp0
, fd
);
7095 tcg_temp_free_i32(fp0
);
7096 tcg_temp_free_i32(fp1
);
7101 check_cp1_64bitmode(ctx
);
7103 TCGv_i32 fp0
= tcg_temp_new_i32();
7104 TCGv_i32 fp1
= tcg_temp_new_i32();
7106 gen_load_fpr32h(fp0
, fs
);
7107 gen_load_fpr32h(fp1
, ft
);
7108 gen_store_fpr32(fp1
, fd
);
7109 gen_store_fpr32h(fp0
, fd
);
7110 tcg_temp_free_i32(fp0
);
7111 tcg_temp_free_i32(fp1
);
7131 check_cp1_64bitmode(ctx
);
7133 TCGv_i64 fp0
= tcg_temp_new_i64();
7134 TCGv_i64 fp1
= tcg_temp_new_i64();
7136 gen_load_fpr64(ctx
, fp0
, fs
);
7137 gen_load_fpr64(ctx
, fp1
, ft
);
7138 if (ctx
->opcode
& (1 << 6)) {
7139 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7140 opn
= condnames_abs
[func
-48];
7142 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7143 opn
= condnames
[func
-48];
7145 tcg_temp_free_i64(fp0
);
7146 tcg_temp_free_i64(fp1
);
7151 generate_exception (ctx
, EXCP_RI
);
7156 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7159 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7162 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7167 /* Coprocessor 3 (FPU) */
7168 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7169 int fd
, int fs
, int base
, int index
)
7171 const char *opn
= "extended float load/store";
7173 TCGv t0
= tcg_temp_new();
7176 gen_load_gpr(t0
, index
);
7177 } else if (index
== 0) {
7178 gen_load_gpr(t0
, base
);
7180 gen_load_gpr(t0
, index
);
7181 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
], t0
);
7183 /* Don't do NOP if destination is zero: we must perform the actual
7185 save_cpu_state(ctx
, 0);
7190 TCGv_i32 fp0
= tcg_temp_new_i32();
7192 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7193 tcg_gen_trunc_tl_i32(fp0
, t0
);
7194 gen_store_fpr32(fp0
, fd
);
7195 tcg_temp_free_i32(fp0
);
7201 check_cp1_registers(ctx
, fd
);
7203 TCGv_i64 fp0
= tcg_temp_new_i64();
7205 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7206 gen_store_fpr64(ctx
, fp0
, fd
);
7207 tcg_temp_free_i64(fp0
);
7212 check_cp1_64bitmode(ctx
);
7213 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7215 TCGv_i64 fp0
= tcg_temp_new_i64();
7217 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7218 gen_store_fpr64(ctx
, fp0
, fd
);
7219 tcg_temp_free_i64(fp0
);
7226 TCGv_i32 fp0
= tcg_temp_new_i32();
7227 TCGv t1
= tcg_temp_new();
7229 gen_load_fpr32(fp0
, fs
);
7230 tcg_gen_extu_i32_tl(t1
, fp0
);
7231 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7232 tcg_temp_free_i32(fp0
);
7240 check_cp1_registers(ctx
, fs
);
7242 TCGv_i64 fp0
= tcg_temp_new_i64();
7244 gen_load_fpr64(ctx
, fp0
, fs
);
7245 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7246 tcg_temp_free_i64(fp0
);
7252 check_cp1_64bitmode(ctx
);
7253 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7255 TCGv_i64 fp0
= tcg_temp_new_i64();
7257 gen_load_fpr64(ctx
, fp0
, fs
);
7258 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7259 tcg_temp_free_i64(fp0
);
7266 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7267 regnames
[index
], regnames
[base
]);
7270 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7271 int fd
, int fr
, int fs
, int ft
)
7273 const char *opn
= "flt3_arith";
7277 check_cp1_64bitmode(ctx
);
7279 TCGv t0
= tcg_temp_local_new();
7280 TCGv_i32 fp
= tcg_temp_new_i32();
7281 TCGv_i32 fph
= tcg_temp_new_i32();
7282 int l1
= gen_new_label();
7283 int l2
= gen_new_label();
7285 gen_load_gpr(t0
, fr
);
7286 tcg_gen_andi_tl(t0
, t0
, 0x7);
7288 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7289 gen_load_fpr32(fp
, fs
);
7290 gen_load_fpr32h(fph
, fs
);
7291 gen_store_fpr32(fp
, fd
);
7292 gen_store_fpr32h(fph
, fd
);
7295 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7297 #ifdef TARGET_WORDS_BIGENDIAN
7298 gen_load_fpr32(fp
, fs
);
7299 gen_load_fpr32h(fph
, ft
);
7300 gen_store_fpr32h(fp
, fd
);
7301 gen_store_fpr32(fph
, fd
);
7303 gen_load_fpr32h(fph
, fs
);
7304 gen_load_fpr32(fp
, ft
);
7305 gen_store_fpr32(fph
, fd
);
7306 gen_store_fpr32h(fp
, fd
);
7309 tcg_temp_free_i32(fp
);
7310 tcg_temp_free_i32(fph
);
7317 TCGv_i32 fp0
= tcg_temp_new_i32();
7318 TCGv_i32 fp1
= tcg_temp_new_i32();
7319 TCGv_i32 fp2
= tcg_temp_new_i32();
7321 gen_load_fpr32(fp0
, fs
);
7322 gen_load_fpr32(fp1
, ft
);
7323 gen_load_fpr32(fp2
, fr
);
7324 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7325 tcg_temp_free_i32(fp0
);
7326 tcg_temp_free_i32(fp1
);
7327 gen_store_fpr32(fp2
, fd
);
7328 tcg_temp_free_i32(fp2
);
7334 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7336 TCGv_i64 fp0
= tcg_temp_new_i64();
7337 TCGv_i64 fp1
= tcg_temp_new_i64();
7338 TCGv_i64 fp2
= tcg_temp_new_i64();
7340 gen_load_fpr64(ctx
, fp0
, fs
);
7341 gen_load_fpr64(ctx
, fp1
, ft
);
7342 gen_load_fpr64(ctx
, fp2
, fr
);
7343 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7344 tcg_temp_free_i64(fp0
);
7345 tcg_temp_free_i64(fp1
);
7346 gen_store_fpr64(ctx
, fp2
, fd
);
7347 tcg_temp_free_i64(fp2
);
7352 check_cp1_64bitmode(ctx
);
7354 TCGv_i64 fp0
= tcg_temp_new_i64();
7355 TCGv_i64 fp1
= tcg_temp_new_i64();
7356 TCGv_i64 fp2
= tcg_temp_new_i64();
7358 gen_load_fpr64(ctx
, fp0
, fs
);
7359 gen_load_fpr64(ctx
, fp1
, ft
);
7360 gen_load_fpr64(ctx
, fp2
, fr
);
7361 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7362 tcg_temp_free_i64(fp0
);
7363 tcg_temp_free_i64(fp1
);
7364 gen_store_fpr64(ctx
, fp2
, fd
);
7365 tcg_temp_free_i64(fp2
);
7372 TCGv_i32 fp0
= tcg_temp_new_i32();
7373 TCGv_i32 fp1
= tcg_temp_new_i32();
7374 TCGv_i32 fp2
= tcg_temp_new_i32();
7376 gen_load_fpr32(fp0
, fs
);
7377 gen_load_fpr32(fp1
, ft
);
7378 gen_load_fpr32(fp2
, fr
);
7379 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7380 tcg_temp_free_i32(fp0
);
7381 tcg_temp_free_i32(fp1
);
7382 gen_store_fpr32(fp2
, fd
);
7383 tcg_temp_free_i32(fp2
);
7389 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7391 TCGv_i64 fp0
= tcg_temp_new_i64();
7392 TCGv_i64 fp1
= tcg_temp_new_i64();
7393 TCGv_i64 fp2
= tcg_temp_new_i64();
7395 gen_load_fpr64(ctx
, fp0
, fs
);
7396 gen_load_fpr64(ctx
, fp1
, ft
);
7397 gen_load_fpr64(ctx
, fp2
, fr
);
7398 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7399 tcg_temp_free_i64(fp0
);
7400 tcg_temp_free_i64(fp1
);
7401 gen_store_fpr64(ctx
, fp2
, fd
);
7402 tcg_temp_free_i64(fp2
);
7407 check_cp1_64bitmode(ctx
);
7409 TCGv_i64 fp0
= tcg_temp_new_i64();
7410 TCGv_i64 fp1
= tcg_temp_new_i64();
7411 TCGv_i64 fp2
= tcg_temp_new_i64();
7413 gen_load_fpr64(ctx
, fp0
, fs
);
7414 gen_load_fpr64(ctx
, fp1
, ft
);
7415 gen_load_fpr64(ctx
, fp2
, fr
);
7416 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7417 tcg_temp_free_i64(fp0
);
7418 tcg_temp_free_i64(fp1
);
7419 gen_store_fpr64(ctx
, fp2
, fd
);
7420 tcg_temp_free_i64(fp2
);
7427 TCGv_i32 fp0
= tcg_temp_new_i32();
7428 TCGv_i32 fp1
= tcg_temp_new_i32();
7429 TCGv_i32 fp2
= tcg_temp_new_i32();
7431 gen_load_fpr32(fp0
, fs
);
7432 gen_load_fpr32(fp1
, ft
);
7433 gen_load_fpr32(fp2
, fr
);
7434 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7435 tcg_temp_free_i32(fp0
);
7436 tcg_temp_free_i32(fp1
);
7437 gen_store_fpr32(fp2
, fd
);
7438 tcg_temp_free_i32(fp2
);
7444 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7446 TCGv_i64 fp0
= tcg_temp_new_i64();
7447 TCGv_i64 fp1
= tcg_temp_new_i64();
7448 TCGv_i64 fp2
= tcg_temp_new_i64();
7450 gen_load_fpr64(ctx
, fp0
, fs
);
7451 gen_load_fpr64(ctx
, fp1
, ft
);
7452 gen_load_fpr64(ctx
, fp2
, fr
);
7453 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7454 tcg_temp_free_i64(fp0
);
7455 tcg_temp_free_i64(fp1
);
7456 gen_store_fpr64(ctx
, fp2
, fd
);
7457 tcg_temp_free_i64(fp2
);
7462 check_cp1_64bitmode(ctx
);
7464 TCGv_i64 fp0
= tcg_temp_new_i64();
7465 TCGv_i64 fp1
= tcg_temp_new_i64();
7466 TCGv_i64 fp2
= tcg_temp_new_i64();
7468 gen_load_fpr64(ctx
, fp0
, fs
);
7469 gen_load_fpr64(ctx
, fp1
, ft
);
7470 gen_load_fpr64(ctx
, fp2
, fr
);
7471 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7472 tcg_temp_free_i64(fp0
);
7473 tcg_temp_free_i64(fp1
);
7474 gen_store_fpr64(ctx
, fp2
, fd
);
7475 tcg_temp_free_i64(fp2
);
7482 TCGv_i32 fp0
= tcg_temp_new_i32();
7483 TCGv_i32 fp1
= tcg_temp_new_i32();
7484 TCGv_i32 fp2
= tcg_temp_new_i32();
7486 gen_load_fpr32(fp0
, fs
);
7487 gen_load_fpr32(fp1
, ft
);
7488 gen_load_fpr32(fp2
, fr
);
7489 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7490 tcg_temp_free_i32(fp0
);
7491 tcg_temp_free_i32(fp1
);
7492 gen_store_fpr32(fp2
, fd
);
7493 tcg_temp_free_i32(fp2
);
7499 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7501 TCGv_i64 fp0
= tcg_temp_new_i64();
7502 TCGv_i64 fp1
= tcg_temp_new_i64();
7503 TCGv_i64 fp2
= tcg_temp_new_i64();
7505 gen_load_fpr64(ctx
, fp0
, fs
);
7506 gen_load_fpr64(ctx
, fp1
, ft
);
7507 gen_load_fpr64(ctx
, fp2
, fr
);
7508 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7509 tcg_temp_free_i64(fp0
);
7510 tcg_temp_free_i64(fp1
);
7511 gen_store_fpr64(ctx
, fp2
, fd
);
7512 tcg_temp_free_i64(fp2
);
7517 check_cp1_64bitmode(ctx
);
7519 TCGv_i64 fp0
= tcg_temp_new_i64();
7520 TCGv_i64 fp1
= tcg_temp_new_i64();
7521 TCGv_i64 fp2
= tcg_temp_new_i64();
7523 gen_load_fpr64(ctx
, fp0
, fs
);
7524 gen_load_fpr64(ctx
, fp1
, ft
);
7525 gen_load_fpr64(ctx
, fp2
, fr
);
7526 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7527 tcg_temp_free_i64(fp0
);
7528 tcg_temp_free_i64(fp1
);
7529 gen_store_fpr64(ctx
, fp2
, fd
);
7530 tcg_temp_free_i64(fp2
);
7536 generate_exception (ctx
, EXCP_RI
);
7539 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7540 fregnames
[fs
], fregnames
[ft
]);
7543 /* ISA extensions (ASEs) */
7544 /* MIPS16 extension to MIPS32 */
7545 /* SmartMIPS extension to MIPS32 */
7547 #if defined(TARGET_MIPS64)
7549 /* MDMX extension to MIPS64 */
7553 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7557 uint32_t op
, op1
, op2
;
7560 /* make sure instructions are on a word boundary */
7561 if (ctx
->pc
& 0x3) {
7562 env
->CP0_BadVAddr
= ctx
->pc
;
7563 generate_exception(ctx
, EXCP_AdEL
);
7567 /* Handle blikely not taken case */
7568 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7569 int l1
= gen_new_label();
7571 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7572 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7573 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7574 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7578 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
7579 tcg_gen_debug_insn_start(ctx
->pc
);
7581 op
= MASK_OP_MAJOR(ctx
->opcode
);
7582 rs
= (ctx
->opcode
>> 21) & 0x1f;
7583 rt
= (ctx
->opcode
>> 16) & 0x1f;
7584 rd
= (ctx
->opcode
>> 11) & 0x1f;
7585 sa
= (ctx
->opcode
>> 6) & 0x1f;
7586 imm
= (int16_t)ctx
->opcode
;
7589 op1
= MASK_SPECIAL(ctx
->opcode
);
7591 case OPC_SLL
: /* Shift with immediate */
7593 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7596 switch ((ctx
->opcode
>> 21) & 0x1f) {
7598 /* rotr is decoded as srl on non-R2 CPUs */
7599 if (env
->insn_flags
& ISA_MIPS32R2
) {
7604 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7607 generate_exception(ctx
, EXCP_RI
);
7611 case OPC_MOVN
: /* Conditional move */
7613 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7614 gen_cond_move(env
, op1
, rd
, rs
, rt
);
7616 case OPC_ADD
... OPC_SUBU
:
7617 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7619 case OPC_SLLV
: /* Shifts */
7621 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7624 switch ((ctx
->opcode
>> 6) & 0x1f) {
7626 /* rotrv is decoded as srlv on non-R2 CPUs */
7627 if (env
->insn_flags
& ISA_MIPS32R2
) {
7632 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7635 generate_exception(ctx
, EXCP_RI
);
7639 case OPC_SLT
: /* Set on less than */
7641 gen_slt(env
, op1
, rd
, rs
, rt
);
7643 case OPC_AND
: /* Logic*/
7647 gen_logic(env
, op1
, rd
, rs
, rt
);
7649 case OPC_MULT
... OPC_DIVU
:
7651 check_insn(env
, ctx
, INSN_VR54XX
);
7652 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7653 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7655 gen_muldiv(ctx
, op1
, rs
, rt
);
7657 case OPC_JR
... OPC_JALR
:
7658 gen_compute_branch(ctx
, op1
, 4, rs
, rd
, sa
);
7660 case OPC_TGE
... OPC_TEQ
: /* Traps */
7662 gen_trap(ctx
, op1
, rs
, rt
, -1);
7664 case OPC_MFHI
: /* Move from HI/LO */
7666 gen_HILO(ctx
, op1
, rd
);
7669 case OPC_MTLO
: /* Move to HI/LO */
7670 gen_HILO(ctx
, op1
, rs
);
7672 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7673 #ifdef MIPS_STRICT_STANDARD
7674 MIPS_INVAL("PMON / selsl");
7675 generate_exception(ctx
, EXCP_RI
);
7677 gen_helper_0i(pmon
, sa
);
7681 generate_exception(ctx
, EXCP_SYSCALL
);
7682 ctx
->bstate
= BS_STOP
;
7685 generate_exception(ctx
, EXCP_BREAK
);
7688 #ifdef MIPS_STRICT_STANDARD
7690 generate_exception(ctx
, EXCP_RI
);
7692 /* Implemented as RI exception for now. */
7693 MIPS_INVAL("spim (unofficial)");
7694 generate_exception(ctx
, EXCP_RI
);
7702 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7703 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7704 check_cp1_enabled(ctx
);
7705 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7706 (ctx
->opcode
>> 16) & 1);
7708 generate_exception_err(ctx
, EXCP_CpU
, 1);
7712 #if defined(TARGET_MIPS64)
7713 /* MIPS64 specific opcodes */
7718 check_insn(env
, ctx
, ISA_MIPS3
);
7720 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7723 switch ((ctx
->opcode
>> 21) & 0x1f) {
7725 /* drotr is decoded as dsrl on non-R2 CPUs */
7726 if (env
->insn_flags
& ISA_MIPS32R2
) {
7731 check_insn(env
, ctx
, ISA_MIPS3
);
7733 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7736 generate_exception(ctx
, EXCP_RI
);
7741 switch ((ctx
->opcode
>> 21) & 0x1f) {
7743 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
7744 if (env
->insn_flags
& ISA_MIPS32R2
) {
7749 check_insn(env
, ctx
, ISA_MIPS3
);
7751 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7754 generate_exception(ctx
, EXCP_RI
);
7758 case OPC_DADD
... OPC_DSUBU
:
7759 check_insn(env
, ctx
, ISA_MIPS3
);
7761 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7765 check_insn(env
, ctx
, ISA_MIPS3
);
7767 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7770 switch ((ctx
->opcode
>> 6) & 0x1f) {
7772 /* drotrv is decoded as dsrlv on non-R2 CPUs */
7773 if (env
->insn_flags
& ISA_MIPS32R2
) {
7778 check_insn(env
, ctx
, ISA_MIPS3
);
7780 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7783 generate_exception(ctx
, EXCP_RI
);
7787 case OPC_DMULT
... OPC_DDIVU
:
7788 check_insn(env
, ctx
, ISA_MIPS3
);
7790 gen_muldiv(ctx
, op1
, rs
, rt
);
7793 default: /* Invalid */
7794 MIPS_INVAL("special");
7795 generate_exception(ctx
, EXCP_RI
);
7800 op1
= MASK_SPECIAL2(ctx
->opcode
);
7802 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7803 case OPC_MSUB
... OPC_MSUBU
:
7804 check_insn(env
, ctx
, ISA_MIPS32
);
7805 gen_muldiv(ctx
, op1
, rs
, rt
);
7808 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7812 check_insn(env
, ctx
, ISA_MIPS32
);
7813 gen_cl(ctx
, op1
, rd
, rs
);
7816 /* XXX: not clear which exception should be raised
7817 * when in debug mode...
7819 check_insn(env
, ctx
, ISA_MIPS32
);
7820 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7821 generate_exception(ctx
, EXCP_DBp
);
7823 generate_exception(ctx
, EXCP_DBp
);
7827 #if defined(TARGET_MIPS64)
7830 check_insn(env
, ctx
, ISA_MIPS64
);
7832 gen_cl(ctx
, op1
, rd
, rs
);
7835 default: /* Invalid */
7836 MIPS_INVAL("special2");
7837 generate_exception(ctx
, EXCP_RI
);
7842 op1
= MASK_SPECIAL3(ctx
->opcode
);
7846 check_insn(env
, ctx
, ISA_MIPS32R2
);
7847 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7850 check_insn(env
, ctx
, ISA_MIPS32R2
);
7851 op2
= MASK_BSHFL(ctx
->opcode
);
7852 gen_bshfl(ctx
, op2
, rt
, rd
);
7855 check_insn(env
, ctx
, ISA_MIPS32R2
);
7857 TCGv t0
= tcg_temp_new();
7861 save_cpu_state(ctx
, 1);
7862 gen_helper_rdhwr_cpunum(t0
);
7863 gen_store_gpr(t0
, rt
);
7866 save_cpu_state(ctx
, 1);
7867 gen_helper_rdhwr_synci_step(t0
);
7868 gen_store_gpr(t0
, rt
);
7871 save_cpu_state(ctx
, 1);
7872 gen_helper_rdhwr_cc(t0
);
7873 gen_store_gpr(t0
, rt
);
7876 save_cpu_state(ctx
, 1);
7877 gen_helper_rdhwr_ccres(t0
);
7878 gen_store_gpr(t0
, rt
);
7881 #if defined(CONFIG_USER_ONLY)
7882 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7883 gen_store_gpr(t0
, rt
);
7886 /* XXX: Some CPUs implement this in hardware.
7887 Not supported yet. */
7889 default: /* Invalid */
7890 MIPS_INVAL("rdhwr");
7891 generate_exception(ctx
, EXCP_RI
);
7898 check_insn(env
, ctx
, ASE_MT
);
7900 TCGv t0
= tcg_temp_new();
7901 TCGv t1
= tcg_temp_new();
7903 gen_load_gpr(t0
, rt
);
7904 gen_load_gpr(t1
, rs
);
7905 gen_helper_fork(t0
, t1
);
7911 check_insn(env
, ctx
, ASE_MT
);
7913 TCGv t0
= tcg_temp_new();
7915 save_cpu_state(ctx
, 1);
7916 gen_load_gpr(t0
, rs
);
7917 gen_helper_yield(t0
, t0
);
7918 gen_store_gpr(t0
, rd
);
7922 #if defined(TARGET_MIPS64)
7923 case OPC_DEXTM
... OPC_DEXT
:
7924 case OPC_DINSM
... OPC_DINS
:
7925 check_insn(env
, ctx
, ISA_MIPS64R2
);
7927 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7930 check_insn(env
, ctx
, ISA_MIPS64R2
);
7932 op2
= MASK_DBSHFL(ctx
->opcode
);
7933 gen_bshfl(ctx
, op2
, rt
, rd
);
7936 default: /* Invalid */
7937 MIPS_INVAL("special3");
7938 generate_exception(ctx
, EXCP_RI
);
7943 op1
= MASK_REGIMM(ctx
->opcode
);
7945 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
7946 case OPC_BLTZAL
... OPC_BGEZALL
:
7947 gen_compute_branch(ctx
, op1
, 4, rs
, -1, imm
<< 2);
7949 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
7951 gen_trap(ctx
, op1
, rs
, -1, imm
);
7954 check_insn(env
, ctx
, ISA_MIPS32R2
);
7957 default: /* Invalid */
7958 MIPS_INVAL("regimm");
7959 generate_exception(ctx
, EXCP_RI
);
7964 check_cp0_enabled(ctx
);
7965 op1
= MASK_CP0(ctx
->opcode
);
7971 #if defined(TARGET_MIPS64)
7975 #ifndef CONFIG_USER_ONLY
7976 gen_cp0(env
, ctx
, op1
, rt
, rd
);
7977 #endif /* !CONFIG_USER_ONLY */
7979 case OPC_C0_FIRST
... OPC_C0_LAST
:
7980 #ifndef CONFIG_USER_ONLY
7981 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
7982 #endif /* !CONFIG_USER_ONLY */
7985 #ifndef CONFIG_USER_ONLY
7987 TCGv t0
= tcg_temp_new();
7989 op2
= MASK_MFMC0(ctx
->opcode
);
7992 check_insn(env
, ctx
, ASE_MT
);
7993 gen_helper_dmt(t0
, t0
);
7994 gen_store_gpr(t0
, rt
);
7997 check_insn(env
, ctx
, ASE_MT
);
7998 gen_helper_emt(t0
, t0
);
7999 gen_store_gpr(t0
, rt
);
8002 check_insn(env
, ctx
, ASE_MT
);
8003 gen_helper_dvpe(t0
, t0
);
8004 gen_store_gpr(t0
, rt
);
8007 check_insn(env
, ctx
, ASE_MT
);
8008 gen_helper_evpe(t0
, t0
);
8009 gen_store_gpr(t0
, rt
);
8012 check_insn(env
, ctx
, ISA_MIPS32R2
);
8013 save_cpu_state(ctx
, 1);
8015 gen_store_gpr(t0
, rt
);
8016 /* Stop translation as we may have switched the execution mode */
8017 ctx
->bstate
= BS_STOP
;
8020 check_insn(env
, ctx
, ISA_MIPS32R2
);
8021 save_cpu_state(ctx
, 1);
8023 gen_store_gpr(t0
, rt
);
8024 /* Stop translation as we may have switched the execution mode */
8025 ctx
->bstate
= BS_STOP
;
8027 default: /* Invalid */
8028 MIPS_INVAL("mfmc0");
8029 generate_exception(ctx
, EXCP_RI
);
8034 #endif /* !CONFIG_USER_ONLY */
8037 check_insn(env
, ctx
, ISA_MIPS32R2
);
8038 gen_load_srsgpr(rt
, rd
);
8041 check_insn(env
, ctx
, ISA_MIPS32R2
);
8042 gen_store_srsgpr(rt
, rd
);
8046 generate_exception(ctx
, EXCP_RI
);
8050 case OPC_ADDI
: /* Arithmetic with immediate opcode */
8052 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8054 case OPC_SLTI
: /* Set on less than with immediate opcode */
8056 gen_slt_imm(env
, op
, rt
, rs
, imm
);
8058 case OPC_ANDI
: /* Arithmetic with immediate opcode */
8062 gen_logic_imm(env
, op
, rt
, rs
, imm
);
8064 case OPC_J
... OPC_JAL
: /* Jump */
8065 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
8066 gen_compute_branch(ctx
, op
, 4, rs
, rt
, offset
);
8068 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
8069 case OPC_BEQL
... OPC_BGTZL
:
8070 gen_compute_branch(ctx
, op
, 4, rs
, rt
, imm
<< 2);
8072 case OPC_LB
... OPC_LWR
: /* Load and stores */
8073 case OPC_SB
... OPC_SW
:
8076 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8079 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
8082 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
8086 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8090 /* Floating point (COP1). */
8095 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8096 check_cp1_enabled(ctx
);
8097 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
8099 generate_exception_err(ctx
, EXCP_CpU
, 1);
8104 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8105 check_cp1_enabled(ctx
);
8106 op1
= MASK_CP1(ctx
->opcode
);
8110 check_insn(env
, ctx
, ISA_MIPS32R2
);
8115 gen_cp1(ctx
, op1
, rt
, rd
);
8117 #if defined(TARGET_MIPS64)
8120 check_insn(env
, ctx
, ISA_MIPS3
);
8121 gen_cp1(ctx
, op1
, rt
, rd
);
8127 check_insn(env
, ctx
, ASE_MIPS3D
);
8130 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
8131 (rt
>> 2) & 0x7, imm
<< 2);
8138 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
8143 generate_exception (ctx
, EXCP_RI
);
8147 generate_exception_err(ctx
, EXCP_CpU
, 1);
8157 /* COP2: Not implemented. */
8158 generate_exception_err(ctx
, EXCP_CpU
, 2);
8162 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8163 check_cp1_enabled(ctx
);
8164 op1
= MASK_CP3(ctx
->opcode
);
8172 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
8190 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
8194 generate_exception (ctx
, EXCP_RI
);
8198 generate_exception_err(ctx
, EXCP_CpU
, 1);
8202 #if defined(TARGET_MIPS64)
8203 /* MIPS64 opcodes */
8205 case OPC_LDL
... OPC_LDR
:
8206 case OPC_SDL
... OPC_SDR
:
8210 check_insn(env
, ctx
, ISA_MIPS3
);
8212 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8215 check_insn(env
, ctx
, ISA_MIPS3
);
8217 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
8221 check_insn(env
, ctx
, ISA_MIPS3
);
8223 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8227 check_insn(env
, ctx
, ASE_MIPS16
);
8228 /* MIPS16: Not implemented. */
8230 check_insn(env
, ctx
, ASE_MDMX
);
8231 /* MDMX: Not implemented. */
8232 default: /* Invalid */
8233 MIPS_INVAL("major opcode");
8234 generate_exception(ctx
, EXCP_RI
);
8237 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8238 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8239 /* Branches completion */
8240 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8241 ctx
->bstate
= BS_BRANCH
;
8242 save_cpu_state(ctx
, 0);
8243 /* FIXME: Need to clear can_do_io. */
8246 /* unconditional branch */
8247 MIPS_DEBUG("unconditional branch");
8248 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8251 /* blikely taken case */
8252 MIPS_DEBUG("blikely branch taken");
8253 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8256 /* Conditional branch */
8257 MIPS_DEBUG("conditional branch");
8259 int l1
= gen_new_label();
8261 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8262 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8264 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8268 /* unconditional branch to register */
8269 MIPS_DEBUG("branch to register");
8270 tcg_gen_mov_tl(cpu_PC
, btarget
);
8271 if (ctx
->singlestep_enabled
) {
8272 save_cpu_state(ctx
, 0);
8273 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8278 MIPS_DEBUG("unknown branch");
8285 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
8289 target_ulong pc_start
;
8290 uint16_t *gen_opc_end
;
8297 qemu_log("search pc %d\n", search_pc
);
8300 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
8303 ctx
.singlestep_enabled
= env
->singlestep_enabled
;
8305 ctx
.bstate
= BS_NONE
;
8306 /* Restore delay slot state from the tb context. */
8307 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
8308 restore_cpu_state(env
, &ctx
);
8309 #ifdef CONFIG_USER_ONLY
8310 ctx
.mem_idx
= MIPS_HFLAG_UM
;
8312 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
8315 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8317 max_insns
= CF_COUNT_MASK
;
8319 qemu_log_mask(CPU_LOG_TB_CPU
, "------------------------------------------------\n");
8320 /* FIXME: This may print out stale hflags from env... */
8321 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
8323 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
8325 while (ctx
.bstate
== BS_NONE
) {
8326 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
8327 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
8328 if (bp
->pc
== ctx
.pc
) {
8329 save_cpu_state(&ctx
, 1);
8330 ctx
.bstate
= BS_BRANCH
;
8331 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8332 /* Include the breakpoint location or the tb won't
8333 * be flushed when it must be. */
8335 goto done_generating
;
8341 j
= gen_opc_ptr
- gen_opc_buf
;
8345 gen_opc_instr_start
[lj
++] = 0;
8347 gen_opc_pc
[lj
] = ctx
.pc
;
8348 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
8349 gen_opc_instr_start
[lj
] = 1;
8350 gen_opc_icount
[lj
] = num_insns
;
8352 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8354 ctx
.opcode
= ldl_code(ctx
.pc
);
8355 decode_opc(env
, &ctx
);
8359 /* Execute a branch and its delay slot as a single instruction.
8360 This is what GDB expects and is consistent with what the
8361 hardware does (e.g. if a delay slot instruction faults, the
8362 reported PC is the PC of the branch). */
8363 if (env
->singlestep_enabled
&& (ctx
.hflags
& MIPS_HFLAG_BMASK
) == 0)
8366 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
8369 if (gen_opc_ptr
>= gen_opc_end
)
8372 if (num_insns
>= max_insns
)
8378 if (tb
->cflags
& CF_LAST_IO
)
8380 if (env
->singlestep_enabled
&& ctx
.bstate
!= BS_BRANCH
) {
8381 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
8382 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8384 switch (ctx
.bstate
) {
8386 gen_helper_interrupt_restart();
8387 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8390 save_cpu_state(&ctx
, 0);
8391 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8394 gen_helper_interrupt_restart();
8403 gen_icount_end(tb
, num_insns
);
8404 *gen_opc_ptr
= INDEX_op_end
;
8406 j
= gen_opc_ptr
- gen_opc_buf
;
8409 gen_opc_instr_start
[lj
++] = 0;
8411 tb
->size
= ctx
.pc
- pc_start
;
8412 tb
->icount
= num_insns
;
8416 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
8417 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
8418 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
8421 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
8425 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
8427 gen_intermediate_code_internal(env
, tb
, 0);
8430 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
8432 gen_intermediate_code_internal(env
, tb
, 1);
8435 static void fpu_dump_state(CPUState
*env
, FILE *f
,
8436 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8440 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
8442 #define printfpr(fp) \
8445 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8446 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8447 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8450 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8451 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8452 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8453 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8454 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8459 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8460 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
8461 get_float_exception_flags(&env
->active_fpu
.fp_status
));
8462 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
8463 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
8464 printfpr(&env
->active_fpu
.fpr
[i
]);
8470 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8471 /* Debug help: The architecture requires 32bit code to maintain proper
8472 sign-extended values on 64bit machines. */
8474 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8477 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
8478 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8483 if (!SIGN_EXT_P(env
->active_tc
.PC
))
8484 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
8485 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
8486 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
8487 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
8488 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
8489 if (!SIGN_EXT_P(env
->btarget
))
8490 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
8492 for (i
= 0; i
< 32; i
++) {
8493 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
8494 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
8497 if (!SIGN_EXT_P(env
->CP0_EPC
))
8498 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
8499 if (!SIGN_EXT_P(env
->lladdr
))
8500 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->lladdr
);
8504 void cpu_dump_state (CPUState
*env
, FILE *f
,
8505 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8510 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",
8511 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
8512 env
->hflags
, env
->btarget
, env
->bcond
);
8513 for (i
= 0; i
< 32; i
++) {
8515 cpu_fprintf(f
, "GPR%02d:", i
);
8516 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
8518 cpu_fprintf(f
, "\n");
8521 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
8522 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
8523 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
8524 env
->CP0_Config0
, env
->CP0_Config1
, env
->lladdr
);
8525 if (env
->hflags
& MIPS_HFLAG_FPU
)
8526 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
8527 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8528 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
8532 static void mips_tcg_init(void)
8537 /* Initialize various static tables. */
8541 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
8542 TCGV_UNUSED(cpu_gpr
[0]);
8543 for (i
= 1; i
< 32; i
++)
8544 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
8545 offsetof(CPUState
, active_tc
.gpr
[i
]),
8547 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
8548 offsetof(CPUState
, active_tc
.PC
), "PC");
8549 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
8550 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
8551 offsetof(CPUState
, active_tc
.HI
[i
]),
8553 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
8554 offsetof(CPUState
, active_tc
.LO
[i
]),
8556 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
8557 offsetof(CPUState
, active_tc
.ACX
[i
]),
8560 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
8561 offsetof(CPUState
, active_tc
.DSPControl
),
8563 bcond
= tcg_global_mem_new(TCG_AREG0
,
8564 offsetof(CPUState
, bcond
), "bcond");
8565 btarget
= tcg_global_mem_new(TCG_AREG0
,
8566 offsetof(CPUState
, btarget
), "btarget");
8567 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
8568 offsetof(CPUState
, hflags
), "hflags");
8570 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
8571 offsetof(CPUState
, active_fpu
.fcr0
),
8573 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
8574 offsetof(CPUState
, active_fpu
.fcr31
),
8577 /* register helpers */
8578 #define GEN_HELPER 2
8584 #include "translate_init.c"
8586 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
8589 const mips_def_t
*def
;
8591 def
= cpu_mips_find_by_name(cpu_model
);
8594 env
= qemu_mallocz(sizeof(CPUMIPSState
));
8595 env
->cpu_model
= def
;
8596 env
->cpu_model_str
= cpu_model
;
8599 #ifndef CONFIG_USER_ONLY
8606 qemu_init_vcpu(env
);
8610 void cpu_reset (CPUMIPSState
*env
)
8612 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
8613 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
8614 log_cpu_state(env
, 0);
8617 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
8620 /* Reset registers to their default values */
8621 env
->CP0_PRid
= env
->cpu_model
->CP0_PRid
;
8622 env
->CP0_Config0
= env
->cpu_model
->CP0_Config0
;
8623 #ifdef TARGET_WORDS_BIGENDIAN
8624 env
->CP0_Config0
|= (1 << CP0C0_BE
);
8626 env
->CP0_Config1
= env
->cpu_model
->CP0_Config1
;
8627 env
->CP0_Config2
= env
->cpu_model
->CP0_Config2
;
8628 env
->CP0_Config3
= env
->cpu_model
->CP0_Config3
;
8629 env
->CP0_Config6
= env
->cpu_model
->CP0_Config6
;
8630 env
->CP0_Config7
= env
->cpu_model
->CP0_Config7
;
8631 env
->CP0_LLAddr_rw_bitmask
= env
->cpu_model
->CP0_LLAddr_rw_bitmask
8632 << env
->cpu_model
->CP0_LLAddr_shift
;
8633 env
->CP0_LLAddr_shift
= env
->cpu_model
->CP0_LLAddr_shift
;
8634 env
->SYNCI_Step
= env
->cpu_model
->SYNCI_Step
;
8635 env
->CCRes
= env
->cpu_model
->CCRes
;
8636 env
->CP0_Status_rw_bitmask
= env
->cpu_model
->CP0_Status_rw_bitmask
;
8637 env
->CP0_TCStatus_rw_bitmask
= env
->cpu_model
->CP0_TCStatus_rw_bitmask
;
8638 env
->CP0_SRSCtl
= env
->cpu_model
->CP0_SRSCtl
;
8639 env
->current_tc
= 0;
8640 env
->SEGBITS
= env
->cpu_model
->SEGBITS
;
8641 env
->SEGMask
= (target_ulong
)((1ULL << env
->cpu_model
->SEGBITS
) - 1);
8642 #if defined(TARGET_MIPS64)
8643 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
8644 env
->SEGMask
|= 3ULL << 62;
8647 env
->PABITS
= env
->cpu_model
->PABITS
;
8648 env
->PAMask
= (target_ulong
)((1ULL << env
->cpu_model
->PABITS
) - 1);
8649 env
->CP0_SRSConf0_rw_bitmask
= env
->cpu_model
->CP0_SRSConf0_rw_bitmask
;
8650 env
->CP0_SRSConf0
= env
->cpu_model
->CP0_SRSConf0
;
8651 env
->CP0_SRSConf1_rw_bitmask
= env
->cpu_model
->CP0_SRSConf1_rw_bitmask
;
8652 env
->CP0_SRSConf1
= env
->cpu_model
->CP0_SRSConf1
;
8653 env
->CP0_SRSConf2_rw_bitmask
= env
->cpu_model
->CP0_SRSConf2_rw_bitmask
;
8654 env
->CP0_SRSConf2
= env
->cpu_model
->CP0_SRSConf2
;
8655 env
->CP0_SRSConf3_rw_bitmask
= env
->cpu_model
->CP0_SRSConf3_rw_bitmask
;
8656 env
->CP0_SRSConf3
= env
->cpu_model
->CP0_SRSConf3
;
8657 env
->CP0_SRSConf4_rw_bitmask
= env
->cpu_model
->CP0_SRSConf4_rw_bitmask
;
8658 env
->CP0_SRSConf4
= env
->cpu_model
->CP0_SRSConf4
;
8659 env
->insn_flags
= env
->cpu_model
->insn_flags
;
8661 #if defined(CONFIG_USER_ONLY)
8662 env
->hflags
= MIPS_HFLAG_UM
;
8663 /* Enable access to the SYNCI_Step register. */
8664 env
->CP0_HWREna
|= (1 << 1);
8666 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
8667 /* If the exception was raised from a delay slot,
8668 come back to the jump. */
8669 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
8671 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
8673 env
->active_tc
.PC
= (int32_t)0xBFC00000;
8674 env
->CP0_Random
= env
->tlb
->nb_tlb
- 1;
8675 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
8677 /* SMP not implemented */
8678 env
->CP0_EBase
= 0x80000000;
8679 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8680 /* vectored interrupts not implemented, timer on int 7,
8681 no performance counters. */
8682 env
->CP0_IntCtl
= 0xe0000000;
8686 for (i
= 0; i
< 7; i
++) {
8687 env
->CP0_WatchLo
[i
] = 0;
8688 env
->CP0_WatchHi
[i
] = 0x80000000;
8690 env
->CP0_WatchLo
[7] = 0;
8691 env
->CP0_WatchHi
[7] = 0;
8693 /* Count register increments in debug mode, EJTAG version 1 */
8694 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8695 env
->hflags
= MIPS_HFLAG_CP0
;
8697 #if defined(TARGET_MIPS64)
8698 if (env
->cpu_model
->insn_flags
& ISA_MIPS3
) {
8699 env
->hflags
|= MIPS_HFLAG_64
;
8702 env
->exception_index
= EXCP_NONE
;
8705 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8706 unsigned long searched_pc
, int pc_pos
, void *puc
)
8708 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
8709 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8710 env
->hflags
|= gen_opc_hflags
[pc_pos
];