]>
git.proxmox.com Git - mirror_qemu.git/blob - target-mips/translate.c
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, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "qemu-common.h"
36 //#define MIPS_DEBUG_DISAS
37 //#define MIPS_DEBUG_SIGN_EXTENSIONS
38 //#define MIPS_SINGLE_STEP
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL
= (0x00 << 26),
46 OPC_REGIMM
= (0x01 << 26),
47 OPC_CP0
= (0x10 << 26),
48 OPC_CP1
= (0x11 << 26),
49 OPC_CP2
= (0x12 << 26),
50 OPC_CP3
= (0x13 << 26),
51 OPC_SPECIAL2
= (0x1C << 26),
52 OPC_SPECIAL3
= (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI
= (0x08 << 26),
55 OPC_ADDIU
= (0x09 << 26),
56 OPC_SLTI
= (0x0A << 26),
57 OPC_SLTIU
= (0x0B << 26),
58 OPC_ANDI
= (0x0C << 26),
59 OPC_ORI
= (0x0D << 26),
60 OPC_XORI
= (0x0E << 26),
61 OPC_LUI
= (0x0F << 26),
62 OPC_DADDI
= (0x18 << 26),
63 OPC_DADDIU
= (0x19 << 26),
64 /* Jump and branches */
66 OPC_JAL
= (0x03 << 26),
67 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
68 OPC_BEQL
= (0x14 << 26),
69 OPC_BNE
= (0x05 << 26),
70 OPC_BNEL
= (0x15 << 26),
71 OPC_BLEZ
= (0x06 << 26),
72 OPC_BLEZL
= (0x16 << 26),
73 OPC_BGTZ
= (0x07 << 26),
74 OPC_BGTZL
= (0x17 << 26),
75 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
77 OPC_LDL
= (0x1A << 26),
78 OPC_LDR
= (0x1B << 26),
79 OPC_LB
= (0x20 << 26),
80 OPC_LH
= (0x21 << 26),
81 OPC_LWL
= (0x22 << 26),
82 OPC_LW
= (0x23 << 26),
83 OPC_LBU
= (0x24 << 26),
84 OPC_LHU
= (0x25 << 26),
85 OPC_LWR
= (0x26 << 26),
86 OPC_LWU
= (0x27 << 26),
87 OPC_SB
= (0x28 << 26),
88 OPC_SH
= (0x29 << 26),
89 OPC_SWL
= (0x2A << 26),
90 OPC_SW
= (0x2B << 26),
91 OPC_SDL
= (0x2C << 26),
92 OPC_SDR
= (0x2D << 26),
93 OPC_SWR
= (0x2E << 26),
94 OPC_LL
= (0x30 << 26),
95 OPC_LLD
= (0x34 << 26),
96 OPC_LD
= (0x37 << 26),
97 OPC_SC
= (0x38 << 26),
98 OPC_SCD
= (0x3C << 26),
99 OPC_SD
= (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1
= (0x31 << 26),
102 OPC_LWC2
= (0x32 << 26),
103 OPC_LDC1
= (0x35 << 26),
104 OPC_LDC2
= (0x36 << 26),
105 OPC_SWC1
= (0x39 << 26),
106 OPC_SWC2
= (0x3A << 26),
107 OPC_SDC1
= (0x3D << 26),
108 OPC_SDC2
= (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX
= (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE
= (0x2F << 26),
113 OPC_PREF
= (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL
= 0x00 | OPC_SPECIAL
,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
128 OPC_SRA
= 0x03 | OPC_SPECIAL
,
129 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
130 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
131 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
132 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
133 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
134 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
135 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
136 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
137 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
138 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
139 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
140 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
141 /* Multiplication / division */
142 OPC_MULT
= 0x18 | OPC_SPECIAL
,
143 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
144 OPC_DIV
= 0x1A | OPC_SPECIAL
,
145 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
146 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
147 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
148 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
149 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
150 /* 2 registers arithmetic / logic */
151 OPC_ADD
= 0x20 | OPC_SPECIAL
,
152 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
153 OPC_SUB
= 0x22 | OPC_SPECIAL
,
154 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
155 OPC_AND
= 0x24 | OPC_SPECIAL
,
156 OPC_OR
= 0x25 | OPC_SPECIAL
,
157 OPC_XOR
= 0x26 | OPC_SPECIAL
,
158 OPC_NOR
= 0x27 | OPC_SPECIAL
,
159 OPC_SLT
= 0x2A | OPC_SPECIAL
,
160 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
161 OPC_DADD
= 0x2C | OPC_SPECIAL
,
162 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
163 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
164 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
166 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
167 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
169 OPC_TGE
= 0x30 | OPC_SPECIAL
,
170 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
171 OPC_TLT
= 0x32 | OPC_SPECIAL
,
172 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
173 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
174 OPC_TNE
= 0x36 | OPC_SPECIAL
,
175 /* HI / LO registers load & stores */
176 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
177 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
178 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
179 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
180 /* Conditional moves */
181 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
182 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
184 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
187 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
188 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
189 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
190 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
191 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
193 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
194 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
195 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
196 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
197 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
198 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
199 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
202 /* Multiplication variants of the vr54xx. */
203 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
206 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
207 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
208 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
209 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
210 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
211 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
212 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
213 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
214 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
215 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
216 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
217 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
218 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
219 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
222 /* REGIMM (rt field) opcodes */
223 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
226 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
227 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
228 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
229 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
230 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
231 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
232 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
233 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
234 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
235 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
236 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
237 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
238 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
239 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
240 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
243 /* Special2 opcodes */
244 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
247 /* Multiply & xxx operations */
248 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
249 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
250 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
251 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
252 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
254 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
255 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
256 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
257 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
259 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
262 /* Special3 opcodes */
263 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
266 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
267 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
268 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
269 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
270 OPC_INS
= 0x04 | OPC_SPECIAL3
,
271 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
272 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
273 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
274 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
275 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
276 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
277 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
278 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
282 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
285 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
286 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
287 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
291 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
294 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
295 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
298 /* Coprocessor 0 (rs field) */
299 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
302 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
303 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
304 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
305 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
306 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
307 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
308 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
309 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
310 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
311 OPC_C0
= (0x10 << 21) | OPC_CP0
,
312 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
313 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
317 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
320 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
321 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
322 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
323 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
324 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
325 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
328 /* Coprocessor 0 (with rs == C0) */
329 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
332 OPC_TLBR
= 0x01 | OPC_C0
,
333 OPC_TLBWI
= 0x02 | OPC_C0
,
334 OPC_TLBWR
= 0x06 | OPC_C0
,
335 OPC_TLBP
= 0x08 | OPC_C0
,
336 OPC_RFE
= 0x10 | OPC_C0
,
337 OPC_ERET
= 0x18 | OPC_C0
,
338 OPC_DERET
= 0x1F | OPC_C0
,
339 OPC_WAIT
= 0x20 | OPC_C0
,
342 /* Coprocessor 1 (rs field) */
343 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
347 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
348 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
349 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
350 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
351 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
352 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
353 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
354 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
355 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
356 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
357 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
358 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
359 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
360 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
361 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
362 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
363 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
366 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
367 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
370 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
371 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
372 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
373 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
377 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
378 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
382 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
383 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
386 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
390 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
391 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
392 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
393 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
394 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
395 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
396 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
397 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
400 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
403 OPC_LWXC1
= 0x00 | OPC_CP3
,
404 OPC_LDXC1
= 0x01 | OPC_CP3
,
405 OPC_LUXC1
= 0x05 | OPC_CP3
,
406 OPC_SWXC1
= 0x08 | OPC_CP3
,
407 OPC_SDXC1
= 0x09 | OPC_CP3
,
408 OPC_SUXC1
= 0x0D | OPC_CP3
,
409 OPC_PREFX
= 0x0F | OPC_CP3
,
410 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
411 OPC_MADD_S
= 0x20 | OPC_CP3
,
412 OPC_MADD_D
= 0x21 | OPC_CP3
,
413 OPC_MADD_PS
= 0x26 | OPC_CP3
,
414 OPC_MSUB_S
= 0x28 | OPC_CP3
,
415 OPC_MSUB_D
= 0x29 | OPC_CP3
,
416 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
417 OPC_NMADD_S
= 0x30 | OPC_CP3
,
418 OPC_NMADD_D
= 0x31 | OPC_CP3
,
419 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
420 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
421 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
422 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
425 /* global register indices */
426 static TCGv cpu_env
, current_tc_gprs
, current_tc_hi
, current_fpu
;
428 /* FPU TNs, global for now. */
429 static TCGv fpu32_T
[3], fpu64_T
[3], fpu32h_T
[3];
431 static inline void tcg_gen_helper_0_i(void *func
, TCGv arg
)
433 TCGv tmp
= tcg_const_i32(arg
);
435 tcg_gen_helper_0_1(func
, tmp
);
439 static inline void tcg_gen_helper_0_ii(void *func
, TCGv arg1
, TCGv arg2
)
441 TCGv tmp1
= tcg_const_i32(arg1
);
442 TCGv tmp2
= tcg_const_i32(arg2
);
444 tcg_gen_helper_0_2(func
, tmp1
, tmp2
);
449 static inline void tcg_gen_helper_0_1i(void *func
, TCGv arg1
, TCGv arg2
)
451 TCGv tmp
= tcg_const_i32(arg2
);
453 tcg_gen_helper_0_2(func
, arg1
, tmp
);
457 static inline void tcg_gen_helper_0_2i(void *func
, TCGv arg1
, TCGv arg2
, TCGv arg3
)
459 TCGv tmp
= tcg_const_i32(arg3
);
461 tcg_gen_helper_0_3(func
, arg1
, arg2
, tmp
);
465 static inline void tcg_gen_helper_0_2ii(void *func
, TCGv arg1
, TCGv arg2
, TCGv arg3
, TCGv arg4
)
467 TCGv tmp1
= tcg_const_i32(arg3
);
468 TCGv tmp2
= tcg_const_i32(arg3
);
470 tcg_gen_helper_0_4(func
, arg1
, arg2
, tmp1
, tmp2
);
475 static inline void tcg_gen_helper_1_i(void *func
, TCGv ret
, TCGv arg
)
477 TCGv tmp
= tcg_const_i32(arg
);
479 tcg_gen_helper_1_1(func
, ret
, tmp
);
483 static inline void tcg_gen_helper_1_1i(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
)
485 TCGv tmp
= tcg_const_i32(arg2
);
487 tcg_gen_helper_1_2(func
, ret
, arg1
, tmp
);
491 static inline void tcg_gen_helper_1_2i(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
, TCGv arg3
)
493 TCGv tmp
= tcg_const_i32(arg3
);
495 tcg_gen_helper_1_3(func
, ret
, arg1
, arg2
, tmp
);
499 static inline void tcg_gen_helper_1_2ii(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
, TCGv arg3
, TCGv arg4
)
501 TCGv tmp1
= tcg_const_i32(arg3
);
502 TCGv tmp2
= tcg_const_i32(arg3
);
504 tcg_gen_helper_1_4(func
, ret
, arg1
, arg2
, tmp1
, tmp2
);
509 typedef struct DisasContext
{
510 struct TranslationBlock
*tb
;
511 target_ulong pc
, saved_pc
;
514 /* Routine used to access memory */
516 uint32_t hflags
, saved_hflags
;
518 target_ulong btarget
;
522 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
523 * exception condition
525 BS_STOP
= 1, /* We want to stop translation for any reason */
526 BS_BRANCH
= 2, /* We reached a branch condition */
527 BS_EXCP
= 3, /* We reached an exception condition */
530 static const char *regnames
[] =
531 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
532 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
533 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
534 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
536 static const char *fregnames
[] =
537 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
538 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
539 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
540 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
542 #ifdef MIPS_DEBUG_DISAS
543 #define MIPS_DEBUG(fmt, args...) \
545 if (loglevel & CPU_LOG_TB_IN_ASM) { \
546 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
547 ctx->pc, ctx->opcode , ##args); \
551 #define MIPS_DEBUG(fmt, args...) do { } while(0)
554 #define MIPS_INVAL(op) \
556 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
557 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
560 /* General purpose registers moves. */
561 static inline void gen_load_gpr (TCGv t
, int reg
)
564 tcg_gen_movi_tl(t
, 0);
566 tcg_gen_ld_tl(t
, current_tc_gprs
, sizeof(target_ulong
) * reg
);
569 static inline void gen_store_gpr (TCGv t
, int reg
)
572 tcg_gen_st_tl(t
, current_tc_gprs
, sizeof(target_ulong
) * reg
);
575 /* Moves to/from HI and LO registers. */
576 static inline void gen_load_LO (TCGv t
, int reg
)
578 tcg_gen_ld_tl(t
, current_tc_hi
,
579 offsetof(CPUState
, LO
)
580 - offsetof(CPUState
, HI
)
581 + sizeof(target_ulong
) * reg
);
584 static inline void gen_store_LO (TCGv t
, int reg
)
586 tcg_gen_st_tl(t
, current_tc_hi
,
587 offsetof(CPUState
, LO
)
588 - offsetof(CPUState
, HI
)
589 + sizeof(target_ulong
) * reg
);
592 static inline void gen_load_HI (TCGv t
, int reg
)
594 tcg_gen_ld_tl(t
, current_tc_hi
, sizeof(target_ulong
) * reg
);
597 static inline void gen_store_HI (TCGv t
, int reg
)
599 tcg_gen_st_tl(t
, current_tc_hi
, sizeof(target_ulong
) * reg
);
602 /* Moves to/from shadow registers. */
603 static inline void gen_load_srsgpr (int from
, int to
)
605 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
608 tcg_gen_movi_tl(r_tmp1
, 0);
610 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
612 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
613 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
614 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
615 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
616 tcg_gen_add_i32(r_tmp2
, cpu_env
, r_tmp2
);
618 tcg_gen_ld_tl(r_tmp1
, r_tmp2
, sizeof(target_ulong
) * from
);
619 tcg_temp_free(r_tmp2
);
621 gen_store_gpr(r_tmp1
, to
);
622 tcg_temp_free(r_tmp1
);
625 static inline void gen_store_srsgpr (int from
, int to
)
628 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
629 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
631 gen_load_gpr(r_tmp1
, from
);
632 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
633 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
634 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
635 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
636 tcg_gen_add_i32(r_tmp2
, cpu_env
, r_tmp2
);
638 tcg_gen_st_tl(r_tmp1
, r_tmp2
, sizeof(target_ulong
) * to
);
639 tcg_temp_free(r_tmp1
);
640 tcg_temp_free(r_tmp2
);
644 /* Floating point register moves. */
645 static inline void gen_load_fpr32 (TCGv t
, int reg
)
647 tcg_gen_ld_i32(t
, current_fpu
, 8 * reg
+ 4 * FP_ENDIAN_IDX
);
650 static inline void gen_store_fpr32 (TCGv t
, int reg
)
652 tcg_gen_st_i32(t
, current_fpu
, 8 * reg
+ 4 * FP_ENDIAN_IDX
);
655 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv t
, int reg
)
657 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
658 tcg_gen_ld_i64(t
, current_fpu
, 8 * reg
);
660 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
661 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
663 tcg_gen_ld_i32(r_tmp1
, current_fpu
, 8 * (reg
| 1) + 4 * FP_ENDIAN_IDX
);
664 tcg_gen_extu_i32_i64(t
, r_tmp1
);
665 tcg_gen_shli_i64(t
, t
, 32);
666 tcg_gen_ld_i32(r_tmp1
, current_fpu
, 8 * (reg
& ~1) + 4 * FP_ENDIAN_IDX
);
667 tcg_gen_extu_i32_i64(r_tmp2
, r_tmp1
);
668 tcg_gen_or_i64(t
, t
, r_tmp2
);
669 tcg_temp_free(r_tmp1
);
670 tcg_temp_free(r_tmp2
);
674 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv t
, int reg
)
676 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
677 tcg_gen_st_i64(t
, current_fpu
, 8 * reg
);
679 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
681 tcg_gen_trunc_i64_i32(r_tmp
, t
);
682 tcg_gen_st_i32(r_tmp
, current_fpu
, 8 * (reg
& ~1) + 4 * FP_ENDIAN_IDX
);
683 tcg_gen_shri_i64(t
, t
, 32);
684 tcg_gen_trunc_i64_i32(r_tmp
, t
);
685 tcg_gen_st_i32(r_tmp
, current_fpu
, 8 * (reg
| 1) + 4 * FP_ENDIAN_IDX
);
686 tcg_temp_free(r_tmp
);
690 static inline void gen_load_fpr32h (TCGv t
, int reg
)
692 tcg_gen_ld_i32(t
, current_fpu
, 8 * reg
+ 4 * !FP_ENDIAN_IDX
);
695 static inline void gen_store_fpr32h (TCGv t
, int reg
)
697 tcg_gen_st_i32(t
, current_fpu
, 8 * reg
+ 4 * !FP_ENDIAN_IDX
);
700 static inline void get_fp_cond (TCGv t
)
702 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
703 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
705 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
706 tcg_gen_shri_i32(r_tmp2
, r_tmp1
, 24);
707 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xfe);
708 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, 23);
709 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, 0x1);
710 tcg_gen_or_i32(t
, r_tmp1
, r_tmp2
);
711 tcg_temp_free(r_tmp1
);
712 tcg_temp_free(r_tmp2
);
715 #define FOP_CONDS(type, fmt) \
716 static GenOpFunc1 * fcmp ## type ## _ ## fmt ## _table[16] = { \
717 do_cmp ## type ## _ ## fmt ## _f, \
718 do_cmp ## type ## _ ## fmt ## _un, \
719 do_cmp ## type ## _ ## fmt ## _eq, \
720 do_cmp ## type ## _ ## fmt ## _ueq, \
721 do_cmp ## type ## _ ## fmt ## _olt, \
722 do_cmp ## type ## _ ## fmt ## _ult, \
723 do_cmp ## type ## _ ## fmt ## _ole, \
724 do_cmp ## type ## _ ## fmt ## _ule, \
725 do_cmp ## type ## _ ## fmt ## _sf, \
726 do_cmp ## type ## _ ## fmt ## _ngle, \
727 do_cmp ## type ## _ ## fmt ## _seq, \
728 do_cmp ## type ## _ ## fmt ## _ngl, \
729 do_cmp ## type ## _ ## fmt ## _lt, \
730 do_cmp ## type ## _ ## fmt ## _nge, \
731 do_cmp ## type ## _ ## fmt ## _le, \
732 do_cmp ## type ## _ ## fmt ## _ngt, \
734 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
736 tcg_gen_helper_0_i(fcmp ## type ## _ ## fmt ## _table[n], cc); \
748 #define OP_COND(name, cond) \
749 void glue(gen_op_, name) (TCGv t0, TCGv t1) \
751 int l1 = gen_new_label(); \
752 int l2 = gen_new_label(); \
754 tcg_gen_brcond_tl(cond, t0, t1, l1); \
755 tcg_gen_movi_tl(t0, 0); \
758 tcg_gen_movi_tl(t0, 1); \
761 OP_COND(eq
, TCG_COND_EQ
);
762 OP_COND(ne
, TCG_COND_NE
);
763 OP_COND(ge
, TCG_COND_GE
);
764 OP_COND(geu
, TCG_COND_GEU
);
765 OP_COND(lt
, TCG_COND_LT
);
766 OP_COND(ltu
, TCG_COND_LTU
);
769 #define OP_CONDI(name, cond) \
770 void glue(gen_op_, name) (TCGv t, target_ulong val) \
772 int l1 = gen_new_label(); \
773 int l2 = gen_new_label(); \
775 tcg_gen_brcondi_tl(cond, t, val, l1); \
776 tcg_gen_movi_tl(t, 0); \
779 tcg_gen_movi_tl(t, 1); \
782 OP_CONDI(lti
, TCG_COND_LT
);
783 OP_CONDI(ltiu
, TCG_COND_LTU
);
786 #define OP_CONDZ(name, cond) \
787 void glue(gen_op_, name) (TCGv t) \
789 int l1 = gen_new_label(); \
790 int l2 = gen_new_label(); \
792 tcg_gen_brcondi_tl(cond, t, 0, l1); \
793 tcg_gen_movi_tl(t, 0); \
796 tcg_gen_movi_tl(t, 1); \
799 OP_CONDZ(gez
, TCG_COND_GE
);
800 OP_CONDZ(gtz
, TCG_COND_GT
);
801 OP_CONDZ(lez
, TCG_COND_LE
);
802 OP_CONDZ(ltz
, TCG_COND_LT
);
805 static inline void gen_save_pc(target_ulong pc
)
807 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
808 TCGv r_tc_off
= tcg_temp_new(TCG_TYPE_I32
);
809 TCGv r_tc_off_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
810 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
812 tcg_gen_movi_tl(r_tmp
, pc
);
813 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
814 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
815 tcg_gen_ext_i32_ptr(r_tc_off_ptr
, r_tc_off
);
816 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_ptr
);
817 tcg_gen_st_tl(r_tmp
, r_ptr
, offsetof(CPUState
, PC
));
818 tcg_temp_free(r_tc_off
);
819 tcg_temp_free(r_tc_off_ptr
);
820 tcg_temp_free(r_ptr
);
821 tcg_temp_free(r_tmp
);
824 static inline void gen_breg_pc(void)
826 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
827 TCGv r_tc_off
= tcg_temp_new(TCG_TYPE_I32
);
828 TCGv r_tc_off_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
829 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
831 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
832 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
833 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
834 tcg_gen_ext_i32_ptr(r_tc_off_ptr
, r_tc_off
);
835 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_ptr
);
836 tcg_gen_st_tl(r_tmp
, r_ptr
, offsetof(CPUState
, PC
));
837 tcg_temp_free(r_tc_off
);
838 tcg_temp_free(r_tc_off_ptr
);
839 tcg_temp_free(r_ptr
);
840 tcg_temp_free(r_tmp
);
843 static inline void gen_save_btarget(target_ulong btarget
)
845 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
847 tcg_gen_movi_tl(r_tmp
, btarget
);
848 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
849 tcg_temp_free(r_tmp
);
852 static always_inline
void gen_save_breg_target(int reg
)
854 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
856 gen_load_gpr(r_tmp
, reg
);
857 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
858 tcg_temp_free(r_tmp
);
861 static always_inline
void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
863 #if defined MIPS_DEBUG_DISAS
864 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
865 fprintf(logfile
, "hflags %08x saved %08x\n",
866 ctx
->hflags
, ctx
->saved_hflags
);
869 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
870 gen_save_pc(ctx
->pc
);
871 ctx
->saved_pc
= ctx
->pc
;
873 if (ctx
->hflags
!= ctx
->saved_hflags
) {
874 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
876 tcg_gen_movi_i32(r_tmp
, ctx
->hflags
);
877 tcg_gen_st_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
878 tcg_temp_free(r_tmp
);
879 ctx
->saved_hflags
= ctx
->hflags
;
880 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
886 gen_save_btarget(ctx
->btarget
);
892 static always_inline
void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
894 ctx
->saved_hflags
= ctx
->hflags
;
895 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
901 ctx
->btarget
= env
->btarget
;
906 static always_inline
void
907 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
909 save_cpu_state(ctx
, 1);
910 tcg_gen_helper_0_ii(do_raise_exception_err
, excp
, err
);
911 tcg_gen_helper_0_0(do_interrupt_restart
);
915 static always_inline
void
916 generate_exception (DisasContext
*ctx
, int excp
)
918 save_cpu_state(ctx
, 1);
919 tcg_gen_helper_0_i(do_raise_exception
, excp
);
920 tcg_gen_helper_0_0(do_interrupt_restart
);
924 /* Addresses computation */
925 static inline void gen_op_addr_add (TCGv t0
, TCGv t1
)
927 tcg_gen_add_tl(t0
, t0
, t1
);
929 #if defined(TARGET_MIPS64)
930 /* For compatibility with 32-bit code, data reference in user mode
931 with Status_UX = 0 should be casted to 32-bit and sign extended.
932 See the MIPS64 PRA manual, section 4.10. */
934 int l1
= gen_new_label();
935 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_I32
);
937 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
938 tcg_gen_andi_i32(r_tmp
, r_tmp
, MIPS_HFLAG_KSU
);
939 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp
, MIPS_HFLAG_UM
, l1
);
940 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_Status
));
941 tcg_gen_andi_i32(r_tmp
, r_tmp
, (1 << CP0St_UX
));
942 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp
, 0, l1
);
943 tcg_temp_free(r_tmp
);
944 tcg_gen_ext32s_i64(t0
, t0
);
950 static always_inline
void check_cp0_enabled(DisasContext
*ctx
)
952 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
953 generate_exception_err(ctx
, EXCP_CpU
, 1);
956 static always_inline
void check_cp1_enabled(DisasContext
*ctx
)
958 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
959 generate_exception_err(ctx
, EXCP_CpU
, 1);
962 /* Verify that the processor is running with COP1X instructions enabled.
963 This is associated with the nabla symbol in the MIPS32 and MIPS64
966 static always_inline
void check_cop1x(DisasContext
*ctx
)
968 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
969 generate_exception(ctx
, EXCP_RI
);
972 /* Verify that the processor is running with 64-bit floating-point
973 operations enabled. */
975 static always_inline
void check_cp1_64bitmode(DisasContext
*ctx
)
977 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
978 generate_exception(ctx
, EXCP_RI
);
982 * Verify if floating point register is valid; an operation is not defined
983 * if bit 0 of any register specification is set and the FR bit in the
984 * Status register equals zero, since the register numbers specify an
985 * even-odd pair of adjacent coprocessor general registers. When the FR bit
986 * in the Status register equals one, both even and odd register numbers
987 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
989 * Multiple 64 bit wide registers can be checked by calling
990 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
992 void check_cp1_registers(DisasContext
*ctx
, int regs
)
994 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
995 generate_exception(ctx
, EXCP_RI
);
998 /* This code generates a "reserved instruction" exception if the
999 CPU does not support the instruction set corresponding to flags. */
1000 static always_inline
void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
1002 if (unlikely(!(env
->insn_flags
& flags
)))
1003 generate_exception(ctx
, EXCP_RI
);
1006 /* This code generates a "reserved instruction" exception if 64-bit
1007 instructions are not enabled. */
1008 static always_inline
void check_mips_64(DisasContext
*ctx
)
1010 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
1011 generate_exception(ctx
, EXCP_RI
);
1014 /* load/store instructions. */
1015 #define OP_LD(insn,fname) \
1016 void inline op_ldst_##insn(TCGv t0, DisasContext *ctx) \
1018 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1025 #if defined(TARGET_MIPS64)
1031 #define OP_ST(insn,fname) \
1032 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1034 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1039 #if defined(TARGET_MIPS64)
1044 #define OP_LD_ATOMIC(insn,fname) \
1045 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1047 tcg_gen_mov_tl(t1, t0); \
1048 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1049 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1051 OP_LD_ATOMIC(ll
,ld32s
);
1052 #if defined(TARGET_MIPS64)
1053 OP_LD_ATOMIC(lld
,ld64
);
1057 #define OP_ST_ATOMIC(insn,fname,almask) \
1058 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1060 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1061 int l1 = gen_new_label(); \
1062 int l2 = gen_new_label(); \
1063 int l3 = gen_new_label(); \
1065 tcg_gen_andi_tl(r_tmp, t0, almask); \
1066 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1067 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1068 generate_exception(ctx, EXCP_AdES); \
1069 gen_set_label(l1); \
1070 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1071 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1072 tcg_temp_free(r_tmp); \
1073 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1074 tcg_gen_movi_tl(t0, 1); \
1076 gen_set_label(l2); \
1077 tcg_gen_movi_tl(t0, 0); \
1078 gen_set_label(l3); \
1080 OP_ST_ATOMIC(sc
,st32
,0x3);
1081 #if defined(TARGET_MIPS64)
1082 OP_ST_ATOMIC(scd
,st64
,0x7);
1086 /* Load and store */
1087 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
1088 int base
, int16_t offset
)
1090 const char *opn
= "ldst";
1091 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1092 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
1095 tcg_gen_movi_tl(t0
, offset
);
1096 } else if (offset
== 0) {
1097 gen_load_gpr(t0
, base
);
1099 gen_load_gpr(t0
, base
);
1100 tcg_gen_movi_tl(t1
, offset
);
1101 gen_op_addr_add(t0
, t1
);
1103 /* Don't do NOP if destination is zero: we must perform the actual
1106 #if defined(TARGET_MIPS64)
1108 op_ldst_lwu(t0
, ctx
);
1109 gen_store_gpr(t0
, rt
);
1113 op_ldst_ld(t0
, ctx
);
1114 gen_store_gpr(t0
, rt
);
1118 op_ldst_lld(t0
, t1
, ctx
);
1119 gen_store_gpr(t0
, rt
);
1123 gen_load_gpr(t1
, rt
);
1124 op_ldst_sd(t0
, t1
, ctx
);
1128 save_cpu_state(ctx
, 1);
1129 gen_load_gpr(t1
, rt
);
1130 op_ldst_scd(t0
, t1
, ctx
);
1131 gen_store_gpr(t0
, rt
);
1135 save_cpu_state(ctx
, 1);
1136 gen_load_gpr(t1
, rt
);
1137 tcg_gen_helper_1_2i(do_ldl
, t1
, t0
, t1
, ctx
->mem_idx
);
1138 gen_store_gpr(t1
, rt
);
1142 save_cpu_state(ctx
, 1);
1143 gen_load_gpr(t1
, rt
);
1144 tcg_gen_helper_0_2i(do_sdl
, t0
, t1
, ctx
->mem_idx
);
1148 save_cpu_state(ctx
, 1);
1149 gen_load_gpr(t1
, rt
);
1150 tcg_gen_helper_1_2i(do_ldr
, t1
, t0
, t1
, ctx
->mem_idx
);
1151 gen_store_gpr(t1
, rt
);
1155 save_cpu_state(ctx
, 1);
1156 gen_load_gpr(t1
, rt
);
1157 tcg_gen_helper_0_2i(do_sdr
, t0
, t1
, ctx
->mem_idx
);
1162 op_ldst_lw(t0
, ctx
);
1163 gen_store_gpr(t0
, rt
);
1167 gen_load_gpr(t1
, rt
);
1168 op_ldst_sw(t0
, t1
, ctx
);
1172 op_ldst_lh(t0
, ctx
);
1173 gen_store_gpr(t0
, rt
);
1177 gen_load_gpr(t1
, rt
);
1178 op_ldst_sh(t0
, t1
, ctx
);
1182 op_ldst_lhu(t0
, ctx
);
1183 gen_store_gpr(t0
, rt
);
1187 op_ldst_lb(t0
, ctx
);
1188 gen_store_gpr(t0
, rt
);
1192 gen_load_gpr(t1
, rt
);
1193 op_ldst_sb(t0
, t1
, ctx
);
1197 op_ldst_lbu(t0
, ctx
);
1198 gen_store_gpr(t0
, rt
);
1202 save_cpu_state(ctx
, 1);
1203 gen_load_gpr(t1
, rt
);
1204 tcg_gen_helper_1_2i(do_lwl
, t1
, t0
, t1
, ctx
->mem_idx
);
1205 gen_store_gpr(t1
, rt
);
1209 save_cpu_state(ctx
, 1);
1210 gen_load_gpr(t1
, rt
);
1211 tcg_gen_helper_0_2i(do_swl
, t0
, t1
, ctx
->mem_idx
);
1215 save_cpu_state(ctx
, 1);
1216 gen_load_gpr(t1
, rt
);
1217 tcg_gen_helper_1_2i(do_lwr
, t1
, t0
, t1
, ctx
->mem_idx
);
1218 gen_store_gpr(t1
, rt
);
1222 save_cpu_state(ctx
, 1);
1223 gen_load_gpr(t1
, rt
);
1224 tcg_gen_helper_0_2i(do_swr
, t0
, t1
, ctx
->mem_idx
);
1228 op_ldst_ll(t0
, t1
, ctx
);
1229 gen_store_gpr(t0
, rt
);
1233 save_cpu_state(ctx
, 1);
1234 gen_load_gpr(t1
, rt
);
1235 op_ldst_sc(t0
, t1
, ctx
);
1236 gen_store_gpr(t0
, rt
);
1241 generate_exception(ctx
, EXCP_RI
);
1244 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1250 /* Load and store */
1251 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1252 int base
, int16_t offset
)
1254 const char *opn
= "flt_ldst";
1255 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1258 tcg_gen_movi_tl(t0
, offset
);
1259 } else if (offset
== 0) {
1260 gen_load_gpr(t0
, base
);
1262 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
1264 gen_load_gpr(t0
, base
);
1265 tcg_gen_movi_tl(t1
, offset
);
1266 gen_op_addr_add(t0
, t1
);
1269 /* Don't do NOP if destination is zero: we must perform the actual
1273 tcg_gen_qemu_ld32s(fpu32_T
[0], t0
, ctx
->mem_idx
);
1274 gen_store_fpr32(fpu32_T
[0], ft
);
1278 gen_load_fpr32(fpu32_T
[0], ft
);
1279 tcg_gen_qemu_st32(fpu32_T
[0], t0
, ctx
->mem_idx
);
1283 tcg_gen_qemu_ld64(fpu64_T
[0], t0
, ctx
->mem_idx
);
1284 gen_store_fpr64(ctx
, fpu64_T
[0], ft
);
1288 gen_load_fpr64(ctx
, fpu64_T
[0], ft
);
1289 tcg_gen_qemu_st64(fpu64_T
[0], t0
, ctx
->mem_idx
);
1294 generate_exception(ctx
, EXCP_RI
);
1297 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1302 /* Arithmetic with immediate operand */
1303 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1304 int rt
, int rs
, int16_t imm
)
1307 const char *opn
= "imm arith";
1308 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1310 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1311 /* If no destination, treat it as a NOP.
1312 For addi, we must generate the overflow exception when needed. */
1316 uimm
= (uint16_t)imm
;
1320 #if defined(TARGET_MIPS64)
1326 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1331 gen_load_gpr(t0
, rs
);
1334 tcg_gen_movi_tl(t0
, imm
<< 16);
1339 #if defined(TARGET_MIPS64)
1348 gen_load_gpr(t0
, rs
);
1354 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1355 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1356 int l1
= gen_new_label();
1358 save_cpu_state(ctx
, 1);
1359 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1360 tcg_gen_addi_tl(t0
, r_tmp1
, uimm
);
1362 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1363 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1364 tcg_gen_xori_tl(r_tmp2
, t0
, uimm
);
1365 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1366 tcg_temp_free(r_tmp2
);
1367 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1368 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1369 tcg_temp_free(r_tmp1
);
1370 /* operands of same sign, result different sign */
1371 generate_exception(ctx
, EXCP_OVERFLOW
);
1374 tcg_gen_ext32s_tl(t0
, t0
);
1379 tcg_gen_ext32s_tl(t0
, t0
);
1380 tcg_gen_addi_tl(t0
, t0
, uimm
);
1381 tcg_gen_ext32s_tl(t0
, t0
);
1384 #if defined(TARGET_MIPS64)
1387 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1388 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1389 int l1
= gen_new_label();
1391 save_cpu_state(ctx
, 1);
1392 tcg_gen_mov_tl(r_tmp1
, t0
);
1393 tcg_gen_addi_tl(t0
, t0
, uimm
);
1395 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1396 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1397 tcg_gen_xori_tl(r_tmp2
, t0
, uimm
);
1398 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1399 tcg_temp_free(r_tmp2
);
1400 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1401 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1402 tcg_temp_free(r_tmp1
);
1403 /* operands of same sign, result different sign */
1404 generate_exception(ctx
, EXCP_OVERFLOW
);
1410 tcg_gen_addi_tl(t0
, t0
, uimm
);
1415 gen_op_lti(t0
, uimm
);
1419 gen_op_ltiu(t0
, uimm
);
1423 tcg_gen_andi_tl(t0
, t0
, uimm
);
1427 tcg_gen_ori_tl(t0
, t0
, uimm
);
1431 tcg_gen_xori_tl(t0
, t0
, uimm
);
1438 tcg_gen_ext32u_tl(t0
, t0
);
1439 tcg_gen_shli_tl(t0
, t0
, uimm
);
1440 tcg_gen_ext32s_tl(t0
, t0
);
1444 tcg_gen_ext32s_tl(t0
, t0
);
1445 tcg_gen_sari_tl(t0
, t0
, uimm
);
1446 tcg_gen_ext32s_tl(t0
, t0
);
1450 switch ((ctx
->opcode
>> 21) & 0x1f) {
1452 tcg_gen_ext32u_tl(t0
, t0
);
1453 tcg_gen_shri_tl(t0
, t0
, uimm
);
1454 tcg_gen_ext32s_tl(t0
, t0
);
1458 /* rotr is decoded as srl on non-R2 CPUs */
1459 if (env
->insn_flags
& ISA_MIPS32R2
) {
1461 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1462 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1464 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1465 tcg_gen_movi_i32(r_tmp2
, 0x20);
1466 tcg_gen_subi_i32(r_tmp2
, r_tmp2
, uimm
);
1467 tcg_gen_shl_i32(r_tmp2
, r_tmp1
, r_tmp2
);
1468 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, uimm
);
1469 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1470 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
1471 tcg_temp_free(r_tmp1
);
1472 tcg_temp_free(r_tmp2
);
1476 tcg_gen_ext32u_tl(t0
, t0
);
1477 tcg_gen_shri_tl(t0
, t0
, uimm
);
1478 tcg_gen_ext32s_tl(t0
, t0
);
1483 MIPS_INVAL("invalid srl flag");
1484 generate_exception(ctx
, EXCP_RI
);
1488 #if defined(TARGET_MIPS64)
1490 tcg_gen_shli_tl(t0
, t0
, uimm
);
1494 tcg_gen_sari_tl(t0
, t0
, uimm
);
1498 switch ((ctx
->opcode
>> 21) & 0x1f) {
1500 tcg_gen_shri_tl(t0
, t0
, uimm
);
1504 /* drotr is decoded as dsrl on non-R2 CPUs */
1505 if (env
->insn_flags
& ISA_MIPS32R2
) {
1507 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1509 tcg_gen_movi_tl(r_tmp1
, 0x40);
1510 tcg_gen_subi_tl(r_tmp1
, r_tmp1
, uimm
);
1511 tcg_gen_shl_tl(r_tmp1
, t0
, r_tmp1
);
1512 tcg_gen_shri_tl(t0
, t0
, uimm
);
1513 tcg_gen_or_tl(t0
, t0
, r_tmp1
);
1514 tcg_temp_free(r_tmp1
);
1518 tcg_gen_shri_tl(t0
, t0
, uimm
);
1523 MIPS_INVAL("invalid dsrl flag");
1524 generate_exception(ctx
, EXCP_RI
);
1529 tcg_gen_shli_tl(t0
, t0
, uimm
+ 32);
1533 tcg_gen_sari_tl(t0
, t0
, uimm
+ 32);
1537 switch ((ctx
->opcode
>> 21) & 0x1f) {
1539 tcg_gen_shri_tl(t0
, t0
, uimm
+ 32);
1543 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1544 if (env
->insn_flags
& ISA_MIPS32R2
) {
1545 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1546 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1548 tcg_gen_movi_tl(r_tmp1
, 0x40);
1549 tcg_gen_movi_tl(r_tmp2
, 32);
1550 tcg_gen_addi_tl(r_tmp2
, r_tmp2
, uimm
);
1551 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1552 tcg_gen_shl_tl(r_tmp1
, t0
, r_tmp1
);
1553 tcg_gen_shr_tl(t0
, t0
, r_tmp2
);
1554 tcg_gen_or_tl(t0
, t0
, r_tmp1
);
1555 tcg_temp_free(r_tmp1
);
1556 tcg_temp_free(r_tmp2
);
1559 tcg_gen_shri_tl(t0
, t0
, uimm
+ 32);
1564 MIPS_INVAL("invalid dsrl32 flag");
1565 generate_exception(ctx
, EXCP_RI
);
1572 generate_exception(ctx
, EXCP_RI
);
1575 gen_store_gpr(t0
, rt
);
1576 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1582 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1583 int rd
, int rs
, int rt
)
1585 const char *opn
= "arith";
1586 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1587 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
1589 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1590 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1591 /* If no destination, treat it as a NOP.
1592 For add & sub, we must generate the overflow exception when needed. */
1596 gen_load_gpr(t0
, rs
);
1597 /* Specialcase the conventional move operation. */
1598 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1599 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1600 gen_store_gpr(t0
, rd
);
1603 gen_load_gpr(t1
, rt
);
1607 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1608 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1609 int l1
= gen_new_label();
1611 save_cpu_state(ctx
, 1);
1612 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1613 tcg_gen_ext32s_tl(r_tmp2
, t1
);
1614 tcg_gen_add_tl(t0
, r_tmp1
, r_tmp2
);
1616 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t1
);
1617 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1618 tcg_gen_xor_tl(r_tmp2
, t0
, t1
);
1619 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1620 tcg_temp_free(r_tmp2
);
1621 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1622 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1623 tcg_temp_free(r_tmp1
);
1624 /* operands of same sign, result different sign */
1625 generate_exception(ctx
, EXCP_OVERFLOW
);
1628 tcg_gen_ext32s_tl(t0
, t0
);
1633 tcg_gen_ext32s_tl(t0
, t0
);
1634 tcg_gen_ext32s_tl(t1
, t1
);
1635 tcg_gen_add_tl(t0
, t0
, t1
);
1636 tcg_gen_ext32s_tl(t0
, t0
);
1641 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1642 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1643 int l1
= gen_new_label();
1645 save_cpu_state(ctx
, 1);
1646 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1647 tcg_gen_ext32s_tl(r_tmp2
, t1
);
1648 tcg_gen_sub_tl(t0
, r_tmp1
, r_tmp2
);
1650 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, t1
);
1651 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t0
);
1652 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1653 tcg_temp_free(r_tmp2
);
1654 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1655 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1656 tcg_temp_free(r_tmp1
);
1657 /* operands of different sign, first operand and result different sign */
1658 generate_exception(ctx
, EXCP_OVERFLOW
);
1661 tcg_gen_ext32s_tl(t0
, t0
);
1666 tcg_gen_ext32s_tl(t0
, t0
);
1667 tcg_gen_ext32s_tl(t1
, t1
);
1668 tcg_gen_sub_tl(t0
, t0
, t1
);
1669 tcg_gen_ext32s_tl(t0
, t0
);
1672 #if defined(TARGET_MIPS64)
1675 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1676 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1677 int l1
= gen_new_label();
1679 save_cpu_state(ctx
, 1);
1680 tcg_gen_mov_tl(r_tmp1
, t0
);
1681 tcg_gen_add_tl(t0
, t0
, t1
);
1683 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t1
);
1684 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1685 tcg_gen_xor_tl(r_tmp2
, t0
, t1
);
1686 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1687 tcg_temp_free(r_tmp2
);
1688 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1689 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1690 tcg_temp_free(r_tmp1
);
1691 /* operands of same sign, result different sign */
1692 generate_exception(ctx
, EXCP_OVERFLOW
);
1698 tcg_gen_add_tl(t0
, t0
, t1
);
1703 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1704 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1705 int l1
= gen_new_label();
1707 save_cpu_state(ctx
, 1);
1708 tcg_gen_mov_tl(r_tmp1
, t0
);
1709 tcg_gen_sub_tl(t0
, t0
, t1
);
1711 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, t1
);
1712 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t0
);
1713 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1714 tcg_temp_free(r_tmp2
);
1715 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1716 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1717 tcg_temp_free(r_tmp1
);
1718 /* operands of different sign, first operand and result different sign */
1719 generate_exception(ctx
, EXCP_OVERFLOW
);
1725 tcg_gen_sub_tl(t0
, t0
, t1
);
1738 tcg_gen_and_tl(t0
, t0
, t1
);
1742 tcg_gen_or_tl(t0
, t0
, t1
);
1743 tcg_gen_not_tl(t0
, t0
);
1747 tcg_gen_or_tl(t0
, t0
, t1
);
1751 tcg_gen_xor_tl(t0
, t0
, t1
);
1755 tcg_gen_ext32s_tl(t0
, t0
);
1756 tcg_gen_ext32s_tl(t1
, t1
);
1757 tcg_gen_mul_tl(t0
, t0
, t1
);
1758 tcg_gen_ext32s_tl(t0
, t0
);
1763 int l1
= gen_new_label();
1765 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1766 gen_store_gpr(t0
, rd
);
1773 int l1
= gen_new_label();
1775 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
1776 gen_store_gpr(t0
, rd
);
1782 tcg_gen_ext32u_tl(t0
, t0
);
1783 tcg_gen_ext32u_tl(t1
, t1
);
1784 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1785 tcg_gen_shl_tl(t0
, t1
, t0
);
1786 tcg_gen_ext32s_tl(t0
, t0
);
1790 tcg_gen_ext32s_tl(t1
, t1
);
1791 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1792 tcg_gen_sar_tl(t0
, t1
, t0
);
1793 tcg_gen_ext32s_tl(t0
, t0
);
1797 switch ((ctx
->opcode
>> 6) & 0x1f) {
1799 tcg_gen_ext32u_tl(t1
, t1
);
1800 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1801 tcg_gen_shr_tl(t0
, t1
, t0
);
1802 tcg_gen_ext32s_tl(t0
, t0
);
1806 /* rotrv is decoded as srlv on non-R2 CPUs */
1807 if (env
->insn_flags
& ISA_MIPS32R2
) {
1808 int l1
= gen_new_label();
1809 int l2
= gen_new_label();
1811 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1812 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1814 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1815 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1816 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I32
);
1818 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1819 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1820 tcg_gen_movi_i32(r_tmp3
, 0x20);
1821 tcg_gen_sub_i32(r_tmp3
, r_tmp3
, r_tmp1
);
1822 tcg_gen_shl_i32(r_tmp3
, r_tmp2
, r_tmp3
);
1823 tcg_gen_shr_i32(r_tmp1
, r_tmp2
, r_tmp1
);
1824 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp3
);
1825 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
1826 tcg_temp_free(r_tmp1
);
1827 tcg_temp_free(r_tmp2
);
1828 tcg_temp_free(r_tmp3
);
1832 tcg_gen_mov_tl(t0
, t1
);
1836 tcg_gen_ext32u_tl(t1
, t1
);
1837 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1838 tcg_gen_shr_tl(t0
, t1
, t0
);
1839 tcg_gen_ext32s_tl(t0
, t0
);
1844 MIPS_INVAL("invalid srlv flag");
1845 generate_exception(ctx
, EXCP_RI
);
1849 #if defined(TARGET_MIPS64)
1851 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1852 tcg_gen_shl_tl(t0
, t1
, t0
);
1856 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1857 tcg_gen_sar_tl(t0
, t1
, t0
);
1861 switch ((ctx
->opcode
>> 6) & 0x1f) {
1863 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1864 tcg_gen_shr_tl(t0
, t1
, t0
);
1868 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1869 if (env
->insn_flags
& ISA_MIPS32R2
) {
1870 int l1
= gen_new_label();
1871 int l2
= gen_new_label();
1873 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1874 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1876 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1878 tcg_gen_movi_tl(r_tmp1
, 0x40);
1879 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, t0
);
1880 tcg_gen_shl_tl(r_tmp1
, t1
, r_tmp1
);
1881 tcg_gen_shr_tl(t0
, t1
, t0
);
1882 tcg_gen_or_tl(t0
, t0
, r_tmp1
);
1883 tcg_temp_free(r_tmp1
);
1887 tcg_gen_mov_tl(t0
, t1
);
1891 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1892 tcg_gen_shr_tl(t0
, t1
, t0
);
1897 MIPS_INVAL("invalid dsrlv flag");
1898 generate_exception(ctx
, EXCP_RI
);
1905 generate_exception(ctx
, EXCP_RI
);
1908 gen_store_gpr(t0
, rd
);
1910 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1916 /* Arithmetic on HI/LO registers */
1917 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1919 const char *opn
= "hilo";
1920 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1922 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1930 gen_store_gpr(t0
, reg
);
1935 gen_store_gpr(t0
, reg
);
1939 gen_load_gpr(t0
, reg
);
1940 gen_store_HI(t0
, 0);
1944 gen_load_gpr(t0
, reg
);
1945 gen_store_LO(t0
, 0);
1950 generate_exception(ctx
, EXCP_RI
);
1953 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1958 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1961 const char *opn
= "mul/div";
1962 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1963 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
1965 gen_load_gpr(t0
, rs
);
1966 gen_load_gpr(t1
, rt
);
1970 int l1
= gen_new_label();
1972 tcg_gen_ext32s_tl(t0
, t0
);
1973 tcg_gen_ext32s_tl(t1
, t1
);
1974 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1976 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
1977 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
1978 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
1980 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
1981 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
1982 tcg_gen_div_i64(r_tmp3
, r_tmp1
, r_tmp2
);
1983 tcg_gen_rem_i64(r_tmp2
, r_tmp1
, r_tmp2
);
1984 tcg_gen_trunc_i64_tl(t0
, r_tmp3
);
1985 tcg_gen_trunc_i64_tl(t1
, r_tmp2
);
1986 tcg_temp_free(r_tmp1
);
1987 tcg_temp_free(r_tmp2
);
1988 tcg_temp_free(r_tmp3
);
1989 tcg_gen_ext32s_tl(t0
, t0
);
1990 tcg_gen_ext32s_tl(t1
, t1
);
1991 gen_store_LO(t0
, 0);
1992 gen_store_HI(t1
, 0);
2000 int l1
= gen_new_label();
2002 tcg_gen_ext32s_tl(t1
, t1
);
2003 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2005 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
2006 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
2007 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I32
);
2009 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
2010 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
2011 tcg_gen_divu_i32(r_tmp3
, r_tmp1
, r_tmp2
);
2012 tcg_gen_remu_i32(r_tmp1
, r_tmp1
, r_tmp2
);
2013 tcg_gen_ext_i32_tl(t0
, r_tmp3
);
2014 tcg_gen_ext_i32_tl(t1
, r_tmp1
);
2015 tcg_temp_free(r_tmp1
);
2016 tcg_temp_free(r_tmp2
);
2017 tcg_temp_free(r_tmp3
);
2018 gen_store_LO(t0
, 0);
2019 gen_store_HI(t1
, 0);
2027 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2028 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2030 tcg_gen_ext32s_tl(t0
, t0
);
2031 tcg_gen_ext32s_tl(t1
, t1
);
2032 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
2033 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
2034 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2035 tcg_temp_free(r_tmp2
);
2036 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2037 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2038 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2039 tcg_temp_free(r_tmp1
);
2040 tcg_gen_ext32s_tl(t0
, t0
);
2041 tcg_gen_ext32s_tl(t1
, t1
);
2042 gen_store_LO(t0
, 0);
2043 gen_store_HI(t1
, 0);
2049 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2050 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2052 tcg_gen_ext32u_tl(t0
, t0
);
2053 tcg_gen_ext32u_tl(t1
, t1
);
2054 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
2055 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
2056 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2057 tcg_temp_free(r_tmp2
);
2058 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2059 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2060 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2061 tcg_temp_free(r_tmp1
);
2062 tcg_gen_ext32s_tl(t0
, t0
);
2063 tcg_gen_ext32s_tl(t1
, t1
);
2064 gen_store_LO(t0
, 0);
2065 gen_store_HI(t1
, 0);
2069 #if defined(TARGET_MIPS64)
2072 int l1
= gen_new_label();
2074 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2076 int l2
= gen_new_label();
2078 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2079 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2081 tcg_gen_movi_tl(t1
, 0);
2082 gen_store_LO(t0
, 0);
2083 gen_store_HI(t1
, 0);
2088 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2089 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2091 tcg_gen_div_i64(r_tmp1
, t0
, t1
);
2092 tcg_gen_rem_i64(r_tmp2
, t0
, t1
);
2093 gen_store_LO(r_tmp1
, 0);
2094 gen_store_HI(r_tmp2
, 0);
2095 tcg_temp_free(r_tmp1
);
2096 tcg_temp_free(r_tmp2
);
2105 int l1
= gen_new_label();
2107 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2109 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2110 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2112 tcg_gen_divu_i64(r_tmp1
, t0
, t1
);
2113 tcg_gen_remu_i64(r_tmp2
, t0
, t1
);
2114 tcg_temp_free(r_tmp1
);
2115 tcg_temp_free(r_tmp2
);
2116 gen_store_LO(r_tmp1
, 0);
2117 gen_store_HI(r_tmp2
, 0);
2124 tcg_gen_helper_0_2(do_dmult
, t0
, t1
);
2128 tcg_gen_helper_0_2(do_dmultu
, t0
, t1
);
2134 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2135 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2136 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2138 tcg_gen_ext32s_tl(t0
, t0
);
2139 tcg_gen_ext32s_tl(t1
, t1
);
2140 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
2141 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
2142 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2145 tcg_gen_extu_tl_i64(r_tmp2
, t0
);
2146 tcg_gen_extu_tl_i64(r_tmp3
, t1
);
2147 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2148 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2149 tcg_temp_free(r_tmp3
);
2150 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2151 tcg_temp_free(r_tmp2
);
2152 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2153 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2154 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2155 tcg_temp_free(r_tmp1
);
2156 tcg_gen_ext32s_tl(t0
, t0
);
2157 tcg_gen_ext32s_tl(t1
, t1
);
2158 gen_store_LO(t0
, 0);
2159 gen_store_HI(t1
, 0);
2165 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2166 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2167 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2169 tcg_gen_ext32u_tl(t0
, t0
);
2170 tcg_gen_ext32u_tl(t1
, t1
);
2171 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
2172 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
2173 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2176 tcg_gen_extu_tl_i64(r_tmp2
, t0
);
2177 tcg_gen_extu_tl_i64(r_tmp3
, t1
);
2178 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2179 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2180 tcg_temp_free(r_tmp3
);
2181 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2182 tcg_temp_free(r_tmp2
);
2183 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2184 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2185 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2186 tcg_temp_free(r_tmp1
);
2187 tcg_gen_ext32s_tl(t0
, t0
);
2188 tcg_gen_ext32s_tl(t1
, t1
);
2189 gen_store_LO(t0
, 0);
2190 gen_store_HI(t1
, 0);
2196 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2197 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2198 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2200 tcg_gen_ext32s_tl(t0
, t0
);
2201 tcg_gen_ext32s_tl(t1
, t1
);
2202 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
2203 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
2204 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2207 tcg_gen_extu_tl_i64(r_tmp2
, t0
);
2208 tcg_gen_extu_tl_i64(r_tmp3
, t1
);
2209 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2210 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2211 tcg_temp_free(r_tmp3
);
2212 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2213 tcg_temp_free(r_tmp2
);
2214 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2215 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2216 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2217 tcg_temp_free(r_tmp1
);
2218 tcg_gen_ext32s_tl(t0
, t0
);
2219 tcg_gen_ext32s_tl(t1
, t1
);
2220 gen_store_LO(t0
, 0);
2221 gen_store_HI(t1
, 0);
2227 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2228 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2229 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2231 tcg_gen_ext32u_tl(t0
, t0
);
2232 tcg_gen_ext32u_tl(t1
, t1
);
2233 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
2234 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
2235 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2238 tcg_gen_extu_tl_i64(r_tmp2
, t0
);
2239 tcg_gen_extu_tl_i64(r_tmp3
, t1
);
2240 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2241 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2242 tcg_temp_free(r_tmp3
);
2243 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2244 tcg_temp_free(r_tmp2
);
2245 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2246 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2247 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2248 tcg_temp_free(r_tmp1
);
2249 tcg_gen_ext32s_tl(t0
, t0
);
2250 tcg_gen_ext32s_tl(t1
, t1
);
2251 gen_store_LO(t0
, 0);
2252 gen_store_HI(t1
, 0);
2258 generate_exception(ctx
, EXCP_RI
);
2261 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2267 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2268 int rd
, int rs
, int rt
)
2270 const char *opn
= "mul vr54xx";
2271 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2272 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2274 gen_load_gpr(t0
, rs
);
2275 gen_load_gpr(t1
, rt
);
2278 case OPC_VR54XX_MULS
:
2279 tcg_gen_helper_1_2(do_muls
, t0
, t0
, t1
);
2282 case OPC_VR54XX_MULSU
:
2283 tcg_gen_helper_1_2(do_mulsu
, t0
, t0
, t1
);
2286 case OPC_VR54XX_MACC
:
2287 tcg_gen_helper_1_2(do_macc
, t0
, t0
, t1
);
2290 case OPC_VR54XX_MACCU
:
2291 tcg_gen_helper_1_2(do_maccu
, t0
, t0
, t1
);
2294 case OPC_VR54XX_MSAC
:
2295 tcg_gen_helper_1_2(do_msac
, t0
, t0
, t1
);
2298 case OPC_VR54XX_MSACU
:
2299 tcg_gen_helper_1_2(do_msacu
, t0
, t0
, t1
);
2302 case OPC_VR54XX_MULHI
:
2303 tcg_gen_helper_1_2(do_mulhi
, t0
, t0
, t1
);
2306 case OPC_VR54XX_MULHIU
:
2307 tcg_gen_helper_1_2(do_mulhiu
, t0
, t0
, t1
);
2310 case OPC_VR54XX_MULSHI
:
2311 tcg_gen_helper_1_2(do_mulshi
, t0
, t0
, t1
);
2314 case OPC_VR54XX_MULSHIU
:
2315 tcg_gen_helper_1_2(do_mulshiu
, t0
, t0
, t1
);
2318 case OPC_VR54XX_MACCHI
:
2319 tcg_gen_helper_1_2(do_macchi
, t0
, t0
, t1
);
2322 case OPC_VR54XX_MACCHIU
:
2323 tcg_gen_helper_1_2(do_macchiu
, t0
, t0
, t1
);
2326 case OPC_VR54XX_MSACHI
:
2327 tcg_gen_helper_1_2(do_msachi
, t0
, t0
, t1
);
2330 case OPC_VR54XX_MSACHIU
:
2331 tcg_gen_helper_1_2(do_msachiu
, t0
, t0
, t1
);
2335 MIPS_INVAL("mul vr54xx");
2336 generate_exception(ctx
, EXCP_RI
);
2339 gen_store_gpr(t0
, rd
);
2340 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2347 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2350 const char *opn
= "CLx";
2351 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2358 gen_load_gpr(t0
, rs
);
2361 tcg_gen_helper_1_1(do_clo
, t0
, t0
);
2365 tcg_gen_helper_1_1(do_clz
, t0
, t0
);
2368 #if defined(TARGET_MIPS64)
2370 tcg_gen_helper_1_1(do_dclo
, t0
, t0
);
2374 tcg_gen_helper_1_1(do_dclz
, t0
, t0
);
2380 generate_exception(ctx
, EXCP_RI
);
2383 gen_store_gpr(t0
, rd
);
2384 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2391 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2392 int rs
, int rt
, int16_t imm
)
2395 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2396 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2399 /* Load needed operands */
2407 /* Compare two registers */
2409 gen_load_gpr(t0
, rs
);
2410 gen_load_gpr(t1
, rt
);
2420 /* Compare register to immediate */
2421 if (rs
!= 0 || imm
!= 0) {
2422 gen_load_gpr(t0
, rs
);
2423 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2430 case OPC_TEQ
: /* rs == rs */
2431 case OPC_TEQI
: /* r0 == 0 */
2432 case OPC_TGE
: /* rs >= rs */
2433 case OPC_TGEI
: /* r0 >= 0 */
2434 case OPC_TGEU
: /* rs >= rs unsigned */
2435 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2437 tcg_gen_movi_tl(t0
, 1);
2439 case OPC_TLT
: /* rs < rs */
2440 case OPC_TLTI
: /* r0 < 0 */
2441 case OPC_TLTU
: /* rs < rs unsigned */
2442 case OPC_TLTIU
: /* r0 < 0 unsigned */
2443 case OPC_TNE
: /* rs != rs */
2444 case OPC_TNEI
: /* r0 != 0 */
2445 /* Never trap: treat as NOP. */
2449 generate_exception(ctx
, EXCP_RI
);
2480 generate_exception(ctx
, EXCP_RI
);
2484 save_cpu_state(ctx
, 1);
2486 int l1
= gen_new_label();
2488 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2489 tcg_gen_helper_0_i(do_raise_exception
, EXCP_TRAP
);
2492 ctx
->bstate
= BS_STOP
;
2498 static always_inline
void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2500 TranslationBlock
*tb
;
2502 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2505 tcg_gen_exit_tb((long)tb
+ n
);
2512 /* Branches (before delay slot) */
2513 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2514 int rs
, int rt
, int32_t offset
)
2516 target_ulong btarget
= -1;
2519 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2520 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2522 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2523 #ifdef MIPS_DEBUG_DISAS
2524 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2526 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
2530 generate_exception(ctx
, EXCP_RI
);
2534 /* Load needed operands */
2540 /* Compare two registers */
2542 gen_load_gpr(t0
, rs
);
2543 gen_load_gpr(t1
, rt
);
2546 btarget
= ctx
->pc
+ 4 + offset
;
2560 /* Compare to zero */
2562 gen_load_gpr(t0
, rs
);
2565 btarget
= ctx
->pc
+ 4 + offset
;
2569 /* Jump to immediate */
2570 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2574 /* Jump to register */
2575 if (offset
!= 0 && offset
!= 16) {
2576 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2577 others are reserved. */
2578 MIPS_INVAL("jump hint");
2579 generate_exception(ctx
, EXCP_RI
);
2582 gen_save_breg_target(rs
);
2585 MIPS_INVAL("branch/jump");
2586 generate_exception(ctx
, EXCP_RI
);
2590 /* No condition to be computed */
2592 case OPC_BEQ
: /* rx == rx */
2593 case OPC_BEQL
: /* rx == rx likely */
2594 case OPC_BGEZ
: /* 0 >= 0 */
2595 case OPC_BGEZL
: /* 0 >= 0 likely */
2596 case OPC_BLEZ
: /* 0 <= 0 */
2597 case OPC_BLEZL
: /* 0 <= 0 likely */
2599 ctx
->hflags
|= MIPS_HFLAG_B
;
2600 MIPS_DEBUG("balways");
2602 case OPC_BGEZAL
: /* 0 >= 0 */
2603 case OPC_BGEZALL
: /* 0 >= 0 likely */
2604 /* Always take and link */
2606 ctx
->hflags
|= MIPS_HFLAG_B
;
2607 MIPS_DEBUG("balways and link");
2609 case OPC_BNE
: /* rx != rx */
2610 case OPC_BGTZ
: /* 0 > 0 */
2611 case OPC_BLTZ
: /* 0 < 0 */
2613 MIPS_DEBUG("bnever (NOP)");
2615 case OPC_BLTZAL
: /* 0 < 0 */
2616 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2617 gen_store_gpr(t0
, 31);
2618 MIPS_DEBUG("bnever and link");
2620 case OPC_BLTZALL
: /* 0 < 0 likely */
2621 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2622 gen_store_gpr(t0
, 31);
2623 /* Skip the instruction in the delay slot */
2624 MIPS_DEBUG("bnever, link and skip");
2627 case OPC_BNEL
: /* rx != rx likely */
2628 case OPC_BGTZL
: /* 0 > 0 likely */
2629 case OPC_BLTZL
: /* 0 < 0 likely */
2630 /* Skip the instruction in the delay slot */
2631 MIPS_DEBUG("bnever and skip");
2635 ctx
->hflags
|= MIPS_HFLAG_B
;
2636 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
2640 ctx
->hflags
|= MIPS_HFLAG_B
;
2641 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
2644 ctx
->hflags
|= MIPS_HFLAG_BR
;
2645 MIPS_DEBUG("jr %s", regnames
[rs
]);
2649 ctx
->hflags
|= MIPS_HFLAG_BR
;
2650 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2653 MIPS_INVAL("branch/jump");
2654 generate_exception(ctx
, EXCP_RI
);
2661 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2662 regnames
[rs
], regnames
[rt
], btarget
);
2666 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2667 regnames
[rs
], regnames
[rt
], btarget
);
2671 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2672 regnames
[rs
], regnames
[rt
], btarget
);
2676 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2677 regnames
[rs
], regnames
[rt
], btarget
);
2681 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2685 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2689 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2695 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2699 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2703 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2707 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2711 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2715 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2719 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2724 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2726 ctx
->hflags
|= MIPS_HFLAG_BC
;
2727 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, bcond
));
2732 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2734 ctx
->hflags
|= MIPS_HFLAG_BL
;
2735 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, bcond
));
2738 MIPS_INVAL("conditional branch/jump");
2739 generate_exception(ctx
, EXCP_RI
);
2743 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2744 blink
, ctx
->hflags
, btarget
);
2746 ctx
->btarget
= btarget
;
2748 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2749 gen_store_gpr(t0
, blink
);
2757 /* special3 bitfield operations */
2758 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2759 int rs
, int lsb
, int msb
)
2761 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2762 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2764 gen_load_gpr(t1
, rs
);
2769 tcg_gen_helper_1_2ii(do_ext
, t0
, t0
, t1
, lsb
, msb
+ 1);
2771 #if defined(TARGET_MIPS64)
2775 tcg_gen_helper_1_2ii(do_dext
, t0
, t0
, t1
, lsb
, msb
+ 1 + 32);
2780 tcg_gen_helper_1_2ii(do_dext
, t0
, t0
, t1
, lsb
+ 32, msb
+ 1);
2785 tcg_gen_helper_1_2ii(do_dext
, t0
, t0
, t1
, lsb
, msb
+ 1);
2791 gen_load_gpr(t0
, rt
);
2792 tcg_gen_helper_1_2ii(do_ins
, t0
, t0
, t1
, lsb
, msb
- lsb
+ 1);
2794 #if defined(TARGET_MIPS64)
2798 gen_load_gpr(t0
, rt
);
2799 tcg_gen_helper_1_2ii(do_dins
, t0
, t0
, t1
, lsb
, msb
- lsb
+ 1 + 32);
2804 gen_load_gpr(t0
, rt
);
2805 tcg_gen_helper_1_2ii(do_dins
, t0
, t0
, t1
, lsb
+ 32, msb
- lsb
+ 1);
2810 gen_load_gpr(t0
, rt
);
2811 tcg_gen_helper_1_2ii(do_dins
, t0
, t0
, t1
, lsb
, msb
- lsb
+ 1);
2816 MIPS_INVAL("bitops");
2817 generate_exception(ctx
, EXCP_RI
);
2822 gen_store_gpr(t0
, rt
);
2827 /* CP0 (MMU and control) */
2828 #ifndef CONFIG_USER_ONLY
2829 static inline void gen_mfc0_load32 (TCGv t
, target_ulong off
)
2831 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
2833 tcg_gen_ld_i32(r_tmp
, cpu_env
, off
);
2834 tcg_gen_ext_i32_tl(t
, r_tmp
);
2835 tcg_temp_free(r_tmp
);
2838 static inline void gen_mfc0_load64 (TCGv t
, target_ulong off
)
2840 tcg_gen_ld_tl(t
, cpu_env
, off
);
2841 tcg_gen_ext32s_tl(t
, t
);
2844 static inline void gen_mtc0_store32 (TCGv t
, target_ulong off
)
2846 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
2848 tcg_gen_trunc_tl_i32(r_tmp
, t
);
2849 tcg_gen_st_i32(r_tmp
, cpu_env
, off
);
2850 tcg_temp_free(r_tmp
);
2853 static inline void gen_mtc0_store64 (TCGv t
, target_ulong off
)
2855 tcg_gen_ext32s_tl(t
, t
);
2856 tcg_gen_st_tl(t
, cpu_env
, off
);
2859 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
2861 const char *rn
= "invalid";
2864 check_insn(env
, ctx
, ISA_MIPS32
);
2870 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Index
));
2874 check_insn(env
, ctx
, ASE_MT
);
2875 tcg_gen_helper_1_0(do_mfc0_mvpcontrol
, t0
);
2879 check_insn(env
, ctx
, ASE_MT
);
2880 tcg_gen_helper_1_0(do_mfc0_mvpconf0
, t0
);
2884 check_insn(env
, ctx
, ASE_MT
);
2885 tcg_gen_helper_1_0(do_mfc0_mvpconf1
, t0
);
2895 tcg_gen_helper_1_0(do_mfc0_random
, t0
);
2899 check_insn(env
, ctx
, ASE_MT
);
2900 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEControl
));
2904 check_insn(env
, ctx
, ASE_MT
);
2905 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf0
));
2909 check_insn(env
, ctx
, ASE_MT
);
2910 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf1
));
2914 check_insn(env
, ctx
, ASE_MT
);
2915 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_YQMask
));
2919 check_insn(env
, ctx
, ASE_MT
);
2920 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_VPESchedule
));
2924 check_insn(env
, ctx
, ASE_MT
);
2925 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_VPEScheFBack
));
2926 rn
= "VPEScheFBack";
2929 check_insn(env
, ctx
, ASE_MT
);
2930 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEOpt
));
2940 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2941 tcg_gen_ext32s_tl(t0
, t0
);
2945 check_insn(env
, ctx
, ASE_MT
);
2946 tcg_gen_helper_1_0(do_mfc0_tcstatus
, t0
);
2950 check_insn(env
, ctx
, ASE_MT
);
2951 tcg_gen_helper_1_0(do_mfc0_tcbind
, t0
);
2955 check_insn(env
, ctx
, ASE_MT
);
2956 tcg_gen_helper_1_0(do_mfc0_tcrestart
, t0
);
2960 check_insn(env
, ctx
, ASE_MT
);
2961 tcg_gen_helper_1_0(do_mfc0_tchalt
, t0
);
2965 check_insn(env
, ctx
, ASE_MT
);
2966 tcg_gen_helper_1_0(do_mfc0_tccontext
, t0
);
2970 check_insn(env
, ctx
, ASE_MT
);
2971 tcg_gen_helper_1_0(do_mfc0_tcschedule
, t0
);
2975 check_insn(env
, ctx
, ASE_MT
);
2976 tcg_gen_helper_1_0(do_mfc0_tcschefback
, t0
);
2986 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2987 tcg_gen_ext32s_tl(t0
, t0
);
2997 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_Context
));
2998 tcg_gen_ext32s_tl(t0
, t0
);
3002 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
3003 rn
= "ContextConfig";
3012 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageMask
));
3016 check_insn(env
, ctx
, ISA_MIPS32R2
);
3017 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageGrain
));
3027 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Wired
));
3031 check_insn(env
, ctx
, ISA_MIPS32R2
);
3032 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf0
));
3036 check_insn(env
, ctx
, ISA_MIPS32R2
);
3037 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf1
));
3041 check_insn(env
, ctx
, ISA_MIPS32R2
);
3042 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf2
));
3046 check_insn(env
, ctx
, ISA_MIPS32R2
);
3047 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf3
));
3051 check_insn(env
, ctx
, ISA_MIPS32R2
);
3052 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf4
));
3062 check_insn(env
, ctx
, ISA_MIPS32R2
);
3063 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_HWREna
));
3073 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3074 tcg_gen_ext32s_tl(t0
, t0
);
3084 tcg_gen_helper_1_0(do_mfc0_count
, t0
);
3087 /* 6,7 are implementation dependent */
3095 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3096 tcg_gen_ext32s_tl(t0
, t0
);
3106 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Compare
));
3109 /* 6,7 are implementation dependent */
3117 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Status
));
3121 check_insn(env
, ctx
, ISA_MIPS32R2
);
3122 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_IntCtl
));
3126 check_insn(env
, ctx
, ISA_MIPS32R2
);
3127 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSCtl
));
3131 check_insn(env
, ctx
, ISA_MIPS32R2
);
3132 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSMap
));
3142 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Cause
));
3152 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3153 tcg_gen_ext32s_tl(t0
, t0
);
3163 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PRid
));
3167 check_insn(env
, ctx
, ISA_MIPS32R2
);
3168 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_EBase
));
3178 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config0
));
3182 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config1
));
3186 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config2
));
3190 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config3
));
3193 /* 4,5 are reserved */
3194 /* 6,7 are implementation dependent */
3196 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config6
));
3200 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config7
));
3210 tcg_gen_helper_1_0(do_mfc0_lladdr
, t0
);
3220 tcg_gen_helper_1_i(do_mfc0_watchlo
, t0
, sel
);
3230 tcg_gen_helper_1_i(do_mfc0_watchhi
, t0
, sel
);
3240 #if defined(TARGET_MIPS64)
3241 check_insn(env
, ctx
, ISA_MIPS3
);
3242 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3243 tcg_gen_ext32s_tl(t0
, t0
);
3252 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3255 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Framemask
));
3264 rn
= "'Diagnostic"; /* implementation dependent */
3269 tcg_gen_helper_1_0(do_mfc0_debug
, t0
); /* EJTAG support */
3273 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3274 rn
= "TraceControl";
3277 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3278 rn
= "TraceControl2";
3281 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3282 rn
= "UserTraceData";
3285 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3296 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3297 tcg_gen_ext32s_tl(t0
, t0
);
3307 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Performance0
));
3308 rn
= "Performance0";
3311 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3312 rn
= "Performance1";
3315 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3316 rn
= "Performance2";
3319 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3320 rn
= "Performance3";
3323 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3324 rn
= "Performance4";
3327 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3328 rn
= "Performance5";
3331 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3332 rn
= "Performance6";
3335 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3336 rn
= "Performance7";
3361 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagLo
));
3368 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataLo
));
3381 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagHi
));
3388 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataHi
));
3398 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3399 tcg_gen_ext32s_tl(t0
, t0
);
3410 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DESAVE
));
3420 #if defined MIPS_DEBUG_DISAS
3421 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3422 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3429 #if defined MIPS_DEBUG_DISAS
3430 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3431 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3435 generate_exception(ctx
, EXCP_RI
);
3438 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
3440 const char *rn
= "invalid";
3443 check_insn(env
, ctx
, ISA_MIPS32
);
3449 tcg_gen_helper_0_1(do_mtc0_index
, t0
);
3453 check_insn(env
, ctx
, ASE_MT
);
3454 tcg_gen_helper_0_1(do_mtc0_mvpcontrol
, t0
);
3458 check_insn(env
, ctx
, ASE_MT
);
3463 check_insn(env
, ctx
, ASE_MT
);
3478 check_insn(env
, ctx
, ASE_MT
);
3479 tcg_gen_helper_0_1(do_mtc0_vpecontrol
, t0
);
3483 check_insn(env
, ctx
, ASE_MT
);
3484 tcg_gen_helper_0_1(do_mtc0_vpeconf0
, t0
);
3488 check_insn(env
, ctx
, ASE_MT
);
3489 tcg_gen_helper_0_1(do_mtc0_vpeconf1
, t0
);
3493 check_insn(env
, ctx
, ASE_MT
);
3494 tcg_gen_helper_0_1(do_mtc0_yqmask
, t0
);
3498 check_insn(env
, ctx
, ASE_MT
);
3499 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_VPESchedule
));
3503 check_insn(env
, ctx
, ASE_MT
);
3504 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_VPEScheFBack
));
3505 rn
= "VPEScheFBack";
3508 check_insn(env
, ctx
, ASE_MT
);
3509 tcg_gen_helper_0_1(do_mtc0_vpeopt
, t0
);
3519 tcg_gen_helper_0_1(do_mtc0_entrylo0
, t0
);
3523 check_insn(env
, ctx
, ASE_MT
);
3524 tcg_gen_helper_0_1(do_mtc0_tcstatus
, t0
);
3528 check_insn(env
, ctx
, ASE_MT
);
3529 tcg_gen_helper_0_1(do_mtc0_tcbind
, t0
);
3533 check_insn(env
, ctx
, ASE_MT
);
3534 tcg_gen_helper_0_1(do_mtc0_tcrestart
, t0
);
3538 check_insn(env
, ctx
, ASE_MT
);
3539 tcg_gen_helper_0_1(do_mtc0_tchalt
, t0
);
3543 check_insn(env
, ctx
, ASE_MT
);
3544 tcg_gen_helper_0_1(do_mtc0_tccontext
, t0
);
3548 check_insn(env
, ctx
, ASE_MT
);
3549 tcg_gen_helper_0_1(do_mtc0_tcschedule
, t0
);
3553 check_insn(env
, ctx
, ASE_MT
);
3554 tcg_gen_helper_0_1(do_mtc0_tcschefback
, t0
);
3564 tcg_gen_helper_0_1(do_mtc0_entrylo1
, t0
);
3574 tcg_gen_helper_0_1(do_mtc0_context
, t0
);
3578 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3579 rn
= "ContextConfig";
3588 tcg_gen_helper_0_1(do_mtc0_pagemask
, t0
);
3592 check_insn(env
, ctx
, ISA_MIPS32R2
);
3593 tcg_gen_helper_0_1(do_mtc0_pagegrain
, t0
);
3603 tcg_gen_helper_0_1(do_mtc0_wired
, t0
);
3607 check_insn(env
, ctx
, ISA_MIPS32R2
);
3608 tcg_gen_helper_0_1(do_mtc0_srsconf0
, t0
);
3612 check_insn(env
, ctx
, ISA_MIPS32R2
);
3613 tcg_gen_helper_0_1(do_mtc0_srsconf1
, t0
);
3617 check_insn(env
, ctx
, ISA_MIPS32R2
);
3618 tcg_gen_helper_0_1(do_mtc0_srsconf2
, t0
);
3622 check_insn(env
, ctx
, ISA_MIPS32R2
);
3623 tcg_gen_helper_0_1(do_mtc0_srsconf3
, t0
);
3627 check_insn(env
, ctx
, ISA_MIPS32R2
);
3628 tcg_gen_helper_0_1(do_mtc0_srsconf4
, t0
);
3638 check_insn(env
, ctx
, ISA_MIPS32R2
);
3639 tcg_gen_helper_0_1(do_mtc0_hwrena
, t0
);
3653 tcg_gen_helper_0_1(do_mtc0_count
, t0
);
3656 /* 6,7 are implementation dependent */
3660 /* Stop translation as we may have switched the execution mode */
3661 ctx
->bstate
= BS_STOP
;
3666 tcg_gen_helper_0_1(do_mtc0_entryhi
, t0
);
3676 tcg_gen_helper_0_1(do_mtc0_compare
, t0
);
3679 /* 6,7 are implementation dependent */
3683 /* Stop translation as we may have switched the execution mode */
3684 ctx
->bstate
= BS_STOP
;
3689 tcg_gen_helper_0_1(do_mtc0_status
, t0
);
3690 /* BS_STOP isn't good enough here, hflags may have changed. */
3691 gen_save_pc(ctx
->pc
+ 4);
3692 ctx
->bstate
= BS_EXCP
;
3696 check_insn(env
, ctx
, ISA_MIPS32R2
);
3697 tcg_gen_helper_0_1(do_mtc0_intctl
, t0
);
3698 /* Stop translation as we may have switched the execution mode */
3699 ctx
->bstate
= BS_STOP
;
3703 check_insn(env
, ctx
, ISA_MIPS32R2
);
3704 tcg_gen_helper_0_1(do_mtc0_srsctl
, t0
);
3705 /* Stop translation as we may have switched the execution mode */
3706 ctx
->bstate
= BS_STOP
;
3710 check_insn(env
, ctx
, ISA_MIPS32R2
);
3711 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_SRSMap
));
3712 /* Stop translation as we may have switched the execution mode */
3713 ctx
->bstate
= BS_STOP
;
3723 tcg_gen_helper_0_1(do_mtc0_cause
, t0
);
3729 /* Stop translation as we may have switched the execution mode */
3730 ctx
->bstate
= BS_STOP
;
3735 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_EPC
));
3749 check_insn(env
, ctx
, ISA_MIPS32R2
);
3750 tcg_gen_helper_0_1(do_mtc0_ebase
, t0
);
3760 tcg_gen_helper_0_1(do_mtc0_config0
, t0
);
3762 /* Stop translation as we may have switched the execution mode */
3763 ctx
->bstate
= BS_STOP
;
3766 /* ignored, read only */
3770 tcg_gen_helper_0_1(do_mtc0_config2
, t0
);
3772 /* Stop translation as we may have switched the execution mode */
3773 ctx
->bstate
= BS_STOP
;
3776 /* ignored, read only */
3779 /* 4,5 are reserved */
3780 /* 6,7 are implementation dependent */
3790 rn
= "Invalid config selector";
3807 tcg_gen_helper_0_1i(do_mtc0_watchlo
, t0
, sel
);
3817 tcg_gen_helper_0_1i(do_mtc0_watchhi
, t0
, sel
);
3827 #if defined(TARGET_MIPS64)
3828 check_insn(env
, ctx
, ISA_MIPS3
);
3829 tcg_gen_helper_0_1(do_mtc0_xcontext
, t0
);
3838 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3841 tcg_gen_helper_0_1(do_mtc0_framemask
, t0
);
3850 rn
= "Diagnostic"; /* implementation dependent */
3855 tcg_gen_helper_0_1(do_mtc0_debug
, t0
); /* EJTAG support */
3856 /* BS_STOP isn't good enough here, hflags may have changed. */
3857 gen_save_pc(ctx
->pc
+ 4);
3858 ctx
->bstate
= BS_EXCP
;
3862 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3863 rn
= "TraceControl";
3864 /* Stop translation as we may have switched the execution mode */
3865 ctx
->bstate
= BS_STOP
;
3868 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3869 rn
= "TraceControl2";
3870 /* Stop translation as we may have switched the execution mode */
3871 ctx
->bstate
= BS_STOP
;
3874 /* Stop translation as we may have switched the execution mode */
3875 ctx
->bstate
= BS_STOP
;
3876 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3877 rn
= "UserTraceData";
3878 /* Stop translation as we may have switched the execution mode */
3879 ctx
->bstate
= BS_STOP
;
3882 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3883 /* Stop translation as we may have switched the execution mode */
3884 ctx
->bstate
= BS_STOP
;
3895 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_DEPC
));
3905 tcg_gen_helper_0_1(do_mtc0_performance0
, t0
);
3906 rn
= "Performance0";
3909 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3910 rn
= "Performance1";
3913 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3914 rn
= "Performance2";
3917 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3918 rn
= "Performance3";
3921 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3922 rn
= "Performance4";
3925 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3926 rn
= "Performance5";
3929 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3930 rn
= "Performance6";
3933 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3934 rn
= "Performance7";
3960 tcg_gen_helper_0_1(do_mtc0_taglo
, t0
);
3967 tcg_gen_helper_0_1(do_mtc0_datalo
, t0
);
3980 tcg_gen_helper_0_1(do_mtc0_taghi
, t0
);
3987 tcg_gen_helper_0_1(do_mtc0_datahi
, t0
);
3998 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_ErrorEPC
));
4009 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_DESAVE
));
4015 /* Stop translation as we may have switched the execution mode */
4016 ctx
->bstate
= BS_STOP
;
4021 #if defined MIPS_DEBUG_DISAS
4022 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4023 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
4030 #if defined MIPS_DEBUG_DISAS
4031 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4032 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
4036 generate_exception(ctx
, EXCP_RI
);
4039 #if defined(TARGET_MIPS64)
4040 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
4042 const char *rn
= "invalid";
4045 check_insn(env
, ctx
, ISA_MIPS64
);
4051 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Index
));
4055 check_insn(env
, ctx
, ASE_MT
);
4056 tcg_gen_helper_1_0(do_mfc0_mvpcontrol
, t0
);
4060 check_insn(env
, ctx
, ASE_MT
);
4061 tcg_gen_helper_1_0(do_mfc0_mvpconf0
, t0
);
4065 check_insn(env
, ctx
, ASE_MT
);
4066 tcg_gen_helper_1_0(do_mfc0_mvpconf1
, t0
);
4076 tcg_gen_helper_1_0(do_mfc0_random
, t0
);
4080 check_insn(env
, ctx
, ASE_MT
);
4081 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEControl
));
4085 check_insn(env
, ctx
, ASE_MT
);
4086 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf0
));
4090 check_insn(env
, ctx
, ASE_MT
);
4091 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf1
));
4095 check_insn(env
, ctx
, ASE_MT
);
4096 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4100 check_insn(env
, ctx
, ASE_MT
);
4101 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4105 check_insn(env
, ctx
, ASE_MT
);
4106 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4107 rn
= "VPEScheFBack";
4110 check_insn(env
, ctx
, ASE_MT
);
4111 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEOpt
));
4121 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4125 check_insn(env
, ctx
, ASE_MT
);
4126 tcg_gen_helper_1_0(do_mfc0_tcstatus
, t0
);
4130 check_insn(env
, ctx
, ASE_MT
);
4131 tcg_gen_helper_1_0(do_mfc0_tcbind
, t0
);
4135 check_insn(env
, ctx
, ASE_MT
);
4136 tcg_gen_helper_1_0(do_dmfc0_tcrestart
, t0
);
4140 check_insn(env
, ctx
, ASE_MT
);
4141 tcg_gen_helper_1_0(do_dmfc0_tchalt
, t0
);
4145 check_insn(env
, ctx
, ASE_MT
);
4146 tcg_gen_helper_1_0(do_dmfc0_tccontext
, t0
);
4150 check_insn(env
, ctx
, ASE_MT
);
4151 tcg_gen_helper_1_0(do_dmfc0_tcschedule
, t0
);
4155 check_insn(env
, ctx
, ASE_MT
);
4156 tcg_gen_helper_1_0(do_dmfc0_tcschefback
, t0
);
4166 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4176 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4180 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4181 rn
= "ContextConfig";
4190 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageMask
));
4194 check_insn(env
, ctx
, ISA_MIPS32R2
);
4195 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageGrain
));
4205 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Wired
));
4209 check_insn(env
, ctx
, ISA_MIPS32R2
);
4210 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf0
));
4214 check_insn(env
, ctx
, ISA_MIPS32R2
);
4215 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf1
));
4219 check_insn(env
, ctx
, ISA_MIPS32R2
);
4220 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf2
));
4224 check_insn(env
, ctx
, ISA_MIPS32R2
);
4225 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf3
));
4229 check_insn(env
, ctx
, ISA_MIPS32R2
);
4230 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf4
));
4240 check_insn(env
, ctx
, ISA_MIPS32R2
);
4241 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_HWREna
));
4251 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4261 tcg_gen_helper_1_0(do_mfc0_count
, t0
);
4264 /* 6,7 are implementation dependent */
4272 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4282 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Compare
));
4285 /* 6,7 are implementation dependent */
4293 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Status
));
4297 check_insn(env
, ctx
, ISA_MIPS32R2
);
4298 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_IntCtl
));
4302 check_insn(env
, ctx
, ISA_MIPS32R2
);
4303 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSCtl
));
4307 check_insn(env
, ctx
, ISA_MIPS32R2
);
4308 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSMap
));
4318 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Cause
));
4328 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4338 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PRid
));
4342 check_insn(env
, ctx
, ISA_MIPS32R2
);
4343 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_EBase
));
4353 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config0
));
4357 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config1
));
4361 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config2
));
4365 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config3
));
4368 /* 6,7 are implementation dependent */
4370 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config6
));
4374 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config7
));
4384 tcg_gen_helper_1_0(do_dmfc0_lladdr
, t0
);
4394 tcg_gen_helper_1_i(do_dmfc0_watchlo
, t0
, sel
);
4404 tcg_gen_helper_1_i(do_mfc0_watchhi
, t0
, sel
);
4414 check_insn(env
, ctx
, ISA_MIPS3
);
4415 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4423 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4426 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Framemask
));
4435 rn
= "'Diagnostic"; /* implementation dependent */
4440 tcg_gen_helper_1_0(do_mfc0_debug
, t0
); /* EJTAG support */
4444 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4445 rn
= "TraceControl";
4448 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4449 rn
= "TraceControl2";
4452 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4453 rn
= "UserTraceData";
4456 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4467 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4477 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Performance0
));
4478 rn
= "Performance0";
4481 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4482 rn
= "Performance1";
4485 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4486 rn
= "Performance2";
4489 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4490 rn
= "Performance3";
4493 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4494 rn
= "Performance4";
4497 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4498 rn
= "Performance5";
4501 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4502 rn
= "Performance6";
4505 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4506 rn
= "Performance7";
4531 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagLo
));
4538 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataLo
));
4551 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagHi
));
4558 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataHi
));
4568 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4579 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DESAVE
));
4589 #if defined MIPS_DEBUG_DISAS
4590 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4591 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4598 #if defined MIPS_DEBUG_DISAS
4599 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4600 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4604 generate_exception(ctx
, EXCP_RI
);
4607 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
4609 const char *rn
= "invalid";
4612 check_insn(env
, ctx
, ISA_MIPS64
);
4618 tcg_gen_helper_0_1(do_mtc0_index
, t0
);
4622 check_insn(env
, ctx
, ASE_MT
);
4623 tcg_gen_helper_0_1(do_mtc0_mvpcontrol
, t0
);
4627 check_insn(env
, ctx
, ASE_MT
);
4632 check_insn(env
, ctx
, ASE_MT
);
4647 check_insn(env
, ctx
, ASE_MT
);
4648 tcg_gen_helper_0_1(do_mtc0_vpecontrol
, t0
);
4652 check_insn(env
, ctx
, ASE_MT
);
4653 tcg_gen_helper_0_1(do_mtc0_vpeconf0
, t0
);
4657 check_insn(env
, ctx
, ASE_MT
);
4658 tcg_gen_helper_0_1(do_mtc0_vpeconf1
, t0
);
4662 check_insn(env
, ctx
, ASE_MT
);
4663 tcg_gen_helper_0_1(do_mtc0_yqmask
, t0
);
4667 check_insn(env
, ctx
, ASE_MT
);
4668 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4672 check_insn(env
, ctx
, ASE_MT
);
4673 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4674 rn
= "VPEScheFBack";
4677 check_insn(env
, ctx
, ASE_MT
);
4678 tcg_gen_helper_0_1(do_mtc0_vpeopt
, t0
);
4688 tcg_gen_helper_0_1(do_mtc0_entrylo0
, t0
);
4692 check_insn(env
, ctx
, ASE_MT
);
4693 tcg_gen_helper_0_1(do_mtc0_tcstatus
, t0
);
4697 check_insn(env
, ctx
, ASE_MT
);
4698 tcg_gen_helper_0_1(do_mtc0_tcbind
, t0
);
4702 check_insn(env
, ctx
, ASE_MT
);
4703 tcg_gen_helper_0_1(do_mtc0_tcrestart
, t0
);
4707 check_insn(env
, ctx
, ASE_MT
);
4708 tcg_gen_helper_0_1(do_mtc0_tchalt
, t0
);
4712 check_insn(env
, ctx
, ASE_MT
);
4713 tcg_gen_helper_0_1(do_mtc0_tccontext
, t0
);
4717 check_insn(env
, ctx
, ASE_MT
);
4718 tcg_gen_helper_0_1(do_mtc0_tcschedule
, t0
);
4722 check_insn(env
, ctx
, ASE_MT
);
4723 tcg_gen_helper_0_1(do_mtc0_tcschefback
, t0
);
4733 tcg_gen_helper_0_1(do_mtc0_entrylo1
, t0
);
4743 tcg_gen_helper_0_1(do_mtc0_context
, t0
);
4747 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4748 rn
= "ContextConfig";
4757 tcg_gen_helper_0_1(do_mtc0_pagemask
, t0
);
4761 check_insn(env
, ctx
, ISA_MIPS32R2
);
4762 tcg_gen_helper_0_1(do_mtc0_pagegrain
, t0
);
4772 tcg_gen_helper_0_1(do_mtc0_wired
, t0
);
4776 check_insn(env
, ctx
, ISA_MIPS32R2
);
4777 tcg_gen_helper_0_1(do_mtc0_srsconf0
, t0
);
4781 check_insn(env
, ctx
, ISA_MIPS32R2
);
4782 tcg_gen_helper_0_1(do_mtc0_srsconf1
, t0
);
4786 check_insn(env
, ctx
, ISA_MIPS32R2
);
4787 tcg_gen_helper_0_1(do_mtc0_srsconf2
, t0
);
4791 check_insn(env
, ctx
, ISA_MIPS32R2
);
4792 tcg_gen_helper_0_1(do_mtc0_srsconf3
, t0
);
4796 check_insn(env
, ctx
, ISA_MIPS32R2
);
4797 tcg_gen_helper_0_1(do_mtc0_srsconf4
, t0
);
4807 check_insn(env
, ctx
, ISA_MIPS32R2
);
4808 tcg_gen_helper_0_1(do_mtc0_hwrena
, t0
);
4822 tcg_gen_helper_0_1(do_mtc0_count
, t0
);
4825 /* 6,7 are implementation dependent */
4829 /* Stop translation as we may have switched the execution mode */
4830 ctx
->bstate
= BS_STOP
;
4835 tcg_gen_helper_0_1(do_mtc0_entryhi
, t0
);
4845 tcg_gen_helper_0_1(do_mtc0_compare
, t0
);
4848 /* 6,7 are implementation dependent */
4852 /* Stop translation as we may have switched the execution mode */
4853 ctx
->bstate
= BS_STOP
;
4858 tcg_gen_helper_0_1(do_mtc0_status
, t0
);
4859 /* BS_STOP isn't good enough here, hflags may have changed. */
4860 gen_save_pc(ctx
->pc
+ 4);
4861 ctx
->bstate
= BS_EXCP
;
4865 check_insn(env
, ctx
, ISA_MIPS32R2
);
4866 tcg_gen_helper_0_1(do_mtc0_intctl
, t0
);
4867 /* Stop translation as we may have switched the execution mode */
4868 ctx
->bstate
= BS_STOP
;
4872 check_insn(env
, ctx
, ISA_MIPS32R2
);
4873 tcg_gen_helper_0_1(do_mtc0_srsctl
, t0
);
4874 /* Stop translation as we may have switched the execution mode */
4875 ctx
->bstate
= BS_STOP
;
4879 check_insn(env
, ctx
, ISA_MIPS32R2
);
4880 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_SRSMap
));
4881 /* Stop translation as we may have switched the execution mode */
4882 ctx
->bstate
= BS_STOP
;
4892 tcg_gen_helper_0_1(do_mtc0_cause
, t0
);
4898 /* Stop translation as we may have switched the execution mode */
4899 ctx
->bstate
= BS_STOP
;
4904 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4918 check_insn(env
, ctx
, ISA_MIPS32R2
);
4919 tcg_gen_helper_0_1(do_mtc0_ebase
, t0
);
4929 tcg_gen_helper_0_1(do_mtc0_config0
, t0
);
4931 /* Stop translation as we may have switched the execution mode */
4932 ctx
->bstate
= BS_STOP
;
4939 tcg_gen_helper_0_1(do_mtc0_config2
, t0
);
4941 /* Stop translation as we may have switched the execution mode */
4942 ctx
->bstate
= BS_STOP
;
4948 /* 6,7 are implementation dependent */
4950 rn
= "Invalid config selector";
4967 tcg_gen_helper_0_1i(do_mtc0_watchlo
, t0
, sel
);
4977 tcg_gen_helper_0_1i(do_mtc0_watchhi
, t0
, sel
);
4987 check_insn(env
, ctx
, ISA_MIPS3
);
4988 tcg_gen_helper_0_1(do_mtc0_xcontext
, t0
);
4996 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4999 tcg_gen_helper_0_1(do_mtc0_framemask
, t0
);
5008 rn
= "Diagnostic"; /* implementation dependent */
5013 tcg_gen_helper_0_1(do_mtc0_debug
, t0
); /* EJTAG support */
5014 /* BS_STOP isn't good enough here, hflags may have changed. */
5015 gen_save_pc(ctx
->pc
+ 4);
5016 ctx
->bstate
= BS_EXCP
;
5020 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
5021 /* Stop translation as we may have switched the execution mode */
5022 ctx
->bstate
= BS_STOP
;
5023 rn
= "TraceControl";
5026 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
5027 /* Stop translation as we may have switched the execution mode */
5028 ctx
->bstate
= BS_STOP
;
5029 rn
= "TraceControl2";
5032 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
5033 /* Stop translation as we may have switched the execution mode */
5034 ctx
->bstate
= BS_STOP
;
5035 rn
= "UserTraceData";
5038 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
5039 /* Stop translation as we may have switched the execution mode */
5040 ctx
->bstate
= BS_STOP
;
5051 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5061 tcg_gen_helper_0_1(do_mtc0_performance0
, t0
);
5062 rn
= "Performance0";
5065 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5066 rn
= "Performance1";
5069 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5070 rn
= "Performance2";
5073 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5074 rn
= "Performance3";
5077 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5078 rn
= "Performance4";
5081 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5082 rn
= "Performance5";
5085 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5086 rn
= "Performance6";
5089 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5090 rn
= "Performance7";
5116 tcg_gen_helper_0_1(do_mtc0_taglo
, t0
);
5123 tcg_gen_helper_0_1(do_mtc0_datalo
, t0
);
5136 tcg_gen_helper_0_1(do_mtc0_taghi
, t0
);
5143 tcg_gen_helper_0_1(do_mtc0_datahi
, t0
);
5154 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5165 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_DESAVE
));
5171 /* Stop translation as we may have switched the execution mode */
5172 ctx
->bstate
= BS_STOP
;
5177 #if defined MIPS_DEBUG_DISAS
5178 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5179 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
5188 #if defined MIPS_DEBUG_DISAS
5189 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5190 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
5194 generate_exception(ctx
, EXCP_RI
);
5196 #endif /* TARGET_MIPS64 */
5198 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5199 int u
, int sel
, int h
)
5201 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5202 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5204 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5205 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
5206 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
5207 tcg_gen_movi_tl(t0
, -1);
5208 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5209 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5210 tcg_gen_movi_tl(t0
, -1);
5216 tcg_gen_helper_1_1(do_mftc0_tcstatus
, t0
, t0
);
5219 tcg_gen_helper_1_1(do_mftc0_tcbind
, t0
, t0
);
5222 tcg_gen_helper_1_1(do_mftc0_tcrestart
, t0
, t0
);
5225 tcg_gen_helper_1_1(do_mftc0_tchalt
, t0
, t0
);
5228 tcg_gen_helper_1_1(do_mftc0_tccontext
, t0
, t0
);
5231 tcg_gen_helper_1_1(do_mftc0_tcschedule
, t0
, t0
);
5234 tcg_gen_helper_1_1(do_mftc0_tcschefback
, t0
, t0
);
5237 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5244 tcg_gen_helper_1_1(do_mftc0_entryhi
, t0
, t0
);
5247 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5253 tcg_gen_helper_1_1(do_mftc0_status
, t0
, t0
);
5256 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5262 tcg_gen_helper_1_1(do_mftc0_debug
, t0
, t0
);
5265 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5270 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5272 } else switch (sel
) {
5273 /* GPR registers. */
5275 tcg_gen_helper_1_1i(do_mftgpr
, t0
, t0
, rt
);
5277 /* Auxiliary CPU registers */
5281 tcg_gen_helper_1_1i(do_mftlo
, t0
, t0
, 0);
5284 tcg_gen_helper_1_1i(do_mfthi
, t0
, t0
, 0);
5287 tcg_gen_helper_1_1i(do_mftacx
, t0
, t0
, 0);
5290 tcg_gen_helper_1_1i(do_mftlo
, t0
, t0
, 1);
5293 tcg_gen_helper_1_1i(do_mfthi
, t0
, t0
, 1);
5296 tcg_gen_helper_1_1i(do_mftacx
, t0
, t0
, 1);
5299 tcg_gen_helper_1_1i(do_mftlo
, t0
, t0
, 2);
5302 tcg_gen_helper_1_1i(do_mfthi
, t0
, t0
, 2);
5305 tcg_gen_helper_1_1i(do_mftacx
, t0
, t0
, 2);
5308 tcg_gen_helper_1_1i(do_mftlo
, t0
, t0
, 3);
5311 tcg_gen_helper_1_1i(do_mfthi
, t0
, t0
, 3);
5314 tcg_gen_helper_1_1i(do_mftacx
, t0
, t0
, 3);
5317 tcg_gen_helper_1_1(do_mftdsp
, t0
, t0
);
5323 /* Floating point (COP1). */
5325 /* XXX: For now we support only a single FPU context. */
5327 gen_load_fpr32(fpu32_T
[0], rt
);
5328 tcg_gen_ext_i32_tl(t0
, fpu32_T
[0]);
5330 gen_load_fpr32h(fpu32h_T
[0], rt
);
5331 tcg_gen_ext_i32_tl(t0
, fpu32h_T
[0]);
5335 /* XXX: For now we support only a single FPU context. */
5336 tcg_gen_helper_1_1i(do_cfc1
, t0
, t0
, rt
);
5338 /* COP2: Not implemented. */
5345 #if defined MIPS_DEBUG_DISAS
5346 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5347 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5351 gen_store_gpr(t0
, rd
);
5357 #if defined MIPS_DEBUG_DISAS
5358 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5359 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5363 generate_exception(ctx
, EXCP_RI
);
5366 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5367 int u
, int sel
, int h
)
5369 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5370 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5372 gen_load_gpr(t0
, rt
);
5373 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5374 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
5375 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
5377 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5378 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5385 tcg_gen_helper_0_1(do_mttc0_tcstatus
, t0
);
5388 tcg_gen_helper_0_1(do_mttc0_tcbind
, t0
);
5391 tcg_gen_helper_0_1(do_mttc0_tcrestart
, t0
);
5394 tcg_gen_helper_0_1(do_mttc0_tchalt
, t0
);
5397 tcg_gen_helper_0_1(do_mttc0_tccontext
, t0
);
5400 tcg_gen_helper_0_1(do_mttc0_tcschedule
, t0
);
5403 tcg_gen_helper_0_1(do_mttc0_tcschefback
, t0
);
5406 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5413 tcg_gen_helper_0_1(do_mttc0_entryhi
, t0
);
5416 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5422 tcg_gen_helper_0_1(do_mttc0_status
, t0
);
5425 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5431 tcg_gen_helper_0_1(do_mttc0_debug
, t0
);
5434 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5439 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5441 } else switch (sel
) {
5442 /* GPR registers. */
5444 tcg_gen_helper_0_1i(do_mttgpr
, t0
, rd
);
5446 /* Auxiliary CPU registers */
5450 tcg_gen_helper_0_1i(do_mttlo
, t0
, 0);
5453 tcg_gen_helper_0_1i(do_mtthi
, t0
, 0);
5456 tcg_gen_helper_0_1i(do_mttacx
, t0
, 0);
5459 tcg_gen_helper_0_1i(do_mttlo
, t0
, 1);
5462 tcg_gen_helper_0_1i(do_mtthi
, t0
, 1);
5465 tcg_gen_helper_0_1i(do_mttacx
, t0
, 1);
5468 tcg_gen_helper_0_1i(do_mttlo
, t0
, 2);
5471 tcg_gen_helper_0_1i(do_mtthi
, t0
, 2);
5474 tcg_gen_helper_0_1i(do_mttacx
, t0
, 2);
5477 tcg_gen_helper_0_1i(do_mttlo
, t0
, 3);
5480 tcg_gen_helper_0_1i(do_mtthi
, t0
, 3);
5483 tcg_gen_helper_0_1i(do_mttacx
, t0
, 3);
5486 tcg_gen_helper_0_1(do_mttdsp
, t0
);
5492 /* Floating point (COP1). */
5494 /* XXX: For now we support only a single FPU context. */
5496 tcg_gen_trunc_tl_i32(fpu32_T
[0], t0
);
5497 gen_store_fpr32(fpu32_T
[0], rd
);
5499 tcg_gen_trunc_tl_i32(fpu32h_T
[0], t0
);
5500 gen_store_fpr32h(fpu32h_T
[0], rd
);
5504 /* XXX: For now we support only a single FPU context. */
5505 tcg_gen_helper_0_1i(do_ctc1
, t0
, rd
);
5507 /* COP2: Not implemented. */
5514 #if defined MIPS_DEBUG_DISAS
5515 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5516 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5525 #if defined MIPS_DEBUG_DISAS
5526 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5527 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5531 generate_exception(ctx
, EXCP_RI
);
5534 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5536 const char *opn
= "ldst";
5545 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5547 gen_mfc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5548 gen_store_gpr(t0
, rt
);
5555 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5557 gen_load_gpr(t0
, rt
);
5558 save_cpu_state(ctx
, 1);
5559 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5564 #if defined(TARGET_MIPS64)
5566 check_insn(env
, ctx
, ISA_MIPS3
);
5572 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5574 gen_dmfc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5575 gen_store_gpr(t0
, rt
);
5581 check_insn(env
, ctx
, ISA_MIPS3
);
5583 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5585 gen_load_gpr(t0
, rt
);
5586 save_cpu_state(ctx
, 1);
5587 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5594 check_insn(env
, ctx
, ASE_MT
);
5599 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5600 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5604 check_insn(env
, ctx
, ASE_MT
);
5605 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5606 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5611 if (!env
->tlb
->do_tlbwi
)
5613 tcg_gen_helper_0_0(env
->tlb
->do_tlbwi
);
5617 if (!env
->tlb
->do_tlbwr
)
5619 tcg_gen_helper_0_0(env
->tlb
->do_tlbwr
);
5623 if (!env
->tlb
->do_tlbp
)
5625 tcg_gen_helper_0_0(env
->tlb
->do_tlbp
);
5629 if (!env
->tlb
->do_tlbr
)
5631 tcg_gen_helper_0_0(env
->tlb
->do_tlbr
);
5635 check_insn(env
, ctx
, ISA_MIPS2
);
5636 save_cpu_state(ctx
, 1);
5637 tcg_gen_helper_0_0(do_eret
);
5638 ctx
->bstate
= BS_EXCP
;
5642 check_insn(env
, ctx
, ISA_MIPS32
);
5643 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5645 generate_exception(ctx
, EXCP_RI
);
5647 save_cpu_state(ctx
, 1);
5648 tcg_gen_helper_0_0(do_deret
);
5649 ctx
->bstate
= BS_EXCP
;
5654 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5655 /* If we get an exception, we want to restart at next instruction */
5657 save_cpu_state(ctx
, 1);
5659 tcg_gen_helper_0_0(do_wait
);
5660 ctx
->bstate
= BS_EXCP
;
5665 generate_exception(ctx
, EXCP_RI
);
5668 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5670 #endif /* !CONFIG_USER_ONLY */
5672 /* CP1 Branches (before delay slot) */
5673 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5674 int32_t cc
, int32_t offset
)
5676 target_ulong btarget
;
5677 const char *opn
= "cp1 cond branch";
5678 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5679 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
5682 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5684 btarget
= ctx
->pc
+ 4 + offset
;
5689 int l1
= gen_new_label();
5690 int l2
= gen_new_label();
5691 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5693 get_fp_cond(r_tmp1
);
5694 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5695 tcg_temp_free(r_tmp1
);
5696 tcg_gen_not_tl(t0
, t0
);
5697 tcg_gen_movi_tl(t1
, 0x1 << cc
);
5698 tcg_gen_and_tl(t0
, t0
, t1
);
5699 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5700 tcg_gen_movi_tl(t0
, 0);
5703 tcg_gen_movi_tl(t0
, 1);
5710 int l1
= gen_new_label();
5711 int l2
= gen_new_label();
5712 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5714 get_fp_cond(r_tmp1
);
5715 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5716 tcg_temp_free(r_tmp1
);
5717 tcg_gen_not_tl(t0
, t0
);
5718 tcg_gen_movi_tl(t1
, 0x1 << cc
);
5719 tcg_gen_and_tl(t0
, t0
, t1
);
5720 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5721 tcg_gen_movi_tl(t0
, 0);
5724 tcg_gen_movi_tl(t0
, 1);
5731 int l1
= gen_new_label();
5732 int l2
= gen_new_label();
5733 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5735 get_fp_cond(r_tmp1
);
5736 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5737 tcg_temp_free(r_tmp1
);
5738 tcg_gen_movi_tl(t1
, 0x1 << cc
);
5739 tcg_gen_and_tl(t0
, t0
, t1
);
5740 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5741 tcg_gen_movi_tl(t0
, 0);
5744 tcg_gen_movi_tl(t0
, 1);
5751 int l1
= gen_new_label();
5752 int l2
= gen_new_label();
5753 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5755 get_fp_cond(r_tmp1
);
5756 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5757 tcg_temp_free(r_tmp1
);
5758 tcg_gen_movi_tl(t1
, 0x1 << cc
);
5759 tcg_gen_and_tl(t0
, t0
, t1
);
5760 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5761 tcg_gen_movi_tl(t0
, 0);
5764 tcg_gen_movi_tl(t0
, 1);
5769 ctx
->hflags
|= MIPS_HFLAG_BL
;
5770 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, bcond
));
5774 int l1
= gen_new_label();
5775 int l2
= gen_new_label();
5776 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5778 get_fp_cond(r_tmp1
);
5779 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5780 tcg_temp_free(r_tmp1
);
5781 tcg_gen_not_tl(t0
, t0
);
5782 tcg_gen_movi_tl(t1
, 0x3 << cc
);
5783 tcg_gen_and_tl(t0
, t0
, t1
);
5784 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5785 tcg_gen_movi_tl(t0
, 0);
5788 tcg_gen_movi_tl(t0
, 1);
5795 int l1
= gen_new_label();
5796 int l2
= gen_new_label();
5797 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5799 get_fp_cond(r_tmp1
);
5800 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5801 tcg_temp_free(r_tmp1
);
5802 tcg_gen_movi_tl(t1
, 0x3 << cc
);
5803 tcg_gen_and_tl(t0
, t0
, t1
);
5804 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5805 tcg_gen_movi_tl(t0
, 0);
5808 tcg_gen_movi_tl(t0
, 1);
5815 int l1
= gen_new_label();
5816 int l2
= gen_new_label();
5817 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5819 get_fp_cond(r_tmp1
);
5820 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5821 tcg_temp_free(r_tmp1
);
5822 tcg_gen_not_tl(t0
, t0
);
5823 tcg_gen_movi_tl(t1
, 0xf << cc
);
5824 tcg_gen_and_tl(t0
, t0
, t1
);
5825 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5826 tcg_gen_movi_tl(t0
, 0);
5829 tcg_gen_movi_tl(t0
, 1);
5836 int l1
= gen_new_label();
5837 int l2
= gen_new_label();
5838 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5840 get_fp_cond(r_tmp1
);
5841 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5842 tcg_temp_free(r_tmp1
);
5843 tcg_gen_movi_tl(t1
, 0xf << cc
);
5844 tcg_gen_and_tl(t0
, t0
, t1
);
5845 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5846 tcg_gen_movi_tl(t0
, 0);
5849 tcg_gen_movi_tl(t0
, 1);
5854 ctx
->hflags
|= MIPS_HFLAG_BC
;
5855 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, bcond
));
5859 generate_exception (ctx
, EXCP_RI
);
5862 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5863 ctx
->hflags
, btarget
);
5864 ctx
->btarget
= btarget
;
5871 /* Coprocessor 1 (FPU) */
5873 #define FOP(func, fmt) (((fmt) << 21) | (func))
5875 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5877 const char *opn
= "cp1 move";
5878 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5882 gen_load_fpr32(fpu32_T
[0], fs
);
5883 tcg_gen_ext_i32_tl(t0
, fpu32_T
[0]);
5884 gen_store_gpr(t0
, rt
);
5888 gen_load_gpr(t0
, rt
);
5889 tcg_gen_trunc_tl_i32(fpu32_T
[0], t0
);
5890 gen_store_fpr32(fpu32_T
[0], fs
);
5894 tcg_gen_helper_1_i(do_cfc1
, t0
, fs
);
5895 gen_store_gpr(t0
, rt
);
5899 gen_load_gpr(t0
, rt
);
5900 tcg_gen_helper_0_1i(do_ctc1
, t0
, fs
);
5904 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
5905 tcg_gen_mov_tl(t0
, fpu64_T
[0]);
5906 gen_store_gpr(t0
, rt
);
5910 gen_load_gpr(t0
, rt
);
5911 tcg_gen_mov_tl(fpu64_T
[0], t0
);
5912 gen_store_fpr64(ctx
, fpu64_T
[0], fs
);
5916 gen_load_fpr32h(fpu32h_T
[0], fs
);
5917 tcg_gen_ext_i32_tl(t0
, fpu32h_T
[0]);
5918 gen_store_gpr(t0
, rt
);
5922 gen_load_gpr(t0
, rt
);
5923 tcg_gen_trunc_tl_i32(fpu32h_T
[0], t0
);
5924 gen_store_fpr32h(fpu32h_T
[0], fs
);
5929 generate_exception (ctx
, EXCP_RI
);
5932 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5938 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5940 int l1
= gen_new_label();
5943 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5944 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
5947 ccbit
= 1 << (24 + cc
);
5955 gen_load_gpr(t0
, rd
);
5956 gen_load_gpr(t1
, rs
);
5958 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
5959 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_I32
);
5961 tcg_gen_ld_ptr(r_ptr
, cpu_env
, offsetof(CPUState
, fpu
));
5962 tcg_gen_ld_i32(r_tmp
, r_ptr
, offsetof(CPUMIPSFPUContext
, fcr31
));
5963 tcg_temp_free(r_ptr
);
5964 tcg_gen_andi_i32(r_tmp
, r_tmp
, ccbit
);
5965 tcg_gen_brcondi_i32(cond
, r_tmp
, 0, l1
);
5966 tcg_temp_free(r_tmp
);
5968 tcg_gen_mov_tl(t0
, t1
);
5972 gen_store_gpr(t0
, rd
);
5976 static inline void gen_movcf_s (int cc
, int tf
)
5980 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5981 int l1
= gen_new_label();
5984 ccbit
= 1 << (24 + cc
);
5993 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
5994 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, ccbit
);
5995 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5996 tcg_gen_movi_i32(fpu32_T
[2], fpu32_T
[0]);
5998 tcg_temp_free(r_tmp1
);
6001 static inline void gen_movcf_d (int cc
, int tf
)
6005 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
6006 int l1
= gen_new_label();
6009 ccbit
= 1 << (24 + cc
);
6018 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
6019 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, ccbit
);
6020 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
6021 tcg_gen_movi_i64(fpu64_T
[2], fpu64_T
[0]);
6023 tcg_temp_free(r_tmp1
);
6026 static inline void gen_movcf_ps (int cc
, int tf
)
6029 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_I32
);
6030 TCGv r_tmp2
= tcg_temp_local_new(TCG_TYPE_I32
);
6031 int l1
= gen_new_label();
6032 int l2
= gen_new_label();
6039 get_fp_cond(r_tmp1
);
6040 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, cc
);
6041 tcg_gen_andi_i32(r_tmp2
, r_tmp1
, 0x1);
6042 tcg_gen_brcondi_i32(cond
, r_tmp2
, 0, l1
);
6043 tcg_gen_movi_i32(fpu32_T
[2], fpu32_T
[0]);
6045 tcg_gen_andi_i32(r_tmp2
, r_tmp1
, 0x2);
6046 tcg_gen_brcondi_i32(cond
, r_tmp2
, 0, l2
);
6047 tcg_gen_movi_i32(fpu32h_T
[2], fpu32h_T
[0]);
6049 tcg_temp_free(r_tmp1
);
6050 tcg_temp_free(r_tmp2
);
6054 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
6055 int ft
, int fs
, int fd
, int cc
)
6057 const char *opn
= "farith";
6058 const char *condnames
[] = {
6076 const char *condnames_abs
[] = {
6094 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6095 uint32_t func
= ctx
->opcode
& 0x3f;
6097 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
6099 gen_load_fpr32(fpu32_T
[0], fs
);
6100 gen_load_fpr32(fpu32_T
[1], ft
);
6101 tcg_gen_helper_0_0(do_float_add_s
);
6102 gen_store_fpr32(fpu32_T
[2], fd
);
6107 gen_load_fpr32(fpu32_T
[0], fs
);
6108 gen_load_fpr32(fpu32_T
[1], ft
);
6109 tcg_gen_helper_0_0(do_float_sub_s
);
6110 gen_store_fpr32(fpu32_T
[2], fd
);
6115 gen_load_fpr32(fpu32_T
[0], fs
);
6116 gen_load_fpr32(fpu32_T
[1], ft
);
6117 tcg_gen_helper_0_0(do_float_mul_s
);
6118 gen_store_fpr32(fpu32_T
[2], fd
);
6123 gen_load_fpr32(fpu32_T
[0], fs
);
6124 gen_load_fpr32(fpu32_T
[1], ft
);
6125 tcg_gen_helper_0_0(do_float_div_s
);
6126 gen_store_fpr32(fpu32_T
[2], fd
);
6131 gen_load_fpr32(fpu32_T
[0], fs
);
6132 tcg_gen_helper_0_0(do_float_sqrt_s
);
6133 gen_store_fpr32(fpu32_T
[2], fd
);
6137 gen_load_fpr32(fpu32_T
[0], fs
);
6138 tcg_gen_helper_0_0(do_float_abs_s
);
6139 gen_store_fpr32(fpu32_T
[2], fd
);
6143 gen_load_fpr32(fpu32_T
[0], fs
);
6144 gen_store_fpr32(fpu32_T
[0], fd
);
6148 gen_load_fpr32(fpu32_T
[0], fs
);
6149 tcg_gen_helper_0_0(do_float_chs_s
);
6150 gen_store_fpr32(fpu32_T
[2], fd
);
6154 check_cp1_64bitmode(ctx
);
6155 gen_load_fpr32(fpu32_T
[0], fs
);
6156 tcg_gen_helper_0_0(do_float_roundl_s
);
6157 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6161 check_cp1_64bitmode(ctx
);
6162 gen_load_fpr32(fpu32_T
[0], fs
);
6163 tcg_gen_helper_0_0(do_float_truncl_s
);
6164 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6168 check_cp1_64bitmode(ctx
);
6169 gen_load_fpr32(fpu32_T
[0], fs
);
6170 tcg_gen_helper_0_0(do_float_ceill_s
);
6171 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6175 check_cp1_64bitmode(ctx
);
6176 gen_load_fpr32(fpu32_T
[0], fs
);
6177 tcg_gen_helper_0_0(do_float_floorl_s
);
6178 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6182 gen_load_fpr32(fpu32_T
[0], fs
);
6183 tcg_gen_helper_0_0(do_float_roundw_s
);
6184 gen_store_fpr32(fpu32_T
[2], fd
);
6188 gen_load_fpr32(fpu32_T
[0], fs
);
6189 tcg_gen_helper_0_0(do_float_truncw_s
);
6190 gen_store_fpr32(fpu32_T
[2], fd
);
6194 gen_load_fpr32(fpu32_T
[0], fs
);
6195 tcg_gen_helper_0_0(do_float_ceilw_s
);
6196 gen_store_fpr32(fpu32_T
[2], fd
);
6200 gen_load_fpr32(fpu32_T
[0], fs
);
6201 tcg_gen_helper_0_0(do_float_floorw_s
);
6202 gen_store_fpr32(fpu32_T
[2], fd
);
6206 gen_load_fpr32(fpu32_T
[0], fs
);
6207 gen_load_fpr32(fpu32_T
[2], fd
);
6208 gen_movcf_s((ft
>> 2) & 0x7, ft
& 0x1);
6209 gen_store_fpr32(fpu32_T
[2], fd
);
6213 gen_load_fpr32(fpu32_T
[0], fs
);
6214 gen_load_fpr32(fpu32_T
[2], fd
);
6216 int l1
= gen_new_label();
6217 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6219 gen_load_gpr(t0
, ft
);
6220 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6222 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6225 gen_store_fpr32(fpu32_T
[2], fd
);
6229 gen_load_fpr32(fpu32_T
[0], fs
);
6230 gen_load_fpr32(fpu32_T
[2], fd
);
6232 int l1
= gen_new_label();
6233 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6235 gen_load_gpr(t0
, ft
);
6236 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6238 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6241 gen_store_fpr32(fpu32_T
[2], fd
);
6246 gen_load_fpr32(fpu32_T
[0], fs
);
6247 tcg_gen_helper_0_0(do_float_recip_s
);
6248 gen_store_fpr32(fpu32_T
[2], fd
);
6253 gen_load_fpr32(fpu32_T
[0], fs
);
6254 tcg_gen_helper_0_0(do_float_rsqrt_s
);
6255 gen_store_fpr32(fpu32_T
[2], fd
);
6259 check_cp1_64bitmode(ctx
);
6260 gen_load_fpr32(fpu32_T
[0], fs
);
6261 gen_load_fpr32(fpu32_T
[2], fd
);
6262 tcg_gen_helper_0_0(do_float_recip2_s
);
6263 gen_store_fpr32(fpu32_T
[2], fd
);
6267 check_cp1_64bitmode(ctx
);
6268 gen_load_fpr32(fpu32_T
[0], fs
);
6269 tcg_gen_helper_0_0(do_float_recip1_s
);
6270 gen_store_fpr32(fpu32_T
[2], fd
);
6274 check_cp1_64bitmode(ctx
);
6275 gen_load_fpr32(fpu32_T
[0], fs
);
6276 tcg_gen_helper_0_0(do_float_rsqrt1_s
);
6277 gen_store_fpr32(fpu32_T
[2], fd
);
6281 check_cp1_64bitmode(ctx
);
6282 gen_load_fpr32(fpu32_T
[0], fs
);
6283 gen_load_fpr32(fpu32_T
[2], ft
);
6284 tcg_gen_helper_0_0(do_float_rsqrt2_s
);
6285 gen_store_fpr32(fpu32_T
[2], fd
);
6289 check_cp1_registers(ctx
, fd
);
6290 gen_load_fpr32(fpu32_T
[0], fs
);
6291 tcg_gen_helper_0_0(do_float_cvtd_s
);
6292 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6296 gen_load_fpr32(fpu32_T
[0], fs
);
6297 tcg_gen_helper_0_0(do_float_cvtw_s
);
6298 gen_store_fpr32(fpu32_T
[2], fd
);
6302 check_cp1_64bitmode(ctx
);
6303 gen_load_fpr32(fpu32_T
[0], fs
);
6304 tcg_gen_helper_0_0(do_float_cvtl_s
);
6305 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6309 check_cp1_64bitmode(ctx
);
6310 gen_load_fpr32(fpu32_T
[0], fs
);
6311 gen_load_fpr32(fpu32_T
[1], ft
);
6312 tcg_gen_extu_i32_i64(fpu64_T
[0], fpu32_T
[0]);
6313 tcg_gen_extu_i32_i64(fpu64_T
[1], fpu32_T
[1]);
6314 tcg_gen_shli_i64(fpu64_T
[1], fpu64_T
[1], 32);
6315 tcg_gen_or_i64(fpu64_T
[2], fpu64_T
[0], fpu64_T
[1]);
6316 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6335 gen_load_fpr32(fpu32_T
[0], fs
);
6336 gen_load_fpr32(fpu32_T
[1], ft
);
6337 if (ctx
->opcode
& (1 << 6)) {
6339 gen_cmpabs_s(func
-48, cc
);
6340 opn
= condnames_abs
[func
-48];
6342 gen_cmp_s(func
-48, cc
);
6343 opn
= condnames
[func
-48];
6347 check_cp1_registers(ctx
, fs
| ft
| fd
);
6348 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6349 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6350 tcg_gen_helper_0_0(do_float_add_d
);
6351 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6356 check_cp1_registers(ctx
, fs
| ft
| fd
);
6357 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6358 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6359 tcg_gen_helper_0_0(do_float_sub_d
);
6360 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6365 check_cp1_registers(ctx
, fs
| ft
| fd
);
6366 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6367 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6368 tcg_gen_helper_0_0(do_float_mul_d
);
6369 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6374 check_cp1_registers(ctx
, fs
| ft
| fd
);
6375 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6376 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6377 tcg_gen_helper_0_0(do_float_div_d
);
6378 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6383 check_cp1_registers(ctx
, fs
| fd
);
6384 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6385 tcg_gen_helper_0_0(do_float_sqrt_d
);
6386 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6390 check_cp1_registers(ctx
, fs
| fd
);
6391 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6392 tcg_gen_helper_0_0(do_float_abs_d
);
6393 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6397 check_cp1_registers(ctx
, fs
| fd
);
6398 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6399 gen_store_fpr64(ctx
, fpu64_T
[0], fd
);
6403 check_cp1_registers(ctx
, fs
| fd
);
6404 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6405 tcg_gen_helper_0_0(do_float_chs_d
);
6406 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6410 check_cp1_64bitmode(ctx
);
6411 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6412 tcg_gen_helper_0_0(do_float_roundl_d
);
6413 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6417 check_cp1_64bitmode(ctx
);
6418 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6419 tcg_gen_helper_0_0(do_float_truncl_d
);
6420 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6424 check_cp1_64bitmode(ctx
);
6425 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6426 tcg_gen_helper_0_0(do_float_ceill_d
);
6427 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6431 check_cp1_64bitmode(ctx
);
6432 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6433 tcg_gen_helper_0_0(do_float_floorl_d
);
6434 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6438 check_cp1_registers(ctx
, fs
);
6439 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6440 tcg_gen_helper_0_0(do_float_roundw_d
);
6441 gen_store_fpr32(fpu32_T
[2], fd
);
6445 check_cp1_registers(ctx
, fs
);
6446 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6447 tcg_gen_helper_0_0(do_float_truncw_d
);
6448 gen_store_fpr32(fpu32_T
[2], fd
);
6452 check_cp1_registers(ctx
, fs
);
6453 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6454 tcg_gen_helper_0_0(do_float_ceilw_d
);
6455 gen_store_fpr32(fpu32_T
[2], fd
);
6459 check_cp1_registers(ctx
, fs
);
6460 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6461 tcg_gen_helper_0_0(do_float_floorw_d
);
6462 gen_store_fpr32(fpu32_T
[2], fd
);
6466 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6467 gen_load_fpr64(ctx
, fpu64_T
[2], fd
);
6468 gen_movcf_d((ft
>> 2) & 0x7, ft
& 0x1);
6469 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6473 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6474 gen_load_fpr64(ctx
, fpu64_T
[2], fd
);
6476 int l1
= gen_new_label();
6477 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6479 gen_load_gpr(t0
, ft
);
6480 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6482 tcg_gen_mov_i64(fpu64_T
[2], fpu64_T
[0]);
6485 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6489 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6490 gen_load_fpr64(ctx
, fpu64_T
[2], fd
);
6492 int l1
= gen_new_label();
6493 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6495 gen_load_gpr(t0
, ft
);
6496 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6498 tcg_gen_mov_i64(fpu64_T
[2], fpu64_T
[0]);
6501 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6505 check_cp1_64bitmode(ctx
);
6506 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6507 tcg_gen_helper_0_0(do_float_recip_d
);
6508 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6512 check_cp1_64bitmode(ctx
);
6513 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6514 tcg_gen_helper_0_0(do_float_rsqrt_d
);
6515 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6519 check_cp1_64bitmode(ctx
);
6520 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6521 gen_load_fpr64(ctx
, fpu64_T
[2], ft
);
6522 tcg_gen_helper_0_0(do_float_recip2_d
);
6523 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6527 check_cp1_64bitmode(ctx
);
6528 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6529 tcg_gen_helper_0_0(do_float_recip1_d
);
6530 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6534 check_cp1_64bitmode(ctx
);
6535 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6536 tcg_gen_helper_0_0(do_float_rsqrt1_d
);
6537 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6541 check_cp1_64bitmode(ctx
);
6542 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6543 gen_load_fpr64(ctx
, fpu64_T
[2], ft
);
6544 tcg_gen_helper_0_0(do_float_rsqrt2_d
);
6545 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6564 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6565 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6566 if (ctx
->opcode
& (1 << 6)) {
6568 check_cp1_registers(ctx
, fs
| ft
);
6569 gen_cmpabs_d(func
-48, cc
);
6570 opn
= condnames_abs
[func
-48];
6572 check_cp1_registers(ctx
, fs
| ft
);
6573 gen_cmp_d(func
-48, cc
);
6574 opn
= condnames
[func
-48];
6578 check_cp1_registers(ctx
, fs
);
6579 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6580 tcg_gen_helper_0_0(do_float_cvts_d
);
6581 gen_store_fpr32(fpu32_T
[2], fd
);
6585 check_cp1_registers(ctx
, fs
);
6586 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6587 tcg_gen_helper_0_0(do_float_cvtw_d
);
6588 gen_store_fpr32(fpu32_T
[2], fd
);
6592 check_cp1_64bitmode(ctx
);
6593 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6594 tcg_gen_helper_0_0(do_float_cvtl_d
);
6595 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6599 gen_load_fpr32(fpu32_T
[0], fs
);
6600 tcg_gen_helper_0_0(do_float_cvts_w
);
6601 gen_store_fpr32(fpu32_T
[2], fd
);
6605 check_cp1_registers(ctx
, fd
);
6606 gen_load_fpr32(fpu32_T
[0], fs
);
6607 tcg_gen_helper_0_0(do_float_cvtd_w
);
6608 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6612 check_cp1_64bitmode(ctx
);
6613 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6614 tcg_gen_helper_0_0(do_float_cvts_l
);
6615 gen_store_fpr32(fpu32_T
[2], fd
);
6619 check_cp1_64bitmode(ctx
);
6620 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6621 tcg_gen_helper_0_0(do_float_cvtd_l
);
6622 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6626 check_cp1_64bitmode(ctx
);
6627 gen_load_fpr32(fpu32_T
[0], fs
);
6628 gen_load_fpr32h(fpu32h_T
[0], fs
);
6629 tcg_gen_helper_0_0(do_float_cvtps_pw
);
6630 gen_store_fpr32(fpu32_T
[2], fd
);
6631 gen_store_fpr32h(fpu32h_T
[2], fd
);
6635 check_cp1_64bitmode(ctx
);
6636 gen_load_fpr32(fpu32_T
[0], fs
);
6637 gen_load_fpr32h(fpu32h_T
[0], fs
);
6638 gen_load_fpr32(fpu32_T
[1], ft
);
6639 gen_load_fpr32h(fpu32h_T
[1], ft
);
6640 tcg_gen_helper_0_0(do_float_add_ps
);
6641 gen_store_fpr32(fpu32_T
[2], fd
);
6642 gen_store_fpr32h(fpu32h_T
[2], fd
);
6646 check_cp1_64bitmode(ctx
);
6647 gen_load_fpr32(fpu32_T
[0], fs
);
6648 gen_load_fpr32h(fpu32h_T
[0], fs
);
6649 gen_load_fpr32(fpu32_T
[1], ft
);
6650 gen_load_fpr32h(fpu32h_T
[1], ft
);
6651 tcg_gen_helper_0_0(do_float_sub_ps
);
6652 gen_store_fpr32(fpu32_T
[2], fd
);
6653 gen_store_fpr32h(fpu32h_T
[2], fd
);
6657 check_cp1_64bitmode(ctx
);
6658 gen_load_fpr32(fpu32_T
[0], fs
);
6659 gen_load_fpr32h(fpu32h_T
[0], fs
);
6660 gen_load_fpr32(fpu32_T
[1], ft
);
6661 gen_load_fpr32h(fpu32h_T
[1], ft
);
6662 tcg_gen_helper_0_0(do_float_mul_ps
);
6663 gen_store_fpr32(fpu32_T
[2], fd
);
6664 gen_store_fpr32h(fpu32h_T
[2], fd
);
6668 check_cp1_64bitmode(ctx
);
6669 gen_load_fpr32(fpu32_T
[0], fs
);
6670 gen_load_fpr32h(fpu32h_T
[0], fs
);
6671 tcg_gen_helper_0_0(do_float_abs_ps
);
6672 gen_store_fpr32(fpu32_T
[2], fd
);
6673 gen_store_fpr32h(fpu32h_T
[2], fd
);
6677 check_cp1_64bitmode(ctx
);
6678 gen_load_fpr32(fpu32_T
[0], fs
);
6679 gen_load_fpr32h(fpu32h_T
[0], fs
);
6680 gen_store_fpr32(fpu32_T
[0], fd
);
6681 gen_store_fpr32h(fpu32h_T
[0], fd
);
6685 check_cp1_64bitmode(ctx
);
6686 gen_load_fpr32(fpu32_T
[0], fs
);
6687 gen_load_fpr32h(fpu32h_T
[0], fs
);
6688 tcg_gen_helper_0_0(do_float_chs_ps
);
6689 gen_store_fpr32(fpu32_T
[2], fd
);
6690 gen_store_fpr32h(fpu32h_T
[2], fd
);
6694 check_cp1_64bitmode(ctx
);
6695 gen_load_fpr32(fpu32_T
[0], fs
);
6696 gen_load_fpr32h(fpu32h_T
[0], fs
);
6697 gen_load_fpr32(fpu32_T
[2], fd
);
6698 gen_load_fpr32h(fpu32h_T
[2], fd
);
6699 gen_movcf_ps((ft
>> 2) & 0x7, ft
& 0x1);
6700 gen_store_fpr32(fpu32_T
[2], fd
);
6701 gen_store_fpr32h(fpu32h_T
[2], fd
);
6705 check_cp1_64bitmode(ctx
);
6706 gen_load_fpr32(fpu32_T
[0], fs
);
6707 gen_load_fpr32h(fpu32h_T
[0], fs
);
6708 gen_load_fpr32(fpu32_T
[2], fd
);
6709 gen_load_fpr32h(fpu32h_T
[2], fd
);
6711 int l1
= gen_new_label();
6712 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6714 gen_load_gpr(t0
, ft
);
6715 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6717 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6718 tcg_gen_mov_i32(fpu32h_T
[2], fpu32h_T
[0]);
6721 gen_store_fpr32(fpu32_T
[2], fd
);
6722 gen_store_fpr32h(fpu32h_T
[2], fd
);
6726 check_cp1_64bitmode(ctx
);
6727 gen_load_fpr32(fpu32_T
[0], fs
);
6728 gen_load_fpr32h(fpu32h_T
[0], fs
);
6729 gen_load_fpr32(fpu32_T
[2], fd
);
6730 gen_load_fpr32h(fpu32h_T
[2], fd
);
6732 int l1
= gen_new_label();
6733 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6735 gen_load_gpr(t0
, ft
);
6736 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6738 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6739 tcg_gen_mov_i32(fpu32h_T
[2], fpu32h_T
[0]);
6742 gen_store_fpr32(fpu32_T
[2], fd
);
6743 gen_store_fpr32h(fpu32h_T
[2], fd
);
6747 check_cp1_64bitmode(ctx
);
6748 gen_load_fpr32(fpu32_T
[0], ft
);
6749 gen_load_fpr32h(fpu32h_T
[0], ft
);
6750 gen_load_fpr32(fpu32_T
[1], fs
);
6751 gen_load_fpr32h(fpu32h_T
[1], fs
);
6752 tcg_gen_helper_0_0(do_float_addr_ps
);
6753 gen_store_fpr32(fpu32_T
[2], fd
);
6754 gen_store_fpr32h(fpu32h_T
[2], fd
);
6758 check_cp1_64bitmode(ctx
);
6759 gen_load_fpr32(fpu32_T
[0], ft
);
6760 gen_load_fpr32h(fpu32h_T
[0], ft
);
6761 gen_load_fpr32(fpu32_T
[1], fs
);
6762 gen_load_fpr32h(fpu32h_T
[1], fs
);
6763 tcg_gen_helper_0_0(do_float_mulr_ps
);
6764 gen_store_fpr32(fpu32_T
[2], fd
);
6765 gen_store_fpr32h(fpu32h_T
[2], fd
);
6769 check_cp1_64bitmode(ctx
);
6770 gen_load_fpr32(fpu32_T
[0], fs
);
6771 gen_load_fpr32h(fpu32h_T
[0], fs
);
6772 gen_load_fpr32(fpu32_T
[2], fd
);
6773 gen_load_fpr32h(fpu32h_T
[2], fd
);
6774 tcg_gen_helper_0_0(do_float_recip2_ps
);
6775 gen_store_fpr32(fpu32_T
[2], fd
);
6776 gen_store_fpr32h(fpu32h_T
[2], fd
);
6780 check_cp1_64bitmode(ctx
);
6781 gen_load_fpr32(fpu32_T
[0], fs
);
6782 gen_load_fpr32h(fpu32h_T
[0], fs
);
6783 tcg_gen_helper_0_0(do_float_recip1_ps
);
6784 gen_store_fpr32(fpu32_T
[2], fd
);
6785 gen_store_fpr32h(fpu32h_T
[2], fd
);
6789 check_cp1_64bitmode(ctx
);
6790 gen_load_fpr32(fpu32_T
[0], fs
);
6791 gen_load_fpr32h(fpu32h_T
[0], fs
);
6792 tcg_gen_helper_0_0(do_float_rsqrt1_ps
);
6793 gen_store_fpr32(fpu32_T
[2], fd
);
6794 gen_store_fpr32h(fpu32h_T
[2], fd
);
6798 check_cp1_64bitmode(ctx
);
6799 gen_load_fpr32(fpu32_T
[0], fs
);
6800 gen_load_fpr32h(fpu32h_T
[0], fs
);
6801 gen_load_fpr32(fpu32_T
[2], ft
);
6802 gen_load_fpr32h(fpu32h_T
[2], ft
);
6803 tcg_gen_helper_0_0(do_float_rsqrt2_ps
);
6804 gen_store_fpr32(fpu32_T
[2], fd
);
6805 gen_store_fpr32h(fpu32h_T
[2], fd
);
6809 check_cp1_64bitmode(ctx
);
6810 gen_load_fpr32h(fpu32h_T
[0], fs
);
6811 tcg_gen_helper_0_0(do_float_cvts_pu
);
6812 gen_store_fpr32(fpu32_T
[2], fd
);
6816 check_cp1_64bitmode(ctx
);
6817 gen_load_fpr32(fpu32_T
[0], fs
);
6818 gen_load_fpr32h(fpu32h_T
[0], fs
);
6819 tcg_gen_helper_0_0(do_float_cvtpw_ps
);
6820 gen_store_fpr32(fpu32_T
[2], fd
);
6821 gen_store_fpr32h(fpu32h_T
[2], fd
);
6825 check_cp1_64bitmode(ctx
);
6826 gen_load_fpr32(fpu32_T
[0], fs
);
6827 tcg_gen_helper_0_0(do_float_cvts_pl
);
6828 gen_store_fpr32(fpu32_T
[2], fd
);
6832 check_cp1_64bitmode(ctx
);
6833 gen_load_fpr32(fpu32_T
[0], fs
);
6834 gen_load_fpr32(fpu32_T
[1], ft
);
6835 gen_store_fpr32h(fpu32_T
[0], fd
);
6836 gen_store_fpr32(fpu32_T
[1], fd
);
6840 check_cp1_64bitmode(ctx
);
6841 gen_load_fpr32(fpu32_T
[0], fs
);
6842 gen_load_fpr32h(fpu32h_T
[1], ft
);
6843 gen_store_fpr32(fpu32h_T
[1], fd
);
6844 gen_store_fpr32h(fpu32_T
[0], fd
);
6848 check_cp1_64bitmode(ctx
);
6849 gen_load_fpr32h(fpu32h_T
[0], fs
);
6850 gen_load_fpr32(fpu32_T
[1], ft
);
6851 gen_store_fpr32(fpu32_T
[1], fd
);
6852 gen_store_fpr32h(fpu32h_T
[0], fd
);
6856 check_cp1_64bitmode(ctx
);
6857 gen_load_fpr32h(fpu32h_T
[0], fs
);
6858 gen_load_fpr32h(fpu32h_T
[1], ft
);
6859 gen_store_fpr32(fpu32h_T
[1], fd
);
6860 gen_store_fpr32h(fpu32h_T
[0], fd
);
6879 check_cp1_64bitmode(ctx
);
6880 gen_load_fpr32(fpu32_T
[0], fs
);
6881 gen_load_fpr32h(fpu32h_T
[0], fs
);
6882 gen_load_fpr32(fpu32_T
[1], ft
);
6883 gen_load_fpr32h(fpu32h_T
[1], ft
);
6884 if (ctx
->opcode
& (1 << 6)) {
6885 gen_cmpabs_ps(func
-48, cc
);
6886 opn
= condnames_abs
[func
-48];
6888 gen_cmp_ps(func
-48, cc
);
6889 opn
= condnames
[func
-48];
6894 generate_exception (ctx
, EXCP_RI
);
6899 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
6902 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
6905 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
6910 /* Coprocessor 3 (FPU) */
6911 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
6912 int fd
, int fs
, int base
, int index
)
6914 const char *opn
= "extended float load/store";
6916 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6917 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
6920 gen_load_gpr(t0
, index
);
6921 } else if (index
== 0) {
6922 gen_load_gpr(t0
, base
);
6924 gen_load_gpr(t0
, base
);
6925 gen_load_gpr(t1
, index
);
6926 gen_op_addr_add(t0
, t1
);
6928 /* Don't do NOP if destination is zero: we must perform the actual
6933 tcg_gen_qemu_ld32s(fpu32_T
[0], t0
, ctx
->mem_idx
);
6934 gen_store_fpr32(fpu32_T
[0], fd
);
6939 check_cp1_registers(ctx
, fd
);
6940 tcg_gen_qemu_ld64(fpu64_T
[0], t0
, ctx
->mem_idx
);
6941 gen_store_fpr64(ctx
, fpu64_T
[0], fd
);
6945 check_cp1_64bitmode(ctx
);
6946 tcg_gen_andi_tl(t0
, t0
, ~0x7);
6947 tcg_gen_qemu_ld64(fpu64_T
[0], t0
, ctx
->mem_idx
);
6948 gen_store_fpr64(ctx
, fpu64_T
[0], fd
);
6953 gen_load_fpr32(fpu32_T
[0], fs
);
6954 tcg_gen_qemu_st32(fpu32_T
[0], t0
, ctx
->mem_idx
);
6960 check_cp1_registers(ctx
, fs
);
6961 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6962 tcg_gen_qemu_st64(fpu64_T
[0], t0
, ctx
->mem_idx
);
6967 check_cp1_64bitmode(ctx
);
6968 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6969 tcg_gen_andi_tl(t0
, t0
, ~0x7);
6970 tcg_gen_qemu_st64(fpu64_T
[0], t0
, ctx
->mem_idx
);
6976 generate_exception(ctx
, EXCP_RI
);
6983 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
6984 regnames
[index
], regnames
[base
]);
6987 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
6988 int fd
, int fr
, int fs
, int ft
)
6990 const char *opn
= "flt3_arith";
6994 check_cp1_64bitmode(ctx
);
6996 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6997 int l1
= gen_new_label();
6998 int l2
= gen_new_label();
7000 gen_load_gpr(t0
, fr
);
7001 tcg_gen_andi_tl(t0
, t0
, 0x7);
7002 gen_load_fpr32(fpu32_T
[0], fs
);
7003 gen_load_fpr32h(fpu32h_T
[0], fs
);
7004 gen_load_fpr32(fpu32_T
[1], ft
);
7005 gen_load_fpr32h(fpu32h_T
[1], ft
);
7007 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7008 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
7009 tcg_gen_mov_i32(fpu32h_T
[2], fpu32h_T
[0]);
7012 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7014 #ifdef TARGET_WORDS_BIGENDIAN
7015 tcg_gen_mov_i32(fpu32h_T
[2], fpu32_T
[0]);
7016 tcg_gen_mov_i32(fpu32_T
[2], fpu32h_T
[1]);
7018 tcg_gen_mov_i32(fpu32h_T
[2], fpu32_T
[1]);
7019 tcg_gen_mov_i32(fpu32_T
[2], fpu32h_T
[0]);
7023 gen_store_fpr32(fpu32_T
[2], fd
);
7024 gen_store_fpr32h(fpu32h_T
[2], fd
);
7029 gen_load_fpr32(fpu32_T
[0], fs
);
7030 gen_load_fpr32(fpu32_T
[1], ft
);
7031 gen_load_fpr32(fpu32_T
[2], fr
);
7032 tcg_gen_helper_0_0(do_float_muladd_s
);
7033 gen_store_fpr32(fpu32_T
[2], fd
);
7038 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7039 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
7040 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
7041 gen_load_fpr64(ctx
, fpu64_T
[2], fr
);
7042 tcg_gen_helper_0_0(do_float_muladd_d
);
7043 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
7047 check_cp1_64bitmode(ctx
);
7048 gen_load_fpr32(fpu32_T
[0], fs
);
7049 gen_load_fpr32h(fpu32h_T
[0], fs
);
7050 gen_load_fpr32(fpu32_T
[1], ft
);
7051 gen_load_fpr32h(fpu32h_T
[1], ft
);
7052 gen_load_fpr32(fpu32_T
[2], fr
);
7053 gen_load_fpr32h(fpu32h_T
[2], fr
);
7054 tcg_gen_helper_0_0(do_float_muladd_ps
);
7055 gen_store_fpr32(fpu32_T
[2], fd
);
7056 gen_store_fpr32h(fpu32h_T
[2], fd
);
7061 gen_load_fpr32(fpu32_T
[0], fs
);
7062 gen_load_fpr32(fpu32_T
[1], ft
);
7063 gen_load_fpr32(fpu32_T
[2], fr
);
7064 tcg_gen_helper_0_0(do_float_mulsub_s
);
7065 gen_store_fpr32(fpu32_T
[2], fd
);
7070 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7071 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
7072 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
7073 gen_load_fpr64(ctx
, fpu64_T
[2], fr
);
7074 tcg_gen_helper_0_0(do_float_mulsub_d
);
7075 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
7079 check_cp1_64bitmode(ctx
);
7080 gen_load_fpr32(fpu32_T
[0], fs
);
7081 gen_load_fpr32h(fpu32h_T
[0], fs
);
7082 gen_load_fpr32(fpu32_T
[1], ft
);
7083 gen_load_fpr32h(fpu32h_T
[1], ft
);
7084 gen_load_fpr32(fpu32_T
[2], fr
);
7085 gen_load_fpr32h(fpu32h_T
[2], fr
);
7086 tcg_gen_helper_0_0(do_float_mulsub_ps
);
7087 gen_store_fpr32(fpu32_T
[2], fd
);
7088 gen_store_fpr32h(fpu32h_T
[2], fd
);
7093 gen_load_fpr32(fpu32_T
[0], fs
);
7094 gen_load_fpr32(fpu32_T
[1], ft
);
7095 gen_load_fpr32(fpu32_T
[2], fr
);
7096 tcg_gen_helper_0_0(do_float_nmuladd_s
);
7097 gen_store_fpr32(fpu32_T
[2], fd
);
7102 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7103 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
7104 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
7105 gen_load_fpr64(ctx
, fpu64_T
[2], fr
);
7106 tcg_gen_helper_0_0(do_float_nmuladd_d
);
7107 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
7111 check_cp1_64bitmode(ctx
);
7112 gen_load_fpr32(fpu32_T
[0], fs
);
7113 gen_load_fpr32h(fpu32h_T
[0], fs
);
7114 gen_load_fpr32(fpu32_T
[1], ft
);
7115 gen_load_fpr32h(fpu32h_T
[1], ft
);
7116 gen_load_fpr32(fpu32_T
[2], fr
);
7117 gen_load_fpr32h(fpu32h_T
[2], fr
);
7118 tcg_gen_helper_0_0(do_float_nmuladd_ps
);
7119 gen_store_fpr32(fpu32_T
[2], fd
);
7120 gen_store_fpr32h(fpu32h_T
[2], fd
);
7125 gen_load_fpr32(fpu32_T
[0], fs
);
7126 gen_load_fpr32(fpu32_T
[1], ft
);
7127 gen_load_fpr32(fpu32_T
[2], fr
);
7128 tcg_gen_helper_0_0(do_float_nmulsub_s
);
7129 gen_store_fpr32(fpu32_T
[2], fd
);
7134 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7135 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
7136 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
7137 gen_load_fpr64(ctx
, fpu64_T
[2], fr
);
7138 tcg_gen_helper_0_0(do_float_nmulsub_d
);
7139 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
7143 check_cp1_64bitmode(ctx
);
7144 gen_load_fpr32(fpu32_T
[0], fs
);
7145 gen_load_fpr32h(fpu32h_T
[0], fs
);
7146 gen_load_fpr32(fpu32_T
[1], ft
);
7147 gen_load_fpr32h(fpu32h_T
[1], ft
);
7148 gen_load_fpr32(fpu32_T
[2], fr
);
7149 gen_load_fpr32h(fpu32h_T
[2], fr
);
7150 tcg_gen_helper_0_0(do_float_nmulsub_ps
);
7151 gen_store_fpr32(fpu32_T
[2], fd
);
7152 gen_store_fpr32h(fpu32h_T
[2], fd
);
7157 generate_exception (ctx
, EXCP_RI
);
7160 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7161 fregnames
[fs
], fregnames
[ft
]);
7164 /* ISA extensions (ASEs) */
7165 /* MIPS16 extension to MIPS32 */
7166 /* SmartMIPS extension to MIPS32 */
7168 #if defined(TARGET_MIPS64)
7170 /* MDMX extension to MIPS64 */
7174 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7178 uint32_t op
, op1
, op2
;
7181 /* make sure instructions are on a word boundary */
7182 if (ctx
->pc
& 0x3) {
7183 env
->CP0_BadVAddr
= ctx
->pc
;
7184 generate_exception(ctx
, EXCP_AdEL
);
7188 /* Handle blikely not taken case */
7189 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7190 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_TL
);
7191 int l1
= gen_new_label();
7193 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7194 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
7195 tcg_gen_brcondi_tl(TCG_COND_NE
, r_tmp
, 0, l1
);
7196 tcg_temp_free(r_tmp
);
7198 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
7200 tcg_gen_movi_i32(r_tmp2
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7201 tcg_gen_st_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, hflags
));
7202 tcg_temp_free(r_tmp2
);
7204 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7207 op
= MASK_OP_MAJOR(ctx
->opcode
);
7208 rs
= (ctx
->opcode
>> 21) & 0x1f;
7209 rt
= (ctx
->opcode
>> 16) & 0x1f;
7210 rd
= (ctx
->opcode
>> 11) & 0x1f;
7211 sa
= (ctx
->opcode
>> 6) & 0x1f;
7212 imm
= (int16_t)ctx
->opcode
;
7215 op1
= MASK_SPECIAL(ctx
->opcode
);
7217 case OPC_SLL
: /* Arithmetic with immediate */
7218 case OPC_SRL
... OPC_SRA
:
7219 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7221 case OPC_MOVZ
... OPC_MOVN
:
7222 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7223 case OPC_SLLV
: /* Arithmetic */
7224 case OPC_SRLV
... OPC_SRAV
:
7225 case OPC_ADD
... OPC_NOR
:
7226 case OPC_SLT
... OPC_SLTU
:
7227 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7229 case OPC_MULT
... OPC_DIVU
:
7231 check_insn(env
, ctx
, INSN_VR54XX
);
7232 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7233 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7235 gen_muldiv(ctx
, op1
, rs
, rt
);
7237 case OPC_JR
... OPC_JALR
:
7238 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
7240 case OPC_TGE
... OPC_TEQ
: /* Traps */
7242 gen_trap(ctx
, op1
, rs
, rt
, -1);
7244 case OPC_MFHI
: /* Move from HI/LO */
7246 gen_HILO(ctx
, op1
, rd
);
7249 case OPC_MTLO
: /* Move to HI/LO */
7250 gen_HILO(ctx
, op1
, rs
);
7252 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7253 #ifdef MIPS_STRICT_STANDARD
7254 MIPS_INVAL("PMON / selsl");
7255 generate_exception(ctx
, EXCP_RI
);
7257 tcg_gen_helper_0_i(do_pmon
, sa
);
7261 generate_exception(ctx
, EXCP_SYSCALL
);
7264 generate_exception(ctx
, EXCP_BREAK
);
7267 #ifdef MIPS_STRICT_STANDARD
7269 generate_exception(ctx
, EXCP_RI
);
7271 /* Implemented as RI exception for now. */
7272 MIPS_INVAL("spim (unofficial)");
7273 generate_exception(ctx
, EXCP_RI
);
7281 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7282 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7283 save_cpu_state(ctx
, 1);
7284 check_cp1_enabled(ctx
);
7285 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7286 (ctx
->opcode
>> 16) & 1);
7288 generate_exception_err(ctx
, EXCP_CpU
, 1);
7292 #if defined(TARGET_MIPS64)
7293 /* MIPS64 specific opcodes */
7295 case OPC_DSRL
... OPC_DSRA
:
7297 case OPC_DSRL32
... OPC_DSRA32
:
7298 check_insn(env
, ctx
, ISA_MIPS3
);
7300 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7303 case OPC_DSRLV
... OPC_DSRAV
:
7304 case OPC_DADD
... OPC_DSUBU
:
7305 check_insn(env
, ctx
, ISA_MIPS3
);
7307 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7309 case OPC_DMULT
... OPC_DDIVU
:
7310 check_insn(env
, ctx
, ISA_MIPS3
);
7312 gen_muldiv(ctx
, op1
, rs
, rt
);
7315 default: /* Invalid */
7316 MIPS_INVAL("special");
7317 generate_exception(ctx
, EXCP_RI
);
7322 op1
= MASK_SPECIAL2(ctx
->opcode
);
7324 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7325 case OPC_MSUB
... OPC_MSUBU
:
7326 check_insn(env
, ctx
, ISA_MIPS32
);
7327 gen_muldiv(ctx
, op1
, rs
, rt
);
7330 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7332 case OPC_CLZ
... OPC_CLO
:
7333 check_insn(env
, ctx
, ISA_MIPS32
);
7334 gen_cl(ctx
, op1
, rd
, rs
);
7337 /* XXX: not clear which exception should be raised
7338 * when in debug mode...
7340 check_insn(env
, ctx
, ISA_MIPS32
);
7341 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7342 generate_exception(ctx
, EXCP_DBp
);
7344 generate_exception(ctx
, EXCP_DBp
);
7348 #if defined(TARGET_MIPS64)
7349 case OPC_DCLZ
... OPC_DCLO
:
7350 check_insn(env
, ctx
, ISA_MIPS64
);
7352 gen_cl(ctx
, op1
, rd
, rs
);
7355 default: /* Invalid */
7356 MIPS_INVAL("special2");
7357 generate_exception(ctx
, EXCP_RI
);
7362 op1
= MASK_SPECIAL3(ctx
->opcode
);
7366 check_insn(env
, ctx
, ISA_MIPS32R2
);
7367 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7370 check_insn(env
, ctx
, ISA_MIPS32R2
);
7371 op2
= MASK_BSHFL(ctx
->opcode
);
7373 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7374 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
7378 gen_load_gpr(t1
, rt
);
7379 tcg_gen_helper_1_2(do_wsbh
, t0
, t0
, t1
);
7380 gen_store_gpr(t0
, rd
);
7383 gen_load_gpr(t1
, rt
);
7384 tcg_gen_ext8s_tl(t0
, t1
);
7385 gen_store_gpr(t0
, rd
);
7388 gen_load_gpr(t1
, rt
);
7389 tcg_gen_ext16s_tl(t0
, t1
);
7390 gen_store_gpr(t0
, rd
);
7392 default: /* Invalid */
7393 MIPS_INVAL("bshfl");
7394 generate_exception(ctx
, EXCP_RI
);
7402 check_insn(env
, ctx
, ISA_MIPS32R2
);
7404 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7408 save_cpu_state(ctx
, 1);
7409 tcg_gen_helper_1_1(do_rdhwr_cpunum
, t0
, t0
);
7412 save_cpu_state(ctx
, 1);
7413 tcg_gen_helper_1_1(do_rdhwr_synci_step
, t0
, t0
);
7416 save_cpu_state(ctx
, 1);
7417 tcg_gen_helper_1_1(do_rdhwr_cc
, t0
, t0
);
7420 save_cpu_state(ctx
, 1);
7421 tcg_gen_helper_1_1(do_rdhwr_ccres
, t0
, t0
);
7424 #if defined (CONFIG_USER_ONLY)
7425 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7428 /* XXX: Some CPUs implement this in hardware. Not supported yet. */
7430 default: /* Invalid */
7431 MIPS_INVAL("rdhwr");
7432 generate_exception(ctx
, EXCP_RI
);
7435 gen_store_gpr(t0
, rt
);
7440 check_insn(env
, ctx
, ASE_MT
);
7442 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7443 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
7445 gen_load_gpr(t0
, rt
);
7446 gen_load_gpr(t1
, rs
);
7447 tcg_gen_helper_0_2(do_fork
, t0
, t1
);
7453 check_insn(env
, ctx
, ASE_MT
);
7455 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7457 gen_load_gpr(t0
, rs
);
7458 tcg_gen_helper_1_1(do_yield
, t0
, t0
);
7459 gen_store_gpr(t0
, rd
);
7463 #if defined(TARGET_MIPS64)
7464 case OPC_DEXTM
... OPC_DEXT
:
7465 case OPC_DINSM
... OPC_DINS
:
7466 check_insn(env
, ctx
, ISA_MIPS64R2
);
7468 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7471 check_insn(env
, ctx
, ISA_MIPS64R2
);
7473 op2
= MASK_DBSHFL(ctx
->opcode
);
7475 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7476 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
7480 gen_load_gpr(t1
, rt
);
7481 tcg_gen_helper_1_2(do_dsbh
, t0
, t0
, t1
);
7484 gen_load_gpr(t1
, rt
);
7485 tcg_gen_helper_1_2(do_dshd
, t0
, t0
, t1
);
7487 default: /* Invalid */
7488 MIPS_INVAL("dbshfl");
7489 generate_exception(ctx
, EXCP_RI
);
7492 gen_store_gpr(t0
, rd
);
7498 default: /* Invalid */
7499 MIPS_INVAL("special3");
7500 generate_exception(ctx
, EXCP_RI
);
7505 op1
= MASK_REGIMM(ctx
->opcode
);
7507 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
7508 case OPC_BLTZAL
... OPC_BGEZALL
:
7509 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
7511 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
7513 gen_trap(ctx
, op1
, rs
, -1, imm
);
7516 check_insn(env
, ctx
, ISA_MIPS32R2
);
7519 default: /* Invalid */
7520 MIPS_INVAL("regimm");
7521 generate_exception(ctx
, EXCP_RI
);
7526 check_cp0_enabled(ctx
);
7527 op1
= MASK_CP0(ctx
->opcode
);
7533 #if defined(TARGET_MIPS64)
7537 #ifndef CONFIG_USER_ONLY
7538 gen_cp0(env
, ctx
, op1
, rt
, rd
);
7541 case OPC_C0_FIRST
... OPC_C0_LAST
:
7542 #ifndef CONFIG_USER_ONLY
7543 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
7547 op2
= MASK_MFMC0(ctx
->opcode
);
7549 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7553 check_insn(env
, ctx
, ASE_MT
);
7554 tcg_gen_helper_1_1(do_dmt
, t0
, t0
);
7557 check_insn(env
, ctx
, ASE_MT
);
7558 tcg_gen_helper_1_1(do_emt
, t0
, t0
);
7561 check_insn(env
, ctx
, ASE_MT
);
7562 tcg_gen_helper_1_1(do_dvpe
, t0
, t0
);
7565 check_insn(env
, ctx
, ASE_MT
);
7566 tcg_gen_helper_1_1(do_evpe
, t0
, t0
);
7569 check_insn(env
, ctx
, ISA_MIPS32R2
);
7570 save_cpu_state(ctx
, 1);
7571 tcg_gen_helper_1_1(do_di
, t0
, t0
);
7572 /* Stop translation as we may have switched the execution mode */
7573 ctx
->bstate
= BS_STOP
;
7576 check_insn(env
, ctx
, ISA_MIPS32R2
);
7577 save_cpu_state(ctx
, 1);
7578 tcg_gen_helper_1_1(do_ei
, t0
, t0
);
7579 /* Stop translation as we may have switched the execution mode */
7580 ctx
->bstate
= BS_STOP
;
7582 default: /* Invalid */
7583 MIPS_INVAL("mfmc0");
7584 generate_exception(ctx
, EXCP_RI
);
7587 gen_store_gpr(t0
, rt
);
7592 check_insn(env
, ctx
, ISA_MIPS32R2
);
7593 gen_load_srsgpr(rt
, rd
);
7596 check_insn(env
, ctx
, ISA_MIPS32R2
);
7597 gen_store_srsgpr(rt
, rd
);
7601 generate_exception(ctx
, EXCP_RI
);
7605 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
7606 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7608 case OPC_J
... OPC_JAL
: /* Jump */
7609 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
7610 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
7612 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
7613 case OPC_BEQL
... OPC_BGTZL
:
7614 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
7616 case OPC_LB
... OPC_LWR
: /* Load and stores */
7617 case OPC_SB
... OPC_SW
:
7621 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7624 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
7628 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7632 /* Floating point (COP1). */
7637 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7638 save_cpu_state(ctx
, 1);
7639 check_cp1_enabled(ctx
);
7640 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
7642 generate_exception_err(ctx
, EXCP_CpU
, 1);
7647 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7648 save_cpu_state(ctx
, 1);
7649 check_cp1_enabled(ctx
);
7650 op1
= MASK_CP1(ctx
->opcode
);
7654 check_insn(env
, ctx
, ISA_MIPS32R2
);
7659 gen_cp1(ctx
, op1
, rt
, rd
);
7661 #if defined(TARGET_MIPS64)
7664 check_insn(env
, ctx
, ISA_MIPS3
);
7665 gen_cp1(ctx
, op1
, rt
, rd
);
7671 check_insn(env
, ctx
, ASE_MIPS3D
);
7674 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
7675 (rt
>> 2) & 0x7, imm
<< 2);
7682 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
7687 generate_exception (ctx
, EXCP_RI
);
7691 generate_exception_err(ctx
, EXCP_CpU
, 1);
7701 /* COP2: Not implemented. */
7702 generate_exception_err(ctx
, EXCP_CpU
, 2);
7706 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7707 save_cpu_state(ctx
, 1);
7708 check_cp1_enabled(ctx
);
7709 op1
= MASK_CP3(ctx
->opcode
);
7717 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
7735 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
7739 generate_exception (ctx
, EXCP_RI
);
7743 generate_exception_err(ctx
, EXCP_CpU
, 1);
7747 #if defined(TARGET_MIPS64)
7748 /* MIPS64 opcodes */
7750 case OPC_LDL
... OPC_LDR
:
7751 case OPC_SDL
... OPC_SDR
:
7756 check_insn(env
, ctx
, ISA_MIPS3
);
7758 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7760 case OPC_DADDI
... OPC_DADDIU
:
7761 check_insn(env
, ctx
, ISA_MIPS3
);
7763 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7767 check_insn(env
, ctx
, ASE_MIPS16
);
7768 /* MIPS16: Not implemented. */
7770 check_insn(env
, ctx
, ASE_MDMX
);
7771 /* MDMX: Not implemented. */
7772 default: /* Invalid */
7773 MIPS_INVAL("major opcode");
7774 generate_exception(ctx
, EXCP_RI
);
7777 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7778 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7779 /* Branches completion */
7780 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7781 ctx
->bstate
= BS_BRANCH
;
7782 save_cpu_state(ctx
, 0);
7785 /* unconditional branch */
7786 MIPS_DEBUG("unconditional branch");
7787 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7790 /* blikely taken case */
7791 MIPS_DEBUG("blikely branch taken");
7792 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7795 /* Conditional branch */
7796 MIPS_DEBUG("conditional branch");
7798 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_TL
);
7799 int l1
= gen_new_label();
7801 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
7802 tcg_gen_brcondi_tl(TCG_COND_NE
, r_tmp
, 0, l1
);
7803 tcg_temp_free(r_tmp
);
7804 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7806 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7810 /* unconditional branch to register */
7811 MIPS_DEBUG("branch to register");
7816 MIPS_DEBUG("unknown branch");
7822 static always_inline
int
7823 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
7827 target_ulong pc_start
;
7828 uint16_t *gen_opc_end
;
7831 if (search_pc
&& loglevel
)
7832 fprintf (logfile
, "search pc %d\n", search_pc
);
7835 /* Leave some spare opc slots for branch handling. */
7836 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
- 16;
7840 ctx
.bstate
= BS_NONE
;
7841 /* Restore delay slot state from the tb context. */
7842 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
7843 restore_cpu_state(env
, &ctx
);
7844 #if defined(CONFIG_USER_ONLY)
7845 ctx
.mem_idx
= MIPS_HFLAG_UM
;
7847 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
7850 if (loglevel
& CPU_LOG_TB_CPU
) {
7851 fprintf(logfile
, "------------------------------------------------\n");
7852 /* FIXME: This may print out stale hflags from env... */
7853 cpu_dump_state(env
, logfile
, fprintf
, 0);
7856 #ifdef MIPS_DEBUG_DISAS
7857 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7858 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
7859 tb
, ctx
.mem_idx
, ctx
.hflags
);
7861 while (ctx
.bstate
== BS_NONE
) {
7862 if (env
->nb_breakpoints
> 0) {
7863 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
7864 if (env
->breakpoints
[j
] == ctx
.pc
) {
7865 save_cpu_state(&ctx
, 1);
7866 ctx
.bstate
= BS_BRANCH
;
7867 tcg_gen_helper_0_i(do_raise_exception
, EXCP_DEBUG
);
7868 /* Include the breakpoint location or the tb won't
7869 * be flushed when it must be. */
7871 goto done_generating
;
7877 j
= gen_opc_ptr
- gen_opc_buf
;
7881 gen_opc_instr_start
[lj
++] = 0;
7883 gen_opc_pc
[lj
] = ctx
.pc
;
7884 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
7885 gen_opc_instr_start
[lj
] = 1;
7887 ctx
.opcode
= ldl_code(ctx
.pc
);
7888 decode_opc(env
, &ctx
);
7891 if (env
->singlestep_enabled
)
7894 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
7897 if (gen_opc_ptr
>= gen_opc_end
)
7900 if (gen_opc_ptr
>= gen_opc_end
)
7903 #if defined (MIPS_SINGLE_STEP)
7907 if (env
->singlestep_enabled
) {
7908 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
7909 tcg_gen_helper_0_i(do_raise_exception
, EXCP_DEBUG
);
7911 switch (ctx
.bstate
) {
7913 tcg_gen_helper_0_0(do_interrupt_restart
);
7914 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7917 save_cpu_state(&ctx
, 0);
7918 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7921 tcg_gen_helper_0_0(do_interrupt_restart
);
7930 *gen_opc_ptr
= INDEX_op_end
;
7932 j
= gen_opc_ptr
- gen_opc_buf
;
7935 gen_opc_instr_start
[lj
++] = 0;
7937 tb
->size
= ctx
.pc
- pc_start
;
7940 #if defined MIPS_DEBUG_DISAS
7941 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7942 fprintf(logfile
, "\n");
7944 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7945 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
7946 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
7947 fprintf(logfile
, "\n");
7949 if (loglevel
& CPU_LOG_TB_CPU
) {
7950 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
7957 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
7959 return gen_intermediate_code_internal(env
, tb
, 0);
7962 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
7964 return gen_intermediate_code_internal(env
, tb
, 1);
7967 void fpu_dump_state(CPUState
*env
, FILE *f
,
7968 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7972 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
7974 #define printfpr(fp) \
7977 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
7978 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
7979 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
7982 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
7983 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
7984 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
7985 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
7986 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
7991 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
7992 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
7993 get_float_exception_flags(&env
->fpu
->fp_status
));
7994 fpu_fprintf(f
, "FT0: "); printfpr(&env
->ft0
);
7995 fpu_fprintf(f
, "FT1: "); printfpr(&env
->ft1
);
7996 fpu_fprintf(f
, "FT2: "); printfpr(&env
->ft2
);
7997 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
7998 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
7999 printfpr(&env
->fpu
->fpr
[i
]);
8005 void dump_fpu (CPUState
*env
)
8009 "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
8010 " LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
8012 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0],
8013 env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
,
8015 fpu_dump_state(env
, logfile
, fprintf
, 0);
8019 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8020 /* Debug help: The architecture requires 32bit code to maintain proper
8021 sign-extened values on 64bit machines. */
8023 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8025 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
8026 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8031 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
8032 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
8033 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
8034 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
8035 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
8036 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
8037 if (!SIGN_EXT_P(env
->btarget
))
8038 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
8040 for (i
= 0; i
< 32; i
++) {
8041 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
8042 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
8045 if (!SIGN_EXT_P(env
->CP0_EPC
))
8046 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
8047 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
8048 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
8052 void cpu_dump_state (CPUState
*env
, FILE *f
,
8053 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8058 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",
8059 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
8060 for (i
= 0; i
< 32; i
++) {
8062 cpu_fprintf(f
, "GPR%02d:", i
);
8063 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
8065 cpu_fprintf(f
, "\n");
8068 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
8069 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
8070 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
8071 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
8072 if (env
->hflags
& MIPS_HFLAG_FPU
)
8073 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
8074 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8075 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
8079 static void mips_tcg_init(void)
8083 /* Initialize various static tables. */
8087 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
8088 current_tc_gprs
= tcg_global_mem_new(TCG_TYPE_PTR
,
8090 offsetof(CPUState
, current_tc_gprs
),
8092 current_tc_hi
= tcg_global_mem_new(TCG_TYPE_PTR
,
8094 offsetof(CPUState
, current_tc_hi
),
8096 current_fpu
= tcg_global_mem_new(TCG_TYPE_PTR
,
8098 offsetof(CPUState
, fpu
),
8101 /* register helpers */
8103 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8106 fpu32_T
[0] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft0
.w
[FP_ENDIAN_IDX
]), "WT0");
8107 fpu32_T
[1] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft1
.w
[FP_ENDIAN_IDX
]), "WT1");
8108 fpu32_T
[2] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft2
.w
[FP_ENDIAN_IDX
]), "WT2");
8109 fpu64_T
[0] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
, offsetof(CPUState
, ft0
.d
), "DT0");
8110 fpu64_T
[1] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
, offsetof(CPUState
, ft1
.d
), "DT1");
8111 fpu64_T
[2] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
, offsetof(CPUState
, ft2
.d
), "DT2");
8112 fpu32h_T
[0] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft0
.w
[!FP_ENDIAN_IDX
]), "WTH0");
8113 fpu32h_T
[1] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft1
.w
[!FP_ENDIAN_IDX
]), "WTH1");
8114 fpu32h_T
[2] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft2
.w
[!FP_ENDIAN_IDX
]), "WTH2");
8119 #include "translate_init.c"
8121 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
8124 const mips_def_t
*def
;
8126 def
= cpu_mips_find_by_name(cpu_model
);
8129 env
= qemu_mallocz(sizeof(CPUMIPSState
));
8132 env
->cpu_model
= def
;
8135 env
->cpu_model_str
= cpu_model
;
8141 void cpu_reset (CPUMIPSState
*env
)
8143 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
8148 #if !defined(CONFIG_USER_ONLY)
8149 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
8150 /* If the exception was raised from a delay slot,
8151 * come back to the jump. */
8152 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
8154 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
8156 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
8158 /* SMP not implemented */
8159 env
->CP0_EBase
= 0x80000000;
8160 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8161 /* vectored interrupts not implemented, timer on int 7,
8162 no performance counters. */
8163 env
->CP0_IntCtl
= 0xe0000000;
8167 for (i
= 0; i
< 7; i
++) {
8168 env
->CP0_WatchLo
[i
] = 0;
8169 env
->CP0_WatchHi
[i
] = 0x80000000;
8171 env
->CP0_WatchLo
[7] = 0;
8172 env
->CP0_WatchHi
[7] = 0;
8174 /* Count register increments in debug mode, EJTAG version 1 */
8175 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8177 env
->exception_index
= EXCP_NONE
;
8178 #if defined(CONFIG_USER_ONLY)
8179 env
->hflags
= MIPS_HFLAG_UM
;
8180 env
->user_mode_only
= 1;
8182 env
->hflags
= MIPS_HFLAG_CP0
;
8184 cpu_mips_register(env
, env
->cpu_model
);
8187 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8188 unsigned long searched_pc
, int pc_pos
, void *puc
)
8190 env
->PC
[env
->current_tc
] = gen_opc_pc
[pc_pos
];
8191 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8192 env
->hflags
|= gen_opc_hflags
[pc_pos
];